|
@ -1,9 +1,9 @@ |
|
|
#include "protocol_impl_service.hpp"
|
|
|
#include "protocol_impl_service.hpp"
|
|
|
|
|
|
|
|
|
#include "base/device_info.hpp"
|
|
|
#include "base/device_info.hpp"
|
|
|
|
|
|
#include "base/hardware.hpp"
|
|
|
#include "report_flag_mgr.hpp"
|
|
|
#include "report_flag_mgr.hpp"
|
|
|
#include "spi.h"
|
|
|
|
|
|
#include "zsdk/tmc/ztmc5130.hpp"
|
|
|
|
|
|
|
|
|
#include "zsdk/modbus/modbus_block_host.hpp"
|
|
|
#include "zsdk/zcanreceiver/zcanreceiver.hpp"
|
|
|
#include "zsdk/zcanreceiver/zcanreceiver.hpp"
|
|
|
#define TAG "PROTO"
|
|
|
#define TAG "PROTO"
|
|
|
using namespace iflytop; |
|
|
using namespace iflytop; |
|
@ -18,10 +18,11 @@ using namespace iflytop; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#define CHECK_MOTOR_INDEX(_subindex) \
|
|
|
#define CHECK_MOTOR_INDEX(_subindex) \
|
|
|
if (_subindex > ZARRAY_SIZE(m_motor)) { \ |
|
|
|
|
|
|
|
|
if (_subindex > Hardware::ins().motorNum()) { \ |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); \ |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); \ |
|
|
return; \ |
|
|
return; \ |
|
|
} |
|
|
} |
|
|
|
|
|
#define GET_PARAM(buff, off) ((((int32_t*)(buff))[off]))
|
|
|
|
|
|
|
|
|
/***********************************************************************************************************************
|
|
|
/***********************************************************************************************************************
|
|
|
* VAR_LIST * |
|
|
* VAR_LIST * |
|
@ -30,15 +31,10 @@ using namespace iflytop; |
|
|
static osTimerId HeartReportTimerId; |
|
|
static osTimerId HeartReportTimerId; |
|
|
static osThreadId PacketRxThreadId; |
|
|
static osThreadId PacketRxThreadId; |
|
|
|
|
|
|
|
|
static ZSPI m_motor_spi; |
|
|
|
|
|
static TMC5130 m_motor[2]; |
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************************************************************
|
|
|
/***********************************************************************************************************************
|
|
|
* FUNCTION_IMPL * |
|
|
* FUNCTION_IMPL * |
|
|
***********************************************************************************************************************/ |
|
|
***********************************************************************************************************************/ |
|
|
|
|
|
|
|
|
#define GET_PARAM(buff, off) ((((int32_t*)(buff))[off]))
|
|
|
|
|
|
|
|
|
|
|
|
static void basic_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { |
|
|
static void basic_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { |
|
|
zcanbus_packet_t* packet = (zcanbus_packet_t*)rawpacket; |
|
|
zcanbus_packet_t* packet = (zcanbus_packet_t*)rawpacket; |
|
|
int32_t paramLen = (len - sizeof(zcanbus_packet_t)) / 4; |
|
|
int32_t paramLen = (len - sizeof(zcanbus_packet_t)) / 4; |
|
@ -102,11 +98,11 @@ static void pump_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t |
|
|
int32_t subindex = GET_PARAM(packet->params, 0); |
|
|
int32_t subindex = GET_PARAM(packet->params, 0); |
|
|
int32_t velocity = GET_PARAM(packet->params, 1); |
|
|
int32_t velocity = GET_PARAM(packet->params, 1); |
|
|
|
|
|
|
|
|
if (subindex > ZARRAY_SIZE(m_motor)) { |
|
|
|
|
|
|
|
|
if (subindex >= Hardware::ins().motorNum()) { |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
m_motor[subindex].rotate(velocity); |
|
|
|
|
|
|
|
|
Hardware::ins().motor(subindex)->rotate(velocity); |
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -116,12 +112,12 @@ static void pump_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t |
|
|
|
|
|
|
|
|
int32_t subindex = GET_PARAM(packet->params, 0); |
|
|
int32_t subindex = GET_PARAM(packet->params, 0); |
|
|
|
|
|
|
|
|
if (subindex > ZARRAY_SIZE(m_motor)) { |
|
|
|
|
|
|
|
|
if (subindex >= Hardware::ins().motorNum()) { |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
m_motor[subindex].stop(); |
|
|
|
|
|
|
|
|
Hardware::ins().motor(subindex)->stop(); |
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -134,12 +130,12 @@ static void pump_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t |
|
|
int32_t irun = GET_PARAM(packet->params, 2); |
|
|
int32_t irun = GET_PARAM(packet->params, 2); |
|
|
int32_t idelay = GET_PARAM(packet->params, 3); |
|
|
int32_t idelay = GET_PARAM(packet->params, 3); |
|
|
|
|
|
|
|
|
if (subindex > ZARRAY_SIZE(m_motor)) { |
|
|
|
|
|
|
|
|
if (subindex >= Hardware::ins().motorNum()) { |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
m_motor[subindex].setIHOLD_IRUN(ihold, irun, idelay); |
|
|
|
|
|
|
|
|
Hardware::ins().motor(subindex)->setIHOLD_IRUN(ihold, irun, idelay); |
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
} else if (packet->function_id == kcmd_pump_set_acc) { |
|
|
} else if (packet->function_id == kcmd_pump_set_acc) { |
|
|
CHECK_PARAM_LEN(paramNum, 2); |
|
|
CHECK_PARAM_LEN(paramNum, 2); |
|
@ -147,13 +143,13 @@ static void pump_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t |
|
|
int32_t subindex = GET_PARAM(packet->params, 0); |
|
|
int32_t subindex = GET_PARAM(packet->params, 0); |
|
|
int32_t acc = GET_PARAM(packet->params, 1); |
|
|
int32_t acc = GET_PARAM(packet->params, 1); |
|
|
|
|
|
|
|
|
if (subindex > ZARRAY_SIZE(m_motor)) { |
|
|
|
|
|
|
|
|
if (subindex >= Hardware::ins().motorNum()) { |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
m_motor[subindex].setAcceleration(acc); |
|
|
|
|
|
m_motor[subindex].setDeceleration(acc); |
|
|
|
|
|
|
|
|
Hardware::ins().motor(subindex)->setAcceleration(acc); |
|
|
|
|
|
Hardware::ins().motor(subindex)->setDeceleration(acc); |
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -166,12 +162,12 @@ static void pump_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t |
|
|
int32_t regadd = GET_PARAM(packet->params, 1); |
|
|
int32_t regadd = GET_PARAM(packet->params, 1); |
|
|
int32_t regval = GET_PARAM(packet->params, 2); |
|
|
int32_t regval = GET_PARAM(packet->params, 2); |
|
|
|
|
|
|
|
|
if (subindex > ZARRAY_SIZE(m_motor)) { |
|
|
|
|
|
|
|
|
if (subindex >= Hardware::ins().motorNum()) { |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
m_motor[subindex].writeInt(regadd, regval); |
|
|
|
|
|
|
|
|
Hardware::ins().motor(subindex)->writeInt(regadd, regval); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 读取5130寄存器
|
|
|
// 读取5130寄存器
|
|
@ -181,16 +177,43 @@ static void pump_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t |
|
|
int32_t subindex = GET_PARAM(packet->params, 0); |
|
|
int32_t subindex = GET_PARAM(packet->params, 0); |
|
|
int32_t regadd = GET_PARAM(packet->params, 1); |
|
|
int32_t regadd = GET_PARAM(packet->params, 1); |
|
|
|
|
|
|
|
|
if (subindex > ZARRAY_SIZE(m_motor)) { |
|
|
|
|
|
|
|
|
if (subindex >= Hardware::ins().motorNum()) { |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); |
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int32_t regval = m_motor[subindex].readInt(regadd); |
|
|
|
|
|
|
|
|
int32_t regval = Hardware::ins().motor(subindex)->readInt(regadd); |
|
|
zcanbus_send_ack(packet, (uint8_t*)®val, sizeof(regval)); |
|
|
zcanbus_send_ack(packet, (uint8_t*)®val, sizeof(regval)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void others_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { |
|
|
|
|
|
zcanbus_packet_t* packet = (zcanbus_packet_t*)rawpacket; |
|
|
|
|
|
int32_t paramNum = (len - sizeof(zcanbus_packet_t)) / 4; |
|
|
|
|
|
|
|
|
|
|
|
// m_atta_mini_air_compressor_ctrl
|
|
|
|
|
|
|
|
|
|
|
|
// 喷液MINI真空泵
|
|
|
|
|
|
if (packet->function_id == kcmd_sl_mini_ac_ctrl) { |
|
|
|
|
|
CHECK_PARAM_LEN(paramNum, 1); |
|
|
|
|
|
Hardware::ins().sl_mini_ac_ctrl()->write(GET_PARAM(packet->params, 0)); |
|
|
|
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
|
|
|
} |
|
|
|
|
|
// 气密性测试MINI真空泵
|
|
|
|
|
|
else if (packet->function_id == kcmd_atta_mini_air_compressor_ctrl) { |
|
|
|
|
|
CHECK_PARAM_LEN(paramNum, 1); |
|
|
|
|
|
Hardware::ins().atta_mini_air_compressor_ctrl()->write(GET_PARAM(packet->params, 0)); |
|
|
|
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 压力传感器数据上报
|
|
|
|
|
|
else if (packet->function_id == kcmd_read_pressure_data) { |
|
|
|
|
|
} |
|
|
|
|
|
// 压力传感器数据上报
|
|
|
|
|
|
else if (packet->function_id == kcmd_set_pressure_data_report_period_ms) { |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/***********************************************************************************************************************
|
|
|
/***********************************************************************************************************************
|
|
|
* SCHEDULER * |
|
|
* SCHEDULER * |
|
|
***********************************************************************************************************************/ |
|
|
***********************************************************************************************************************/ |
|
@ -206,6 +229,7 @@ static void zcanbus_on_rx(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t l |
|
|
|
|
|
|
|
|
basic_func_impl(from, to, rawpacket, len); |
|
|
basic_func_impl(from, to, rawpacket, len); |
|
|
pump_func_impl(from, to, rawpacket, len); |
|
|
pump_func_impl(from, to, rawpacket, len); |
|
|
|
|
|
others_func_impl(from, to, rawpacket, len); |
|
|
|
|
|
|
|
|
ZLOGI(TAG, "process end"); |
|
|
ZLOGI(TAG, "process end"); |
|
|
} |
|
|
} |
|
@ -221,33 +245,9 @@ static void zcanbus_on_connected(bool connected) { |
|
|
* EXT * |
|
|
* EXT * |
|
|
***********************************************************************************************************************/ |
|
|
***********************************************************************************************************************/ |
|
|
|
|
|
|
|
|
void hardware_init() { |
|
|
|
|
|
m_motor_spi.init(&MOTOR_SPI); |
|
|
|
|
|
m_motor[0].initialize(&m_motor_spi, MOTOR1_ENN, MOTOR1_CSN); |
|
|
|
|
|
m_motor[0].setIHOLD_IRUN(1, 15, 0); |
|
|
|
|
|
m_motor[0].setMotorShaft(true); |
|
|
|
|
|
m_motor[0].setAcceleration(300000); |
|
|
|
|
|
m_motor[0].setDeceleration(300000); |
|
|
|
|
|
|
|
|
|
|
|
m_motor[1].initialize(&m_motor_spi, MOTOR2_ENN, MOTOR2_CSN); |
|
|
|
|
|
m_motor[1].setIHOLD_IRUN(1, 15, 0); |
|
|
|
|
|
m_motor[1].setMotorShaft(true); |
|
|
|
|
|
m_motor[1].setAcceleration(300000); |
|
|
|
|
|
m_motor[1].setDeceleration(300000); |
|
|
|
|
|
|
|
|
|
|
|
int32_t chipv0 = m_motor[0].readChipVERSION(); // 5130:0x11
|
|
|
|
|
|
int32_t chipv1 = m_motor[1].readChipVERSION(); // 5130:0x11
|
|
|
|
|
|
|
|
|
|
|
|
// m_motor[0].rotate(500000);
|
|
|
|
|
|
// m_motor[1].rotate(500000);
|
|
|
|
|
|
|
|
|
|
|
|
ZLOGI(TAG, "chipv0: %x, chipv1: %x", chipv0, chipv1); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void protocol_impl_service_init() { //
|
|
|
void protocol_impl_service_init() { //
|
|
|
|
|
|
|
|
|
|
|
|
Hardware::ins().init(); |
|
|
ForceReportFlagMgr::ins()->init(); |
|
|
ForceReportFlagMgr::ins()->init(); |
|
|
hardware_init(); |
|
|
|
|
|
|
|
|
|
|
|
zcanbus_init(deviceInfo_getBoardId()); |
|
|
zcanbus_init(deviceInfo_getBoardId()); |
|
|
zcanbus_reglistener(zcanbus_on_rx); |
|
|
zcanbus_reglistener(zcanbus_on_rx); |
|
|