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.
63 lines
5.8 KiB
63 lines
5.8 KiB
#include "zmodule_device_manager.hpp"
|
|
|
|
#include <assert.h>
|
|
using namespace iflytop;
|
|
using namespace std;
|
|
|
|
#define PROXY_IMPL(type, functionName, ...) \
|
|
type *module = nullptr; \
|
|
int32_t ecode = findModule<type>(id, &module); \
|
|
if (ecode != 0) { \
|
|
return ecode; \
|
|
} \
|
|
return module->functionName(__VA_ARGS__);
|
|
|
|
void ZModuleDeviceManager::initialize(IZcanCmderMaster *cancmder) {
|
|
m_cancmder = cancmder;
|
|
assert(m_cancmder != nullptr);
|
|
}
|
|
void ZModuleDeviceManager::registerModule(ZIModule *module) {
|
|
assert(module != nullptr);
|
|
int32_t id = 0;
|
|
module->getid(&id);
|
|
uint16_t id16 = id;
|
|
m_modulers[id16] = module;
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* ZIModule *
|
|
*******************************************************************************/
|
|
int32_t ZModuleDeviceManager::module_stop(uint16_t id) { PROXY_IMPL(ZIModule, module_stop); }
|
|
int32_t ZModuleDeviceManager::module_break(uint16_t id) { PROXY_IMPL(ZIModule, module_break); }
|
|
int32_t ZModuleDeviceManager::module_get_last_exec_status(uint16_t id, int32_t *ack0) { PROXY_IMPL(ZIModule, module_get_last_exec_status, ack0); }
|
|
int32_t ZModuleDeviceManager::module_get_status(uint16_t id, int32_t *status) { PROXY_IMPL(ZIModule, module_get_status, status); }
|
|
int32_t ZModuleDeviceManager::module_set_param(uint16_t id, int32_t param_id, int32_t param_value) { PROXY_IMPL(ZIModule, module_set_param, param_id, param_value); }
|
|
int32_t ZModuleDeviceManager::module_get_param(uint16_t id, int32_t param_id, int32_t *param_value) { PROXY_IMPL(ZIModule, module_get_param, param_id, param_value); }
|
|
int32_t ZModuleDeviceManager::module_readio(uint16_t id, int32_t *io) { PROXY_IMPL(ZIModule, module_readio, io); }
|
|
int32_t ZModuleDeviceManager::module_writeio(uint16_t id, int32_t io) { PROXY_IMPL(ZIModule, module_writeio, io); }
|
|
int32_t ZModuleDeviceManager::module_read_adc(uint16_t id, int32_t adcindex, int32_t *adc) { PROXY_IMPL(ZIModule, module_read_adc, adcindex, adc); }
|
|
int32_t ZModuleDeviceManager::module_get_error(uint16_t id, int32_t *iserror) { PROXY_IMPL(ZIModule, module_get_error, iserror); }
|
|
int32_t ZModuleDeviceManager::module_clear_error(uint16_t id) { PROXY_IMPL(ZIModule, module_clear_error); }
|
|
int32_t ZModuleDeviceManager::module_set_inited_flag(uint16_t id, int32_t flag) { PROXY_IMPL(ZIModule, module_set_inited_flag, flag); }
|
|
int32_t ZModuleDeviceManager::module_get_inited_flag(uint16_t id, int32_t *flag) { PROXY_IMPL(ZIModule, module_get_inited_flag, flag); }
|
|
/*******************************************************************************
|
|
* ZIMotor *
|
|
*******************************************************************************/
|
|
int32_t ZModuleDeviceManager::motor_enable(uint16_t id, int32_t enable) { PROXY_IMPL(ZIMotor, motor_enable, enable); }
|
|
int32_t ZModuleDeviceManager::motor_rotate(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acc) { PROXY_IMPL(ZIMotor, motor_rotate, direction, motor_velocity, acc); }
|
|
int32_t ZModuleDeviceManager::motor_move_by(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acc) { PROXY_IMPL(ZIMotor, motor_move_by, distance, motor_velocity, acc); }
|
|
int32_t ZModuleDeviceManager::motor_move_to(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acc) { PROXY_IMPL(ZIMotor, motor_move_to, position, motor_velocity, acc); }
|
|
int32_t ZModuleDeviceManager::motor_move_to_with_torque(uint16_t id, int32_t pos, int32_t torque) { PROXY_IMPL(ZIMotor, motor_move_to_with_torque, pos, torque); }
|
|
int32_t ZModuleDeviceManager::motor_rotate_acctime(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acctime) { PROXY_IMPL(ZIMotor, motor_rotate_acctime, direction, motor_velocity, acctime); }
|
|
int32_t ZModuleDeviceManager::motor_move_by_acctime(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acctime) { PROXY_IMPL(ZIMotor, motor_move_by_acctime, distance, motor_velocity, acctime); }
|
|
int32_t ZModuleDeviceManager::motor_move_to_acctime(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acctime) { PROXY_IMPL(ZIMotor, motor_move_to_acctime, position, motor_velocity, acctime); }
|
|
int32_t ZModuleDeviceManager::motor_move_to_zero_forward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { PROXY_IMPL(ZIMotor, motor_move_to_zero_forward, findzerospeed, findzeroedge_speed, acc, overtime); }
|
|
int32_t ZModuleDeviceManager::motor_move_to_zero_backward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { PROXY_IMPL(ZIMotor, motor_move_to_zero_backward, findzerospeed, findzeroedge_speed, acc, overtime); }
|
|
int32_t ZModuleDeviceManager::motor_read_pos(uint16_t id, int32_t *pos) { PROXY_IMPL(ZIMotor, motor_read_pos, pos); }
|
|
int32_t ZModuleDeviceManager::motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos) { PROXY_IMPL(ZIMotor, motor_set_current_pos_by_change_shift, pos); }
|
|
/*******************************************************************************
|
|
* ZIXYMotor *
|
|
*******************************************************************************/
|
|
int32_t ZModuleDeviceManager::xymotor_enable(uint16_t id, int32_t enable) { PROXY_IMPL(ZIXYMotor, xymotor_enable, enable); }
|
|
int32_t ZModuleDeviceManager::xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity) { PROXY_IMPL(ZIXYMotor, xymotor_move_by, dx, dy, motor_velocity); }
|
|
int32_t ZModuleDeviceManager::xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity) { PROXY_IMPL(ZIXYMotor, xymotor_move_to, x, y, motor_velocity); }
|