Browse Source

update

master
zhaohe 1 year ago
parent
commit
9e36995287
  1. 2
      iflytop_canbus_protocol
  2. 4
      usrc/base/config_service.cpp
  3. 37
      usrc/base/hardware.cpp
  4. 46
      usrc/base/hardware.hpp
  5. 11
      usrc/main.cpp
  6. 92
      usrc/protocol_impl/protocol_impl_service.cpp
  7. 2
      zsdk

2
iflytop_canbus_protocol

@ -1 +1 @@
Subproject commit 26cce0d53b0e3332d7a658f0032779a18ce97128
Subproject commit c01f84e2ad44f02f615ceec55762e9eda995c0a1

4
usrc/base/config_service.cpp

@ -10,7 +10,7 @@ static void dump_config(config_t *pcfg) {
ZLOGI(TAG, "=============== config ===============");
ZLOGI(TAG, "configMark : %08x", pcfg->configMark);
ZLOGI(TAG, "placeHolder: %08x", pcfg->placeHolder);
ZLOGI(TAG, "======================================");
ZLOGI(TAG, "=");
}
static void create_default_config(config_t *default_cfg) { //
default_cfg->configMark = FLASH_MASK_VAL;
@ -20,7 +20,6 @@ static void create_default_config(config_t *default_cfg) { //
void config_init(void) {
ZLOGI(TAG, "config_init");
// flash��ʼ��
_default_val_config.configMark = FLASH_MASK_VAL;
_default_val_config.placeHolder = 0;
@ -31,7 +30,6 @@ void config_init(void) {
zflash_factory_reset();
}
// ��ӡ������Ϣ
dump_config(&_config);
}
config_t *config_get(void) { return &_config; }

37
usrc/base/hardware.cpp

@ -0,0 +1,37 @@
#include "hardware.hpp"
#include "zsdk/zcanreceiver/zcanreceiver.hpp"
#define TAG "PROTO"
using namespace iflytop;
/***********************************************************************************************************************
* EXT *
***********************************************************************************************************************/
void Hardware::init() {
m_motor_spi.init(&MOTOR_SPI);
m_modbusBlockHost.initialize(&huart3);
m_sl_mini_ac_ctrl.initAsOutput(PD14, kxs_gpio_nopull, true, false); // m_sl_mini_ac_ctrl
m_atta_mini_air_compressor_ctrl.initAsOutput(PD15, kxs_gpio_nopull, true, false); // m_atta_mini_air_compressor_ctrl
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);
m_pressureSensorBus.init(&m_modbusBlockHost, nullptr, 1000, 1000);
}

46
usrc/base/hardware.hpp

@ -0,0 +1,46 @@
#include <stddef.h>
#include <stdio.h>
#include "base/config_service.hpp"
#include "base/device_info.hpp"
#include "spi.h"
#include "usart.h"
#include "zsdk/modbus/modbus_block_host.hpp"
#include "zsdk/pxx_pressure_sensor_driver/pxx_pressure_sensor_bus.hpp"
#include "zsdk/tmc/ztmc5130.hpp"
#include "zsdk/zsdk.hpp"
void hardware_init();
namespace iflytop {
class Hardware {
ZSPI m_motor_spi; //
ModbusBlockHost m_modbusBlockHost; //
TMC5130 m_motor[2]; // 蠕动泵控制
ZGPIO m_sl_mini_ac_ctrl; // 喷液空压机(MINI)
ZGPIO m_atta_mini_air_compressor_ctrl; // 气密性测试空压机(MINI)
PXXPressureSensorBus m_pressureSensorBus; // PXX压力传感器总线
public:
static Hardware& ins() {
static Hardware ins;
return ins;
}
void init();
int32_t motorNum() { return ZARRAY_SIZE(m_motor); }
TMC5130* motor(int32_t index) {
if (index < ZARRAY_SIZE(m_motor)) {
return &m_motor[index];
}
return nullptr;
}
ZGPIO* sl_mini_ac_ctrl() { return &m_sl_mini_ac_ctrl; }
ZGPIO* atta_mini_air_compressor_ctrl() { return &m_atta_mini_air_compressor_ctrl; }
PXXPressureSensorBus* pressureSensorBus() { return &m_pressureSensorBus; }
};
} // namespace iflytop

11
usrc/main.cpp

@ -39,18 +39,23 @@ void umain() {
config_init();
deviceInfo_init();
ZLOGI(TAG, "%s ", PROJECT);
ZLOGI(TAG, "======================= boardinfo ==================== ");
ZLOGI(TAG, "project : %s ", PROJECT);
ZLOGI(TAG, "version : %d ", SOFTWARE_VERSION);
ZLOGI(TAG, "pversion: %d", deviceInfo_getProtocolVersion());
ZLOGI(TAG, "sn : %s", sn_get_str());
ZLOGI(TAG, "boardId : %d", deviceInfo_getBoardId());
ZLOGI(TAG, "=");
ZLOGI(TAG, "======================= init info ==================== ");
protocol_impl_service_init();
ZLOGI(TAG, "=");
ZLOGI(TAG, "system init done");
ZLOGI(TAG, "======================= sysinfo ======================= ");
SysMgr::ins()->initedFinished();
SysMgr::ins()->dumpSysInfo();
ZLOGI(TAG, "=");
while (true) {
osDelay(1);
debug_light_ctrl();

92
usrc/protocol_impl/protocol_impl_service.cpp

@ -1,9 +1,9 @@
#include "protocol_impl_service.hpp"
#include "base/device_info.hpp"
#include "base/hardware.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"
#define TAG "PROTO"
using namespace iflytop;
@ -18,10 +18,11 @@ using namespace iflytop;
}
#define CHECK_MOTOR_INDEX(_subindex) \
if (_subindex > ZARRAY_SIZE(m_motor)) { \
if (_subindex > Hardware::ins().motorNum()) { \
zcanbus_send_errorack(packet, kerr_invalid_param); \
return; \
}
#define GET_PARAM(buff, off) ((((int32_t*)(buff))[off]))
/***********************************************************************************************************************
* VAR_LIST *
@ -30,15 +31,10 @@ using namespace iflytop;
static osTimerId HeartReportTimerId;
static osThreadId PacketRxThreadId;
static ZSPI m_motor_spi;
static TMC5130 m_motor[2];
/***********************************************************************************************************************
* 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) {
zcanbus_packet_t* packet = (zcanbus_packet_t*)rawpacket;
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 velocity = GET_PARAM(packet->params, 1);
if (subindex > ZARRAY_SIZE(m_motor)) {
if (subindex >= Hardware::ins().motorNum()) {
zcanbus_send_errorack(packet, kerr_invalid_param);
return;
}
m_motor[subindex].rotate(velocity);
Hardware::ins().motor(subindex)->rotate(velocity);
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);
if (subindex > ZARRAY_SIZE(m_motor)) {
if (subindex >= Hardware::ins().motorNum()) {
zcanbus_send_errorack(packet, kerr_invalid_param);
return;
}
m_motor[subindex].stop();
Hardware::ins().motor(subindex)->stop();
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 idelay = GET_PARAM(packet->params, 3);
if (subindex > ZARRAY_SIZE(m_motor)) {
if (subindex >= Hardware::ins().motorNum()) {
zcanbus_send_errorack(packet, kerr_invalid_param);
return;
}
m_motor[subindex].setIHOLD_IRUN(ihold, irun, idelay);
Hardware::ins().motor(subindex)->setIHOLD_IRUN(ihold, irun, idelay);
zcanbus_send_ack(packet, NULL, 0);
} else if (packet->function_id == kcmd_pump_set_acc) {
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 acc = GET_PARAM(packet->params, 1);
if (subindex > ZARRAY_SIZE(m_motor)) {
if (subindex >= Hardware::ins().motorNum()) {
zcanbus_send_errorack(packet, kerr_invalid_param);
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);
}
@ -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 regval = GET_PARAM(packet->params, 2);
if (subindex > ZARRAY_SIZE(m_motor)) {
if (subindex >= Hardware::ins().motorNum()) {
zcanbus_send_errorack(packet, kerr_invalid_param);
return;
}
m_motor[subindex].writeInt(regadd, regval);
Hardware::ins().motor(subindex)->writeInt(regadd, regval);
}
// 读取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 regadd = GET_PARAM(packet->params, 1);
if (subindex > ZARRAY_SIZE(m_motor)) {
if (subindex >= Hardware::ins().motorNum()) {
zcanbus_send_errorack(packet, kerr_invalid_param);
return;
}
int32_t regval = m_motor[subindex].readInt(regadd);
int32_t regval = Hardware::ins().motor(subindex)->readInt(regadd);
zcanbus_send_ack(packet, (uint8_t*)&regval, 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 *
***********************************************************************************************************************/
@ -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);
pump_func_impl(from, to, rawpacket, len);
others_func_impl(from, to, rawpacket, len);
ZLOGI(TAG, "process end");
}
@ -221,33 +245,9 @@ static void zcanbus_on_connected(bool connected) {
* 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() { //
Hardware::ins().init();
ForceReportFlagMgr::ins()->init();
hardware_init();
zcanbus_init(deviceInfo_getBoardId());
zcanbus_reglistener(zcanbus_on_rx);

2
zsdk

@ -1 +1 @@
Subproject commit de4e73aa05048332167a744fe64118ca4bc6b0d7
Subproject commit b8f10eae25ded517701a56b1e609f6608ed04f7a
Loading…
Cancel
Save