From 809bca3e910a56f9c0abf11fce1f1aeb7b378c2e Mon Sep 17 00:00:00 2001 From: luocai Date: Fri, 21 Jun 2024 15:11:18 +0800 Subject: [PATCH] add status query command. --- Analyser/ModuleCommunication.cpp | 13 +++++++++++++ Analyser/ModuleCommunication.h | 2 ++ Analyser/qml/OperationItem.qml | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/Analyser/ModuleCommunication.cpp b/Analyser/ModuleCommunication.cpp index 84eaafb..f94b51e 100644 --- a/Analyser/ModuleCommunication.cpp +++ b/Analyser/ModuleCommunication.cpp @@ -169,6 +169,13 @@ void ModuleCommunication::uploadImageData(uint32_t offset, const uint8_t *data, delete[] buffer; } +void ModuleCommunication::requestCurrentStatus() { + auto [frameData, frameSize] = generateFrame(GetCurrentStatus); + m_serialPort->write(reinterpret_cast(frameData), frameSize); + LOG_CAT(info, GUI) << "发送状态指令: " << protocolDataFormatString(frameData, frameSize); + LOG_CAT(info, GUI) << Separator; +} + ModuleCommunication::MessageId ModuleCommunication::currentMessageId() const { return m_currentMessageId; } @@ -294,6 +301,12 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) { case UploadImageData: { break; } + case GetCurrentStatus: { + LOG_CAT(info, GUI) << "模组: " << protocolDataFormatString(data, size); + LOG_CAT(info, GUI) << "模组当前状态: " << static_cast(data[7]); + LOG_CAT(info, GUI) << Separator; + break; + } default: LOG(warning) << "unknown reply command: 0x" << (static_cast(replyId) & 0xff) << ", data: " << protocolDataFormatString(data, size); diff --git a/Analyser/ModuleCommunication.h b/Analyser/ModuleCommunication.h index c9ff104..96972c3 100644 --- a/Analyser/ModuleCommunication.h +++ b/Analyser/ModuleCommunication.h @@ -20,6 +20,7 @@ public: Reply = 0, Note = 0x01, Reset = 0x10, + GetCurrentStatus = 0x11, Verify = 0x12, EnrollSingle = 0x1D, EnrollGetImage = 0x1E, @@ -154,6 +155,7 @@ public: void uploadImageInfo(const UploadImageInformation &info); void uploadImageData(uint32_t offset, const uint8_t *data, uint32_t size); + Q_INVOKABLE void requestCurrentStatus(); MessageId currentMessageId() const; static std::string protocolDataFormatString(const uint8_t *data, int size); diff --git a/Analyser/qml/OperationItem.qml b/Analyser/qml/OperationItem.qml index 6ea2f9c..a504af5 100644 --- a/Analyser/qml/OperationItem.qml +++ b/Analyser/qml/OperationItem.qml @@ -122,6 +122,10 @@ ColumnLayout { text: "复位" onClicked: App.module.reset() } + Button { + text: "状态查询" + onClicked: App.module.requestCurrentStatus() + } } } }