Files
gcs-nf/Plugins/MavLinkNode/inc/ThreadTemplet.h
T

150 lines
2.6 KiB
C++
Raw Normal View History

2021-04-29 09:54:21 +08:00
#ifndef THREADTEMPLET_H
#define THREADTEMPLET_H
#include <QObject>
#include "QThread"
#include "QFile"
#include "QDebug"
2021-07-07 18:30:41 +08:00
#include "mavlink.h"
2022-12-26 14:46:04 +08:00
#include "QtEndian"
#include "QDataStream"
#include "QFile"
#include "QDateTime"
#include "ParsePack.h"
#include "QMutex"
2021-04-29 09:54:21 +08:00
#ifdef QtMavlinkNode
#include <mavlinknodeglobal.h>
2021-07-07 18:30:41 +08:00
class MAVLINKNODESHARED_EXPORT ThreadTemplet : public QObject {
2021-04-29 09:54:21 +08:00
#else
2021-07-09 13:28:13 +08:00
class ThreadTemplet : public QObject
2021-04-29 09:54:21 +08:00
{
#endif
Q_OBJECT
public:
explicit ThreadTemplet(QObject *parent = nullptr);
~ThreadTemplet();
signals:
2021-07-09 17:17:01 +08:00
Q_INVOKABLE void error(QVariant type);
2021-07-09 13:28:13 +08:00
2021-07-09 17:17:01 +08:00
Q_INVOKABLE void SendMessageTo(quint8 ch, quint8 *data,quint16 len);
2021-07-07 18:30:41 +08:00
2021-07-09 17:17:01 +08:00
Q_INVOKABLE void showMessage(const QString &message,int TimeOut = 0);
2021-04-29 09:54:21 +08:00
public slots:
//地面站对外接口
void setGCSID(int m_sysid, int m_compid);
void setID(int m_sysid,int m_compid);
2021-07-07 18:30:41 +08:00
2021-07-09 17:17:01 +08:00
//线程对外接口
2021-07-09 13:28:13 +08:00
void setRunFrq(qreal frq);
2021-07-07 18:30:41 +08:00
void start();
void stop();
bool isActive(void)
2021-04-29 09:54:21 +08:00
{
return running_flag;
}
2021-07-07 18:30:41 +08:00
bool isInterruptionRequested(void)
{
return QThread::currentThread()->isInterruptionRequested();
2021-04-29 09:54:21 +08:00
}
float frq(void)
2021-07-07 18:30:41 +08:00
{
return running_frq;
}
2021-04-29 09:54:21 +08:00
2022-12-26 14:46:04 +08:00
void setPlogName(QString name)
{
plogFileName = name;
}
2021-04-29 09:54:21 +08:00
//缓存对外接口
2021-07-09 17:17:01 +08:00
Q_INVOKABLE void setbuff(quint32 src,QByteArray data);
2021-07-07 18:30:41 +08:00
void initbuff(void);
QByteArray readbuff(quint32 src);
2021-07-07 18:30:41 +08:00
void Send(mavlink_message_t msg);
2021-04-29 09:54:21 +08:00
2022-12-26 14:46:04 +08:00
bool setLogData(QString name, uint8_t type, mavlink_message_t msg);
2021-04-29 09:54:21 +08:00
private slots:
//线程私有接口
2021-07-07 18:30:41 +08:00
virtual void process();
2021-04-29 09:54:21 +08:00
//缓存私有接口
//解析
protected:
typedef struct {
qint32 max_size;
quint8 select;
QByteArray buff[2];
}_buffdef;
enum SourceType{
c_sock = 0,
s_port = 1
};
enum _modetype {
Nop_Mode = 0,
RecieveMode,
TransmitMode
};
typedef struct {
bool isWaitingforValue;
}_recieve;
typedef struct {
bool isWaitingforACK;
uint8_t type;
}_transmit;
typedef struct
{
_recieve recieve;
_transmit transmit;
_modetype m_Mode;
}_status_;
_status_ status;
2021-04-29 09:54:21 +08:00
bool running_flag = false;
2021-07-09 13:28:13 +08:00
qreal running_frq = 0.01;//1Hz
2021-07-07 18:30:41 +08:00
QThread *thread = nullptr;
_buffdef serial_buff;
_buffdef client_buff;
int GCS_SysID = 0xF1;
int GCS_CompID = MAV_COMP_ID_MISSIONPLANNER;
//目标id
uint8_t sysid;
uint8_t compid;
2021-04-29 09:54:21 +08:00
2022-12-26 14:46:04 +08:00
Parser2_t parser;
Packer2_t packer;
QString plogFileName;
QMutex mutex;
2021-04-29 09:54:21 +08:00
};
#endif // THREADTEMPLET_H