From 9d8c71e2bea33fa9590e666c93c7267c41b71d34 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Wed, 5 Jun 2024 18:39:27 +0800 Subject: [PATCH] update --- .../step_motor_ctrl_module/step_motor_ctrl_module.cpp | 14 ++++++++++---- .../step_motor_ctrl_module/step_motor_ctrl_module.hpp | 3 +-- components/tmc/ic/ztmc5130.hpp | 4 ++-- components/zcancmder/zcan_protocol_parser.cpp | 6 +++--- components/zcancmder/zcan_protocol_parser.hpp | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) 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 11d4d6d..d249ac1 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp @@ -70,7 +70,7 @@ int32_t StepMotorCtrlModule::module_xxx_reg(int32_t param_id, bool read, int32_t case kreg_step_motor_iholddelay: case kreg_step_motor_max_d: case kreg_step_motor_min_d: - return 0; + return 0; } return suc; } @@ -150,8 +150,14 @@ int32_t StepMotorCtrlModule::step_motor_read_io_state(int32_t ioindex, int32_t* return 0; } -int32_t StepMotorCtrlModule::step_motor_read_motoric_status(int32_t* errorflag) { - *errorflag = m_state.motorStatus; +int32_t StepMotorCtrlModule::step_motor_read_tmc5130_status(int32_t* status) { + // *errorflag = m_state.motorStatus; + TMC5130* tmc5130 = dynamic_cast(m_stepM1); + if (tmc5130) { + static_assert(sizeof(TMC5130::DevStatusReg_t) == 4); + auto devStatus = tmc5130->getDevStatus(); + memcpy(status, &devStatus, sizeof(int32_t)); + } return 0; } @@ -203,7 +209,7 @@ void StepMotorCtrlModule::dumpTMC5130Status(TMC5130::DevStatusReg_t* status) { void StepMotorCtrlModule::setErrorFlag(int32_t ecode, uint32_t motorStatue) { creg.module_errorcode = ecode; - m_state.motorStatus = motorStatue; + // m_state.motorStatus = motorStatue; } bool StepMotorCtrlModule::check_when_run() { diff --git a/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp b/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp index c1c0de3..19465e7 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp @@ -35,7 +35,6 @@ class StepMotorCtrlModule : public ZIModule, public ZIStepMotor { int32_t after_move_pos; int32_t before_move_pos; int32_t enable; - uint32_t motorStatus; } state_t; private: @@ -83,7 +82,7 @@ class StepMotorCtrlModule : public ZIModule, public ZIStepMotor { virtual int32_t step_motor_active_cfg() override; virtual int32_t step_motor_read_io_state(int32_t ioindex, int32_t* state) override; - virtual int32_t step_motor_read_motoric_status(int32_t* errorflag) override; + virtual int32_t step_motor_read_tmc5130_status(int32_t* errorflag) override; public: IStepperMotor* getMotor() { return m_stepM1; } diff --git a/components/tmc/ic/ztmc5130.hpp b/components/tmc/ic/ztmc5130.hpp index 47075bd..90f62ef 100644 --- a/components/tmc/ic/ztmc5130.hpp +++ b/components/tmc/ic/ztmc5130.hpp @@ -126,12 +126,12 @@ class TMC5130 : public IStepperMotor { virtual void setNoAccLimit(bool enable) override; public: - DevStatusReg_t getDevStatus() { + DevStatusReg_t getDevStatus() { // R 读后不清 static_assert(sizeof(DevStatusReg_t) == 4); uint32_t value = readInt(TMC5130_DRVSTATUS); return *(DevStatusReg_t *)&value; } - GState_t getGState() { + GState_t getGState() { // R+C 读后自动清除 static_assert(sizeof(GState_t) == 4); uint32_t value = readInt(TMC5130_GSTAT); return *(GState_t *)&value; diff --git a/components/zcancmder/zcan_protocol_parser.cpp b/components/zcancmder/zcan_protocol_parser.cpp index 8f1ac89..9be0dd3 100644 --- a/components/zcancmder/zcan_protocol_parser.cpp +++ b/components/zcancmder/zcan_protocol_parser.cpp @@ -33,7 +33,7 @@ void ZCanProtocolParser::initialize(IZCanReceiver* cancmder) { REGFN(step_motor_active_cfg); REGFN(step_motor_stop); REGFN(step_motor_read_io_state); - REGFN(step_motor_read_motoric_status); + REGFN(step_motor_read_tmc5130_status); REGFN(mini_servo_enable); REGFN(mini_servo_read_pos); @@ -247,11 +247,11 @@ int32_t ZCanProtocolParser::step_motor_read_io_state(cmdcontxt_t* cxt) { return module->step_motor_read_io_state(cxt->params[0], ack); } -int32_t ZCanProtocolParser::step_motor_read_motoric_status(cmdcontxt_t* cxt) { +int32_t ZCanProtocolParser::step_motor_read_tmc5130_status(cmdcontxt_t* cxt) { CHECK_AND_GET_MODULE(0); int32_t* ack = (int32_t*)cxt->ackbuf; cxt->acklen = 4; - return module->step_motor_read_motoric_status(&ack[0]); + return module->step_motor_read_tmc5130_status(&ack[0]); } #undef MODULE_CLASS diff --git a/components/zcancmder/zcan_protocol_parser.hpp b/components/zcancmder/zcan_protocol_parser.hpp index f26e7ae..b48da31 100644 --- a/components/zcancmder/zcan_protocol_parser.hpp +++ b/components/zcancmder/zcan_protocol_parser.hpp @@ -68,7 +68,7 @@ class ZCanProtocolParser : public IZCanReceiverListener { static int32_t step_motor_easy_move_to_io(cmdcontxt_t* cxt); static int32_t step_motor_active_cfg(cmdcontxt_t* cxt); static int32_t step_motor_read_io_state(cmdcontxt_t* cxt); - static int32_t step_motor_read_motoric_status(cmdcontxt_t* cxt); + static int32_t step_motor_read_tmc5130_status(cmdcontxt_t* cxt); static int32_t mini_servo_enable(cmdcontxt_t* cxt);