diff --git a/dep/zlinuxcomponents b/dep/zlinuxcomponents index f34921f..432d59a 160000 --- a/dep/zlinuxcomponents +++ b/dep/zlinuxcomponents @@ -1 +1 @@ -Subproject commit f34921f0c541f97c487dd39c07f75a64308f0606 +Subproject commit 432d59aa981a3a05e1937d71fdcf8e8f241f35d9 diff --git a/src/service/a8000_scirpt_processer.cpp b/src/service/a8000_scirpt_processer.cpp index 1f21bf9..d7624f3 100644 --- a/src/service/a8000_scirpt_processer.cpp +++ b/src/service/a8000_scirpt_processer.cpp @@ -48,7 +48,7 @@ int32_t A8000ScriptProcesser::sendCanPacket(shared_ptr string cmd = context->cmd; vector& cmdandvar = context->cmd_and_var; shared_ptr rxpacket; - m_iflytopCanProtocolControler->sendCanPacket(txpacket, rxpacket, 30); + m_iflytopCanProtocolControler->sendCanPacket(txpacket, rxpacket, 50); if (!rxpacket) { context->printfInfo = fmt::format("error:overtime"); logger->error("sendCanPacket error:overtime"); @@ -150,7 +150,6 @@ void A8000ScriptProcesser::step_motor_read_pos(shared_ptr context, int32_t targetStepMotorId, int32_t& idle) {} void A8000ScriptProcesser::step_motor_read_state(shared_ptr context, int32_t targetStepMotorId, int32_t& state) { A8000ScriptProcesser::CtrlPointConfig cpcfg = getStepMotorConfig(targetStepMotorId, SAMC_REG_STAT_STATUS); readReg(cpcfg.m_deviceId, cpcfg.m_ctrlPointId, state, context); @@ -159,14 +158,19 @@ void A8000ScriptProcesser::step_motor_stop(shared_ptr A8000ScriptProcesser::CtrlPointConfig cpcfg = getStepMotorConfig(targetStepMotorId, SAMC_REG_ACT_STOP); writeReg(cpcfg.m_deviceId, cpcfg.m_ctrlPointId, 0, context); } +void A8000ScriptProcesser::step_motor_clear_exception(shared_ptr context, int32_t targetStepMotorId) { + A8000ScriptProcesser::CtrlPointConfig cpcfg = getStepMotorConfig(targetStepMotorId, SAMC_REG_ACT_CLEAR_EXCEPTION); + writeReg(cpcfg.m_deviceId, cpcfg.m_ctrlPointId, 0, context); +} + void A8000ScriptProcesser::sleep_ms(shared_ptr context, int32_t ms) { usleep(ms * 1000); } void A8000ScriptProcesser::step_motor_wait_for_idle(shared_ptr context, int32_t targetStepMotorId) { int32_t state = 0; - step_motor_is_idle(context, targetStepMotorId, state); + step_motor_read_state(context, targetStepMotorId, state); // ThisThread thisThread; while (state != 0) { usleep(300 * 1000); - step_motor_is_idle(context, targetStepMotorId, state); + step_motor_read_state(context, targetStepMotorId, state); logger->info("step_motor({}) wait_for_idle:{}", targetStepMotorId, state); } } @@ -281,13 +285,12 @@ void A8000ScriptProcesser::docmd(shared_ptr context) { CHECK_CMD_PARAMETER(1); int32_t retval = 0; step_motor_read_state(context, context->getvarInt(1), retval); - } else if (cmd == "step_motor_is_idle") { - CHECK_CMD_PARAMETER(1); - int32_t retval = 0; - step_motor_is_idle(context, context->getvarInt(1), retval); } else if (cmd == "step_motor_stop") { CHECK_CMD_PARAMETER(1); step_motor_stop(context, context->getvarInt(1)); + } else if (cmd == "step_motor_clear_exception") { + CHECK_CMD_PARAMETER(1); + step_motor_clear_exception(context, context->getvarInt(1)); } else if (cmd == "step_motor_wait_for_idle") { CHECK_CMD_PARAMETER(1); step_motor_wait_for_idle(context, context->getvarInt(1)); @@ -313,6 +316,9 @@ void A8000ScriptProcesser::docmd(shared_ptr context) { } else if (cmd == "scara_wait_for_idle") { CHECK_CMD_PARAMETER(1); scara_wait_for_idle(context, context->getvarInt(1)); + } else if (cmd == "sleep_ms") { + CHECK_CMD_PARAMETER(1); + sleep_ms(context, context->getvarInt(1)); } // // diff --git a/src/service/a8000_scirpt_processer.hpp b/src/service/a8000_scirpt_processer.hpp index aeb1560..b021064 100644 --- a/src/service/a8000_scirpt_processer.hpp +++ b/src/service/a8000_scirpt_processer.hpp @@ -53,7 +53,7 @@ class A8000ScriptProcesser : public enable_shared_from_this m_iflytopCanProtocolControler; shared_ptr m_scriptProcesser; - int index = 0; + uint16_t index = 0; class CtrlPointConfig { public: @@ -113,8 +113,8 @@ class A8000ScriptProcesser : public enable_shared_from_this context, int32_t targetStepMotorId); void step_motor_read_pos(shared_ptr context, int32_t targetStepMotorId, int32_t &pos); void step_motor_read_state(shared_ptr context, int32_t targetStepMotorId, int32_t &state); - void step_motor_is_idle(shared_ptr context, int32_t targetStepMotorId, int32_t &idle); void step_motor_stop(shared_ptr context, int32_t targetStepMotorId); + void step_motor_clear_exception(shared_ptr context, int32_t targetStepMotorId); void sleep_ms(shared_ptr context, int32_t ms); void step_motor_wait_for_idle(shared_ptr context, int32_t targetStepMotorId); diff --git a/src/service/scirpt_processer.cpp b/src/service/scirpt_processer.cpp index 4438a17..2a86239 100644 --- a/src/service/scirpt_processer.cpp +++ b/src/service/scirpt_processer.cpp @@ -86,9 +86,33 @@ void ScriptProcesser::_executeCommand(string cmd, string& result) { logger->info("do: {} ==> {}", cmd, context->printfInfo); } -void ScriptProcesser::executeCommand(string cmd, string& result) { // +void ScriptProcesser::executeCommand(string scriptcmd, string& result) { // unique_ptr thread; - thread.reset(new Thread("executeCommand", [this, cmd, &result]() { _executeCommand(cmd, result); })); + thread.reset(new Thread("executeCommand", [this, scriptcmd, &result]() { + // _executeCommand(cmd, result); + logger->info("script_thread start"); + + // ZLOGI(TAG, "cmdstr1: %s %d %d", cmdstr, strlen(cmdstr), m_uart.getRxDataLen()); + char* cmdstr = strdup(scriptcmd.c_str()); + int cmdstr_len = strlen(cmdstr); + string strresult; + for (size_t i = 0; i < cmdstr_len; i++) { + if (cmdstr[i] == '\r' || cmdstr[i] == '\n') { + cmdstr[i] = '\0'; + } + } + // ZLOGI(TAG, "cmdstr2: %s %d %d", cmdstr, strlen(cmdstr), m_uart.getRxDataLen()); + for (size_t i = 0; i < cmdstr_len; i++) { + if (cmdstr[i] != '\0') { + string cmd = string(&cmdstr[i]); + _executeCommand(cmd, strresult); + result += strresult + "\n"; + i = cmd.size() + i; + } + } + + logger->info("script_thread end"); + })); while (!thread->isWaitingForJoin()) { usleep(100 * 1000); }