147 lines
2.3 KiB
C++
147 lines
2.3 KiB
C++
#ifndef RCPROCESS_H
|
|
#define RCPROCESS_H
|
|
|
|
#include <QObject>
|
|
#include "QThread"
|
|
#include "QFile"
|
|
#include "QDebug"
|
|
#include "QtEndian"
|
|
#include "QDateTime"
|
|
#include "QTimer"
|
|
|
|
#include "mavlink.h"
|
|
#include "sbusparser.h"
|
|
|
|
|
|
#ifdef QtMavlinkNode
|
|
#include <mavlinknodeglobal.h>
|
|
class MAVLINKNODESHARED_EXPORT rcprocess : public QObject {
|
|
#else
|
|
class rcprocess : public QObject
|
|
{
|
|
#endif
|
|
Q_OBJECT
|
|
|
|
public:
|
|
typedef struct {
|
|
qint32 max_size;
|
|
quint8 select;
|
|
QByteArray buff[2];
|
|
}_buffdef;
|
|
|
|
|
|
|
|
explicit rcprocess(QObject *parent = nullptr);
|
|
~rcprocess();
|
|
|
|
|
|
void setGCSID(int m_sysid, int m_compid)
|
|
{
|
|
Current_sysID = m_sysid;
|
|
Current_CompID = m_compid;
|
|
}
|
|
|
|
signals:
|
|
|
|
void SendMessageTo(quint8 ch, quint8 *data,quint16 len);
|
|
|
|
void new_remote_ctrl(QList<uint16_t>);
|
|
|
|
|
|
void showMessage(const QString &message,int TimeOut = 0);
|
|
|
|
public slots:
|
|
//线程对外接口
|
|
void setRunFrq(uint32_t frq);
|
|
void start();
|
|
void stop();
|
|
bool isActive(void)
|
|
{
|
|
return running_flag;
|
|
}
|
|
|
|
|
|
|
|
|
|
//缓存对外接口
|
|
void setID(int m_sysid, int m_compid);
|
|
void setbuff(quint32 src, QByteArray data);
|
|
|
|
|
|
void SoftRCUpdate(QList<uint16_t> rc);
|
|
void setRCActive(uint32_t value)
|
|
{
|
|
isRCActive = value;
|
|
qDebug() << "set ch" << isRCActive;
|
|
}
|
|
|
|
private slots:
|
|
//线程私有接口
|
|
void Send(mavlink_message_t msg);
|
|
void process();
|
|
|
|
//缓存私有接口
|
|
void initbuff(void);
|
|
QByteArray readbuff(quint32 src);
|
|
|
|
|
|
void update15Hz(void);
|
|
|
|
|
|
//解析
|
|
void parse(quint32 src,QByteArray datagram);
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int Current_sysID = 0xF1;
|
|
int Current_CompID = MAV_COMP_ID_MISSIONPLANNER;
|
|
|
|
//目标id
|
|
uint8_t sysid;
|
|
uint8_t compid;
|
|
|
|
enum SourceType{
|
|
c_sock = 0,
|
|
s_port = 1
|
|
};
|
|
|
|
bool hasConneted = false;
|
|
int32_t CommucationOverCount = 5;
|
|
uint64_t CommucationOverTimer = 5000;
|
|
|
|
uint8_t GCS_System_ID = 0xFF;
|
|
|
|
bool running_flag = false;
|
|
quint32 running_frq = 200;//200Hz
|
|
|
|
QThread *thread;
|
|
|
|
|
|
QByteArray databuff;
|
|
|
|
_buffdef serial_buff;
|
|
_buffdef client_buff;
|
|
|
|
|
|
uint16_t rcin[20];
|
|
int rcin_cnt = 0;
|
|
bool rcin_update = true;
|
|
|
|
uint32_t isRCActive = 0;
|
|
|
|
SBusParser sbus;
|
|
QList<uint16_t> sbuslist;
|
|
|
|
|
|
QTimer *timer = nullptr;
|
|
|
|
|
|
};
|
|
|
|
|
|
#endif // RCPROCESS_H
|
|
|