From 541da22a0f3afd3b6f8b55646d6cca7958512dc0 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sat, 14 Oct 2023 22:27:45 +0800 Subject: [PATCH] update --- components/cmdscheduler/cmd_scheduler.cpp | 9 ++---- components/cmdscheduler/cmd_scheduler.hpp | 1 - components/eq_20_asb_motor/eq20_servomotor.cpp | 39 +++++++++++++++----------- components/hardware/uart/zuart_helper.cpp | 9 ++++-- components/modbus/modbus_block_host.cpp | 14 ++++----- 5 files changed, 37 insertions(+), 35 deletions(-) diff --git a/components/cmdscheduler/cmd_scheduler.cpp b/components/cmdscheduler/cmd_scheduler.cpp index cb3c16a..6021d3f 100644 --- a/components/cmdscheduler/cmd_scheduler.cpp +++ b/components/cmdscheduler/cmd_scheduler.cpp @@ -13,16 +13,10 @@ void CmdScheduler::registerCmd(std::string cmd, const char* helpinfo, int npara, CMD cmdinfo; cmdinfo.call_cmd = call_cmd; cmdinfo.help_info = helpinfo; - m_cmdMap[cmd] = cmdinfo; cmdinfo.npara = npara; -} - -void CmdScheduler::registerCmd(std::string cmd, call_cmd_t call_cmd) { - CMD cmdinfo; - cmdinfo.call_cmd = call_cmd; - cmdinfo.help_info = "..."; m_cmdMap[cmd] = cmdinfo; } + void CmdScheduler::regbasiccmd() { this->registerCmd("help", "", 0, [this](Context* context) { ZLOGI(TAG, "help"); @@ -115,6 +109,7 @@ int32_t CmdScheduler::callcmd(const char* cmd) { Context context; context.argc = argc; context.argv = argv; + // ZLOGI(TAG, "callcmd:argc %d %d", argc, cmder->second.npara); if (cmder->second.npara != context.argc - 1) return err::kce_cmd_param_num_error; int32_t ret = cmder->second.call_cmd(&context); if (ret == 0) { diff --git a/components/cmdscheduler/cmd_scheduler.hpp b/components/cmdscheduler/cmd_scheduler.hpp index 06bba17..fe0e66a 100644 --- a/components/cmdscheduler/cmd_scheduler.hpp +++ b/components/cmdscheduler/cmd_scheduler.hpp @@ -67,7 +67,6 @@ class CmdScheduler { public: void initialize(UART_HandleTypeDef* huart, uint32_t rxbufsize); - void registerCmd(std::string cmd, call_cmd_t call_cmd); void registerCmd(std::string cmd, const char* helpinfo, int npara, call_cmd_t call_cmd); void tx(const char* data, int len); diff --git a/components/eq_20_asb_motor/eq20_servomotor.cpp b/components/eq_20_asb_motor/eq20_servomotor.cpp index 51c6e51..8733e6e 100644 --- a/components/eq_20_asb_motor/eq20_servomotor.cpp +++ b/components/eq_20_asb_motor/eq20_servomotor.cpp @@ -16,13 +16,21 @@ void Eq20ServoMotor::init(ModbusBlockHost *modbusBlockHost, int id) { ZASSERT(m_modbusBlockHost != NULL); } -#define DO(exptr) \ - { \ - int32_t __ret = exptr; \ - if (__ret != 0) { \ - ZLOGE(TAG, "do %s %d", #exptr, __ret); \ - return __ret; \ - } \ +#define DO(exptr) \ + { \ + int32_t __ret = exptr; \ + if (__ret != 0) { \ + ZLOGE(TAG, "do %s fail,%d ", #exptr, __ret); \ + return __ret; \ + } \ + } + +#define DO_NOLOG(exptr) \ + { \ + int32_t __ret = exptr; \ + if (__ret != 0) { \ + return __ret; \ + } \ } int32_t Eq20ServoMotor::move_to(int32_t topos, int32_t rpm, int32_t acctime) { @@ -123,13 +131,14 @@ int32_t Eq20ServoMotor::get_servo_internal_state(servo_internal_status_t &state) } #define AUTO_RESEND(exptr) \ - int ret = 0; \ + int32_t ret = 0; \ for (size_t i = 0; i < m_auto_resendtimes; i++) { \ ret = exptr; \ if (ret == 0) { \ return 0; \ } \ - } + } \ + return ret; int32_t Eq20ServoMotor::writereg(uint32_t regadd, int32_t value) { // AUTO_RESEND(_writereg(regadd, value)); @@ -161,27 +170,25 @@ int32_t Eq20ServoMotor::_read_pn_bit(uint32_t pnadd, int32_t off, int32_t &value * REG * *******************************************************************************/ int32_t Eq20ServoMotor::_writereg(uint32_t regadd, int32_t value) { // - DO(m_modbusBlockHost->writeReg10Muti(m_deviceId, regadd, (uint16_t *)&value, 2, 100)); - return 0; + return m_modbusBlockHost->writeReg10Muti(m_deviceId, regadd, (uint16_t *)&value, 2, 100); } int32_t Eq20ServoMotor::_readreg(uint32_t regadd, int32_t &value) { // - DO(m_modbusBlockHost->readReg03Muti(m_deviceId, regadd, (uint16_t *)&value, 2, 100)); - return 0; + return m_modbusBlockHost->readReg03Muti(m_deviceId, regadd, (uint16_t *)&value, 2, 100); } int32_t Eq20ServoMotor::_write_reg_bit(uint32_t regadd, int32_t off, int32_t value) { int32_t regval; - DO(_readreg(regadd, regval)); + DO_NOLOG(_readreg(regadd, regval)); if (value) { regval |= (1 << off); } else { regval &= ~(1 << off); } - DO(_writereg(regadd, regval)); + DO_NOLOG(_writereg(regadd, regval)); return 0; } int32_t Eq20ServoMotor::_read_reg_bit(uint32_t regadd, int32_t off, int32_t &value) { int32_t regval; - DO(_readreg(regadd, regval)); + DO_NOLOG(_readreg(regadd, regval)); value = (regval >> off) & 0x01; return 0; } \ No newline at end of file diff --git a/components/hardware/uart/zuart_helper.cpp b/components/hardware/uart/zuart_helper.cpp index 8f606e1..4f24880 100644 --- a/components/hardware/uart/zuart_helper.cpp +++ b/components/hardware/uart/zuart_helper.cpp @@ -1,6 +1,9 @@ #include "zuart_helper.hpp" + +#include "sdk\components\zprotocols\errorcode\errorcode.hpp" + using namespace iflytop; -#define DEBUG 0 +#define DEBUG 1 #if DEBUG static void dumphex(char* tag, uint8_t* data, uint8_t len) { printf("%s:", tag); @@ -55,7 +58,7 @@ int32_t ZUARTHelper::tx_and_rx(uint8_t* tx, uint8_t txdatalen, uint8_t* rx, uint } HAL_UART_DMAStop(m_uart); if (overtime_flag) { - return false; + return err::kce_overtime; } - return true; + return 0; } \ No newline at end of file diff --git a/components/modbus/modbus_block_host.cpp b/components/modbus/modbus_block_host.cpp index 92ef834..5e3f0db 100644 --- a/components/modbus/modbus_block_host.cpp +++ b/components/modbus/modbus_block_host.cpp @@ -6,16 +6,14 @@ using namespace iflytop; #define TAG "ModbusBlockHost" -#define DO(exptr) \ - { \ - int32_t __ret = exptr; \ - if (__ret != 0) { \ - ZLOGE(TAG, "do %s %d", #exptr, __ret); \ - return __ret; \ - } \ +#define DO(exptr) \ + { \ + int32_t __ret = exptr; \ + if (__ret != 0) { \ + return __ret; \ + } \ } -#define DEBUG 0 ModbusBlockHost::ModbusBlockHost() {} ModbusBlockHost::~ModbusBlockHost() {}