feat: Service Registry + Bridge 解耦架构 + 全工程代码清理
## 架构升级:Service Registry + Bridge 模式 - 新增 PluginSDK/IPluginServices.h:10 个纯虚服务接口(IDataProvider/ILinkProvider/...) - 新增 MavLinkServiceBridge:单 QObject 实现全部服务,隔离 MavLinkNode 依赖 - 升级 PluginManifest:支持 plugin.json 的 provides/consumes 声明式依赖 - 实现 ExtensionHost::autoWire():元对象自省自动连接信号槽 - 集成到 AppController:initModules() 中创建桥接器并注册到 ServiceRegistry - CockpitPlugin 演示服务发现:initialize() 中通过 PluginContext 查找服务 ## 代码清理 - Plugins/opmap:~280 行死代码(waypointsetting 100行注释块/tilematrix 54行/等27个文件) - Plugins/MavLinkNode:~200 行 GBK 乱码注释翻译为 UTF-8 + 12 行注释死代码 - Plugins/ToolsUI:~222 行死代码(ECU.cpp 82行/INS.cpp 113行/Parse/ToolsUI 等) - StatusUI/Setting/MissionUI:~65 行注释死代码 - Cockpit/leftladder.cpp:10 处 GBK 乱码翻译为中文 - 清理头文件注释掉的 #include(19 处)、空 if-else 分支、注释变量声明 ## 编译验证 - [100%] Built target GCS 零错误 - 运行时 timeout 3s 正常退出,无崩溃
This commit is contained in:
@@ -0,0 +1,353 @@
|
||||
#ifndef MAVLINKNODE_H
|
||||
#define MAVLINKNODE_H
|
||||
|
||||
#include <QObject>
|
||||
#include "QThread"
|
||||
#include "QFile"
|
||||
#include "QDebug"
|
||||
|
||||
#include "mavlink.h"
|
||||
#include "replay.h"
|
||||
#include "missionprocess.h"
|
||||
#include "parameterprocess.h"
|
||||
#include "commandprocess.h"
|
||||
#include "statusprocess.h"
|
||||
#include "Terminal.h"
|
||||
#include "sbusparser.h"
|
||||
#include "QUdpSocket"
|
||||
|
||||
#include "rcprocess.h"
|
||||
#include "rtkprocess.h"
|
||||
|
||||
#include "ThreadTemplet.h"
|
||||
#include "../DataLogger.h"
|
||||
|
||||
|
||||
#ifdef QtMavlinkNode
|
||||
#include <mavlinknodeglobal.h>
|
||||
class MAVLINKNODESHARED_EXPORT MavLinkNode : public ThreadTemplet {
|
||||
#else
|
||||
class MavLinkNode : public ThreadTemplet
|
||||
{
|
||||
#endif
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
typedef struct {
|
||||
int sysid; /* ID of message sender system/aircraft */
|
||||
int compid; /* ID of the message sender component */
|
||||
|
||||
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;
|
||||
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;
|
||||
mavlink_aoa_ssa_t aoa_ssa;
|
||||
mavlink_emb_atmo_com_t emb_atom_com;
|
||||
mavlink_turbinestate_t turbinstate;
|
||||
mavlink_bmustate_t bmustate;
|
||||
mavlink_ccmstate_t ccmstate;
|
||||
mavlink_serial_control_t serial_control;
|
||||
|
||||
mavlink_statustext_t statustext;
|
||||
|
||||
}_vehicle;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t flag;//0x23f8
|
||||
uint16_t id;//1
|
||||
int32_t time;//(second+min*60+hour*3600)*1000
|
||||
int32_t lng;//*10000000
|
||||
int32_t lat;//*10000000
|
||||
int32_t alt;//*10
|
||||
int32_t ve;
|
||||
int32_t vn;
|
||||
int32_t vu;
|
||||
int32_t v;
|
||||
int32_t course;//*10
|
||||
}_showinfo;//192.168.5.8:10038
|
||||
|
||||
|
||||
explicit MavLinkNode(QObject *parent = nullptr);
|
||||
~MavLinkNode();
|
||||
|
||||
_vehicle vehicle;
|
||||
QHash<int,_vehicle> vehicleList;
|
||||
|
||||
Replay *replay = nullptr;
|
||||
|
||||
MissionProcess *Mission = nullptr;
|
||||
ParameterProcess *Parameter = nullptr;
|
||||
commandprocess *Commander = nullptr;
|
||||
statusprocess *Status = nullptr;
|
||||
terminal *Terminal = nullptr;
|
||||
rcprocess *RC = nullptr;
|
||||
rtkprocess *rtk = nullptr;
|
||||
|
||||
bool isCommunicationLost = false;
|
||||
|
||||
// 通讯状态机:Connected(正常) / Lost(丢失) / Recovering(恢复观察期)
|
||||
enum CommState { Connected, Lost, Recovering };
|
||||
CommState m_commState = Connected;
|
||||
bool m_commandBlocked = false; // 指令下发阻断标志
|
||||
QTimer *m_recoveryTimer = nullptr; // 恢复观察期定时器
|
||||
|
||||
uint64_t rate_in = 0;
|
||||
uint64_t count_in = 0;
|
||||
|
||||
uint64_t rate_out = 0;
|
||||
uint64_t count_out = 0;
|
||||
|
||||
|
||||
|
||||
uint64_t bittotal = 0;
|
||||
|
||||
uint64_t parserSuccess = 0;
|
||||
uint64_t parserFailure = 0;
|
||||
|
||||
|
||||
uint64_t TotalFrame_1s = 0;
|
||||
uint64_t LossFrame_1s = 0;
|
||||
|
||||
float rssi = 100;
|
||||
|
||||
|
||||
|
||||
QByteArray rtkrawdata;
|
||||
|
||||
|
||||
QByteArray csvData;
|
||||
|
||||
QByteArray autopilot_version_csv;
|
||||
QByteArray sys_status_csv;
|
||||
QByteArray heartbeat_csv;
|
||||
QByteArray ping_csv;
|
||||
QByteArray attitude_csv;
|
||||
QByteArray ins1_csv;
|
||||
QByteArray ins2_csv;
|
||||
QByteArray gps_raw_int_csv;
|
||||
QByteArray global_position_int_csv;
|
||||
QByteArray servo_output_raw_csv[10];
|
||||
QByteArray rc_channels_raw_csv;
|
||||
QByteArray nav_controller_output_csv;
|
||||
QByteArray airspeed_autocal_csv;
|
||||
QByteArray rpm_csv;
|
||||
QByteArray scaled_pressure_csv;
|
||||
QByteArray extended_sys_state_csv;
|
||||
QByteArray battery_status_csv;
|
||||
QByteArray vibration_csv;
|
||||
QByteArray enginestate_csv;
|
||||
QByteArray vfr_hud_csv;
|
||||
QByteArray aoa_ssa_csv;
|
||||
QByteArray emb_atom_com_csv;
|
||||
QByteArray turbinstate_csv;
|
||||
QByteArray bmustate_csv;
|
||||
QByteArray ccmstate_csv;
|
||||
QByteArray serial_control_csv;
|
||||
|
||||
|
||||
QFile * autopilot_version_file = nullptr;
|
||||
QFile * sys_status_file = nullptr;
|
||||
QFile * heartbeat_file = nullptr;
|
||||
QFile * ping_file = nullptr;
|
||||
QFile * attitude_file = nullptr;
|
||||
QFile * ins1_file = nullptr;
|
||||
QFile * ins2_file = nullptr;
|
||||
QFile * gps_raw_int_file = nullptr;
|
||||
QFile * global_position_int_file = nullptr;
|
||||
QFile * servo_output_raw_file = nullptr;
|
||||
QFile * rc_channels_raw_file = nullptr;
|
||||
QFile * nav_controller_output_file = nullptr;
|
||||
QFile * airspeed_autocal_file = nullptr;
|
||||
QFile * rpm_file = nullptr;
|
||||
QFile * scaled_pressure_file = nullptr;
|
||||
QFile * extended_sys_state_file = nullptr;
|
||||
QFile * battery_status_file = nullptr;
|
||||
QFile * vibration_file = nullptr;
|
||||
QFile * enginestate_file = nullptr;
|
||||
QFile * vfr_hud_file = nullptr;
|
||||
QFile * aoa_ssa_file = nullptr;
|
||||
QFile * emb_atom_com_file = nullptr;
|
||||
QFile * turbinstate_file = nullptr;
|
||||
QFile * bmustate_file = nullptr;
|
||||
QFile * ccmstate_file = nullptr;
|
||||
QFile * serial_control_file = nullptr;
|
||||
|
||||
|
||||
int infoExportID = 1;
|
||||
|
||||
DataLogger *m_dataLogger = nullptr;
|
||||
|
||||
signals:
|
||||
|
||||
void signal_autopilot_version();
|
||||
void signal_sys_status();
|
||||
void signal_heartbeat();
|
||||
void signal_ping();
|
||||
void signal_attitude();
|
||||
void signal_ins1(mavlink_ins1_t ins);
|
||||
void signal_ins2(mavlink_ins2_t ins);
|
||||
void signal_gps_raw_int();
|
||||
void signal_global_position_int();
|
||||
void signal_servo_output_raw(int sysid,mavlink_servo_output_raw_t servo);
|
||||
void signal_rc_channels_raw();
|
||||
void signal_nav_controller_output();
|
||||
void signal_airspeed_autocal();
|
||||
void signal_rpm();
|
||||
void signal_scaled_pressure();
|
||||
void signal_extended_sys_state();
|
||||
void signal_battery_status();
|
||||
void signal_vibration();
|
||||
void signal_enginestate();
|
||||
void signal_vfr_hud();
|
||||
void signal_aoa_ssa();
|
||||
void signal_emb_atom_com();
|
||||
void signal_turbinstate();
|
||||
void signal_bmustate();
|
||||
void signal_ccmstate();
|
||||
void signal_serial_control();
|
||||
|
||||
|
||||
void signal_vehicle(MavLinkNode::_vehicle vehicle);
|
||||
|
||||
|
||||
void SendMessageToExport(quint8 ch, quint8 *data,quint16 len);
|
||||
|
||||
void updateDlink(float rssi,uint64_t in,uint64_t out);
|
||||
void CommuniationLost(bool);
|
||||
void communicationStateChanged(int state); // 通讯状态变更(0=Connected, 1=Lost, 2=Recovering)
|
||||
|
||||
void beep(int);
|
||||
|
||||
void addVehicles(int sysid,int compid);
|
||||
|
||||
void recievemsg(mavlink_message_t msg);
|
||||
|
||||
void state_updated();
|
||||
void parameter_updated();
|
||||
//void mission_updated();
|
||||
|
||||
void setCurrentID(int sysid,int compid);
|
||||
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
void recieveData(const int &id,const QByteArray &data);
|
||||
|
||||
|
||||
|
||||
public slots:
|
||||
//线程对外接口
|
||||
void CreateCSV(void);
|
||||
|
||||
//缓存对外接口
|
||||
void readPendingDatagramsReplay(void);
|
||||
|
||||
void setCurrentSelected(int sysid,int compid);
|
||||
|
||||
void setLogfile(QString file);
|
||||
|
||||
void setGCSID(int id);
|
||||
|
||||
void infoExport(_showinfo info);
|
||||
|
||||
// 查询指令阻断状态(通讯丢失期间禁止下发指令)
|
||||
bool isCommandBlocked(void) const { return m_commandBlocked; }
|
||||
|
||||
private slots:
|
||||
//线程私有接口
|
||||
void process();
|
||||
|
||||
//缓存私有接口
|
||||
|
||||
|
||||
void TimerOut(void);
|
||||
void LogTimerOut(void);
|
||||
void timer_1s_Out(void);
|
||||
|
||||
|
||||
|
||||
|
||||
//解析
|
||||
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);
|
||||
//
|
||||
|
||||
//check for new vehicle
|
||||
void CheckVehicle(int sysid, int compid);
|
||||
|
||||
// 通讯状态恢复观察期回调
|
||||
void onRecoveryTimerOut(void);
|
||||
|
||||
private:
|
||||
// CSV 文件写入辅助函数(消除重复的 open/write/close 模式)
|
||||
static void writeCsvFile(QFile *&file, const QString &filePath, const QByteArray &data);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
int Current_sysID = 0xF1;
|
||||
int Current_CompID = MAV_COMP_ID_MISSIONPLANNER;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QTimer *gdt_timer = nullptr;
|
||||
QTimer *timer = nullptr;
|
||||
|
||||
|
||||
QByteArray databuff;
|
||||
|
||||
_buffdef serial_buff;
|
||||
_buffdef client_buff;
|
||||
|
||||
QString mavlogFileName;
|
||||
QFile *mavLogFile = NULL;
|
||||
|
||||
QTimer *logTimer = nullptr;
|
||||
|
||||
|
||||
|
||||
QTimer *timer_1s = nullptr;
|
||||
|
||||
QDateTime startuptime;
|
||||
|
||||
};
|
||||
|
||||
#endif // MAVLINKNODE_H
|
||||
Reference in New Issue
Block a user