feat:初始化wuhan_QT界面代码
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
#ifndef APPCONTEXT_H
|
||||
#define APPCONTEXT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QVector>
|
||||
#include "global.h"
|
||||
|
||||
class UdpCommunication;
|
||||
class MockVehicle;
|
||||
|
||||
// 故障历史记录
|
||||
struct FaultRecord {
|
||||
QString time; // "2026-05-16 10:08"
|
||||
QString system; // 机器人底盘 / 机械臂 / 洗消系统 / 气体检测仪
|
||||
QString code; // 故障代码
|
||||
QString desc; // 故障名称
|
||||
};
|
||||
|
||||
// ===================== 应用上下文(单例) =====================
|
||||
// 持有:通信层、参数存储、全局状态(模式/急停/通信状态)、遥测数据快照
|
||||
class AppContext : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static AppContext* instance();
|
||||
|
||||
UdpCommunication* comm() const { return m_comm; }
|
||||
MockVehicle* vehicle() const { return m_vehicle; }
|
||||
|
||||
// 遥测数据快照(由通信层填充)
|
||||
Telemetry telemetry;
|
||||
|
||||
// 全局状态
|
||||
Mode mode = Mode::Drive; // 行车/机械臂模式(机械旋钮)
|
||||
bool estopTriggered = false; // 急停是否触发(需人工复位)
|
||||
bool washRunning = false; // 洗消运行中(消除/消毒共用)
|
||||
bool gasRunning = false; // 气体检测仪检测中
|
||||
|
||||
// ===================== 存储区参数(QSettings 持久化) =====================
|
||||
double getDouble(const QString& key, double def) const;
|
||||
void setDouble(const QString& key, double val);
|
||||
QString getString(const QString& key, const QString& def) const;
|
||||
void setString(const QString& key, const QString& val);
|
||||
|
||||
// 密码
|
||||
QString password() const;
|
||||
void setPassword(const QString& pwd);
|
||||
QString adminPassword() const;
|
||||
|
||||
// 洗消/底盘参数出厂值与键名
|
||||
static QString keySpeed() { return "param/speed"; } // 车速 km/h,出厂 4.5
|
||||
static QString keyPumpFlow() { return "param/pump_flow"; } // 柱塞泵流量,出厂 20
|
||||
static QString keyFoamRatio() { return "param/foam_ratio"; } // 发泡倍数,出厂 6
|
||||
static QString keyFoamPercent(){ return "param/foam_percent"; }// 泡沫比例,出厂 3
|
||||
static QString keyAirFlow() { return "param/air_flow"; } // 空压机流量,出厂 100
|
||||
|
||||
// 故障历史(⑫故障查询数据源)
|
||||
QVector<FaultRecord> faultHistory;
|
||||
void appendFault(const QString& system, const QString& code, const QString& desc);
|
||||
|
||||
// 急停复位(人工复位)
|
||||
void resetEstop();
|
||||
|
||||
// 触发急停(软急停/物理急停统一入口)
|
||||
void triggerEstop();
|
||||
|
||||
// 模式切换(行车/机械臂,由面板机械旋钮或演示按钮触发)
|
||||
void setMode(Mode m);
|
||||
|
||||
signals:
|
||||
void modeChanged(Mode m);
|
||||
void estopChanged(bool triggered);
|
||||
void commChanged(bool ok);
|
||||
|
||||
private:
|
||||
explicit AppContext(QObject* parent = nullptr);
|
||||
void seedFaultHistory();
|
||||
QSettings* m_settings = nullptr;
|
||||
UdpCommunication* m_comm = nullptr;
|
||||
MockVehicle* m_vehicle = nullptr;
|
||||
};
|
||||
|
||||
// 便捷访问宏
|
||||
#define CTX AppContext::instance()
|
||||
|
||||
#endif // APPCONTEXT_H
|
||||
Reference in New Issue
Block a user