添加定时器
This commit is contained in:
@@ -28,6 +28,24 @@ MavLinkNode::MavLinkNode(QObject *parent) : QObject(parent)
|
||||
int Current_sysID = 0xFB;
|
||||
int Current_CompID = MAV_COMP_ID_MISSIONPLANNER;
|
||||
|
||||
CommucationOverTimer = 5000;
|
||||
|
||||
|
||||
timer = new QTimer(this);
|
||||
timer->moveToThread(thread);
|
||||
timer->setInterval(CommucationOverTimer);
|
||||
|
||||
connect(thread, SIGNAL(started()), timer, SLOT(start()));
|
||||
connect(timer,SIGNAL(timeout()),
|
||||
this,SLOT(TimerOut,Qt::DirectConnection));
|
||||
|
||||
//timer->start();
|
||||
|
||||
qDebug() << "start timer";
|
||||
|
||||
|
||||
//comm
|
||||
|
||||
replay = new Replay();
|
||||
connect(replay,SIGNAL(readReady()),
|
||||
this,SLOT(readPendingDatagramsReplay()),Qt::DirectConnection);
|
||||
@@ -63,6 +81,7 @@ MavLinkNode::MavLinkNode(QObject *parent) : QObject(parent)
|
||||
connect(Commander,SIGNAL(showMessage(QString,int)),
|
||||
this,SIGNAL(showMessage(QString,int)),Qt::DirectConnection);
|
||||
|
||||
isCommunicationLost = false;
|
||||
|
||||
showMessage(tr("解锁才能有航迹,需要修正,示波器显示时间不对"));
|
||||
}
|
||||
@@ -117,6 +136,13 @@ MavLinkNode::~MavLinkNode()
|
||||
}
|
||||
}
|
||||
|
||||
if(timer)
|
||||
{
|
||||
timer->stop();
|
||||
delete timer;
|
||||
}
|
||||
|
||||
|
||||
if(thread->isRunning())
|
||||
{
|
||||
thread->quit();
|
||||
@@ -160,6 +186,8 @@ void MavLinkNode::start()
|
||||
qDebug() << "MavLinkNode thread start" << running_flag;
|
||||
|
||||
|
||||
|
||||
|
||||
if(replay)
|
||||
{
|
||||
replay->start();
|
||||
@@ -210,6 +238,8 @@ void MavLinkNode::stop()
|
||||
//这里一直在解码,一直检查双缓冲里面是否有数据,有就解码,没有就休息
|
||||
void MavLinkNode::process()//线程函数
|
||||
{
|
||||
|
||||
|
||||
uint8_t count = 0;
|
||||
QByteArray datagram = nullptr;
|
||||
while (running_flag)
|
||||
@@ -244,6 +274,13 @@ void MavLinkNode::process()//线程函数
|
||||
thread->wait();
|
||||
}
|
||||
|
||||
void MavLinkNode::TimerOut(void)
|
||||
{
|
||||
isCommunicationLost = true;
|
||||
qDebug() << "timeout" << "communication lost";
|
||||
}
|
||||
|
||||
|
||||
void MavLinkNode::initbuff(void)
|
||||
{
|
||||
client_buff.max_size = 10 * 1024 *1024;//10M
|
||||
@@ -358,6 +395,10 @@ void MavLinkNode::Mavlinkparse(quint32 src,QByteArray datagram)
|
||||
count++;
|
||||
if(msg.sysid < 250) //过滤地面站发过来的数据
|
||||
{
|
||||
//timer->start();
|
||||
isCommunicationLost = true;
|
||||
|
||||
|
||||
MAVLinkRcv_Handler(msg); //接收完一帧数据并处理
|
||||
emit recievemsg(msg); //将信息广播出去
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user