线程修正
This commit is contained in:
@@ -12,7 +12,6 @@ terminal::terminal(QObject *parent) : ThreadTemplet(parent)
|
|||||||
terminal::~terminal()
|
terminal::~terminal()
|
||||||
{
|
{
|
||||||
qDebug() << "stop terminal" << QThread::currentThreadId();
|
qDebug() << "stop terminal" << QThread::currentThreadId();
|
||||||
//stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void terminal::process()//线程函数
|
void terminal::process()//线程函数
|
||||||
@@ -26,7 +25,7 @@ void terminal::process()//线程函数
|
|||||||
switch(status.m_Mode)
|
switch(status.m_Mode)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
case Nop_Mode : break;
|
case Nop_Mode : QThread::yieldCurrentThread();break;
|
||||||
case RecieveMode : ReadStateMachine();break;
|
case RecieveMode : ReadStateMachine();break;
|
||||||
case TransmitMode : WriteStateMachine();break;
|
case TransmitMode : WriteStateMachine();break;
|
||||||
}
|
}
|
||||||
@@ -35,7 +34,6 @@ void terminal::process()//线程函数
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
QThread::yieldCurrentThread();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,8 @@ ThreadTemplet::ThreadTemplet(QObject *parent) : QObject(parent)
|
|||||||
thread = new QThread();
|
thread = new QThread();
|
||||||
this->moveToThread(thread);
|
this->moveToThread(thread);
|
||||||
connect(thread, &QThread::started, this, &ThreadTemplet::process);
|
connect(thread, &QThread::started, this, &ThreadTemplet::process);
|
||||||
//connect(thread, &QThread::finished, this, &ThreadTemplet::deleteLater);
|
|
||||||
|
|
||||||
|
|
||||||
setRunFrq(1);//1hz
|
|
||||||
initbuff();
|
initbuff();
|
||||||
|
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +21,7 @@ ThreadTemplet::~ThreadTemplet()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadTemplet::setRunFrq(uint32_t frq)
|
void ThreadTemplet::setRunFrq(qreal frq)
|
||||||
{
|
{
|
||||||
if((frq != 0)||(frq <= 1000))
|
if((frq != 0)||(frq <= 1000))
|
||||||
{
|
{
|
||||||
@@ -80,13 +76,13 @@ void ThreadTemplet::process()//线程函数
|
|||||||
{
|
{
|
||||||
QThread::msleep(1000/frq());
|
QThread::msleep(1000/frq());
|
||||||
|
|
||||||
qDebug() << QThread::idealThreadCount();
|
//qDebug() << QThread::idealThreadCount();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
do something
|
do something
|
||||||
*/
|
*/
|
||||||
|
|
||||||
emit showMessage(tr("软件没有正常启动,请重启"));
|
emit error(tr("thread run base"));
|
||||||
|
|
||||||
|
|
||||||
if(isInterruptionRequested())//退出
|
if(isInterruptionRequested())//退出
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include <mavlinknodeglobal.h>
|
#include <mavlinknodeglobal.h>
|
||||||
class MAVLINKNODESHARED_EXPORT ThreadTemplet : public QObject {
|
class MAVLINKNODESHARED_EXPORT ThreadTemplet : public QObject {
|
||||||
#else
|
#else
|
||||||
class ThreadTemplet : public QThread
|
class ThreadTemplet : public QObject
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -25,6 +25,8 @@ public:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
void error(QVariant type);
|
||||||
|
|
||||||
void SendMessageTo(quint8 ch, quint8 *data,quint16 len);
|
void SendMessageTo(quint8 ch, quint8 *data,quint16 len);
|
||||||
|
|
||||||
void showMessage(const QString &message,int TimeOut = 0);
|
void showMessage(const QString &message,int TimeOut = 0);
|
||||||
@@ -35,7 +37,7 @@ public slots:
|
|||||||
void setID(int m_sysid,int m_compid);
|
void setID(int m_sysid,int m_compid);
|
||||||
|
|
||||||
//线程对外接口
|
//线程对外接口
|
||||||
void setRunFrq(uint32_t frq);
|
void setRunFrq(qreal frq);
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
bool isActive(void)
|
bool isActive(void)
|
||||||
@@ -108,7 +110,7 @@ protected:
|
|||||||
_status_ status;
|
_status_ status;
|
||||||
|
|
||||||
bool running_flag = false;
|
bool running_flag = false;
|
||||||
float running_frq = 10;//10Hz
|
qreal running_frq = 0.01;//1Hz
|
||||||
|
|
||||||
QThread *thread = nullptr;
|
QThread *thread = nullptr;
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ commandprocess::commandprocess(QObject *parent) : ThreadTemplet(parent)
|
|||||||
commandprocess::~commandprocess()
|
commandprocess::~commandprocess()
|
||||||
{
|
{
|
||||||
qDebug() << "stop commmand" << QThread::currentThreadId();
|
qDebug() << "stop commmand" << QThread::currentThreadId();
|
||||||
//stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void commandprocess::process()//线程函数
|
void commandprocess::process()//线程函数
|
||||||
@@ -41,9 +40,6 @@ void commandprocess::process()//线程函数
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
QThread::yieldCurrentThread();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -241,7 +241,6 @@ MavLinkNode::~MavLinkNode()
|
|||||||
rtk = nullptr;
|
rtk = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//stop();
|
|
||||||
qDebug() << "stop mavlink" << QThread::currentThreadId();
|
qDebug() << "stop mavlink" << QThread::currentThreadId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,7 +708,7 @@ void MavLinkNode::Mavlinkparse(quint32 src,QByteArray datagram)
|
|||||||
case MAVLINK_PARSE_STATE_GOT_BAD_CRC1:{
|
case MAVLINK_PARSE_STATE_GOT_BAD_CRC1:{
|
||||||
parserFailure += 1;
|
parserFailure += 1;
|
||||||
qDebug() << "MAVLINK_PARSE_STATE_GOT_BAD_CRC1";
|
qDebug() << "MAVLINK_PARSE_STATE_GOT_BAD_CRC1";
|
||||||
emit showMessage("mavlink parse CRC error");
|
emit showMessage("mavlink got bad crc1");
|
||||||
}break;
|
}break;
|
||||||
case MAVLINK_PARSE_STATE_SIGNATURE_WAIT:{
|
case MAVLINK_PARSE_STATE_SIGNATURE_WAIT:{
|
||||||
qDebug() << "MAVLINK_PARSE_STATE_SIGNATURE_WAIT";
|
qDebug() << "MAVLINK_PARSE_STATE_SIGNATURE_WAIT";
|
||||||
@@ -802,7 +801,6 @@ void MavLinkNode::StatusParse(mavlink_message_t msg)
|
|||||||
}break;
|
}break;
|
||||||
case MAVLINK_MSG_ID_HEARTBEAT: {
|
case MAVLINK_MSG_ID_HEARTBEAT: {
|
||||||
mavlink_msg_heartbeat_decode(&msg,&vehicle.heartbeat);
|
mavlink_msg_heartbeat_decode(&msg,&vehicle.heartbeat);
|
||||||
//qDebug() << "recieve heartbeat";
|
|
||||||
|
|
||||||
Status->m_heartbeat.autopilot = vehicle.heartbeat.autopilot;
|
Status->m_heartbeat.autopilot = vehicle.heartbeat.autopilot;
|
||||||
Status->m_heartbeat.base_mode = vehicle.heartbeat.base_mode;
|
Status->m_heartbeat.base_mode = vehicle.heartbeat.base_mode;
|
||||||
@@ -1187,65 +1185,3 @@ void MavLinkNode::setLogfile(QString file)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
void MavLinkNode::saveExcel(QString filepath)
|
|
||||||
{
|
|
||||||
//QString filepath = QFileDialog::getSaveFileName(this,tr("Save orbit"),".",tr("Microsoft Office 2007 (*.xlsx)"));//获取保存路径
|
|
||||||
if(!filepath.isEmpty()){
|
|
||||||
QAxObject *excel = new QAxObject(this);
|
|
||||||
excel->setControl("Excel.Application");//连接Excel控件
|
|
||||||
excel->dynamicCall("SetVisible (bool Visible)","false");//不显示窗体
|
|
||||||
excel->setProperty("DisplayAlerts", false);//不显示任何警告信息。如果为true那么在关闭是会出现类似“文件已修改,是否保存”的提示
|
|
||||||
|
|
||||||
QAxObject *workbooks = excel->querySubObject("WorkBooks");//获取工作簿集合
|
|
||||||
workbooks->dynamicCall("Add");//新建一个工作簿
|
|
||||||
QAxObject *workbook = excel->querySubObject("ActiveWorkBook");//获取当前工作簿
|
|
||||||
QAxObject *worksheets = workbook->querySubObject("Sheets");//获取工作表集合
|
|
||||||
QAxObject *worksheet = worksheets->querySubObject("Item(int)",1);//获取工作表集合的工作表1,即sheet1
|
|
||||||
|
|
||||||
QAxObject *cellA,*cellB,*cellC,*cellD;
|
|
||||||
|
|
||||||
//设置标题
|
|
||||||
int cellrow=1;
|
|
||||||
QString A="A"+QString::number(cellrow);//设置要操作的单元格,如A1
|
|
||||||
QString B="B"+QString::number(cellrow);
|
|
||||||
QString C="C"+QString::number(cellrow);
|
|
||||||
QString D="D"+QString::number(cellrow);
|
|
||||||
cellA = worksheet->querySubObject("Range(QVariant, QVariant)",A);//获取单元格
|
|
||||||
cellB = worksheet->querySubObject("Range(QVariant, QVariant)",B);
|
|
||||||
cellC = worksheet->querySubObject("Range(QVariant, QVariant)",C);
|
|
||||||
cellD = worksheet->querySubObject("Range(QVariant, QVariant)",D);
|
|
||||||
cellA->dynamicCall("SetValue(const QVariant&)",QVariant("流水号"));//设置单元格的值
|
|
||||||
cellB->dynamicCall("SetValue(const QVariant&)",QVariant("用户名"));
|
|
||||||
cellC->dynamicCall("SetValue(const QVariant&)",QVariant("金额"));
|
|
||||||
cellD->dynamicCall("SetValue(const QVariant&)",QVariant("日期"));
|
|
||||||
cellrow++;
|
|
||||||
|
|
||||||
int rows=this->model->rowCount();
|
|
||||||
for(int i=0;i<rows;i++){
|
|
||||||
QString A="A"+QString::number(cellrow);//设置要操作的单元格,如A1
|
|
||||||
QString B="B"+QString::number(cellrow);
|
|
||||||
QString C="C"+QString::number(cellrow);
|
|
||||||
QString D="D"+QString::number(cellrow);
|
|
||||||
cellA = worksheet->querySubObject("Range(QVariant, QVariant)",A);//获取单元格
|
|
||||||
cellB = worksheet->querySubObject("Range(QVariant, QVariant)",B);
|
|
||||||
cellC=worksheet->querySubObject("Range(QVariant, QVariant)",C);
|
|
||||||
cellD=worksheet->querySubObject("Range(QVariant, QVariant)",D);
|
|
||||||
cellA->dynamicCall("SetValue(const QVariant&)",QVariant(this->model->item(i,0)->data(Qt::DisplayRole).toString()));//设置单元格的值
|
|
||||||
cellB->dynamicCall("SetValue(const QVariant&)",QVariant(this->model->item(i,1)->data(Qt::DisplayRole).toString()));
|
|
||||||
cellC->dynamicCall("SetValue(const QVariant&)",QVariant(this->model->item(i,2)->data(Qt::DisplayRole).toString()));
|
|
||||||
cellD->dynamicCall("SetValue(const QVariant&)",QVariant(this->model->item(i,3)->data(Qt::DisplayRole).toString()));
|
|
||||||
cellrow++;
|
|
||||||
}
|
|
||||||
|
|
||||||
workbook->dynamicCall("SaveAs(const QString&)",QDir::toNativeSeparators(filepath));//保存至filepath,注意一定要用QDir::toNativeSeparators将路径中的"/"转换为"\",不然一定保存不了。
|
|
||||||
workbook->dynamicCall("Close()");//关闭工作簿
|
|
||||||
excel->dynamicCall("Quit()");//关闭excel
|
|
||||||
delete excel;
|
|
||||||
excel=nullptr;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
MissionProcess::MissionProcess(QObject *parent) : ThreadTemplet(parent)
|
MissionProcess::MissionProcess(QObject *parent) : ThreadTemplet(parent)
|
||||||
{
|
{
|
||||||
setRunFrq(20);//默认50Hz频率运行
|
setRunFrq(20);//默认20Hz频率运行
|
||||||
|
|
||||||
mission_status.m_Mode = Nop_Mode;
|
mission_status.m_Mode = Nop_Mode;
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,6 @@ MissionProcess::MissionProcess(QObject *parent) : ThreadTemplet(parent)
|
|||||||
MissionProcess::~MissionProcess()
|
MissionProcess::~MissionProcess()
|
||||||
{
|
{
|
||||||
qDebug() << "stop mission" << QThread::currentThreadId();
|
qDebug() << "stop mission" << QThread::currentThreadId();
|
||||||
//stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MissionProcess::process()//线程函数
|
void MissionProcess::process()//线程函数
|
||||||
@@ -46,8 +45,6 @@ void MissionProcess::process()//线程函数
|
|||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
QThread::yieldCurrentThread();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -175,23 +175,8 @@ private:
|
|||||||
QList<mapcontrol::WayPointItem *> wplist;
|
QList<mapcontrol::WayPointItem *> wplist;
|
||||||
|
|
||||||
|
|
||||||
//bool isReadMission = false;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//bool isWriteMission = false;
|
|
||||||
|
|
||||||
|
|
||||||
QMap<int,mapcontrol::WayPointItem::_property> items;
|
QMap<int,mapcontrol::WayPointItem::_property> items;
|
||||||
|
|
||||||
//bool ismTimerTimeOut = false;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // MISSIONPROCESS_H
|
#endif // MISSIONPROCESS_H
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ ParameterProcess::ParameterProcess(QObject *parent) : ThreadTemplet(parent)
|
|||||||
ParameterProcess::~ParameterProcess()
|
ParameterProcess::~ParameterProcess()
|
||||||
{
|
{
|
||||||
qDebug() << "stop parameter" << QThread::currentThreadId();
|
qDebug() << "stop parameter" << QThread::currentThreadId();
|
||||||
//stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParameterProcess::process()//线程函数
|
void ParameterProcess::process()//线程函数
|
||||||
|
|||||||
@@ -107,9 +107,6 @@ private slots:
|
|||||||
void request_read(const char *id, int16_t index);
|
void request_read(const char *id, int16_t index);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void readError();
|
|
||||||
|
|
||||||
|
|
||||||
void RecieveValue(mavlink_message_t msg);
|
void RecieveValue(mavlink_message_t msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ rcprocess::rcprocess(QObject *parent) : ThreadTemplet(parent)
|
|||||||
rcprocess::~rcprocess()
|
rcprocess::~rcprocess()
|
||||||
{
|
{
|
||||||
qDebug() << "stop rc" << QThread::currentThreadId();
|
qDebug() << "stop rc" << QThread::currentThreadId();
|
||||||
//stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//这里一直在解码,一直检查双缓冲里面是否有数据,有就解码,没有就休息
|
//这里一直在解码,一直检查双缓冲里面是否有数据,有就解码,没有就休息
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ Replay::Replay(QObject *parent) : ThreadTemplet(parent)
|
|||||||
Replay::~Replay()
|
Replay::~Replay()
|
||||||
{
|
{
|
||||||
qDebug() << "stop replay" << QThread::currentThreadId();
|
qDebug() << "stop replay" << QThread::currentThreadId();
|
||||||
//stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Replay::process()//线程函数
|
void Replay::process()//线程函数
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ rtkprocess::rtkprocess(QObject *parent) : ThreadTemplet(parent)
|
|||||||
rtkprocess::~rtkprocess()
|
rtkprocess::~rtkprocess()
|
||||||
{
|
{
|
||||||
qDebug() << "stop rtk" << QThread::currentThreadId();
|
qDebug() << "stop rtk" << QThread::currentThreadId();
|
||||||
//stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rtkprocess::process()//线程函数
|
void rtkprocess::process()//线程函数
|
||||||
@@ -41,7 +40,6 @@ void rtkprocess::process()//线程函数
|
|||||||
|
|
||||||
if(isInterruptionRequested())//退出
|
if(isInterruptionRequested())//退出
|
||||||
{
|
{
|
||||||
qDebug() << "want to exit";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
QThread::yieldCurrentThread();
|
QThread::yieldCurrentThread();
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ statusprocess::statusprocess(QObject *parent) : ThreadTemplet(parent)
|
|||||||
statusprocess::~statusprocess()
|
statusprocess::~statusprocess()
|
||||||
{
|
{
|
||||||
qDebug() << "stop status" << QThread::currentThreadId();
|
qDebug() << "stop status" << QThread::currentThreadId();
|
||||||
//stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -40,13 +39,11 @@ void statusprocess::process()//线程函数
|
|||||||
m_heartbeat.mavlink_version);
|
m_heartbeat.mavlink_version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//qDebug() << "yunxing" << (quint64)QDateTime::currentMSecsSinceEpoch() << frq() << status.m_Mode;
|
|
||||||
|
|
||||||
if(isInterruptionRequested())//退出
|
if(isInterruptionRequested())//退出
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
QThread::yieldCurrentThread();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user