#pragma execution_character_set("utf-8") #pragma once #include #include #include "Common.h" #include "frame/Frame.h" class SetupService : QObject { Q_OBJECT public: static SetupService *GetInstance() { if(!m_pInstance) { m_mutex.lock(); if(!m_pInstance) { m_pInstance = new SetupService(); } m_mutex.unlock(); } return m_pInstance; } SetupService(const SetupService&)= delete; SetupService& operator=(const SetupService&)= delete; void SendData(unsigned char cmd, std::string data = "", int msec=1000, unsigned char from=0); void SendData(unsigned char cmd, Data *data, int msec=1000, unsigned char from=0); SYS_STATUS currStatus() { return m_currStatus; } signals: void recv_base_setup_rsp(QString portName, unsigned char cmd, QByteArray recvData); void recv_advance_setup_rsp(QString portName, unsigned char cmd, QByteArray recvData); public slots: void slot_recvData(QString portName, unsigned char cmd, QByteArray data); void slot_recvTimeout(QString portName); void slot_getRecordFinish(int result); private: SetupService() : m_currStatus(SYS_STATUS_IDLE), m_currCmd(FRAME_CMD_START), m_currCmdFrom(0) {}; private: static SetupService *m_pInstance; static QMutex m_mutex; SYS_STATUS m_currStatus; // 当前状态 unsigned char m_currCmd; // 当前指令 unsigned char m_currCmdFrom; // 当前指令来源,0-基础设置,1-高级设置 private: // 垃圾回收类,它的唯一工作就是在析构函数中删除DeviceFactory的实例 class Garbo { public: ~Garbo() { if (SetupService::m_pInstance) { // 销毁设备管理单例实例 delete SetupService::m_pInstance; } } }; // 定义一个静态成员,在程序结束时,系统会调用它的析构函数 static Garbo m_Garbo; };