From 3d9596ed38e389011865b5c30f14a1807c7d05a4 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Fri, 6 Oct 2023 13:04:49 +0800 Subject: [PATCH] update --- .../motor_laser_code_scanne.cpp | 21 ++++- .../motor_laser_code_scanne.hpp | 5 +- components/zcancmder/zcanreceiver.cpp | 10 ++- components/zcancmder/zcanreceiver.hpp | 2 +- .../zcan_mini_servo_ctrl_module.cpp | 89 ++-------------------- .../zcan_mini_servo_ctrl_module.hpp | 1 + .../zcan_motor_laser_code_scanner_scan_module.cpp | 52 +++---------- .../zcan_motor_laser_code_scanner_scan_module.hpp | 2 + .../zcancmder_module/zcan_pipette_module.cpp | 3 + .../zcancmder_module/zcan_pipette_module.hpp | 1 + .../zcan_step_motor_ctrl_module.cpp | 56 ++------------ .../zcan_step_motor_ctrl_module.hpp | 1 + .../zcancmder_module/zcan_xy_robot_module.cpp | 3 +- .../zcancmder_module/zcan_xy_robot_module.hpp | 1 + components/zprotocols/errorcode | 2 +- components/zprotocols/zcancmder | 2 +- 16 files changed, 69 insertions(+), 182 deletions(-) diff --git a/components/motor_laser_code_scanner/motor_laser_code_scanne.cpp b/components/motor_laser_code_scanner/motor_laser_code_scanne.cpp index f0ef408..7a86e57 100644 --- a/components/motor_laser_code_scanner/motor_laser_code_scanne.cpp +++ b/components/motor_laser_code_scanner/motor_laser_code_scanne.cpp @@ -73,9 +73,26 @@ int32_t MotorLaserCodeScanner::stop_scan() { return 0; }; -int32_t MotorLaserCodeScanner::get_scan_result(scan_result_t** result) { +int32_t MotorLaserCodeScanner::get_scan_result(u16 sector_index, u16 sector_size, zcancmder_read_ram_ack_t& ack) { + zlock_guard lock(m_lock); if (m_thread.isworking()) return err::kce_device_is_busy; - *result = m_scan_result; + uint8_t* src_data = m_scan_result->scan_result + sector_index * sector_size; + int32_t src_data_len = m_scan_result->each_scan_result_len * m_scan_result->scan_reult_nums; + + return assign_scan_result(sector_index, sector_size, src_data, src_data_len, ack); +} +int32_t MotorLaserCodeScanner::assign_scan_result(u16 sector_index, u16 sector_size, u8* src_data, s32 src_data_len, zcancmder_read_ram_ack_t& ack) { + if (sector_size > sizeof(ack.packet)) return err::kce_buffer_not_enough; + + uint8_t* copy_s = (uint8_t*)src_data + sector_index * sector_size; + int32_t copy_len = (int32_t)src_data_len - sector_size * sector_index; + + if (copy_len > sector_size) copy_len = sector_size; + if (copy_len < 0) copy_len = 0; + + ack.len = copy_len; + if (ack.len < sector_size) ack.is_end = 1; + memcpy(ack.packet, copy_s, copy_len); return 0; } diff --git a/components/motor_laser_code_scanner/motor_laser_code_scanne.hpp b/components/motor_laser_code_scanner/motor_laser_code_scanne.hpp index e51d2d3..64272c1 100644 --- a/components/motor_laser_code_scanner/motor_laser_code_scanne.hpp +++ b/components/motor_laser_code_scanner/motor_laser_code_scanne.hpp @@ -29,9 +29,10 @@ class MotorLaserCodeScanner : public I_MotorLaserCodeScanner { // virtual int32_t stop_scan() override; // - virtual int32_t get_scan_result(scan_result_t** result) override; + virtual int32_t get_scan_result(u16 sector_index, u16 sector_size, zcancmder_read_ram_ack_t& ack) override; private: - void call_action_cb(action_cb_status_t status_cb, int32_t status); + void call_action_cb(action_cb_status_t status_cb, int32_t status); + int32_t assign_scan_result(u16 sector_index, u16 sector_size, u8* src_data, s32 src_data_len, zcancmder_read_ram_ack_t& ack); }; }; // namespace iflytop diff --git a/components/zcancmder/zcanreceiver.cpp b/components/zcancmder/zcanreceiver.cpp index bf1ed71..cba0a07 100644 --- a/components/zcancmder/zcanreceiver.cpp +++ b/components/zcancmder/zcanreceiver.cpp @@ -184,12 +184,14 @@ void ZCanCmder::sendExecStatusReport(Cmdheader_t *rxcmdheader, uint8_t *data, si sendPacket(txbuff, sizeof(Cmdheader_t) + len); } -void ZCanCmder::sendErrorAck(Cmdheader_t *cmdheader, uint32_t errcode) { +void ZCanCmder::sendErrorAck(Cmdheader_t *cmdheader, uint16_t id, uint32_t errcode) { Cmdheader_t *txheader = (Cmdheader_t *)txbuff; memcpy(txheader, cmdheader, sizeof(Cmdheader_t)); - txheader->packetType = kpt_error_ack; - memcpy(txheader->data, &errcode, sizeof(errcode)); - sendPacket(txbuff, sizeof(Cmdheader_t) + sizeof(errcode)); + txheader->packetType = kpt_error_ack; + zcan_cmder_error_ack_t *error_ack = (zcan_cmder_error_ack_t *)txheader->data; + error_ack->id = id; + error_ack->errorcode = errcode; + sendPacket(txbuff, sizeof(Cmdheader_t) + sizeof(zcan_cmder_error_ack_t)); } bool ZCanCmder::sendPacketSub(int npacket, int packetIndex, uint8_t *packet, size_t len, int overtimems) { diff --git a/components/zcancmder/zcanreceiver.hpp b/components/zcancmder/zcanreceiver.hpp index 5ff04ee..e9d84d6 100644 --- a/components/zcancmder/zcanreceiver.hpp +++ b/components/zcancmder/zcanreceiver.hpp @@ -105,7 +105,7 @@ class ZCanCmder : public ZCanIRQListener { void sendPacket(uint8_t *packet, size_t len); void sendExecStatusReport(Cmdheader_t *rxcmdheader, uint8_t *data, size_t len); void sendAck(Cmdheader_t *rxcmdheader, uint8_t *data, size_t len); - void sendErrorAck(Cmdheader_t *cmdheader, uint32_t errcode); + void sendErrorAck(Cmdheader_t *cmdheader, uint16_t id, uint32_t errcode); bool sendPacketSub(int npacket, int packetIndex, uint8_t *packet, size_t len, int overtimems); uint8_t getDeviceId() { return m_config->deviceId; } void setTxPacketInterval(int interval_ms) { txPacketInterval_ms = interval_ms; } diff --git a/components/zcancmder_module/zcan_mini_servo_ctrl_module.cpp b/components/zcancmder_module/zcan_mini_servo_ctrl_module.cpp index b08ca78..6e9fb69 100644 --- a/components/zcancmder_module/zcan_mini_servo_ctrl_module.cpp +++ b/components/zcancmder_module/zcan_mini_servo_ctrl_module.cpp @@ -6,37 +6,13 @@ void ZCanMiniServoCtrlModule::initialize(ZCanCmder* cancmder, int id, I_MiniServ m_cancmder = cancmder; m_id = id; m_module = module; + m_lock.init(); cancmder->registerListener(this); } void ZCanMiniServoCtrlModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { -#if 0 -ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_enable, CMD(u8 id; u8 enable;), ACK(u8 id;)); -ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_stop, CMD(u8 id; u8 stop_type;), ACK(u8 id;)); -ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_position_calibrate, CMD(u8 id; s32 calibrate_pos;), ACK(u8 id;)); - -ZPACKET_CMD_ACK_AND_REPORT(kcmd_mini_servo_ctrl_rotate, CMD(s32 speed; s32 torque; s32 run_time;), ACK(u8 id;), REPORT(u8 id; I_MiniServoModule::rotate_cb_status_t report;)); -ZPACKET_CMD_ACK_AND_REPORT(kcmd_mini_servo_ctrl_move_to, CMD(s32 pos; s32 speed; s32 torque;), ACK(u8 id;), REPORT(u8 id; I_MiniServoModule::move_to_cb_status_t report;)); -ZPACKET_CMD_ACK_AND_REPORT(kcmd_mini_servo_ctrl_move_by, CMD(s32 pos; s32 speed; s32 torque;), ACK(u8 id;), REPORT(u8 id; I_MiniServoModule::move_by_cb_status_t report;)); -ZPACKET_CMD_ACK_AND_REPORT(kcmd_mini_servo_ctrl_run_with_torque, CMD(s32 torque; s32 run_time;), ACK(u8 id;), REPORT(u8 id; I_MiniServoModule::run_with_torque_cb_status_t report;)); -ZPACKET_CMD_ACK_AND_REPORT(kcmd_mini_servo_ctrl_move_by_nolimit, CMD(s32 pos; s32 speed; s32 torque;), ACK(u8 id;), REPORT(u8 id; I_MiniServoModule::move_by_nolimit_cb_status_t report;)); - -ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_read_version, CMD(u8 id;), ACK(u8 id; I_MiniServoModule::version_t ack;)); -ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_read_status, CMD(u8 id;), ACK(u8 id; I_MiniServoModule::status_t ack;)); -ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_read_detailed_status, CMD(u8 id;), ACK(u8 id; I_MiniServoModule::detailed_status_t ack;)); - -ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_set_run_param, CMD(u8 id; u8 opt_type; I_MiniServoModule::run_param_t param;), ACK(u8 id; I_MiniServoModule::run_param_t ack;)); -ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_set_basic_param, CMD(u8 id; u8 opt_type; I_MiniServoModule::basic_param_t param;), ACK(u8 id; I_MiniServoModule::basic_param_t ack;)); -ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_set_warning_limit_param, CMD(u8 id; u8 opt_type; I_MiniServoModule::warning_limit_param_t param;), ACK(u8 id; I_MiniServoModule::warning_limit_param_t ack;)); - -ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_get_run_param, CMD(u8 id; u8 opt_type;), ACK(u8 id; I_MiniServoModule::run_param_t ack;)); -ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_get_basic_param, CMD(u8 id; u8 opt_type;), ACK(u8 id; I_MiniServoModule::basic_param_t ack;)); -ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_get_warning_limit_param, CMD(u8 id; u8 opt_type;), ACK(u8 id; I_MiniServoModule::warning_limit_param_t ack;)); -#endif -#if 0 - PROCESS_PACKET(kcmd_step_motor_ctrl_enable, m_id) { errorcode = m_module->enable(cmd->enable); } - END_PP(); -#endif + zlock_guard l(m_lock); + PROCESS_PACKET(kcmd_mini_servo_ctrl_enable, m_id) { errorcode = m_module->enable(cmd->enable); } END_PP(); @@ -45,77 +21,28 @@ ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_get_warning_limit_param, CMD(u8 id; u8 opt_ PROCESS_PACKET(kcmd_mini_servo_ctrl_position_calibrate, m_id) { errorcode = m_module->position_calibrate(cmd->calibrate_pos); } END_PP(); -#if 0 - PROCESS_PACKET(kcmd_xy_robot_ctrl_move_by, m_id) { // - errorcode = m_xyRobotCtrlModule->move_by(cmd->dx, cmd->dy, [this, cmdheader](I_XYRobotCtrlModule::move_by_cb_status_t& status) { - osDelay(5); // 用来保证回执消息在前面 - kcmd_xy_robot_ctrl_move_by_report_t report = {0}; - ZLOGI(TAG, "kcmd_xy_robot_ctrl_move_by exec_status:%d %d %d", status.exec_status, status.dx, status.dy); - - report.id = m_id; - report.status = status; - m_cancmder->sendExecStatusReport(cmdheader, (uint8_t*)&report, sizeof(report)); - }); - } - END_PP(); -#endif PROCESS_PACKET(kcmd_mini_servo_ctrl_rotate, m_id) { // - errorcode = m_module->rotate(cmd->speed, cmd->torque, cmd->run_time, [this, cmdheader](int32_t status) { - osDelay(5); // 用来保证回执消息在前面 - kcmd_mini_servo_ctrl_rotate_report_t report = {0}; - ZLOGI(TAG, "report kcmd_mini_servo_ctrl_rotate exec_status:%d", status); - report.id = m_id; - report.exec_status = status; - m_cancmder->sendExecStatusReport(cmdheader, (uint8_t*)&report, sizeof(report)); - }); + errorcode = m_module->rotate(cmd->speed, cmd->torque, cmd->run_time, [this, cmdheader](int32_t status) { PROCESS_REPORT(kcmd_mini_servo_ctrl_rotate); }); } END_PP(); PROCESS_PACKET(kcmd_mini_servo_ctrl_move_to, m_id) { // - errorcode = m_module->move_to(cmd->pos, cmd->speed, cmd->torque, [this, cmdheader](int32_t status) { - osDelay(5); // 用来保证回执消息在前面 - kcmd_mini_servo_ctrl_move_to_report_t report = {0}; - ZLOGI(TAG, "report kcmd_mini_servo_ctrl_move_to exec_status:%d", status); - report.id = m_id; - report.exec_status = status; - m_cancmder->sendExecStatusReport(cmdheader, (uint8_t*)&report, sizeof(report)); - }); + errorcode = m_module->move_to(cmd->pos, cmd->speed, cmd->torque, [this, cmdheader](int32_t status) { PROCESS_REPORT(kcmd_mini_servo_ctrl_move_to); }); } END_PP(); PROCESS_PACKET(kcmd_mini_servo_ctrl_move_by, m_id) { // - errorcode = m_module->move_by(cmd->pos, cmd->speed, cmd->torque, [this, cmdheader](int32_t status) { - osDelay(5); // 用来保证回执消息在前面 - kcmd_mini_servo_ctrl_move_by_report_t report = {0}; - ZLOGI(TAG, "report kcmd_mini_servo_ctrl_move_by exec_status:%d", status); - report.id = m_id; - report.exec_status = status; - m_cancmder->sendExecStatusReport(cmdheader, (uint8_t*)&report, sizeof(report)); - }); + errorcode = m_module->move_by(cmd->pos, cmd->speed, cmd->torque, [this, cmdheader](int32_t status) { PROCESS_REPORT(kcmd_mini_servo_ctrl_move_by); }); } END_PP(); PROCESS_PACKET(kcmd_mini_servo_ctrl_run_with_torque, m_id) { // - errorcode = m_module->run_with_torque(cmd->torque, cmd->run_time, [this, cmdheader](int32_t status) { - osDelay(5); // 用来保证回执消息在前面 - kcmd_mini_servo_ctrl_run_with_torque_report_t report = {0}; - ZLOGI(TAG, "report kcmd_mini_servo_ctrl_run_with_torque exec_status:%d", status); - report.id = m_id; - report.exec_status = status; - m_cancmder->sendExecStatusReport(cmdheader, (uint8_t*)&report, sizeof(report)); - }); + errorcode = m_module->run_with_torque(cmd->torque, cmd->run_time, [this, cmdheader](int32_t status) { PROCESS_REPORT(kcmd_mini_servo_ctrl_run_with_torque); }); } END_PP(); PROCESS_PACKET(kcmd_mini_servo_ctrl_move_by_nolimit, m_id) { // - errorcode = m_module->move_by_nolimit(cmd->pos, cmd->speed, cmd->torque, [this, cmdheader](int32_t status) { - osDelay(5); // 用来保证回执消息在前面 - kcmd_mini_servo_ctrl_move_by_nolimit_report_t report = {0}; - ZLOGI(TAG, "report kcmd_mini_servo_ctrl_move_by_nolimit exec_status:%d", status); - report.id = m_id; - report.exec_status = status; - m_cancmder->sendExecStatusReport(cmdheader, (uint8_t*)&report, sizeof(report)); - }); + errorcode = m_module->move_by_nolimit(cmd->pos, cmd->speed, cmd->torque, [this, cmdheader](int32_t status) { PROCESS_REPORT(kcmd_mini_servo_ctrl_move_by_nolimit); }); } END_PP(); diff --git a/components/zcancmder_module/zcan_mini_servo_ctrl_module.hpp b/components/zcancmder_module/zcan_mini_servo_ctrl_module.hpp index b640068..8837f4e 100644 --- a/components/zcancmder_module/zcan_mini_servo_ctrl_module.hpp +++ b/components/zcancmder_module/zcan_mini_servo_ctrl_module.hpp @@ -8,6 +8,7 @@ class ZCanMiniServoCtrlModule : public ZCanCmderListener { I_MiniServoModule* m_module; uint8_t m_txbuf[128] = {0}; + zmutex m_lock; public: void initialize(ZCanCmder* cancmder, int id, I_MiniServoModule* module); diff --git a/components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.cpp b/components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.cpp index aa0f423..7135719 100644 --- a/components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.cpp +++ b/components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.cpp @@ -1,4 +1,6 @@ #include "zcan_motor_laser_code_scanner_scan_module.hpp" + +#include "string.h" using namespace iflytop; #define TAG "ZcanMotorLaserCodeScannerScanModule" @@ -7,26 +9,19 @@ void ZcanMotorLaserCodeScannerScanModule::initialize(ZCanCmder* cancmder, int id m_cancmder = cancmder; m_id = id; m_module = module; + m_lock.init(); cancmder->registerListener(this); } void ZcanMotorLaserCodeScannerScanModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { -#if 0 -ZPACKET_CMD_ACK_AND_REPORT(kcmd_motor_laser_code_scanner_scan, - CMD(u8 id; // - s32 moveby_distance; // - s32 scan_interval_distance; // - s32 each_sample_times; // - s32 transmitting_tube_amplification; // 0.001 - s32 receiving_tube_amplification; // 0.001 - ), - ACK(u8 id;), REPORT(u8 id; int32_t exec_status;)); -ZPACKET_CMD_ACK(kcmd_motor_laser_code_scanner_stop_scan, CMD(u8 id;), ACK(u8 id;)); -ZPACKET_CMD_ACK(kcmd_motor_laser_code_scanner_get_scan_result, CMD(u8 id; u16 packetoff;), ACK(u8 id; u8 endpacket; u8 packetlen; u8 packet[];)); -#endif + zlock_guard l(m_lock); PROCESS_PACKET(kcmd_motor_laser_code_scanner_scan, m_id) { - errorcode = m_module->start_scan( // - cmd->moveby_distance, cmd->scan_interval_distance, cmd->each_sample_times, cmd->transmitting_tube_amplification, cmd->receiving_tube_amplification, // + errorcode = m_module->start_scan( // + cmd->moveby_distance, // + cmd->scan_interval_distance, // + cmd->each_sample_times, // + cmd->transmitting_tube_amplification, // + cmd->receiving_tube_amplification, // [this, cmdheader](int32_t status) { PROCESS_REPORT(kcmd_motor_laser_code_scanner_scan); }); } END_PP(); @@ -34,30 +29,7 @@ ZPACKET_CMD_ACK(kcmd_motor_laser_code_scanner_get_scan_result, CMD(u8 id; u16 pa PROCESS_PACKET(kcmd_motor_laser_code_scanner_stop_scan, m_id) { errorcode = m_module->stop_scan(); } END_PP(); - if (rxcmd->iscmd(kcmd_motor_laser_code_scanner_get_scan_result)) { - #if 0 - auto* cmd = rxcmd->get_data_as(); - auto cmdheader = rxcmd->get_cmdheader(); - uint32_t errorcode = 0; - if (cmd->id == m_id) { - - I_MotorLaserCodeScanner::scan_result_t* result = nullptr; - u8 packetoff = cmd->packetoff; - errorcode = m_module->get_scan_result(&result); - - - if (errorcode == 0) { - } - // scan_result_t* result; - if (errorcode == 0) { - m_cancmder->sendAck(rxcmd->get_cmdheader(), m_txbuf, sizeof(*ack)); - } else { - m_cancmder->sendErrorAck(rxcmd->get_cmdheader(), errorcode); - } - return; - - } - #endif - } + PROCESS_PACKET(kcmd_motor_laser_code_scanner_get_scan_result, m_id) { errorcode = m_module->get_scan_result(cmd->sector_index, cmd->sector_size, ack->ack); } + END_PP(); } #endif \ No newline at end of file diff --git a/components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.hpp b/components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.hpp index 43c3793..3032ee7 100644 --- a/components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.hpp +++ b/components/zcancmder_module/zcan_motor_laser_code_scanner_scan_module.hpp @@ -3,6 +3,7 @@ // #include "sdk/components/zprotocols/zcancmder/api/i_pipette_module.hpp" #include "sdk/components/zprotocols/zcancmder/api/i_motor_laser_code_scanner.hpp" #include "sdk\components\zcancmder\zcanreceiver.hpp" +#include "sdk\os\zos.hpp" namespace iflytop { class ZcanMotorLaserCodeScannerScanModule : public ZCanCmderListener { @@ -11,6 +12,7 @@ class ZcanMotorLaserCodeScannerScanModule : public ZCanCmderListener { I_MotorLaserCodeScanner* m_module; uint8_t m_txbuf[512] = {0}; + zmutex m_lock; public: void initialize(ZCanCmder* cancmder, int id, I_MotorLaserCodeScanner* module); diff --git a/components/zcancmder_module/zcan_pipette_module.cpp b/components/zcancmder_module/zcan_pipette_module.cpp index 11e021e..9677f5d 100644 --- a/components/zcancmder_module/zcan_pipette_module.cpp +++ b/components/zcancmder_module/zcan_pipette_module.cpp @@ -7,9 +7,12 @@ void ZcanPipetteModule::initialize(ZCanCmder* cancmder, int id, I_PipetteModule* m_cancmder = cancmder; m_id = id; m_module = module; + m_lock.init(); cancmder->registerListener(this); } void ZcanPipetteModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { + zlock_guard l(m_lock); + PROCESS_PACKET(kcmd_pipette_module_enable, m_id) { errorcode = m_module->enable(cmd->enable); } END_PP(); PROCESS_PACKET(kcmd_pipette_module_stop, m_id) { errorcode = m_module->stop(cmd->stop_type); } diff --git a/components/zcancmder_module/zcan_pipette_module.hpp b/components/zcancmder_module/zcan_pipette_module.hpp index 575c717..0081f46 100644 --- a/components/zcancmder_module/zcan_pipette_module.hpp +++ b/components/zcancmder_module/zcan_pipette_module.hpp @@ -10,6 +10,7 @@ class ZcanPipetteModule : public ZCanCmderListener { I_PipetteModule* m_module; uint8_t m_txbuf[128] = {0}; + zmutex m_lock; public: void initialize(ZCanCmder* cancmder, int id, I_PipetteModule* module); diff --git a/components/zcancmder_module/zcan_step_motor_ctrl_module.cpp b/components/zcancmder_module/zcan_step_motor_ctrl_module.cpp index dab4af6..af2ca1e 100644 --- a/components/zcancmder_module/zcan_step_motor_ctrl_module.cpp +++ b/components/zcancmder_module/zcan_step_motor_ctrl_module.cpp @@ -7,10 +7,11 @@ void ZCanStepMotorCtrlModule::initialize(ZCanCmder* cancmder, int id, I_StepMoto m_cancmder = cancmder; m_id = id; m_module = module; + m_lock.init(); cancmder->registerListener(this); } void ZCanStepMotorCtrlModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { - // printf("ZCanStepMotorCtrlModule::onRceivePacket %d %d\n", rxcmd->get_cmdheader()->cmdid, rxcmd->get_cmdheader()->subcmdid); + zlock_guard l(m_lock); PROCESS_PACKET(kcmd_step_motor_ctrl_enable, m_id) { errorcode = m_module->enable(cmd->enable); } END_PP(); @@ -19,54 +20,21 @@ void ZCanStepMotorCtrlModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { END_PP(); PROCESS_PACKET(kcmd_step_motor_ctrl_move_to_zero, m_id) { - errorcode = m_module->move_to_zero([this, cmdheader](int32_t status) { - osDelay(5); // 用来保证回执消息在前面 - kcmd_step_motor_ctrl_move_to_zero_report_t report = {0}; - ZLOGI(TAG, "kcmd_step_motor_ctrl_move_to_zero exec_status:%d", status); - - report.id = m_id; - report.exec_status = status; - m_cancmder->sendExecStatusReport(cmdheader, (uint8_t*)&report, sizeof(report)); - }); + errorcode = m_module->move_to_zero([this, cmdheader](int32_t status) { PROCESS_REPORT(kcmd_step_motor_ctrl_move_to_zero); }); } END_PP(); PROCESS_PACKET(kcmd_step_motor_ctrl_move_to_zero_with_calibrate, m_id) { - errorcode = m_module->move_to_zero_with_calibrate(cmd->nowx, [this, cmdheader](int32_t status) { - osDelay(5); // 用来保证回执消息在前面 - kcmd_step_motor_ctrl_move_to_zero_with_calibrate_report_t report = {0}; - ZLOGI(TAG, "kcmd_step_motor_ctrl_move_to_zero_with_calibrate exec_status:%d", status); - - report.id = m_id; - report.exec_status = status; - m_cancmder->sendExecStatusReport(cmdheader, (uint8_t*)&report, sizeof(report)); - }); + errorcode = m_module->move_to_zero_with_calibrate(cmd->nowx, [this, cmdheader](int32_t status) { PROCESS_REPORT(kcmd_step_motor_ctrl_move_to_zero_with_calibrate); }); } END_PP(); PROCESS_PACKET(kcmd_step_motor_ctrl_move_to, m_id) { - errorcode = m_module->move_to(cmd->x, [this, cmdheader](int32_t status) { - osDelay(5); // 用来保证回执消息在前面 - kcmd_step_motor_ctrl_move_to_report_t report = {0}; - ZLOGI(TAG, "kcmd_step_motor_ctrl_move_to exec_status:%d ", status); - - report.id = m_id; - report.exec_status = status; - m_cancmder->sendExecStatusReport(cmdheader, (uint8_t*)&report, sizeof(report)); - }); + errorcode = m_module->move_to(cmd->x, [this, cmdheader](int32_t status) { PROCESS_REPORT(kcmd_step_motor_ctrl_move_to); }); } END_PP(); PROCESS_PACKET(kcmd_step_motor_ctrl_move_by, m_id) { - errorcode = m_module->move_by(cmd->dx, [this, cmdheader](int32_t status) { - osDelay(5); // 用来保证回执消息在前面 - kcmd_step_motor_ctrl_move_by_report_t report = {0}; - // ZLOGI(TAG, "kcmd_step_motor_ctrl_move_by exec_status:%d %d", status.exec_status, status.dx); - ZLOGI(TAG, "kcmd_step_motor_ctrl_move_by exec_status:%d ", status); - - report.id = m_id; - report.exec_status = status; - m_cancmder->sendExecStatusReport(cmdheader, (uint8_t*)&report, sizeof(report)); - }); + errorcode = m_module->move_by(cmd->dx, [this, cmdheader](int32_t status) { PROCESS_REPORT(kcmd_step_motor_ctrl_move_by); }); } END_PP(); @@ -74,16 +42,7 @@ void ZCanStepMotorCtrlModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { END_PP(); PROCESS_PACKET(kcmd_step_motor_ctrl_rotate, m_id) { - errorcode = m_module->rotate(cmd->speed, cmd->run_time, [this, cmdheader](int32_t status) { - osDelay(5); // 用来保证回执消息在前面 - kcmd_step_motor_ctrl_rotate_report_t report = {0}; - // ZLOGI(TAG, "kcmd_step_motor_ctrl_rotate exec_status:%d %d", status.exec_status, status.lastforms); - ZLOGI(TAG, "kcmd_step_motor_ctrl_rotate exec_status:%d ", status); - - report.id = m_id; - report.exec_status = status; - m_cancmder->sendExecStatusReport(cmdheader, (uint8_t*)&report, sizeof(report)); - }); + errorcode = m_module->rotate(cmd->speed, cmd->run_time, [this, cmdheader](int32_t status) { PROCESS_REPORT(kcmd_step_motor_ctrl_rotate); }); } END_PP(); @@ -111,6 +70,5 @@ void ZCanStepMotorCtrlModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { errorcode = m_module->get_base_param(ack->ack); } END_PP(); - } #endif \ No newline at end of file diff --git a/components/zcancmder_module/zcan_step_motor_ctrl_module.hpp b/components/zcancmder_module/zcan_step_motor_ctrl_module.hpp index a65ad4b..f85882d 100644 --- a/components/zcancmder_module/zcan_step_motor_ctrl_module.hpp +++ b/components/zcancmder_module/zcan_step_motor_ctrl_module.hpp @@ -8,6 +8,7 @@ class ZCanStepMotorCtrlModule : public ZCanCmderListener { I_StepMotorCtrlModule* m_module; uint8_t m_txbuf[128] = {0}; + zmutex m_lock; public: void initialize(ZCanCmder* cancmder, int id, I_StepMotorCtrlModule* m_module); diff --git a/components/zcancmder_module/zcan_xy_robot_module.cpp b/components/zcancmder_module/zcan_xy_robot_module.cpp index ac96a50..0b0c38a 100644 --- a/components/zcancmder_module/zcan_xy_robot_module.cpp +++ b/components/zcancmder_module/zcan_xy_robot_module.cpp @@ -7,10 +7,11 @@ void ZCANXYRobotCtrlModule::initialize(ZCanCmder* cancmder, int id, I_XYRobotCtr m_cancmder = cancmder; m_id = id; m_xyRobotCtrlModule = xyRobotCtrlModule; + m_lock.init(); cancmder->registerListener(this); } void ZCANXYRobotCtrlModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { - // printf("ZCANXYRobotCtrlModule::onRceivePacket %d %d\n", rxcmd->get_cmdheader()->cmdid, rxcmd->get_cmdheader()->subcmdid); + zlock_guard l(m_lock); PROCESS_PACKET(kcmd_xy_robot_ctrl_enable, m_id) { // errorcode = m_xyRobotCtrlModule->enable(cmd->enable); diff --git a/components/zcancmder_module/zcan_xy_robot_module.hpp b/components/zcancmder_module/zcan_xy_robot_module.hpp index 435498d..c01a26f 100644 --- a/components/zcancmder_module/zcan_xy_robot_module.hpp +++ b/components/zcancmder_module/zcan_xy_robot_module.hpp @@ -9,6 +9,7 @@ class ZCANXYRobotCtrlModule : public ZCanCmderListener { I_XYRobotCtrlModule* m_xyRobotCtrlModule; uint8_t m_txbuf[128] = {0}; + zmutex m_lock; public: void initialize(ZCanCmder* cancmder, int id, I_XYRobotCtrlModule* xyRobotCtrlModule); diff --git a/components/zprotocols/errorcode b/components/zprotocols/errorcode index 3ea1062..e59570a 160000 --- a/components/zprotocols/errorcode +++ b/components/zprotocols/errorcode @@ -1 +1 @@ -Subproject commit 3ea10620670f4d40e220ed2ac75df734065fe3a6 +Subproject commit e59570a8472eb15a8fc4d43e1f9f9d50fdf3d614 diff --git a/components/zprotocols/zcancmder b/components/zprotocols/zcancmder index f42c8b0..20e1197 160000 --- a/components/zprotocols/zcancmder +++ b/components/zprotocols/zcancmder @@ -1 +1 @@ -Subproject commit f42c8b067d48afa49e565c02e81827deaba10bb5 +Subproject commit 20e1197365b8384b7168085f75818d475d2add22