repay
This commit is contained in:
+69
-10
@@ -16,6 +16,7 @@ DLink::DLink(QObject *parent) : QObject(parent)
|
||||
}
|
||||
|
||||
|
||||
|
||||
connect(this,SIGNAL(recieveMessage(quint32,QByteArray)),
|
||||
this,SLOT(record(quint32,QByteArray)));
|
||||
|
||||
@@ -41,12 +42,15 @@ DLink::DLink(QObject *parent) : QObject(parent)
|
||||
mavlinknode->start();
|
||||
//其他协议节点。。。
|
||||
|
||||
|
||||
|
||||
replay("./Tlog/20200818210716.tlog");
|
||||
|
||||
|
||||
}
|
||||
DLink::~DLink()
|
||||
{
|
||||
stopPort();
|
||||
|
||||
|
||||
//查询所有的接口,然后删除
|
||||
if (mavLogFile)
|
||||
{
|
||||
@@ -63,12 +67,14 @@ DLink::~DLink()
|
||||
int DLink::SendMessageTo(quint8 ch, quint8 *msg, quint16 len)
|
||||
{
|
||||
//让这个函数在其他线程运行
|
||||
/*
|
||||
QString num;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
num.append(QString::number(msg[i],16).toUpper());
|
||||
num.append(" ");
|
||||
}
|
||||
qDebug() << num;
|
||||
*/
|
||||
//Q_UNUSED(ch);
|
||||
|
||||
//更加ch选择
|
||||
@@ -294,6 +300,8 @@ bool DLink::setupClient(const QHostAddress &local_addr,int local_port,const QHos
|
||||
}
|
||||
else
|
||||
{
|
||||
Clientsock->leaveMulticastGroup(remote_addr);
|
||||
Clientsock->close();
|
||||
isSuccess = false;
|
||||
qWarning() << "sock not open";
|
||||
}
|
||||
@@ -301,6 +309,8 @@ bool DLink::setupClient(const QHostAddress &local_addr,int local_port,const QHos
|
||||
else
|
||||
{
|
||||
isSuccess = false;
|
||||
Clientsock->leaveMulticastGroup(remote_addr);
|
||||
Clientsock->close();
|
||||
qWarning("sock is not binded.");
|
||||
delete Clientsock;
|
||||
}
|
||||
@@ -311,9 +321,11 @@ bool DLink::setupClient(const QHostAddress &local_addr,int local_port,const QHos
|
||||
|
||||
void DLink::readPendingDatagramsSerialPort(void)
|
||||
{
|
||||
QByteArray datagram = serialPort->readAll();
|
||||
|
||||
emit recieveMessage(SourceType::s_port,datagram);
|
||||
if(serialPort)
|
||||
{
|
||||
QByteArray datagram = serialPort->readAll();
|
||||
emit recieveMessage(SourceType::s_port,datagram);
|
||||
}
|
||||
}
|
||||
|
||||
void DLink::readPendingDatagramsClient(void)
|
||||
@@ -328,22 +340,69 @@ void DLink::readPendingDatagramsClient(void)
|
||||
}
|
||||
}
|
||||
|
||||
void DLink::readPendingDatagramsReplay(void)
|
||||
{
|
||||
|
||||
if(play)
|
||||
{
|
||||
QByteArray datagram = play->readAll();
|
||||
emit recieveMessage(SourceType::c_sock,datagram);
|
||||
//qDebug() << "play" << datagram;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if(play)
|
||||
{
|
||||
QByteArray datagram = play->readAll();
|
||||
|
||||
if(serialPort)
|
||||
{
|
||||
serialPort->write(datagram);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DLink::record(quint32 src,QByteArray data)
|
||||
{
|
||||
Q_UNUSED(src)
|
||||
|
||||
//加时间撮
|
||||
|
||||
if (mavLogFile)
|
||||
{
|
||||
char buff[sizeof(quint64)];
|
||||
|
||||
quint64 currentTimestamp = ((quint64)QDateTime::currentMSecsSinceEpoch()) * 1000;
|
||||
qToBigEndian(currentTimestamp, buff);
|
||||
|
||||
data.append(buff);
|
||||
|
||||
//使用数据流的方式可能更好
|
||||
mavLogFile->write((const char *)data, sizeof(data));
|
||||
mavLogFile->write((const char *)data,data.size());
|
||||
//qDebug() << data;
|
||||
}
|
||||
}
|
||||
|
||||
void DLink::replay(quint32 src,QByteArray data)
|
||||
void DLink::replay(QString file)
|
||||
{
|
||||
//定时器回放
|
||||
//得到文件的路
|
||||
if(!play)
|
||||
{
|
||||
play = new Replay();
|
||||
|
||||
connect(play,&Replay::readReady,
|
||||
this,&DLink::readPendingDatagramsReplay);
|
||||
}
|
||||
|
||||
play->setLogfile(file);
|
||||
//使用多线程进行读取数据
|
||||
play->start();//开始线程
|
||||
|
||||
/*QThread::sleep(100);
|
||||
play->stop();
|
||||
QThread::sleep(100);
|
||||
play->start();*/
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user