From 8691aaccb11538496a6898eacebb031048d4a324 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Wed, 12 Jun 2024 11:29:12 +0800 Subject: [PATCH] update --- .../pipette_module/pipette_ctrl_module_v2.cpp | 2 +- components/sensors/smtp2/smtp2.cpp | 2 +- components/zcancmder/protocol_event_bus_sender.cpp | 66 ++++++++++++++++++++++ components/zcancmder/protocol_event_bus_sender.hpp | 33 +++++++++++ 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 components/zcancmder/protocol_event_bus_sender.cpp create mode 100644 components/zcancmder/protocol_event_bus_sender.hpp diff --git a/components/pipette_module/pipette_ctrl_module_v2.cpp b/components/pipette_module/pipette_ctrl_module_v2.cpp index 47e1971..b157141 100644 --- a/components/pipette_module/pipette_ctrl_module_v2.cpp +++ b/components/pipette_module/pipette_ctrl_module_v2.cpp @@ -1,5 +1,5 @@ #include "pipette_ctrl_module_v2.hpp" - +#include "sdk\components\zcancmder\protocol_event_bus_sender.hpp" using namespace iflytop; #define TAG "PipetteModule" diff --git a/components/sensors/smtp2/smtp2.cpp b/components/sensors/smtp2/smtp2.cpp index 0f3d380..e7a71e1 100644 --- a/components/sensors/smtp2/smtp2.cpp +++ b/components/sensors/smtp2/smtp2.cpp @@ -435,7 +435,7 @@ int32_t SMTP2::doaction_block(function action) { // int32_t state = getState(); osDelay(100); - bool isbusy; + bool isbusy = false; err::error_t error; int32_t ecode = getState(isbusy, error); diff --git a/components/zcancmder/protocol_event_bus_sender.cpp b/components/zcancmder/protocol_event_bus_sender.cpp new file mode 100644 index 0000000..356e527 --- /dev/null +++ b/components/zcancmder/protocol_event_bus_sender.cpp @@ -0,0 +1,66 @@ +#include "protocol_event_bus_sender.hpp" +namespace iflytop { +using namespace std; + +void ProtocolEventBusSender::initialize(IZCanReceiver* zcanreceiver) { + m_zcanreceiver = zcanreceiver; + lock_.init(); +} + + +void ProtocolEventBusSender::push_reg_state_change_event(int32_t moduleid, int32_t regindex, int32_t oldval, int32_t toval) { + zlock_guard l(lock_); + + zcr_cmd_header_t* cmd_header = (zcr_cmd_header_t*)txbuf; + int32_t* data = (int32_t*)cmd_header->data; + cmd_header->subModuleid = moduleid; + cmd_header->cmdMainId = zcr::kevent_bus_reg_change_report >> 8; + cmd_header->subModuleid = zcr::kevent_bus_reg_change_report & 0xff; + + data[0] = regindex; + data[1] = oldval; + data[2] = toval; + m_zcanreceiver->triggerEvent(cmd_header, (uint8_t*)data, 4 * 3); +} + +void ProtocolEventBusSender::report(int32_t moduleid, int32_t cmdindex, int32_t data0) { + zlock_guard l(lock_); + + zcr_cmd_header_t* cmd_header = (zcr_cmd_header_t*)txbuf; + int32_t* data = (int32_t*)cmd_header->data; + cmd_header->subModuleid = moduleid; + cmd_header->cmdMainId = cmdindex >> 8; + cmd_header->subModuleid = cmdindex & 0xff; + + data[0] = data0; + m_zcanreceiver->triggerEvent(cmd_header, (uint8_t*)data, 4 * 1); +} +void ProtocolEventBusSender::report(int32_t moduleid, int32_t cmdindex, int32_t data0, int32_t data1) { + zlock_guard l(lock_); + + zcr_cmd_header_t* cmd_header = (zcr_cmd_header_t*)txbuf; + int32_t* data = (int32_t*)cmd_header->data; + cmd_header->subModuleid = moduleid; + cmd_header->cmdMainId = cmdindex >> 8; + cmd_header->subModuleid = cmdindex & 0xff; + + data[0] = data0; + data[1] = data1; + m_zcanreceiver->triggerEvent(cmd_header, (uint8_t*)data, 4 * 1); +} +void ProtocolEventBusSender::report(int32_t moduleid, int32_t cmdindex, int32_t data0, int32_t data1, int32_t data2) { + zlock_guard l(lock_); + + zcr_cmd_header_t* cmd_header = (zcr_cmd_header_t*)txbuf; + int32_t* data = (int32_t*)cmd_header->data; + cmd_header->subModuleid = moduleid; + cmd_header->cmdMainId = cmdindex >> 8; + cmd_header->subModuleid = cmdindex & 0xff; + + data[0] = data0; + data[1] = data1; + data[2] = data2; + m_zcanreceiver->triggerEvent(cmd_header, (uint8_t*)data, 4 * 1); +} + +} // namespace iflytop \ No newline at end of file diff --git a/components/zcancmder/protocol_event_bus_sender.hpp b/components/zcancmder/protocol_event_bus_sender.hpp new file mode 100644 index 0000000..9e9eed2 --- /dev/null +++ b/components/zcancmder/protocol_event_bus_sender.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include "a8000_protocol\protocol.hpp" +#include "basic.hpp" +#include "sdk/os/zos.hpp" + +namespace iflytop { +using namespace std; + +class ProtocolEventBusSender { + IZCanReceiver* m_zcanreceiver = nullptr; + zmutex lock_; + + uint8_t txbuf[128]; + + public: + static ProtocolEventBusSender* inst() { + static ProtocolEventBusSender instance; + return &instance; + } + + void initialize(IZCanReceiver* zcanreceiver); + + void push_reg_state_change_event(int32_t moduleid, int32_t regindex, int32_t oldval, int32_t toval); + + void report(int32_t moduleid, int32_t cmdindex, int32_t data0); + void report(int32_t moduleid, int32_t cmdindex, int32_t data0, int32_t data1); + void report(int32_t moduleid, int32_t cmdindex, int32_t data0, int32_t data1, int32_t data2); + + private: + void _report(int32_t moduleid, int32_t cmdindex, int32_t ndata, int32_t* data); +}; +} // namespace iflytop