21 changed files with 1209 additions and 494 deletions
-
4.settings/language.settings.xml
-
2Core/Src/main.c
-
2sdk
-
0usrc.bak/can_cmd_reg_fn_reg.cpp
-
2usrc.bak/device.cpp
-
0usrc.bak/device.hpp
-
104usrc.bak/driver/preportional_valve_ctrl.cpp
-
51usrc.bak/driver/preportional_valve_ctrl.hpp
-
29usrc.bak/main.cpp
-
24usrc.bak/project.hpp
-
0usrc.bak/uart_debug_fn_reg.cpp
-
26usrc/driver/preportional_valve_ctrl.cpp
-
363usrc/hardware.cpp
-
15usrc/hardware.hpp
-
154usrc/main.cpp
-
27usrc/main.hpp
-
4usrc/project.hpp
@ -1 +1 @@ |
|||
Subproject commit 22d7d685c4a5adaa0e3515a290fdb5c31d594b39 |
|||
Subproject commit 5751b8278aab13053c715341d3c1fde48f770280 |
@ -0,0 +1,104 @@ |
|||
#include "preportional_valve_ctrl.hpp"
|
|||
using namespace iflytop; |
|||
|
|||
#define WORK_STATE_REG 0x0000
|
|||
#define CTRL_STATE_REG 0x0001
|
|||
#define POS_STATE_REG 0x0013
|
|||
|
|||
void PreportionalValveCtrl::initialize(UART_HandleTypeDef* huart) { m_modbusBlockHost.initialize(huart); } |
|||
|
|||
int32_t PreportionalValveCtrl::setValvePos(int32_t valueid, int32_t pos) { //
|
|||
|
|||
/**
|
|||
* @brief 发送失败重发3次 |
|||
*/ |
|||
for (size_t i = 0; i < 3; i++) { |
|||
int32_t err = _setValvePos(valueid, pos); |
|||
if (err == 0) return 0; |
|||
} |
|||
return 1; |
|||
} |
|||
int32_t PreportionalValveCtrl::_setValvePos(int32_t valueid, int32_t pos) { //
|
|||
if (valueid > 255 || valueid < 1) { |
|||
return 1; |
|||
} |
|||
bool ret = m_modbusBlockHost.writeReg06(valueid, CTRL_STATE_REG, pos, 30); |
|||
if (!ret) return 1; |
|||
m_last_set_valve_ticket = HAL_GetTick(); |
|||
m_targetpos[valueid] = pos; |
|||
return 0; |
|||
} |
|||
int32_t PreportionalValveCtrl::getValvePos(int32_t valueid, int32_t* pos) { |
|||
// return m_modbusBlockHost.readReg03(valueid, POS_STATE_REG, pos, 30);
|
|||
uint16_t pos16 = 0; |
|||
bool ret = m_modbusBlockHost.readReg03(valueid, POS_STATE_REG, &pos16, 30); |
|||
*pos = pos16; |
|||
if (!ret) return 1; |
|||
return 0; |
|||
} |
|||
int32_t PreportionalValveCtrl::getValveOrderPos(int32_t valueid, int32_t* pos) { |
|||
uint16_t pos16 = 0; |
|||
bool ret = m_modbusBlockHost.readReg03(valueid, CTRL_STATE_REG, &pos16, 30); |
|||
*pos = pos16; |
|||
if (!ret) return 1; |
|||
return 0; |
|||
} |
|||
#define TAG "PreportionalValveCtrl"
|
|||
|
|||
int32_t PreportionalValveCtrl::isBusy(int32_t valueid, int32_t* busy) { |
|||
#if 1
|
|||
int32_t orderpos = 0; |
|||
int32_t pos = 0; |
|||
int32_t err = 0; |
|||
|
|||
#if 0
|
|||
err = getValveOrderPos(valueid, &orderpos); |
|||
if (err != 0) return err; |
|||
#endif
|
|||
orderpos = m_targetpos[valueid]; |
|||
|
|||
err = getValvePos(valueid, &pos); |
|||
if (err != 0) return err; |
|||
|
|||
if (abs(m_targetpos[valueid] - pos) <= 11) { |
|||
*busy = 0; |
|||
} else { |
|||
*busy = 1; |
|||
} |
|||
return 0; |
|||
#endif
|
|||
|
|||
#if 0
|
|||
|
|||
/**
|
|||
* @brief |
|||
* 比例阀当前状态的更新是有延迟的,例如下发指令控制比例阀开合到90%,下发执行后(收到指令的回执), |
|||
* 此时读取比例阀状态,比例阀的状态并非运动中,而是stop,需要等待一段时间后,再读取状态,状态才是运动中。 |
|||
*/ |
|||
if (haspassedms(m_last_set_valve_ticket) < 300) { |
|||
*busy = 1; |
|||
return 0; |
|||
} |
|||
int32_t valve1state = 0; |
|||
int32_t err = 0; |
|||
|
|||
err = getValveWorkState(1, &valve1state); |
|||
if (err != 0) return err; |
|||
|
|||
if (valve1state == kstate_stop) { |
|||
*busy = 0; |
|||
} else { |
|||
*busy = 1; |
|||
} |
|||
return 0; |
|||
|
|||
#endif
|
|||
} |
|||
|
|||
int32_t PreportionalValveCtrl::getValveWorkState(int32_t valueid, int32_t* state) { |
|||
uint16_t state16 = 0; |
|||
bool ret = m_modbusBlockHost.readReg03(valueid, WORK_STATE_REG, &state16, 30); |
|||
*state = state16; |
|||
if (!ret) return 1; |
|||
return 0; |
|||
} |
@ -0,0 +1,51 @@ |
|||
//
|
|||
// Created by zwsd
|
|||
//
|
|||
|
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
#include <stdio.h>
|
|||
|
|||
#include "sdk/hal/zhal.hpp"
|
|||
#include "sdk\components\modbus\modbus_block_host.hpp"
|
|||
|
|||
/**
|
|||
* @brief |
|||
* |
|||
* https://iflytop1.feishu.cn/wiki/GQwCwHMqFiaJRwks80ncwaYKnSe
|
|||
*/ |
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
class PreportionalValveCtrl { |
|||
public: |
|||
typedef enum { |
|||
kstate_stop = 0x0, |
|||
kstate_running_forward = 0xaa, |
|||
kstate_running_backward = 0xbb, |
|||
kstate_err_state = 0xea, |
|||
} work_state_t; |
|||
|
|||
private: |
|||
/* data */ |
|||
ModbusBlockHost m_modbusBlockHost; |
|||
int32_t val = 0; |
|||
uint32_t m_last_set_valve_ticket = 0; |
|||
uint16_t m_targetpos[255]; |
|||
|
|||
public: |
|||
PreportionalValveCtrl(){}; |
|||
~PreportionalValveCtrl(){}; |
|||
|
|||
void initialize(UART_HandleTypeDef* huart); |
|||
int32_t setValvePos(int32_t valueid, int32_t pos); |
|||
int32_t getValvePos(int32_t valueid, int32_t* pos); |
|||
int32_t getValveOrderPos(int32_t valueid, int32_t* pos); |
|||
int32_t isBusy(int32_t valueid, int32_t* busy); |
|||
int32_t getValveWorkState(int32_t valueid, int32_t* state); |
|||
|
|||
private: |
|||
int32_t _setValvePos(int32_t valueid, int32_t pos); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -0,0 +1,29 @@ |
|||
#include "device.hpp"
|
|||
#define TAG "main"
|
|||
namespace iflytop { |
|||
extern void uart_debug_fn_reg(); |
|||
extern void can_cmd_reg_fn_reg(); |
|||
}; // namespace iflytop
|
|||
|
|||
using namespace iflytop; |
|||
extern "C"{ |
|||
void umain(void) { |
|||
ZHALCORE::cfg_t oscfg = { |
|||
.delayhtim = &DELAY_US_TIMER, |
|||
.debuguart = &DEBUG_UART, |
|||
}; |
|||
ZHALCORE::getInstance()->initialize(oscfg); |
|||
|
|||
ZLOGI(TAG, "pipeline_disinfection_liquid_path_control:%s", VERSION); |
|||
|
|||
device_init(); |
|||
uart_debug_fn_reg(); |
|||
can_cmd_reg_fn_reg(); |
|||
ZLOGI(TAG, "init done"); |
|||
while (1) { |
|||
cmdScheduler.schedule(); |
|||
ZHALCORE::getInstance()->loop(); |
|||
HAL_IWDG_Refresh(&hiwdg); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
#pragma once
|
|||
|
|||
#define VERSION "v1.2"
|
|||
// 设备ID
|
|||
#define DEVICE_ID (2)
|
|||
// 调试串口
|
|||
#define DEBUG_UART huart1
|
|||
// 调试指示灯
|
|||
#define DEBUG_LIGHT_GPIO PE8
|
|||
// 微秒延迟定时器,注意该延时定时器需要按照以下文档进行配置
|
|||
// http://192.168.1.3:3000/zwikipedia/iflytop_wikipedia/src/branch/master/doc/stm32cubemx_us_timer.md
|
|||
#define DELAY_US_TIMER htim6
|
|||
#define MICROSWITCH_NUM 6
|
|||
//
|
|||
#define MOTOR_SPI hspi1
|
|||
|
|||
#define TMC5130_MOTOR_NUM 2
|
|||
#define MOTOR_CH(n) (n)
|
|||
// FYBJ_PY
|
|||
#define MOTOR2_CSN PA4 //
|
|||
#define MOTOR2_ENN PE11
|
|||
// FYBJ_TJ_DRV
|
|||
#define MOTOR1_CSN PC4 //
|
|||
#define MOTOR1_ENN PE12
|
@ -0,0 +1,363 @@ |
|||
#include "hardware.hpp"
|
|||
|
|||
#include <stddef.h>
|
|||
#include <stdio.h>
|
|||
|
|||
#include "main.h"
|
|||
#include "project.hpp"
|
|||
//
|
|||
// #include "sdk/components/single_axis_motor_control_v2/single_axis_motor_control_v2.hpp"
|
|||
#include "sdk/components/iflytop_can_slave_modules/idcard_reader_service.hpp"
|
|||
#include "sdk/components/single_axis_motor_control/single_axis_motor_control.hpp"
|
|||
#include "sdk/hal/zhal.hpp"
|
|||
#include "sdk\components\iflytop_can_slave_modules\io_control_service.hpp"
|
|||
#include "sdk\components\iflytop_can_slave_v1\iflytop_can_slave.hpp"
|
|||
#include "sdk\components\m3078\m3078_code_scaner.hpp"
|
|||
#include "sdk\components\tmc\ic\ztmc4361A.hpp"
|
|||
#include "sdk\components\tmc\ic\ztmc5130.hpp"
|
|||
//
|
|||
#include "driver/preportional_valve_ctrl.hpp"
|
|||
#include "sdk\components\huacheng_sensor\dp600_pressure_sensor.hpp"
|
|||
#include "sdk\components\zcan_module\huacheng_pressure_sensor.hpp"
|
|||
#include "sdk\components\zcan_module\zcan_basic_order_module.hpp"
|
|||
#include "sdk\components\zcan_module\zcan_pump_ctrl_module.hpp"
|
|||
#include "sdk\components\zcan_module\zcan_trigle_warning_light_ctl_module.hpp"
|
|||
|
|||
using namespace iflytop; |
|||
#define TAG "main"
|
|||
|
|||
TMC5130 m_motor1; |
|||
TMC5130 m_motor2; |
|||
|
|||
ZGPIO triLight_R; |
|||
ZGPIO triLight_G; |
|||
ZGPIO triLight_Y; |
|||
ZGPIO triLight_BEEP; |
|||
|
|||
ZCanBasicOrderModule m_basicOrderModule; |
|||
ZCanPumpCtrlModule m_pumpCtrlModule; |
|||
ZCanTrigleWarningLightCtlModule m_warningLightCtlModule; |
|||
HuachengPressureSensor m_huachengPressureSensor; |
|||
|
|||
DP600PressureSensor m_dp600PressureSensor2; |
|||
DP600PressureSensor m_dp600PressureSensor3; |
|||
DP600PressureSensor m_dp600PressureSensor4; |
|||
|
|||
ZGPIO IO_PD13_IN; |
|||
ZGPIO IO_PC7_IN; |
|||
|
|||
ZGPIO OUT_PD14; |
|||
ZGPIO OUT_PD15; |
|||
|
|||
void setmotor(TMC5130 *motor, int16_t acc_rpm2, int16_t rpm, int16_t idlepower, int16_t power) { |
|||
int32_t ppm = rpm / 60.0 * 51200; |
|||
int32_t acc = acc_rpm2 / 60.0 * 51200; |
|||
|
|||
int16_t _idlepower = 1; |
|||
int16_t _power = 31; |
|||
|
|||
if (idlepower > 0 && idlepower < 31) { |
|||
_idlepower = idlepower; |
|||
} |
|||
if (power > 0 && power < 31) { |
|||
_power = power; |
|||
} |
|||
|
|||
motor->setIHOLD_IRUN(_idlepower, _power, 10); // 5W
|
|||
motor->setAcceleration(acc); |
|||
motor->setDeceleration(acc); |
|||
motor->rotate(ppm); |
|||
} |
|||
PreportionalValveCtrl m_PreportionalValveHost; |
|||
|
|||
int32_t preportional_valve_is_busy(int32_t *busy) { |
|||
int32_t valve1state = 0; |
|||
int32_t valve2state = 0; |
|||
int32_t err = 0; |
|||
*busy = 1; |
|||
|
|||
err = m_PreportionalValveHost.isBusy(1, &valve1state); |
|||
if (err != 0) return err; |
|||
err = m_PreportionalValveHost.isBusy(2, &valve2state); |
|||
if (err != 0) return err; |
|||
|
|||
if (valve1state == 0 && valve2state == 0) { |
|||
*busy = 0; |
|||
} else { |
|||
*busy = 1; |
|||
} |
|||
return 0; |
|||
} |
|||
|
|||
void air_compressor_read_pressure(int32_t *ack) { //
|
|||
DP600PressureSensor::sensor_data_t d = m_huachengPressureSensor.readsensordata(2); |
|||
*ack = d.value; |
|||
} |
|||
|
|||
void Hardware::initialize(int deviceId) { |
|||
m_device_id = deviceId; |
|||
// IO_PD13_IN.initAsInput(PD13, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/);
|
|||
// IO_PC7_IN.initAsInput(PC7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, false /*mirror*/);
|
|||
{ |
|||
TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR1_ENN, .csn_pin = MOTOR1_CSN}; |
|||
|
|||
m_motor1.initialize(&cfg); |
|||
int32_t chipv = m_motor1.readChipVERSION(); |
|||
ZLOGI(TAG, "m_motor1:%lx", chipv); |
|||
m_motor1.setIHOLD_IRUN(1, 20, 0); |
|||
m_motor1.setMotorShaft(true); |
|||
|
|||
m_motor1.setAcceleration(300000); |
|||
m_motor1.setDeceleration(300000); |
|||
// m_motor1.rotate(1000000);
|
|||
} |
|||
|
|||
{ |
|||
TMC5130::cfg_t cfg = {.hspi = &MOTOR_SPI, .enn_pin = MOTOR2_ENN, .csn_pin = MOTOR2_CSN}; |
|||
|
|||
m_motor2.initialize(&cfg); |
|||
int32_t chipv = m_motor2.readChipVERSION(); |
|||
ZLOGI(TAG, "m_motor2:%lx", chipv); |
|||
m_motor2.setIHOLD_IRUN(1, 20, 0); // 5W
|
|||
m_motor2.setMotorShaft(true); |
|||
|
|||
m_motor2.setAcceleration(300000); |
|||
m_motor2.setDeceleration(300000); |
|||
// m_motor2.rotate(1000000);
|
|||
} |
|||
|
|||
triLight_R.initAsOutput(PD8, ZGPIO::kMode_nopull, true, false); |
|||
triLight_G.initAsOutput(PD7, ZGPIO::kMode_nopull, true, false); |
|||
triLight_Y.initAsOutput(PD9, ZGPIO::kMode_nopull, true, false); |
|||
triLight_BEEP.initAsOutput(PD10, ZGPIO::kMode_nopull, true, false); |
|||
|
|||
#if 0
|
|||
m_dp600PressureSensor2.initialize(&huart3, 2); |
|||
m_dp600PressureSensor3.initialize(&huart3, 3); |
|||
m_dp600PressureSensor4.initialize(&huart3, 4); |
|||
|
|||
OUT_PD14.initAsOutput(PD14, ZGPIO::kMode_nopull, false, true); |
|||
OUT_PD15.initAsOutput(PD15, ZGPIO::kMode_nopull, true, false); |
|||
#endif
|
|||
} |
|||
|
|||
void dumpdp600data(DP600PressureSensor::sensor_data_t *data) { |
|||
ZLOGI(TAG, "value:%d", data->value); |
|||
ZLOGI(TAG, "zero_point:%d", data->zero_point); |
|||
ZLOGI(TAG, "range_full_point:%d", data->range_full_point); |
|||
ZLOGI(TAG, "precision:%d", data->precision); |
|||
ZLOGI(TAG, "pressure_unit:%d", data->pressure_unit); |
|||
} |
|||
|
|||
void packet_kcmd_read_huacheng_pressure_sensor_data(int id, DP600PressureSensor::sensor_data_t *dp600data, uint8_t *receipt, int32_t &receiptsize) { |
|||
receipt[0] = id; |
|||
receipt[1] = 0; |
|||
receipt[2] = dp600data->precision; |
|||
receipt[3] = dp600data->pressure_unit; |
|||
memcpy(receipt + 4, &dp600data->value, 2); |
|||
memcpy(receipt + 6, &dp600data->zero_point, 2); |
|||
memcpy(receipt + 8, &dp600data->range_full_point, 2); |
|||
receiptsize = 10; |
|||
} |
|||
|
|||
int32_t Hardware::process_rx_packet(from_where_t fromwhere, uint8_t *packet, int32_t len, uint8_t *receipt, int32_t &receiptsize, bool &matching) { |
|||
Cmdheader_t *cmdheader = (Cmdheader_t *)packet; |
|||
if (fromwhere == kuart) printf("rx: cmdid:%d subcmdid:%d id:%d\n", cmdheader->cmdid, cmdheader->subcmdid, cmdheader->data[0]); |
|||
|
|||
/**
|
|||
* @brief Ping |
|||
*/ |
|||
PROCESS_CMD(kcmd_ping, 0, m_device_id) { |
|||
receipt[0] = cmdheader->data[0]; |
|||
receiptsize = 1; |
|||
return 0; |
|||
} |
|||
|
|||
/**
|
|||
* @brief 控制加液泵 |
|||
*/ |
|||
PROCESS_CMD(kcmd_peristaltic_pump_ctl, 1, 1) { |
|||
int16_t acc = *(int16_t *)(&cmdheader->data[2]); |
|||
int16_t rpm = *(int16_t *)(&cmdheader->data[4]); |
|||
int16_t idlepower = cmdheader->data[6]; |
|||
int16_t power = cmdheader->data[7]; |
|||
|
|||
printf("kcmd_peristaltic_pump_ctl 1 acc:%d rpm:%d idlepower:%d power:%d\n", acc, rpm, idlepower, power); |
|||
|
|||
setmotor(&m_motor1, acc, rpm, idlepower, power); |
|||
receipt[0] = cmdheader->data[0]; |
|||
receiptsize = 1; |
|||
return 0; |
|||
} |
|||
|
|||
/**
|
|||
* @brief 控制-喷液泵 |
|||
*/ |
|||
PROCESS_CMD(kcmd_peristaltic_pump_ctl, 1, 2) { |
|||
int16_t acc = *(int16_t *)(&cmdheader->data[2]); |
|||
int16_t rpm = *(int16_t *)(&cmdheader->data[4]); |
|||
int16_t idlepower = cmdheader->data[6]; |
|||
int16_t power = cmdheader->data[7]; |
|||
printf("kcmd_peristaltic_pump_ctl 2 acc:%d rpm:%d idlepower:%d power:%d\n", acc, rpm, idlepower, power); |
|||
|
|||
setmotor(&m_motor2, acc, rpm, idlepower, power); |
|||
receipt[0] = cmdheader->data[0]; |
|||
receiptsize = 1; |
|||
return 0; |
|||
} |
|||
|
|||
/**
|
|||
* @brief 三色指示灯控制 |
|||
*/ |
|||
PROCESS_CMD(kcmd_triple_warning_light_ctl, 0, 1) { |
|||
/**
|
|||
* @brief 0:设置状态 |
|||
* cmd: |
|||
* [0]:SENSORID |
|||
* [2]:红色灯状态 |
|||
* [3]:黄色灯状态 |
|||
* [4]:绿色灯状态 |
|||
* [5]:蜂鸣器状态 |
|||
* ack : b0:id |
|||
* ack_datalen : 1 |
|||
*/ |
|||
uint8_t id = cmdheader->data[0]; |
|||
uint8_t r = cmdheader->data[2]; |
|||
uint8_t g = cmdheader->data[3]; |
|||
uint8_t b = cmdheader->data[4]; |
|||
uint8_t beep = cmdheader->data[5]; |
|||
|
|||
triLight_R.setState(r != 0); |
|||
triLight_G.setState(g != 0); |
|||
triLight_Y.setState(b != 0); |
|||
triLight_BEEP.setState(beep != 0); |
|||
|
|||
receipt[0] = cmdheader->data[0]; |
|||
receiptsize = 1; |
|||
} |
|||
|
|||
if ((cmdheader->cmdid == (uint16_t)kcmd_air_compressor_valve1_set) && (cmdheader->subcmdid == 0)) { |
|||
uint32_t val = *(uint32_t *)(&cmdheader->data[0]); |
|||
OUT_PD14.setState(val != 0); |
|||
matching = true; |
|||
} |
|||
|
|||
if ((cmdheader->cmdid == (uint16_t)kcmd_air_compressor_valve2_set) && (cmdheader->subcmdid == 0)) { |
|||
uint32_t val = *(uint32_t *)(&cmdheader->data[0]); |
|||
OUT_PD14.setState(val != 0); |
|||
matching = true; |
|||
} |
|||
|
|||
if ((cmdheader->cmdid == (uint16_t)kcmd_proportional_read_state) && (cmdheader->subcmdid == 0)) { |
|||
matching = true; |
|||
|
|||
int32_t ack = 0; |
|||
int32_t ecode = preportional_valve_is_busy(&ack); |
|||
|
|||
int32_t *p_receipt_32 = (int32_t *)receipt; |
|||
*p_receipt_32 = ack; |
|||
receiptsize = 4; |
|||
} |
|||
|
|||
if ((cmdheader->cmdid == (uint16_t)kcmd_set_proportional_valve) && (cmdheader->subcmdid == 0)) { |
|||
int32_t para0 = *(int32_t *)(&cmdheader->data[0]); |
|||
int32_t para1 = *(int32_t *)(&cmdheader->data[4]); |
|||
if (para0 == 1) { |
|||
matching = true; |
|||
m_PreportionalValveHost.setValvePos(1, para1); |
|||
} else if (para0 == 2) { |
|||
matching = true; |
|||
m_PreportionalValveHost.setValvePos(2, para1); |
|||
} |
|||
} |
|||
static DP600PressureSensor::sensor_data_t dp600data; |
|||
if ((cmdheader->cmdid == (uint16_t)kcmd_air_compressor_read_pressure) && (cmdheader->subcmdid == 0)) { |
|||
matching = true; |
|||
bool suc = m_dp600PressureSensor2.readVal(&dp600data); |
|||
if (!suc) return 1002; |
|||
int32_t *p_receipt_32 = (int32_t *)receipt; |
|||
*p_receipt_32 = dp600data.value; |
|||
receiptsize = 4; |
|||
} |
|||
|
|||
#if 0
|
|||
/**
|
|||
* @brief 获取蒸发仓水浸状态 |
|||
*/ |
|||
PROCESS_CMD(kcmd_proportional_read_water_immersion_sensor, 0, 0) { |
|||
((int32_t *)receipt)[0] = !IO_PC7_IN.getState(); |
|||
receiptsize = 4; |
|||
return 0; |
|||
} |
|||
|
|||
/**
|
|||
* @brief 获取设备底盘水浸传感器 |
|||
*/ |
|||
PROCESS_CMD(kcmd_proportional_read_water_immersion_sensor, 0, 1) { |
|||
((int32_t *)receipt)[0] = !IO_PD13_IN.getState(); |
|||
receiptsize = 4; |
|||
return 0; |
|||
} |
|||
|
|||
#endif
|
|||
|
|||
/**
|
|||
* @brief 液位测量压力传感器 |
|||
*/ |
|||
PROCESS_CMD(kcmd_read_huacheng_pressure_sensor, 0, 1) { |
|||
static ModbusBlockHost modbusBlockHost; |
|||
modbusBlockHost.initialize(&huart3); |
|||
int16_t val[1] = {0}; |
|||
bool suc = modbusBlockHost.readReg03Muti(1, 0x00, (uint16_t *)val, 1, 50); |
|||
if (!suc) return 1002; |
|||
dp600data.precision = 3; |
|||
dp600data.pressure_unit = 1; |
|||
dp600data.value = val[0]; |
|||
dp600data.zero_point = 0; |
|||
dp600data.range_full_point = 0; |
|||
packet_kcmd_read_huacheng_pressure_sensor_data(cmdheader->data[0], &dp600data, receipt, receiptsize); |
|||
if (fromwhere == kuart) { |
|||
dumpdp600data(&dp600data); |
|||
} |
|||
return 0; |
|||
} |
|||
/**
|
|||
* @brief 空压机压力传感器 |
|||
*/ |
|||
PROCESS_CMD(kcmd_read_huacheng_pressure_sensor, 0, 2) { |
|||
bool suc = m_dp600PressureSensor2.readVal(&dp600data); |
|||
if (!suc) return 1002; |
|||
packet_kcmd_read_huacheng_pressure_sensor_data(cmdheader->data[0], &dp600data, receipt, receiptsize); |
|||
if (fromwhere == kuart) { |
|||
dumpdp600data(&dp600data); |
|||
} |
|||
return 0; |
|||
} |
|||
/**
|
|||
* @brief 加液蠕动泵压力传感器 |
|||
*/ |
|||
PROCESS_CMD(kcmd_read_huacheng_pressure_sensor, 0, 3) { |
|||
bool suc = m_dp600PressureSensor3.readVal(&dp600data); |
|||
if (!suc) return 1002; |
|||
packet_kcmd_read_huacheng_pressure_sensor_data(cmdheader->data[0], &dp600data, receipt, receiptsize); |
|||
if (fromwhere == kuart) { |
|||
dumpdp600data(&dp600data); |
|||
} |
|||
return 0; |
|||
} |
|||
/**
|
|||
* @brief 喷射蠕动泵压力传感器 |
|||
*/ |
|||
PROCESS_CMD(kcmd_read_huacheng_pressure_sensor, 0, 4) { |
|||
bool suc = m_dp600PressureSensor4.readVal(&dp600data); |
|||
if (!suc) return 1002; |
|||
packet_kcmd_read_huacheng_pressure_sensor_data(cmdheader->data[0], &dp600data, receipt, receiptsize); |
|||
if (fromwhere == kuart) { |
|||
dumpdp600data(&dp600data); |
|||
} |
|||
return 0; |
|||
} |
|||
|
|||
return 0; |
|||
} |
|||
void Hardware::loop() {} |
@ -0,0 +1,15 @@ |
|||
#include <stdint.h>
|
|||
|
|||
namespace iflytop { |
|||
class Hardware { |
|||
public: |
|||
typedef enum { kcan, kuart } from_where_t; |
|||
int32_t m_device_id = 0; |
|||
|
|||
public: |
|||
void initialize(int deviceId); |
|||
int32_t process_rx_packet(from_where_t fromwhere, uint8_t *packet, int32_t len, uint8_t *receipt, int32_t &receiptsize, bool &matching); |
|||
void loop(); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -1,29 +1,157 @@ |
|||
#include "device.hpp"
|
|||
#include "main.hpp"
|
|||
|
|||
#include <stddef.h>
|
|||
#include <stdio.h>
|
|||
|
|||
#include "main.h"
|
|||
#include "project.hpp"
|
|||
//
|
|||
// #include "sdk/components/single_axis_motor_control_v2/single_axis_motor_control_v2.hpp"
|
|||
#include "sdk/components/iflytop_can_slave_modules/idcard_reader_service.hpp"
|
|||
#include "sdk/components/single_axis_motor_control/single_axis_motor_control.hpp"
|
|||
#include "sdk/hal/zhal.hpp"
|
|||
#include "sdk\components\iflytop_can_slave_modules\io_control_service.hpp"
|
|||
#include "sdk\components\iflytop_can_slave_v1\iflytop_can_slave.hpp"
|
|||
#include "sdk\components\m3078\m3078_code_scaner.hpp"
|
|||
#include "sdk\components\tmc\ic\ztmc4361A.hpp"
|
|||
#include "sdk\components\tmc\ic\ztmc5130.hpp"
|
|||
//
|
|||
#include "hardware.hpp"
|
|||
#include "sdk\components\huacheng_sensor\dp600_pressure_sensor.hpp"
|
|||
#include "sdk\components\string_utils.hpp"
|
|||
#include "sdk\components\zcan_module\huacheng_pressure_sensor.hpp"
|
|||
#include "sdk\components\zcan_module\zcan_basic_order_module.hpp"
|
|||
#include "sdk\components\zcan_module\zcan_pump_ctrl_module.hpp"
|
|||
#include "sdk\components\zcan_module\zcan_trigle_warning_light_ctl_module.hpp"
|
|||
|
|||
#define TAG "main"
|
|||
namespace iflytop { |
|||
extern void uart_debug_fn_reg(); |
|||
extern void can_cmd_reg_fn_reg(); |
|||
}; // namespace iflytop
|
|||
Main gmain; |
|||
}; |
|||
|
|||
using namespace iflytop; |
|||
extern "C"{ |
|||
void umain(void) { |
|||
|
|||
void dumphexdata(uint8_t *data, int32_t len) { |
|||
for (int32_t i = 0; i < len; i++) { |
|||
printf("%02X ", data[i]); |
|||
} |
|||
printf("\n"); |
|||
} |
|||
|
|||
/*******************************************************************************
|
|||
* GLOBAL * |
|||
*******************************************************************************/ |
|||
|
|||
IflytopCanProtocolStackProcesser m_protocolStack; |
|||
Hardware m_hardware; |
|||
ZGPIO debuglight; |
|||
ZCanReceiver m_canReceiver; |
|||
|
|||
/*******************************************************************************
|
|||
* MESSAGE_HANDLER * |
|||
*******************************************************************************/ |
|||
/**
|
|||
* @brief 处理CAN接收到消息 |
|||
*/ |
|||
void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) { |
|||
// ZLOGI(TAG, "onRceivePacket from %d %d", rxbuf->id, len);
|
|||
static uint8_t rxdata[1024] = {0}; |
|||
memset(rxdata, 0, sizeof(rxdata)); |
|||
Cmdheader_t *cmdheader = (Cmdheader_t *)packet; |
|||
bool match = false; |
|||
int32_t receipt_size = 0; |
|||
int32_t ecode = m_hardware.process_rx_packet(Hardware::from_where_t::kcan, packet, len, rxdata, receipt_size, match); |
|||
if (match) { |
|||
if (ecode != 0) { |
|||
m_canReceiver.sendErrorAck(cmdheader, ecode); |
|||
} else { |
|||
m_canReceiver.sendAck(cmdheader, rxdata, receipt_size); |
|||
} |
|||
} |
|||
} |
|||
/**
|
|||
* @brief 处理串口接收到的消息 |
|||
*/ |
|||
|
|||
static void processUARTEachLine(char *packet, size_t len) { |
|||
static uint8_t rxdata[1024] = {0}; |
|||
int32_t receipt_size = 0; |
|||
bool match = false; |
|||
|
|||
memset(rxdata, 0, sizeof(rxdata)); |
|||
|
|||
//
|
|||
int32_t bytelen = 0; |
|||
uint8_t *hexbytes = StringUtils::hex_str_to_bytes((char *)packet, len, bytelen); |
|||
if (hexbytes == NULL) { |
|||
ZLOGE(TAG, "hex_str_to_bytes failed"); |
|||
return; |
|||
} |
|||
dumphexdata(hexbytes, bytelen); |
|||
int32_t ecode = m_hardware.process_rx_packet(Hardware::kuart, hexbytes, bytelen, rxdata, receipt_size, match); |
|||
if (match) { |
|||
printf("match\n"); |
|||
if (ecode < 0) { |
|||
printf("ecode :%d\n", ecode); |
|||
return; |
|||
} |
|||
dumphexdata(rxdata, receipt_size); |
|||
} |
|||
printf("\n"); |
|||
} |
|||
|
|||
static void processUartRX(uint8_t *packet, size_t len) { |
|||
for (size_t i = 0; i < len; i++) { |
|||
if (packet[i] == '\n' || packet[i] == '\r') { |
|||
packet[i] = '\0'; |
|||
} |
|||
} |
|||
|
|||
for (size_t i = 0; i < len; i++) { |
|||
if (i == 0) { |
|||
processUARTEachLine((char *)packet, strlen((char *)packet)); |
|||
} else if (packet[i - 1] == '\0' && packet[i] != '\0') { |
|||
processUARTEachLine((char *)packet + i, strlen((char *)packet + i)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/*******************************************************************************
|
|||
* MAIN * |
|||
*******************************************************************************/ |
|||
void Main::run() { |
|||
ZHALCORE::cfg_t oscfg = { |
|||
.delayhtim = &DELAY_US_TIMER, |
|||
.debuguart = &DEBUG_UART, |
|||
}; |
|||
ZHALCORE::getInstance()->initialize(oscfg); |
|||
|
|||
ZLOGI(TAG, "pipeline_disinfection_liquid_path_control:%s", VERSION); |
|||
ZLOGI(TAG, "little_disinfection_liquid_path_control:%s", VERSION); |
|||
|
|||
debuglight.initAsOutput(DEBUG_LIGHT_GPIO, ZGPIO::kMode_nopull, false, false); |
|||
ZHAL_CORE_REG(200, { debuglight.toggleState(); }); |
|||
|
|||
m_hardware.initialize(DEVICE_ID); |
|||
|
|||
static ZUART uartreceiver; |
|||
static ZUART::cfg_t uartreceiver_cfg = { |
|||
.name = "uartreceiver", |
|||
.huart = &DEBUG_UART, |
|||
.rxbuffersize = 512, |
|||
.rxovertime_ms = 30, |
|||
}; |
|||
uartreceiver.initialize(&uartreceiver_cfg); |
|||
uartreceiver.setrxcb([this](uint8_t *data, size_t len) { processUartRX(data, len); }); |
|||
uartreceiver.startRxIt(); |
|||
|
|||
ZCanReceiver::CFG *cfg = m_canReceiver.createCFG(DEVICE_ID); |
|||
m_canReceiver.init(cfg); |
|||
m_canReceiver.registerListener(this); |
|||
|
|||
device_init(); |
|||
uart_debug_fn_reg(); |
|||
can_cmd_reg_fn_reg(); |
|||
ZLOGI(TAG, "init done"); |
|||
while (1) { |
|||
cmdScheduler.schedule(); |
|||
ZHALCORE::getInstance()->loop(); |
|||
HAL_IWDG_Refresh(&hiwdg); |
|||
m_hardware.loop(); |
|||
uartreceiver.forceCchedule(); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,27 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
#include <stdio.h>
|
|||
|
|||
#include <functional>
|
|||
|
|||
#include "sdk\components\iflytop_can_slave_modules\device_base_control_service.hpp"
|
|||
#include "sdk\components\iflytop_can_slave_v1\iflytop_can_slave.hpp"
|
|||
#include "sdk\components\zcanreceiver\zcanreceiver.hpp"
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
class Main : public ZCanRceiverListener { |
|||
private: |
|||
/* data */ |
|||
public: |
|||
virtual void onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len); |
|||
|
|||
Main(/* args */){}; |
|||
~Main(){}; |
|||
void run(); |
|||
}; |
|||
extern Main gmain; |
|||
} // namespace iflytop
|
|||
|
|||
extern "C" { |
|||
void umain(void) { iflytop::gmain.run(); } |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue