You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
172 lines
9.4 KiB
172 lines
9.4 KiB
#pragma once
|
|
#include <map>
|
|
|
|
#include "api/api.hpp"
|
|
#include "api\i_zcan_cmder_master.hpp"
|
|
#include "cmdid.hpp"
|
|
|
|
namespace iflytop {
|
|
class ZModuleDeviceManager {
|
|
private:
|
|
map<uint16_t, ZIModule *> m_modulers;
|
|
IZcanCmderMaster *m_cancmder = nullptr;
|
|
|
|
public:
|
|
void initialize(IZcanCmderMaster *m_cancmder);
|
|
void registerModule(ZIModule *module);
|
|
/*******************************************************************************
|
|
* ZIModule *
|
|
*******************************************************************************/
|
|
|
|
#if 0
|
|
virtual ~ZIModule() {}
|
|
|
|
virtual int32_t getid(int32_t *id) = 0;
|
|
|
|
virtual int32_t module_stop() = 0;
|
|
virtual int32_t module_break() = 0;
|
|
virtual int32_t module_get_last_exec_status(int32_t *status) = 0;
|
|
virtual int32_t module_get_status(int32_t *status) = 0;
|
|
virtual int32_t module_get_error(int32_t *iserror) = 0;
|
|
virtual int32_t module_clear_error() = 0;
|
|
|
|
virtual int32_t module_set_param(int32_t param_id, int32_t param_value) { return err::koperation_not_support; }
|
|
virtual int32_t module_get_param(int32_t param_id, int32_t *param_value) { return err::koperation_not_support; }
|
|
|
|
virtual int32_t module_readio(int32_t *io) { return err::koperation_not_support; }
|
|
virtual int32_t module_writeio(int32_t io) { return err::koperation_not_support; }
|
|
|
|
virtual int32_t module_read_adc(int32_t adcindex, int32_t *adc) { return err::koperation_not_support; }
|
|
|
|
virtual int32_t module_set_inited_flag(int32_t flag) {
|
|
m_inited_flag = flag;
|
|
return 0;
|
|
}
|
|
virtual int32_t module_get_inited_flag(int32_t *flag) {
|
|
*flag = m_inited_flag;
|
|
return 0;
|
|
}
|
|
// kmodule_factory_reset = CMDID(1, 14), // para:{}, ack:{}
|
|
// kmodule_flush_cfg = CMDID(1, 15), // para:{}, ack:{}
|
|
// kmodule_active_cfg = CMDID(1, 16), // para:{}, ack:{}
|
|
|
|
virtual int32_t module_factory_reset() { return err::koperation_not_support; }
|
|
virtual int32_t module_flush_cfg() { return err::koperation_not_support; }
|
|
virtual int32_t module_active_cfg() { return err::koperation_not_support; }
|
|
|
|
virtual int32_t module_enable(int32_t enable) override;
|
|
#endif
|
|
virtual int32_t module_stop(uint16_t id);
|
|
virtual int32_t module_break(uint16_t id);
|
|
|
|
virtual int32_t module_get_last_exec_status(uint16_t id, int32_t *status);
|
|
virtual int32_t module_get_status(uint16_t id, int32_t *status);
|
|
|
|
virtual int32_t module_set_param(uint16_t id, int32_t param_id, int32_t param_value);
|
|
virtual int32_t module_get_param(uint16_t id, int32_t param_id, int32_t *param_value);
|
|
|
|
virtual int32_t module_readio(uint16_t id, int32_t *io);
|
|
virtual int32_t module_writeio(uint16_t id, int32_t ioindex, int32_t io);
|
|
|
|
virtual int32_t module_read_adc(uint16_t id, int32_t adcindex, int32_t *adc);
|
|
|
|
virtual int32_t module_get_error(uint16_t id, int32_t *iserror);
|
|
virtual int32_t module_clear_error(uint16_t id);
|
|
|
|
virtual int32_t module_set_inited_flag(uint16_t id, int32_t flag);
|
|
virtual int32_t module_get_inited_flag(uint16_t id, int32_t *flag);
|
|
|
|
virtual int32_t module_factory_reset(uint16_t id);
|
|
virtual int32_t module_flush_cfg(uint16_t id);
|
|
virtual int32_t module_active_cfg(uint16_t id);
|
|
|
|
|
|
virtual int32_t module_read_raw(uint16_t id, int32_t startadd, uint8_t *data, int32_t *len);
|
|
virtual int32_t module_enable(uint16_t id, int32_t enable);
|
|
|
|
virtual int32_t module_start(uint16_t id);
|
|
|
|
/*******************************************************************************
|
|
* ZIMotor *
|
|
*******************************************************************************/
|
|
#if 0
|
|
virtual int32_t motor_enable(int32_t enable) { return err::koperation_not_support; }
|
|
virtual int32_t motor_rotate(int32_t direction, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
|
|
virtual int32_t motor_move_by(int32_t distance, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
|
|
virtual int32_t motor_move_to(int32_t position, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
|
|
|
|
virtual int32_t motor_rotate_acctime(int32_t direction, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
|
|
virtual int32_t motor_move_by_acctime(int32_t distance, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
|
|
virtual int32_t motor_move_to_acctime(int32_t position, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
|
|
|
|
virtual int32_t motor_rotate_with_torque(int32_t direction, int32_t torque) { return err::koperation_not_support; }
|
|
virtual int32_t motor_move_to_torque(int32_t pos, int32_t torque, int32_t overtime) { return err::koperation_not_support; }
|
|
|
|
virtual int32_t motor_move_to_zero_forward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; }
|
|
virtual int32_t motor_move_to_zero_backward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; }
|
|
|
|
virtual int32_t motor_move_to_zero_forward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; }
|
|
virtual int32_t motor_move_to_zero_backward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; }
|
|
|
|
virtual int32_t motor_read_pos(int32_t* pos) { return err::koperation_not_support; }
|
|
virtual int32_t motor_set_current_pos_by_change_shift(int32_t pos) { return err::koperation_not_support; } // Ò»°ãÓÃÓÚ¶æ»ú
|
|
virtual int32_t motor_calculated_pos_by_move_to_zero() { return err::koperation_not_support; }
|
|
|
|
#endif
|
|
virtual int32_t motor_enable(uint16_t id, int32_t enable);
|
|
virtual int32_t motor_rotate(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acc);
|
|
virtual int32_t motor_move_by(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acc);
|
|
virtual int32_t motor_move_to(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acc);
|
|
virtual int32_t motor_rotate_acctime(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acctime);
|
|
virtual int32_t motor_move_by_acctime(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acctime);
|
|
virtual int32_t motor_move_to_acctime(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acctime);
|
|
virtual int32_t motor_move_to_zero_forward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
|
|
virtual int32_t motor_move_to_zero_backward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
|
|
virtual int32_t motor_rotate_with_torque(uint16_t id, int32_t direction, int32_t torque);
|
|
virtual int32_t motor_read_pos(uint16_t id, int32_t *pos);
|
|
virtual int32_t motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos);
|
|
virtual int32_t motor_move_to_zero_forward_and_calculated_shift(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
|
|
virtual int32_t motor_move_to_zero_backward_and_calculated_shift(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
|
|
virtual int32_t motor_move_to_torque(uint16_t id, int32_t pos, int32_t torque, int32_t overtime);
|
|
virtual int32_t motor_calculated_pos_by_move_to_zero(uint16_t id);
|
|
|
|
/*******************************************************************************
|
|
* ZIXYMotor *
|
|
*******************************************************************************/
|
|
#if 0
|
|
virtual ~ZIXYMotor() {}
|
|
virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; }
|
|
virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; }
|
|
virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; }
|
|
virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; }
|
|
virtual int32_t xymotor_move_to_zero_and_calculated_shift() { return err::koperation_not_support; }
|
|
virtual int32_t xymotor_read_pos(int32_t *x, int32_t *y) { return err::koperation_not_support; }
|
|
virtual int32_t xymotor_calculated_pos_by_move_to_zero() { return err::koperation_not_support; }
|
|
#endif
|
|
virtual int32_t xymotor_enable(uint16_t id, int32_t enable);
|
|
virtual int32_t xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity);
|
|
virtual int32_t xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity);
|
|
virtual int32_t xymotor_move_to_zero(uint16_t id);
|
|
virtual int32_t xymotor_move_to_zero_and_calculated_shift(uint16_t id);
|
|
virtual int32_t xymotor_read_pos(uint16_t id, int32_t *x, int32_t *y);
|
|
virtual int32_t xymotor_calculated_pos_by_move_to_zero(uint16_t id);
|
|
|
|
virtual ~ZModuleDeviceManager() {}
|
|
|
|
private:
|
|
template <typename T>
|
|
int32_t findModule(uint16_t id, T **module) {
|
|
auto it = m_modulers.find(id);
|
|
if (it == m_modulers.end()) {
|
|
return err::kmodule_not_found;
|
|
}
|
|
T *_module = dynamic_cast<T *>(it->second);
|
|
if (_module == nullptr) {
|
|
return err::koperation_not_support;
|
|
}
|
|
*module = _module;
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
} // namespace iflytop
|