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.
244 lines
14 KiB
244 lines
14 KiB
#pragma once
|
|
#include <list>
|
|
#include <map>
|
|
|
|
#include "api/api.hpp"
|
|
#include "api/i_zcan_cmder_master.hpp"
|
|
#include "cmdid.hpp"
|
|
|
|
namespace iflytop {
|
|
using namespace std;
|
|
class ZModuleDeviceManager {
|
|
private:
|
|
map<uint16_t, ZIModule *> m_modulers;
|
|
IZcanCmderMaster *m_cancmder = nullptr;
|
|
|
|
typedef function<void(int32_t moduleid, int32_t regindex, int32_t oldval, int32_t toval)> regval_change_event_t;
|
|
|
|
regval_change_event_t m_on_reg_val_change_event_cb;
|
|
list<regval_change_event_t> m_on_reg_val_change_event_cbs;
|
|
|
|
public:
|
|
void initialize(IZcanCmderMaster *m_cancmder);
|
|
void registerModule(ZIModule *module);
|
|
|
|
void regOnRegValChangeEvent(regval_change_event_t on_regval_change_event) { m_on_reg_val_change_event_cbs.push_back(on_regval_change_event); }
|
|
void callOnRegValChangeEvent(int32_t moduleid, int32_t regindex, int32_t oldval, int32_t toval) {
|
|
for (auto &cb : m_on_reg_val_change_event_cbs)
|
|
if (cb) cb(moduleid, regindex, oldval,toval);
|
|
}
|
|
|
|
void for_each_module(function<void(int32_t moduleid)> cb) {
|
|
for (auto &it : m_modulers) {
|
|
if (cb) cb(it.first);
|
|
}
|
|
}
|
|
/*******************************************************************************
|
|
* 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_reg(int32_t param_id, int32_t param_value) { return err::koperation_not_support; }
|
|
virtual int32_t module_get_reg(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_ping(uint16_t id);
|
|
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_reg(uint16_t id, int32_t param_id, int32_t param_value);
|
|
virtual int32_t module_get_reg(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; }
|
|
|
|
virtual int32_t motor_easy_rotate(int32_t direction) { return err::koperation_not_support; };
|
|
virtual int32_t motor_easy_move_by(int32_t distance) { return err::koperation_not_support; };
|
|
virtual int32_t motor_easy_move_to(int32_t position) { return err::koperation_not_support; };
|
|
virtual int32_t motor_easy_move_to_zero(int32_t direction) { return err::koperation_not_support; };
|
|
virtual int32_t motor_easy_set_current_pos(int32_t pos) { 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);
|
|
|
|
virtual int32_t motor_easy_rotate(uint16_t id, int32_t direction);
|
|
virtual int32_t motor_easy_move_by(uint16_t id, int32_t distance);
|
|
virtual int32_t motor_easy_move_to(uint16_t id, int32_t position);
|
|
virtual int32_t motor_easy_move_to_zero(uint16_t id, int32_t direction);
|
|
virtual int32_t motor_easy_set_current_pos(uint16_t id, int32_t pos);
|
|
|
|
/*******************************************************************************
|
|
* 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);
|
|
|
|
#if 0
|
|
virtual int32_t code_scaner_start_scan() { return err::koperation_not_support; }
|
|
virtual int32_t code_scaner_stop_scan() { return err::koperation_not_support; }
|
|
virtual int32_t code_scaner_read_scaner_result(int32_t startadd, uint8_t *data, int32_t *len) { return err::koperation_not_support; }
|
|
|
|
virtual int32_t code_scaner_start_scan(uint16_t id);
|
|
virtual int32_t code_scaner_stop_scan(uint16_t id);
|
|
virtual int32_t code_scaner_read_scaner_result(uint16_t id, int32_t startadd, uint8_t *data, int32_t *len);
|
|
#endif
|
|
|
|
#if 0
|
|
virtual int32_t pipette_ctrl_init_device() { return err::koperation_not_support; };
|
|
virtual int32_t pipette_ctrl_put_tip() { return err::koperation_not_support; };
|
|
virtual int32_t pipette_ctrl_move_to_ul(int32_t ul) { return err::koperation_not_support; };
|
|
#endif
|
|
|
|
virtual int32_t pipette_ctrl_init_device(uint16_t id);
|
|
virtual int32_t pipette_ctrl_put_tip(uint16_t id);
|
|
virtual int32_t pipette_ctrl_move_to_ul(uint16_t id, int32_t ul);
|
|
|
|
#if 0
|
|
virtual int32_t a8000_optical_module_power_ctrl(int32_t state) = 0;
|
|
virtual int32_t a8000_optical_open_laser(int32_t type) = 0;
|
|
virtual int32_t a8000_optical_close_laser(int32_t type) = 0;
|
|
virtual int32_t a8000_optical_set_laster_gain(int32_t type, int32_t gain) = 0;
|
|
virtual int32_t a8000_optical_set_scan_amp_gain(int32_t type, int32_t gain) = 0;
|
|
virtual int32_t a8000_optical_read_scanner_adc_val(int32_t type, int32_t* adcval) = 0;
|
|
virtual int32_t a8000_optical_read_laster_adc_val(int32_t type, int32_t* adcval) = 0;
|
|
virtual int32_t a8000_optical_scan_current_point_amp_adc_val(int32_t type, int32_t lastergain, int32_t ampgain, int32_t* laster_fb_val, int32_t* adcval) = 0;
|
|
#endif
|
|
|
|
virtual int32_t a8000_optical_module_power_ctrl(uint16_t id, int32_t state);
|
|
virtual int32_t a8000_optical_open_laser(uint16_t id, int32_t type);
|
|
virtual int32_t a8000_optical_close_laser(uint16_t id, int32_t type);
|
|
virtual int32_t a8000_optical_set_laster_gain(uint16_t id, int32_t type, int32_t gain);
|
|
virtual int32_t a8000_optical_set_scan_amp_gain(uint16_t id, int32_t type, int32_t gain);
|
|
virtual int32_t a8000_optical_read_scanner_adc_val(uint16_t id, int32_t type, int32_t *adcval);
|
|
virtual int32_t a8000_optical_read_laster_adc_val(uint16_t id, int32_t type, int32_t *adcval);
|
|
virtual int32_t a8000_optical_scan_current_point_amp_adc_val(uint16_t id, int32_t type, int32_t lastergain, int32_t ampgain, int32_t *laster_fb_val, int32_t *adcval);
|
|
|
|
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
|