164 lines
3.4 KiB
C++
164 lines
3.4 KiB
C++
#ifndef PARAMETERPROCESS_H
|
||
#define PARAMETERPROCESS_H
|
||
|
||
#include <QObject>
|
||
|
||
#include "QDebug"
|
||
#include "QThread"
|
||
#include "mavlink.h"
|
||
#include "QTimer"
|
||
#include "QTime"
|
||
|
||
//#include "ParameterInspector/ParameterInspector.h"
|
||
|
||
#ifdef QtMavlinkNode
|
||
#include <mavlinknodeglobal.h>
|
||
class MAVLINKNODESHARED_EXPORT ParameterProcess : public QObject{
|
||
#else
|
||
class ParameterProcess : public QObject
|
||
{
|
||
#endif
|
||
Q_OBJECT
|
||
|
||
|
||
enum _modetype {
|
||
Nop_Mode = 0,
|
||
RecieveMode,
|
||
TransmitMode
|
||
};
|
||
|
||
enum _readtype {
|
||
All = 0,
|
||
One = 1
|
||
};
|
||
|
||
|
||
typedef struct {
|
||
//bool isWaitingforCount;
|
||
bool isWaitingforValue;
|
||
|
||
_readtype type;
|
||
|
||
}_recieve;
|
||
|
||
typedef struct {
|
||
uint32_t count;
|
||
//bool isWaiteforRequest;
|
||
bool isWaitingforValue;
|
||
}_transmit;
|
||
|
||
typedef struct
|
||
{
|
||
_recieve recieve;
|
||
_transmit transmit;
|
||
|
||
|
||
_modetype m_Mode;
|
||
|
||
}_parameter_;
|
||
|
||
|
||
public:
|
||
explicit ParameterProcess(QObject *parent = nullptr);
|
||
|
||
_parameter_ status;
|
||
|
||
|
||
void setGCSID(int m_sysid, int m_compid)
|
||
{
|
||
Current_sysID = m_sysid;
|
||
Current_CompID = m_compid;
|
||
}
|
||
// ParameterInspector *paramInspect;
|
||
|
||
|
||
|
||
public slots:
|
||
|
||
void setID(int m_sysid, int m_compid);
|
||
|
||
//读取和写入指令
|
||
void ReadCmd(uint8_t m_sysid, uint8_t m_compid, uint8_t type);
|
||
void WriteCmd(uint8_t m_sysid, uint8_t m_compid , const char *id, uint8_t type, float value);
|
||
|
||
|
||
|
||
//线程对外接口
|
||
void setRunFrq(uint32_t frq);
|
||
void start();
|
||
void stop();
|
||
bool isActive(void)
|
||
{
|
||
return running_flag;
|
||
}
|
||
|
||
void Parse(mavlink_message_t msg);
|
||
|
||
private slots:
|
||
//线程私有接口
|
||
void SendMessage(mavlink_message_t msg);
|
||
|
||
void process();
|
||
|
||
//状态机
|
||
void ReadStateMachine(void);
|
||
void WriteStateMachine(void);
|
||
|
||
|
||
//所有的相关函数
|
||
void set(const char *id, uint8_t type, float value);
|
||
void value(float value);
|
||
void ext_ack(float value);
|
||
void ext_set(const char *id, uint8_t type, float value);
|
||
void ext_value(float value);
|
||
void request_list(void);
|
||
void request_read(const char *id, int16_t index);
|
||
|
||
signals:
|
||
void showMessage(const QString &message,int TimeOut = 0);
|
||
|
||
void readError();
|
||
|
||
void SendMessageTo(quint8 ch, quint8 *data,quint16 len);
|
||
|
||
void RecieveValue(mavlink_message_t msg);
|
||
|
||
private:
|
||
//线程运行参数
|
||
bool running_flag = false;
|
||
quint32 running_frq = 200;//200Hz
|
||
QThread *thread = nullptr;
|
||
|
||
//目标id
|
||
uint8_t sysid;
|
||
uint8_t compid;
|
||
|
||
|
||
//本机的id
|
||
int Current_sysID = 0xF1;
|
||
int Current_CompID = 0xF1;
|
||
|
||
|
||
//超时时间(ms)
|
||
int readTimeout = 3000;
|
||
int sendTimeout = 3000;
|
||
|
||
mavlink_param_set_t param_set;//
|
||
mavlink_param_union_t param_union;
|
||
mavlink_param_value_t param_value;//
|
||
mavlink_param_map_rc_t param_map;
|
||
mavlink_param_ext_ack_t param_ext_ack;
|
||
mavlink_param_ext_set_t param_ext_set;
|
||
mavlink_param_ext_value_t param_ext_value;
|
||
mavlink_param_request_list_t param_request_list;//
|
||
mavlink_param_request_read_t param_request_read;//
|
||
mavlink_param_union_double_t param_union_double;
|
||
mavlink_param_ext_request_list_t param_ext_request_list;
|
||
mavlink_param_ext_request_read_t param_ext_request_read;
|
||
|
||
|
||
|
||
};
|
||
|
||
#endif // PARAMETERPROCESS_H
|