diff --git a/components/zcan_module/zcan_basic_order_module.cpp b/components/zcan_module/zcan_basic_order_module.cpp index 67f42e3..a703bc0 100644 --- a/components/zcan_module/zcan_basic_order_module.cpp +++ b/components/zcan_module/zcan_basic_order_module.cpp @@ -14,6 +14,7 @@ void ZCanBasicOrderModule::initialize(ZCanReceiver* zcanReceiver) { void ZCanBasicOrderModule::regInputCtl(readfn_t fn) { m_readfn = fn; } void ZCanBasicOrderModule::regOutCtl(writefn_t fn) { m_writefn = fn; } +void ZCanBasicOrderModule::regReadAdcVal(readadcval_t fn) { m_readadcval = fn; } void ZCanBasicOrderModule::onRceivePacket(CanPacketRxBuffer* rxbuf, uint8_t* packet, size_t len) { // @@ -71,6 +72,20 @@ void ZCanBasicOrderModule::onRceivePacket(CanPacketRxBuffer* rxbuf, uint8_t* pac m_zcanReceiver->sendPacket(txbuff, sizeof(Cmdheader_t) + 2); return; } + } else if (cmdheader->cmdid == kcmd_readadc_raw && cmdheader->subcmdid == 0) { + /** + * @brief 读取ADC数值 + */ + uint8_t id = cmdheader->data[0]; + int32_t val = 0; + if (m_readfn && m_readadcval(id, val)) { + // + uint8_t txbuff[2 + 4] = {0}; + txbuff[0] = id; + *(int32_t*)(&txbuff[2]) = val; + m_zcanReceiver->sendAck(cmdheader, txbuff, sizeof(txbuff)); + return; + } } } diff --git a/components/zcan_module/zcan_basic_order_module.hpp b/components/zcan_module/zcan_basic_order_module.hpp index a2229a4..f1121c4 100644 --- a/components/zcan_module/zcan_basic_order_module.hpp +++ b/components/zcan_module/zcan_basic_order_module.hpp @@ -14,11 +14,13 @@ class ZCanBasicOrderModule : public ZCanRceiverListener { private: ZCanReceiver* m_zcanReceiver; - typedef function readfn_t; - typedef function writefn_t; + typedef function readfn_t; + typedef function writefn_t; + typedef function readadcval_t; - readfn_t m_readfn; - writefn_t m_writefn; + readfn_t m_readfn; + writefn_t m_writefn; + readadcval_t m_readadcval; uint8_t txbuff[32]; @@ -31,6 +33,7 @@ class ZCanBasicOrderModule : public ZCanRceiverListener { void regInputCtl(readfn_t fn); void regOutCtl(writefn_t fn); + void regReadAdcVal(readadcval_t fn); public: virtual void onRceivePacket(CanPacketRxBuffer* rxbuf, uint8_t* packet, size_t len); diff --git a/components/zcanreceiver/cmd.hpp b/components/zcanreceiver/cmd.hpp index 3f68c17..51810a1 100644 --- a/components/zcanreceiver/cmd.hpp +++ b/components/zcanreceiver/cmd.hpp @@ -20,9 +20,10 @@ typedef enum { } PacketType_t; typedef enum { - kcmd_ping = 0, - kcmd_read_io = 1, - kcmd_set_io = 2, + kcmd_ping = 0, + kcmd_read_io = 1, + kcmd_set_io = 2, + kcmd_readadc_raw = 3, kcmd_m211887_operation = 1000, // 维萨拉压力传感器 kcmd_read_presure_sensor = 1001,