添加航点的线程
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
#include "missionprocess.h"
|
||||
|
||||
MissionProcess::MissionProcess(QObject *parent) : QObject(parent)
|
||||
{
|
||||
//mission thread
|
||||
/*
|
||||
Missionthread = new QThread();
|
||||
this->moveToThread(Missionthread);
|
||||
connect(Missionthread, &QThread::started, this, &MavLinkNode::process);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void MissionProcess::setRunFrq(uint32_t frq)
|
||||
{
|
||||
if((frq != 0)||(frq <= 1000))
|
||||
{
|
||||
running_frq = frq;
|
||||
qDebug() << "set mission thread running frquency:" <<frq <<"Hz";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MissionProcess::start()
|
||||
{
|
||||
if(Missionthread == nullptr)
|
||||
{
|
||||
Missionthread = new QThread();
|
||||
this->moveToThread(Missionthread);
|
||||
connect(Missionthread, &QThread::started, this, &MissionProcess::process);
|
||||
}
|
||||
|
||||
if(!Missionthread->isRunning())
|
||||
{
|
||||
running_flag = true;
|
||||
Missionthread->start();
|
||||
qDebug() << "thread start" << running_flag;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "thread has started";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MissionProcess::stop()
|
||||
{
|
||||
if(Missionthread->isRunning())
|
||||
{
|
||||
running_flag = false;
|
||||
qDebug() << "thread stop" << running_flag;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "thread is not running";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//这里一直传输和接收航线信息
|
||||
void MissionProcess::process()//线程函数
|
||||
{
|
||||
uint8_t count = 0;
|
||||
while (running_flag)
|
||||
{
|
||||
count ++;
|
||||
QThread::msleep(1000/running_frq);
|
||||
|
||||
|
||||
}
|
||||
//退出线程
|
||||
Missionthread->quit();
|
||||
Missionthread->deleteLater();
|
||||
Missionthread = nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user