From 02924767b0aba7f226ba1a445e054c0041c99853 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sat, 4 Nov 2023 22:13:01 +0800 Subject: [PATCH] update --- components/cmdscheduler/cmd_scheduler_v2.cpp | 4 +- .../step_motor_ctrl_module.cpp | 4 +- ...o_computer_module_device_script_cmder_paser.cpp | 55 +++++++++++++++++++++- ...o_computer_module_device_script_cmder_paser.hpp | 3 ++ 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/components/cmdscheduler/cmd_scheduler_v2.cpp b/components/cmdscheduler/cmd_scheduler_v2.cpp index e969276..a0baa77 100644 --- a/components/cmdscheduler/cmd_scheduler_v2.cpp +++ b/components/cmdscheduler/cmd_scheduler_v2.cpp @@ -45,7 +45,7 @@ void CmdSchedulerV2::initialize(ZIUartReceiver* receiver) { // m_uart->initialize(&cfg); m_uart->startRx([this](uint8_t* data, size_t len) { if (m_dataisready) return; - if(len == 0) return; + if (len == 0) return; memcpy(rxbuf, data, len); rxbuf[len] = '\0'; m_rxsize = len; @@ -142,7 +142,7 @@ int32_t CmdSchedulerV2::callcmd(const char* cmd, ICmdParserACK* ack) { */ auto cmder = m_cmdMap.find(string(argv[0])); if (cmder != m_cmdMap.end()) { - if (cmder->second.npara != argc - 1) { + if (cmder->second.npara >= 0 && cmder->second.npara != argc - 1) { ack->ecode = err::kcmd_param_num_error; return err::kcmd_param_num_error; } diff --git a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp index 3480a88..a84bf83 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp @@ -901,7 +901,7 @@ int32_t StepMotorCtrlModule::motor_easy_move_by(int32_t distance) { m_status_cb = nullptr; m_thread.stop(); return motor_move_by(distance, m_param.maxspeed, m_param.acc); - 0; + }; int32_t StepMotorCtrlModule::motor_easy_move_to(int32_t position) { zlock_guard lock(m_lock); @@ -916,4 +916,4 @@ int32_t StepMotorCtrlModule::motor_easy_move_to_zero(int32_t direction) { } else { return err::koperation_not_support; } -}; \ No newline at end of file +}; diff --git a/components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.cpp b/components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.cpp index 35fcef7..5b050fa 100644 --- a/components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.cpp +++ b/components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.cpp @@ -353,11 +353,64 @@ void MicroComputerModuleDeviceScriptCmderPaser::initialize(ICmdParser* cancmder, m_cmdParser = cancmder; m_deviceManager = deviceManager; - cancmder->regCMD("dumpreg", "dumpreg (mid)", 1, [this](int32_t paramN, const char* paraV[], ICmdParserACK* ack) { do_dumpreg(paramN, paraV, ack); }); + cancmder->regCMD("dumpreg", "(mid)", 1, [this](int32_t paramN, const char* paraV[], ICmdParserACK* ack) { do_dumpreg(paramN, paraV, ack); }); cancmder->regCMD("scanmodule", "()", 0, [this](int32_t paramN, const char* paraV[], ICmdParserACK* ack) { do_scan_module(paramN, paraV, ack); }); deviceManager->regOnRegValChangeEvent([this](int32_t moduleid, int32_t event_id, int32_t eventval) { // ZLOGI(TAG, "onRegValChangeEvent(%d,%d,%d)", moduleid, event_id, eventval); }); + + cancmder->regCMD("app_wait_for_module", "(mid,timeout)", -1, [this](int32_t paramN, const char* paraV[], ICmdParserACK* ack) { + do_wait_for_module(paramN, paraV, ack); + }); +} + +void MicroComputerModuleDeviceScriptCmderPaser::do_wait_for_module(int32_t paramN, const char* paraV[], ICmdParserACK* ack) { + if (paramN < 1) { + ack->ecode = err::kcmd_param_num_error; + return; + } + if (paramN > 2) { + ack->ecode = err::kcmd_param_num_error; + return; + } + + int32_t moduleId = atoi(paraV[0]); + int32_t timeout = 0; + if (paramN == 2) { + timeout = atoi(paraV[1]); + } + return do_wait_for_module(moduleId, timeout, ack); +} +void MicroComputerModuleDeviceScriptCmderPaser::do_wait_for_module(int32_t moduleid, int32_t timeout, ICmdParserACK* ack) { + ThisThread thisThread; + int32_t remaining = timeout; + int32_t i = 0; + while (!thisThread.getExitFlag()) { + int32_t status = 0; + int32_t ecode = m_deviceManager->module_get_status(moduleid, &status); + if (ecode == 0 && status == 0) { + ZLOGI(TAG, "wait for module %d ok", moduleid); + ack->ecode = 0; + return; + } + + /** + * @brief ³¬Ê±Í˳ö + */ + if (timeout > 0) { + remaining -= 30; + if (remaining <= 0) { + ack->ecode = err::kovertime; + return; + } + } + /** + * @brief + */ + i++; + if (i % 10 == 0) ZLOGI(TAG, "wait for module %d %d", moduleid, status); + thisThread.sleep(30); + } } void MicroComputerModuleDeviceScriptCmderPaser::do_scan_module(int32_t paramN, const char* paraV[], ICmdParserACK* ack) { diff --git a/components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.hpp b/components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.hpp index bc6a0b8..5a48e39 100644 --- a/components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.hpp +++ b/components/zprotocol_helper/micro_computer_module_device_script_cmder_paser.hpp @@ -17,6 +17,9 @@ class MicroComputerModuleDeviceScriptCmderPaser : public ZModuleDeviceScriptCmde void do_dumpstate(int32_t moduleId) {} void do_scan_module(int32_t paramN, const char* paraV[], ICmdParserACK* ack); + + void do_wait_for_module(int32_t paramN, const char* paraV[], ICmdParserACK* ack); + void do_wait_for_module(int32_t moduleid, int32_t timeout, ICmdParserACK* ack); }; } // namespace iflytop