b
This commit is contained in:
@@ -3,16 +3,18 @@
|
||||
ThreadTemplet::ThreadTemplet(QObject *parent) : QObject(parent)
|
||||
{
|
||||
running_flag = false;
|
||||
thread = new QThread();
|
||||
this->moveToThread(thread);
|
||||
connect(thread, &QThread::started, this, &ThreadTemplet::process);
|
||||
setRunFrq(50);//default frq = 50
|
||||
moveToThread(this);
|
||||
//connect(this, &ThreadTemplet::started, this, &ThreadTemplet::process);
|
||||
//setRunFrq(50);//default frq = 50
|
||||
|
||||
start();
|
||||
|
||||
}
|
||||
|
||||
ThreadTemplet::~ThreadTemplet()
|
||||
{
|
||||
stop();
|
||||
quit();
|
||||
wait();
|
||||
}
|
||||
|
||||
void ThreadTemplet::setRunFrq(uint32_t frq)
|
||||
@@ -24,45 +26,6 @@ void ThreadTemplet::setRunFrq(uint32_t frq)
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadTemplet::start()
|
||||
{
|
||||
if(!thread->isRunning())
|
||||
{
|
||||
running_flag = true;
|
||||
thread->start();
|
||||
qDebug() << "thread start" << running_flag;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "thread has started";
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadTemplet::stop()
|
||||
{
|
||||
if(thread)
|
||||
{
|
||||
if(!thread->isFinished())
|
||||
{
|
||||
running_flag = false;
|
||||
|
||||
disconnect(thread, nullptr, nullptr, nullptr);
|
||||
|
||||
|
||||
thread->quit();
|
||||
thread->deleteLater();
|
||||
|
||||
thread = nullptr;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "thread is not running";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ThreadTemplet::process()//线程函数
|
||||
{
|
||||
@@ -75,7 +38,11 @@ void ThreadTemplet::process()//线程函数
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ThreadTemplet::run(void)
|
||||
{
|
||||
|
||||
exec();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
#ifdef QtMavlinkNode
|
||||
#include <mavlinknodeglobal.h>
|
||||
class MAVLINKNODESHARED_EXPORT ThreadTemplet : public QObject {
|
||||
class MAVLINKNODESHARED_EXPORT ThreadTemplet : public QThread {
|
||||
#else
|
||||
class ThreadTemplet : public QObject
|
||||
class ThreadTemplet : public QThread
|
||||
{
|
||||
#endif
|
||||
Q_OBJECT
|
||||
@@ -38,6 +38,7 @@ public slots:
|
||||
virtual void setRunFrq(uint32_t frq);
|
||||
virtual void start();
|
||||
virtual void stop();
|
||||
virtual void run();
|
||||
virtual bool isActive(void)
|
||||
{
|
||||
return running_flag;
|
||||
|
||||
@@ -132,8 +132,12 @@ MavLinkNode::MavLinkNode(QObject *parent) : QObject(parent)
|
||||
|
||||
RC = new rcprocess();
|
||||
RC->setGCSID(Current_sysID,Current_CompID);
|
||||
connect(RC,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
/* connect(RC,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),
|
||||
this,SIGNAL(SendMessageTo(quint8,quint8*,quint16)),Qt::DirectConnection);
|
||||
*/
|
||||
|
||||
connect(RC,&rcprocess::SendMessageTo,
|
||||
this,&MavLinkNode::SendMessageTo);
|
||||
|
||||
|
||||
connect(this,SIGNAL(setCurrentID(int,int)),
|
||||
@@ -325,6 +329,8 @@ void MavLinkNode::start()
|
||||
{
|
||||
qDebug() << "MavLinkNode thread has started";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "rcprocess.h"
|
||||
|
||||
|
||||
rcprocess::rcprocess(QObject *parent) : QObject(parent)
|
||||
{
|
||||
//初始化ID
|
||||
@@ -98,6 +99,7 @@ void rcprocess::stop()
|
||||
|
||||
|
||||
thread->quit();
|
||||
thread->wait();
|
||||
thread->deleteLater();
|
||||
|
||||
thread = nullptr;
|
||||
@@ -107,12 +109,7 @@ void rcprocess::stop()
|
||||
{
|
||||
qDebug() << "thread is not running";
|
||||
}
|
||||
|
||||
qDebug() << "thread ";
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//这里一直在解码,一直检查双缓冲里面是否有数据,有就解码,没有就休息
|
||||
|
||||
@@ -12,6 +12,7 @@ rtkprocess::rtkprocess(QObject *parent) : ThreadTemplet(parent)
|
||||
rtkprocess::~rtkprocess()
|
||||
{
|
||||
stop();
|
||||
|
||||
}
|
||||
|
||||
void rtkprocess::setID(int m_sysid,int m_compid)
|
||||
|
||||
Reference in New Issue
Block a user