Files
gcs-nf/MavLinkNode/mavlinknode.h
T

195 lines
4.4 KiB
C++
Raw Normal View History

#ifndef MAVLINKNODE_H
2020-03-07 14:46:50 +08:00
#define MAVLINKNODE_H
#include <QObject>
#include "QThread"
2020-08-20 17:48:09 +08:00
#include "QFile"
2020-03-07 14:46:50 +08:00
#include "QDebug"
#include "mavlink.h"
2020-08-20 17:48:09 +08:00
#include "replay.h"
2020-03-07 14:46:50 +08:00
#include "missionprocess.h"
#include "parameterprocess.h"
2020-04-03 09:39:31 +08:00
#include "commandprocess.h"
2020-03-07 14:46:50 +08:00
#ifdef QtMavlinkNode
#include <mavlinknodeglobal.h>
class MAVLINKNODESHARED_EXPORT MavLinkNode : public QObject {
#else
class MavLinkNode : public QObject
{
#endif
Q_OBJECT
typedef struct {
qint32 max_size;
quint8 select;
QByteArray buff[2];
}_buffdef;
typedef struct {
2020-04-09 20:19:56 +08:00
uint8_t sysid; /* ID of message sender system/aircraft */
uint8_t compid; /* ID of the message sender component */
2020-03-07 14:46:50 +08:00
mavlink_autopilot_version_t autopilot_version;
mavlink_sys_status_t sys_status;
mavlink_heartbeat_t heartbeat;
mavlink_ping_t ping;
mavlink_attitude_t attitude;
mavlink_ins1_t ins1;
mavlink_ins2_t ins2;
2020-03-07 14:46:50 +08:00
mavlink_gps_raw_int_t gps_raw_int;
mavlink_global_position_int_t global_position_int;
mavlink_servo_output_raw_t servo_output_raw;
mavlink_rc_channels_raw_t rc_channels_raw;
mavlink_nav_controller_output_t nav_controller_output;
mavlink_airspeed_autocal_t airspeed_autocal;
mavlink_rpm_t rpm;
mavlink_scaled_pressure_t scaled_pressure;
mavlink_extended_sys_state_t extended_sys_state;
mavlink_battery_status_t battery_status;
mavlink_vibration_t vibration;
mavlink_enginestate_t enginestate;
mavlink_vfr_hud_t vfr_hud;
2020-10-15 22:21:38 +08:00
mavlink_aoa_ssa_t aoa_ssa;
2020-10-22 11:27:45 +08:00
mavlink_emb_atmo_com_t emb_atom_com;
2020-10-07 12:24:23 +08:00
mavlink_turbinestate_t turbinstate;
mavlink_bmustate_t bmustate;
mavlink_ccmstate_t ccmstate;
2020-03-07 14:46:50 +08:00
}_vehicle;
2020-10-15 22:21:38 +08:00
2020-03-07 14:46:50 +08:00
public:
explicit MavLinkNode(QObject *parent = nullptr);
~MavLinkNode();
_vehicle vehicle;
2020-08-20 17:48:09 +08:00
Replay *replay = nullptr;
2020-08-20 17:48:09 +08:00
MissionProcess *Mission = nullptr;
ParameterProcess *Parameter = nullptr;
commandprocess *Commander = nullptr;
2020-08-04 23:18:58 +08:00
2020-10-12 14:39:16 +08:00
bool isCommunicationLost = false;
2020-08-04 23:18:58 +08:00
2020-10-13 18:41:23 +08:00
uint64_t bitrate = 0;
uint64_t bitcount = 0;
uint64_t bittotal = 0;
uint64_t parserSuccess = 0;
uint64_t parserFailure = 0;
float rssi = 100;
2020-03-07 14:46:50 +08:00
signals:
2020-10-12 21:08:37 +08:00
void CommuniationLost(bool);
2020-07-01 18:22:49 +08:00
void showMessage(const QString &message,int TimeOut = 0);
2020-06-05 18:05:16 +08:00
2020-08-07 17:15:58 +08:00
void beep(void);
2020-06-01 18:25:33 +08:00
void addVehicles(int sysid,int compid);
void SendMessageTo(quint8 ch, quint8 *data,quint16 len);
void recievemsg(mavlink_message_t msg);
2020-03-07 14:46:50 +08:00
void state_updated();
void parameter_updated();
//void mission_updated();
2020-06-02 18:39:43 +08:00
void setCurrentID(int sysid,int compid);
2020-06-05 18:05:16 +08:00
void setAltitude(int sysid,int compid,double roll,double pitch,double yaw);
void setPos(int sysid,int compid,double x,double y,double z);
void setHeading(int sysid,int compid,double x,double y,double z);
2020-03-07 14:46:50 +08:00
public slots:
//线程对外接口
void setRunFrq(uint32_t frq);
void start();
void stop();
2020-08-12 22:12:44 +08:00
bool isActive(void)
{
return running_flag;
}
2020-10-12 14:39:16 +08:00
2020-03-07 14:46:50 +08:00
//缓存对外接口
2020-08-20 17:48:09 +08:00
void readPendingDatagramsReplay(void);
2020-03-07 14:46:50 +08:00
void setbuff(quint32 src, QByteArray data);
2020-06-02 18:39:43 +08:00
void setCurrentSelected(int sysid,int compid);
2020-08-20 17:48:09 +08:00
void setLogfile(QString file);
2020-03-07 14:46:50 +08:00
2020-10-12 14:39:16 +08:00
2020-03-07 14:46:50 +08:00
private slots:
//线程私有接口
void process();
//缓存私有接口
void initbuff(void);
QByteArray readbuff(quint32 src);
2020-10-12 14:39:16 +08:00
void TimerOut(void);
2020-03-07 14:46:50 +08:00
//解析
void Mavlinkparse(quint32 src,QByteArray datagram);
void MAVLinkRcv_Handler(mavlink_message_t msg);
void StatusParse(mavlink_message_t msg);
void CommandParse(mavlink_message_t msg);
//
2020-03-07 14:46:50 +08:00
2020-06-01 18:25:33 +08:00
//check for new vehicle
void CheckVehicle(int sysid, int compid);
2020-03-07 14:46:50 +08:00
protected:
2020-08-04 23:18:58 +08:00
int Current_sysID = 0xF1;
2020-08-05 22:39:33 +08:00
int Current_CompID = MAV_COMP_ID_MISSIONPLANNER;
2020-06-02 18:39:43 +08:00
2020-03-07 14:46:50 +08:00
enum SourceType{
c_sock = 0,
s_port = 1
};
2020-10-13 18:41:23 +08:00
bool hasConneted = false;
2020-10-12 21:08:37 +08:00
int32_t CommucationOverCount = 5;
2020-10-12 14:39:16 +08:00
uint64_t CommucationOverTimer = 5000;
2020-08-04 23:18:58 +08:00
uint8_t GCS_System_ID = 0xFF;
2020-03-07 14:46:50 +08:00
bool running_flag = false;
quint32 running_frq = 200;//200Hz
2020-08-20 17:48:09 +08:00
QThread *thread;
2020-03-07 14:46:50 +08:00
QThread *Parameterthread;
2020-06-01 18:25:33 +08:00
QHash<int,int> vehicleList;
2020-10-12 14:39:16 +08:00
QTimer *timer = nullptr;
2020-06-01 18:25:33 +08:00
2020-03-07 14:46:50 +08:00
_buffdef serial_buff;
_buffdef client_buff;
2020-08-20 17:48:09 +08:00
QFile *mavLogFile = NULL;
2020-03-07 14:46:50 +08:00
};
#endif // MAVLINKNODE_H