Browse Source

update

master
zhaohe 2 years ago
parent
commit
1cf026cdba
  1. 2
      dep/zlinuxcomponents
  2. 22
      src/service/a8000_scirpt_processer.cpp
  3. 4
      src/service/a8000_scirpt_processer.hpp
  4. 28
      src/service/scirpt_processer.cpp

2
dep/zlinuxcomponents

@ -1 +1 @@
Subproject commit f34921f0c541f97c487dd39c07f75a64308f0606
Subproject commit 432d59aa981a3a05e1937d71fdcf8e8f241f35d9

22
src/service/a8000_scirpt_processer.cpp

@ -48,7 +48,7 @@ int32_t A8000ScriptProcesser::sendCanPacket(shared_ptr<ScriptProcesser::Context>
string cmd = context->cmd;
vector<string>& cmdandvar = context->cmd_and_var;
shared_ptr<icps::Packet> 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<ScriptProcesser::Conte
A8000ScriptProcesser::CtrlPointConfig cpcfg = getStepMotorConfig(targetStepMotorId, SAMC_REG_STAT_CURRENT_POS);
readReg(cpcfg.m_deviceId, cpcfg.m_ctrlPointId, pos, context);
}
void A8000ScriptProcesser::step_motor_is_idle(shared_ptr<ScriptProcesser::Context> context, int32_t targetStepMotorId, int32_t& idle) {}
void A8000ScriptProcesser::step_motor_read_state(shared_ptr<ScriptProcesser::Context> 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<ScriptProcesser::Context>
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<ScriptProcesser::Context> 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<ScriptProcesser::Context> context, int32_t ms) { usleep(ms * 1000); }
void A8000ScriptProcesser::step_motor_wait_for_idle(shared_ptr<ScriptProcesser::Context> 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<ScriptProcesser::Context> 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<ScriptProcesser::Context> 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));
}
//
//

4
src/service/a8000_scirpt_processer.hpp

@ -53,7 +53,7 @@ class A8000ScriptProcesser : public enable_shared_from_this<A8000ScriptProcesser
shared_ptr<IflytopCanProtocolControler> m_iflytopCanProtocolControler;
shared_ptr<ScriptProcesser> m_scriptProcesser;
int index = 0;
uint16_t index = 0;
class CtrlPointConfig {
public:
@ -113,8 +113,8 @@ class A8000ScriptProcesser : public enable_shared_from_this<A8000ScriptProcesser
void step_motor_move_to_zero(shared_ptr<ScriptProcesser::Context> context, int32_t targetStepMotorId);
void step_motor_read_pos(shared_ptr<ScriptProcesser::Context> context, int32_t targetStepMotorId, int32_t &pos);
void step_motor_read_state(shared_ptr<ScriptProcesser::Context> context, int32_t targetStepMotorId, int32_t &state);
void step_motor_is_idle(shared_ptr<ScriptProcesser::Context> context, int32_t targetStepMotorId, int32_t &idle);
void step_motor_stop(shared_ptr<ScriptProcesser::Context> context, int32_t targetStepMotorId);
void step_motor_clear_exception(shared_ptr<ScriptProcesser::Context> context, int32_t targetStepMotorId);
void sleep_ms(shared_ptr<ScriptProcesser::Context> context, int32_t ms);
void step_motor_wait_for_idle(shared_ptr<ScriptProcesser::Context> context, int32_t targetStepMotorId);

28
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;
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);
}

Loading…
Cancel
Save