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.
193 lines
9.1 KiB
193 lines
9.1 KiB
#include "app_zmodule_device_manager.hpp"
|
|
|
|
#include "sdk/os/zos.hpp"
|
|
|
|
#define TAG "APPDM"
|
|
|
|
#define DM ZModuleDeviceManager
|
|
|
|
using namespace iflytop;
|
|
void APPDM::initialize(IZcanCmderMaster *m_cancmder) { //
|
|
DM::initialize(m_cancmder);
|
|
}
|
|
|
|
void APPDM::registerModule(ZIModule *module) { DM::registerModule(module); }
|
|
/*******************************************************************************
|
|
* ZIModule *
|
|
*******************************************************************************/
|
|
|
|
#define DOCMD(exptr) \
|
|
{ \
|
|
int32_t errcode = exptr; \
|
|
if (errcode != 0) { \
|
|
ZLOGE(TAG, "do %s fail,errcode %s(%d)", #exptr, err::error2str(errcode), errcode); \
|
|
} \
|
|
return errcode; \
|
|
}
|
|
|
|
int32_t APPDM::module_stop(uint16_t id) { //
|
|
ZLOGI(TAG, "module_stop %d", id);
|
|
DOCMD(DM::module_stop(id));
|
|
}
|
|
int32_t APPDM::module_break(uint16_t id) { //
|
|
|
|
ZLOGI(TAG, "module_break %d", id);
|
|
DOCMD(DM::module_break(id));
|
|
}
|
|
|
|
int32_t APPDM::module_get_last_exec_status(uint16_t id, int32_t *status) { //
|
|
DOCMD(DM::module_get_last_exec_status(id, status));
|
|
}
|
|
int32_t APPDM::module_get_status(uint16_t id, int32_t *status) { //
|
|
DOCMD(DM::module_get_status(id, status));
|
|
}
|
|
|
|
int32_t APPDM::module_set_param(uint16_t id, int32_t param_id, int32_t param_value) { //
|
|
ZLOGI(TAG, "module_set_param %d %d", id, param_value);
|
|
DOCMD(DM::module_set_param(id, param_id, param_value));
|
|
}
|
|
int32_t APPDM::module_get_param(uint16_t id, int32_t param_id, int32_t *param_value) { //
|
|
DOCMD(DM::module_get_param(id, param_id, param_value));
|
|
}
|
|
|
|
int32_t APPDM::module_readio(uint16_t id, int32_t *io) { //
|
|
DOCMD(DM::module_readio(id, io));
|
|
}
|
|
int32_t APPDM::module_writeio(uint16_t id, int32_t io) { //
|
|
|
|
ZLOGI(TAG, "module_writeio %d %d", id, io);
|
|
DOCMD(DM::module_writeio(id, io));
|
|
}
|
|
|
|
int32_t APPDM::module_read_adc(uint16_t id, int32_t adcindex, int32_t *adc) { //
|
|
DOCMD(DM::module_read_adc(id, adcindex, adc));
|
|
}
|
|
|
|
int32_t APPDM::module_get_error(uint16_t id, int32_t *iserror) { //
|
|
DOCMD(DM::module_get_error(id, iserror));
|
|
}
|
|
int32_t APPDM::module_clear_error(uint16_t id) { //
|
|
ZLOGI(TAG, "module_clear_error %d", id);
|
|
DOCMD(DM::module_clear_error(id));
|
|
}
|
|
|
|
int32_t APPDM::module_set_inited_flag(uint16_t id, int32_t flag) { //
|
|
ZLOGI(TAG, "module_set_inited_flag %d %d", id, flag);
|
|
DOCMD(DM::module_set_inited_flag(id, flag));
|
|
}
|
|
int32_t APPDM::module_get_inited_flag(uint16_t id, int32_t *flag) { //
|
|
DOCMD(DM::module_get_inited_flag(id, flag));
|
|
}
|
|
|
|
int32_t APPDM::module_factory_reset(uint16_t id) { //
|
|
ZLOGI(TAG, "module_factory_reset %d", id);
|
|
DOCMD(DM::module_factory_reset(id));
|
|
}
|
|
int32_t APPDM::module_flush_cfg(uint16_t id) { //
|
|
ZLOGI(TAG, "module_flush_cfg %d", id);
|
|
DOCMD(DM::module_flush_cfg(id));
|
|
}
|
|
int32_t APPDM::module_active_cfg(uint16_t id) { //
|
|
ZLOGI(TAG, "module_active_cfg %d", id);
|
|
DOCMD(DM::module_active_cfg(id));
|
|
}
|
|
|
|
int32_t APPDM::module_set_state(uint16_t id, int32_t state_id, int32_t state_value) { //
|
|
ZLOGI(TAG, "module_set_state %d %d %d", id, state_id, state_value);
|
|
DOCMD(DM::module_set_state(id, state_id, state_value));
|
|
}
|
|
int32_t APPDM::module_get_state(uint16_t id, int32_t state_id, int32_t *state_value) { //
|
|
DOCMD(DM::module_get_state(id, state_id, state_value));
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* ZIMotor *
|
|
*******************************************************************************/
|
|
|
|
int32_t APPDM::motor_enable(uint16_t id, int32_t enable) { //
|
|
ZLOGI(TAG, "motor_enable %d %d", id, enable);
|
|
DOCMD(DM::motor_enable(id, enable));
|
|
}
|
|
int32_t APPDM::motor_rotate(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acc) { //
|
|
ZLOGI(TAG, "motor_rotate %d %d %d %d", id, direction, motor_velocity, acc);
|
|
DOCMD(DM::motor_rotate(id, direction, motor_velocity, acc));
|
|
}
|
|
int32_t APPDM::motor_move_by(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acc) { //
|
|
ZLOGI(TAG, "motor_move_by %d %d %d %d", id, distance, motor_velocity, acc);
|
|
DOCMD(DM::motor_move_by(id, distance, motor_velocity, acc));
|
|
}
|
|
int32_t APPDM::motor_move_to(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acc) { //
|
|
ZLOGI(TAG, "motor_move_to %d %d %d %d", id, position, motor_velocity, acc);
|
|
DOCMD(DM::motor_move_to(id, position, motor_velocity, acc));
|
|
}
|
|
int32_t APPDM::motor_rotate_acctime(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acctime) { //
|
|
ZLOGI(TAG, "motor_rotate_acctime %d %d %d %d", id, direction, motor_velocity, acctime);
|
|
DOCMD(DM::motor_rotate_acctime(id, direction, motor_velocity, acctime));
|
|
}
|
|
int32_t APPDM::motor_move_by_acctime(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acctime) { //
|
|
ZLOGI(TAG, "motor_move_by_acctime %d %d %d %d", id, distance, motor_velocity, acctime);
|
|
DOCMD(DM::motor_move_by_acctime(id, distance, motor_velocity, acctime));
|
|
}
|
|
int32_t APPDM::motor_move_to_acctime(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acctime) { //
|
|
ZLOGI(TAG, "motor_move_to_acctime %d %d %d %d", id, position, motor_velocity, acctime);
|
|
DOCMD(DM::motor_move_to_acctime(id, position, motor_velocity, acctime));
|
|
}
|
|
int32_t APPDM::motor_move_to_zero_forward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { //
|
|
ZLOGI(TAG, "motor_move_to_zero_forward %d %d %d %d %d", id, findzerospeed, findzeroedge_speed, acc, overtime);
|
|
DOCMD(DM::motor_move_to_zero_forward(id, findzerospeed, findzeroedge_speed, acc, overtime));
|
|
}
|
|
int32_t APPDM::motor_move_to_zero_backward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { //
|
|
ZLOGI(TAG, "motor_move_to_zero_backward %d %d %d %d %d", id, findzerospeed, findzeroedge_speed, acc, overtime);
|
|
DOCMD(DM::motor_move_to_zero_backward(id, findzerospeed, findzeroedge_speed, acc, overtime));
|
|
}
|
|
int32_t APPDM::motor_rotate_with_torque(uint16_t id, int32_t direction, int32_t torque) { //
|
|
ZLOGI(TAG, "motor_rotate_with_torque %d %d %d", id, direction, torque);
|
|
DOCMD(DM::motor_rotate_with_torque(id, direction, torque));
|
|
}
|
|
int32_t APPDM::motor_read_pos(uint16_t id, int32_t *pos) { //
|
|
DOCMD(DM::motor_read_pos(id, pos));
|
|
}
|
|
int32_t APPDM::motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos) { //
|
|
ZLOGI(TAG, "motor_set_current_pos_by_change_shift %d %d", id, pos);
|
|
DOCMD(DM::motor_set_current_pos_by_change_shift(id, pos));
|
|
}
|
|
int32_t APPDM::motor_move_to_zero_forward_and_calculated_shift(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { //
|
|
ZLOGI(TAG, "motor_move_to_zero_forward_and_calculated_shift %d %d %d %d %d", id, findzerospeed, findzeroedge_speed, acc, overtime);
|
|
DOCMD(DM::motor_move_to_zero_forward_and_calculated_shift(id, findzerospeed, findzeroedge_speed, acc, overtime));
|
|
}
|
|
int32_t APPDM::motor_move_to_zero_backward_and_calculated_shift(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { //
|
|
ZLOGI(TAG, "motor_move_to_zero_backward_and_calculated_shift %d %d %d %d %d", id, findzerospeed, findzeroedge_speed, acc, overtime);
|
|
DOCMD(DM::motor_move_to_zero_backward_and_calculated_shift(id, findzerospeed, findzeroedge_speed, acc, overtime));
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* ZIXYMotor *
|
|
*******************************************************************************/
|
|
|
|
int32_t APPDM::xymotor_enable(uint16_t id, int32_t enable) { //
|
|
ZLOGI(TAG, "xymotor_enable %d %d", id, enable);
|
|
DOCMD(DM::xymotor_enable(id, enable));
|
|
}
|
|
int32_t APPDM::xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity) { //
|
|
ZLOGI(TAG, "xymotor_move_by %d %d %d %d", id, dx, dy, motor_velocity);
|
|
DOCMD(DM::xymotor_move_by(id, dx, dy, motor_velocity));
|
|
}
|
|
int32_t APPDM::xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity) { //
|
|
ZLOGI(TAG, "xymotor_move_to %d %d %d %d", id, x, y, motor_velocity);
|
|
DOCMD(DM::xymotor_move_to(id, x, y, motor_velocity));
|
|
}
|
|
int32_t APPDM::xymotor_move_to_zero(uint16_t id) { //
|
|
ZLOGI(TAG, "xymotor_move_to_zero %d", id);
|
|
DOCMD(DM::xymotor_move_to_zero(id));
|
|
}
|
|
int32_t APPDM::xymotor_move_to_zero_and_calculated_shift(uint16_t id) { //
|
|
ZLOGI(TAG, "xymotor_move_to_zero_and_calculated_shift %d", id);
|
|
DOCMD(DM::xymotor_move_to_zero_and_calculated_shift(id));
|
|
}
|
|
int32_t APPDM::xymotor_read_pos(uint16_t id, int32_t *x, int32_t *y) { //
|
|
DOCMD(DM::xymotor_read_pos(id, x, y));
|
|
}
|
|
int32_t APPDM::xymotor_calculated_pos_by_move_to_zero(uint16_t id) { //
|
|
ZLOGI(TAG, "xymotor_calculated_pos_by_move_to_zero %d", id);
|
|
DOCMD(DM::xymotor_calculated_pos_by_move_to_zero(id));
|
|
}
|