diff --git a/a8000_protocol b/a8000_protocol index 508a8f8..86281b7 160000 --- a/a8000_protocol +++ b/a8000_protocol @@ -1 +1 @@ -Subproject commit 508a8f8be82e5272ae21140cafbf7aee274f1367 +Subproject commit 86281b73f485c01783197227b58d0a19699c7198 diff --git a/sdk/components/api/zi_module.cpp b/sdk/components/api/zi_module.cpp new file mode 100644 index 0000000..01844fe --- /dev/null +++ b/sdk/components/api/zi_module.cpp @@ -0,0 +1,96 @@ + +#include "zi_module.hpp" + +#include + +#include + +using namespace iflytop; + +int32_t ZIModule::getid() { + int32_t id = 0; + getid(&id); + return id; +}; + +int32_t ZIModule::module_ping() { return 0; }; +int32_t ZIModule::module_set_reg(int32_t param_id, int32_t param_value) { return _module_xxx_reg(param_id, false, param_value); } +int32_t ZIModule::module_get_reg(int32_t param_id, int32_t *param_value) { return _module_xxx_reg(param_id, true, *param_value); } + +int32_t ZIModule::_module_xxx_reg(int32_t param_id, bool read, int32_t &val) { + if (param_id == kreg_module_version) { + if (read) { + module_get_version(&val); + return 0; + } else { + return 0; + } + } + + else if (param_id == kreg_module_type) { + if (read) { + module_get_type(&val); + return 0; + } else { + return 0; + } + } + + else if (param_id == kreg_module_status) { + if (read) { + module_get_status(&val); + return 0; + } else { + return 0; + } + } + + else if (param_id == kreg_module_errorcode) { + if (read) { + val = creg.module_errorcode; + return 0; + } else { + return 0; + } + } + + return module_xxx_reg(param_id, read, val); +} + +int32_t ZIModule::_module_set_reg(int32_t regoff, int32_t *regval, int32_t val, int32_t min, int32_t max) { + if (val < min || val > max) { + return err::kparam_out_of_range; + } + *regval = val; + return 0; +} +int32_t ZIModule::_module_get_reg(int32_t regoff, int32_t regval, int32_t &val) { + val = regval; + return 0; +} +int32_t ZIModule::_module_set_reg_float(int32_t regoff, float *regval, int32_t val, float precision, int32_t min, int32_t max) { + if (val < min || val > max) { + return err::kparam_out_of_range; + } + *regval = val * precision; + return 0; +} +int32_t ZIModule::_module_get_reg_float(int32_t regoff, float regval, int32_t &val, float precision) { + val = regval / precision; + return 0; +} + +int32_t ZIModule::module_get_error(int32_t *iserror) { + *iserror = creg.module_errorcode; + return 0; +} +int32_t ZIModule::module_clear_error() { + creg.module_errorcode = 0; + creg.module_status = 0; + return 0; +} + +int32_t ZIModule::module_get_status(int32_t *status) { + *status = creg.module_status; + return 0; +} diff --git a/sdk/components/api/zi_module.hpp b/sdk/components/api/zi_module.hpp new file mode 100644 index 0000000..678ff3d --- /dev/null +++ b/sdk/components/api/zi_module.hpp @@ -0,0 +1,87 @@ +#pragma once +#include + +#include + +#include "a8000_protocol\protocol.hpp" +namespace iflytop { +using namespace std; + +#define REG_SET(reg, ...) _module_set_reg(param_id, ®, val, ##__VA_ARGS__) +#define REG_GET(reg) _module_get_reg(param_id, reg, val) + +#define REG_SET_FLOAT(reg, precision, ...) _module_set_reg_float(param_id, ®, val, precision, ##__VA_ARGS__) +#define REG_GET_FLOAT(reg, precision) _module_get_reg_float(param_id, reg, val, precision) + +#define ACTION_NONE 0 +#define PROCESS_REG(param_id, readaction, writeacton) \ + case param_id: { \ + if (read) { \ + return readaction; \ + } else { \ + return writeacton; \ + } \ + } break; + +#define ENABLE_MODULE(name, type, version) \ + public: \ + virtual int32_t module_get_version(int32_t *val) { \ + *val = version; \ + return 0; \ + } \ + virtual int32_t module_get_type(int32_t *val) { \ + *val = type; \ + return 0; \ + } + +#define MODULE_COMMON_PROCESS_REG_CB() + +typedef struct { + int32_t module_errorcode; + int32_t module_status; +} module_common_reg_t; + +class ZIModule { + int32_t m_inited_flag = 0; + + protected: + module_common_reg_t creg; + + public: + virtual ~ZIModule() {} + + public: + virtual int32_t getid(); + virtual int32_t module_ping(); + virtual int32_t module_get_error(int32_t *iserror); + virtual int32_t module_clear_error(); + virtual int32_t module_set_reg(int32_t param_id, int32_t param_value); + virtual int32_t module_get_reg(int32_t param_id, int32_t *param_value); + virtual int32_t module_get_status(int32_t *status); + virtual int32_t module_get_version(int32_t *val) = 0; + virtual int32_t module_get_type(int32_t *val) = 0; + virtual int32_t module_stop() { return 0; } + virtual int32_t module_active_cfg() { return 0; } + + /*********************************************************************************************************************** + * 用户实现 * + ***********************************************************************************************************************/ + virtual int32_t getid(int32_t *id) = 0; + virtual int32_t module_xxx_reg(int32_t param_id, bool read, int32_t &val) = 0; + + public: + // slice + virtual int32_t bfcall(int32_t cmdid, uint8_t *param, int32_t len) { return 0; }; + virtual void aftercall(int32_t cmdid, uint8_t *param, int32_t len, uint8_t *ack, int32_t acklen, int32_t ret) {}; + + protected: + virtual int32_t _module_set_reg(int32_t regoff, int32_t *regval, int32_t val, int32_t min = INT32_MIN, int32_t max = INT32_MAX); + virtual int32_t _module_get_reg(int32_t regoff, int32_t regval, int32_t &val); + virtual int32_t _module_set_reg_float(int32_t regoff, float *regval, int32_t val, float precision, int32_t min = INT32_MIN, int32_t max = INT32_MAX); + virtual int32_t _module_get_reg_float(int32_t regoff, float regval, int32_t &val, float precision); + virtual int32_t _module_xxx_reg(int32_t param_id, bool read, int32_t &val); + + public: + public: +}; +} // namespace iflytop diff --git a/sdk/components/mini_servo_motor/mini_servo_motor_ctrl_module.hpp b/sdk/components/mini_servo_motor/mini_servo_motor_ctrl_module.hpp index 15e3105..b7e10f8 100644 --- a/sdk/components/mini_servo_motor/mini_servo_motor_ctrl_module.hpp +++ b/sdk/components/mini_servo_motor/mini_servo_motor_ctrl_module.hpp @@ -4,6 +4,7 @@ // #include "feite_servo_motor.hpp" #include "sdk\components\zcancmder\zcanreceiver.hpp" +#include "sdk\components\api\zi_module.hpp" namespace iflytop { class MiniServoCtrlModule : public ZIModule{ diff --git a/sdk/components/pipette_module/pipette_ctrl_module_v2.hpp b/sdk/components/pipette_module/pipette_ctrl_module_v2.hpp index d6abc59..8917164 100644 --- a/sdk/components/pipette_module/pipette_ctrl_module_v2.hpp +++ b/sdk/components/pipette_module/pipette_ctrl_module_v2.hpp @@ -6,6 +6,8 @@ #include "sdk\components\tmc\basic\tmc_ic_interface.hpp" #include "sdk\components\tmc\ic\ztmc5130.hpp" #include "sdk\components\zcancmder\zcanreceiver.hpp" +#include "sdk\components\api\zi_module.hpp" + // #include "StepMotorCtrlModule" /** diff --git a/sdk/components/sensors/m3078/m3078_code_scaner.hpp b/sdk/components/sensors/m3078/m3078_code_scaner.hpp index a24345f..23b4c1e 100644 --- a/sdk/components/sensors/m3078/m3078_code_scaner.hpp +++ b/sdk/components/sensors/m3078/m3078_code_scaner.hpp @@ -5,6 +5,7 @@ #pragma once #include "a8000_protocol\protocol.hpp" #include "sdk/os/zos.hpp" +#include "sdk\components\api\zi_module.hpp" /** * @brief diff --git a/sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp b/sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp index 2a13687..1856690 100644 --- a/sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp +++ b/sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp @@ -4,6 +4,9 @@ #include "sdk\components\tmc\basic\tmc_ic_interface.hpp" #include "sdk\components\tmc\ic\ztmc5130.hpp" #include "sdk\components\zcancmder\zcanreceiver.hpp" +#include "sdk\components\api\zi_module.hpp" +#include "sdk\components\api\zi_module.hpp" + namespace iflytop { class StepMotorCtrlModule : public ZIModule { ENABLE_MODULE(StepMotorCtrlModule, ktmc_step_motor, PC_VERSION); diff --git a/sdk/components/tmc/ic/ztmc5130.cpp b/sdk/components/tmc/ic/ztmc5130.cpp index f34d0b0..05e4e89 100644 --- a/sdk/components/tmc/ic/ztmc5130.cpp +++ b/sdk/components/tmc/ic/ztmc5130.cpp @@ -1,6 +1,6 @@ #include "ztmc5130.hpp" -#include "a8000_protocol\api\apibasic\errorcode.hpp" +#include "a8000_protocol\protocol.hpp" #include "sdk/os/zos.hpp" #ifdef HAL_SPI_MODULE_ENABLED diff --git a/sdk/components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.hpp b/sdk/components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.hpp index bc83586..635fb94 100644 --- a/sdk/components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.hpp +++ b/sdk/components/water_cooling_temperature_control_module/water_cooling_temperature_control_module.hpp @@ -22,10 +22,11 @@ #include "sdk\components\api\zi_pwm_fan_ctrl_module.hpp" #include "sdk\components\api\zi_pwm_pump_ctrl_module.hpp" // -#include "a8000_protocol\api\zi_module.hpp" +#include "sdk\components\api\zi_module.hpp" #include "pid_module.hpp" #include "sdk\components\api\zi_temperature_sensor.hpp" #include "sdk\components\ti\drv8710.hpp" +#include "sdk\components\api\zi_module.hpp" namespace iflytop { /** diff --git a/sdk/components/xy_robot_ctrl_module/xy_robot_ctrl_module.hpp b/sdk/components/xy_robot_ctrl_module/xy_robot_ctrl_module.hpp index 9241a94..f4ba869 100644 --- a/sdk/components/xy_robot_ctrl_module/xy_robot_ctrl_module.hpp +++ b/sdk/components/xy_robot_ctrl_module/xy_robot_ctrl_module.hpp @@ -5,6 +5,7 @@ #include "sdk\components\tmc\basic\tmc_ic_interface.hpp" #include "sdk\components\tmc\ic\ztmc5130.hpp" #include "sdk\components\zcancmder\zcanreceiver.hpp" +#include "sdk\components\api\zi_module.hpp" namespace iflytop { diff --git a/sdk/components/zcancmder/protocol_event_bus_sender.hpp b/sdk/components/zcancmder/protocol_event_bus_sender.hpp index 460c0bb..28494b5 100644 --- a/sdk/components/zcancmder/protocol_event_bus_sender.hpp +++ b/sdk/components/zcancmder/protocol_event_bus_sender.hpp @@ -4,6 +4,7 @@ #include "basic.hpp" #include "sdk/os/zos.hpp" #include "sdk\components\zcancmder\zcanreceiver.hpp" +#include "sdk\components\api\zi_module.hpp" namespace iflytop { using namespace std; diff --git a/sdk/components/zcancmder/zcan_board_module.hpp b/sdk/components/zcancmder/zcan_board_module.hpp index 6a50413..9dca415 100644 --- a/sdk/components/zcancmder/zcan_board_module.hpp +++ b/sdk/components/zcancmder/zcan_board_module.hpp @@ -9,6 +9,7 @@ #include "sdk/chip/api/zi_temperature.hpp" #include "sdk\chip\api\zi_adc.hpp" #include "a8000_protocol\protocol.hpp" +#include "sdk\components\api\zi_module.hpp" /** * @brief diff --git a/sdk/components/zcancmder/zcan_protocol_parser.hpp b/sdk/components/zcancmder/zcan_protocol_parser.hpp index 44a1c45..b552333 100644 --- a/sdk/components/zcancmder/zcan_protocol_parser.hpp +++ b/sdk/components/zcancmder/zcan_protocol_parser.hpp @@ -3,6 +3,7 @@ #include "a8000_protocol\protocol.hpp" #include "sdk\components\zcancmder\zcanreceiver.hpp" +#include "sdk\components\api\zi_module.hpp" #define CMDFN(name) static int32_t name(cmdcontxt_t* cxt) #define CMDFN_IMPL(name) int32_t ZCanProtocolParser::name(cmdcontxt_t* cxt) diff --git a/sdk/components/zcancmder/zcanreceiver.hpp b/sdk/components/zcancmder/zcanreceiver.hpp index a0d454a..ee4b5fc 100644 --- a/sdk/components/zcancmder/zcanreceiver.hpp +++ b/sdk/components/zcancmder/zcanreceiver.hpp @@ -6,6 +6,8 @@ #include "a8000_protocol\protocol.hpp" #include "basic.hpp" #include "sdk/os/zos.hpp" +#include "sdk\components\api\zi_module.hpp" + #ifdef HAL_CAN_MODULE_ENABLED namespace iflytop { using namespace zcr; diff --git a/usrc/public_service/ext_board_impl.hpp b/usrc/public_service/ext_board_impl.hpp index 1773012..60839d0 100644 --- a/usrc/public_service/ext_board_impl.hpp +++ b/usrc/public_service/ext_board_impl.hpp @@ -8,6 +8,8 @@ #include "instance_init.hpp" #include "sdk/chip/chip.hpp" #include "sdk/os/zos.hpp" +#include "sdk\components\api\zi_module.hpp" + // namespace iflytop { diff --git a/usrc/subboards/subboard100_idcard_reader/eeprom_service.hpp b/usrc/subboards/subboard100_idcard_reader/eeprom_service.hpp index 0c9eeb1..97f7d20 100644 --- a/usrc/subboards/subboard100_idcard_reader/eeprom_service.hpp +++ b/usrc/subboards/subboard100_idcard_reader/eeprom_service.hpp @@ -5,6 +5,7 @@ #include "sdk\components\zcancmder\protocol_event_bus_sender.hpp" // #include "sdk\os\zos.hpp" +#include "sdk\components\api\zi_module.hpp" #ifdef HAL_I2C_MODULE_ENABLED namespace iflytop { diff --git a/usrc/subboards/subboard20_plate_clamp_case/plate_code_scaner_module.hpp b/usrc/subboards/subboard20_plate_clamp_case/plate_code_scaner_module.hpp index 55a3bf0..2a9b0b5 100644 --- a/usrc/subboards/subboard20_plate_clamp_case/plate_code_scaner_module.hpp +++ b/usrc/subboards/subboard20_plate_clamp_case/plate_code_scaner_module.hpp @@ -6,6 +6,7 @@ #include "sdk\chip\api\zi_adc.hpp" #include "sdk\components\hardware\adc\z_simple_adc.hpp" #include "sdk\components\step_motor_ctrl_module\step_motor_ctrl_module.hpp" +#include "sdk\components\api\zi_module.hpp" namespace iflytop { using namespace std; diff --git a/usrc/subboards/subboard40_and_50_temperature_ctrl/zcan_fan_ctrl_module.hpp b/usrc/subboards/subboard40_and_50_temperature_ctrl/zcan_fan_ctrl_module.hpp index f875cf0..06a9877 100644 --- a/usrc/subboards/subboard40_and_50_temperature_ctrl/zcan_fan_ctrl_module.hpp +++ b/usrc/subboards/subboard40_and_50_temperature_ctrl/zcan_fan_ctrl_module.hpp @@ -18,6 +18,7 @@ // #include "a8000_protocol\protocol.hpp" #include "sdk\components\api\zi_pwm_fan_ctrl_module.hpp" +#include "sdk\components\api\zi_module.hpp" namespace iflytop { /** diff --git a/usrc/subboards/subboard90_optical_module/optical_module_v2.hpp b/usrc/subboards/subboard90_optical_module/optical_module_v2.hpp index 4fc1576..e613c8a 100644 --- a/usrc/subboards/subboard90_optical_module/optical_module_v2.hpp +++ b/usrc/subboards/subboard90_optical_module/optical_module_v2.hpp @@ -6,6 +6,7 @@ #include "sdk\chip\api\zi_adc.hpp" #include "sdk\components\hardware\adc\z_simple_adc.hpp" #include "sdk\components\step_motor_ctrl_module\step_motor_ctrl_module.hpp" +#include "sdk\components\api\zi_module.hpp" namespace iflytop { using namespace std;