diff --git a/.cproject b/.cproject
index 92ee012..6915ae2 100644
--- a/.cproject
+++ b/.cproject
@@ -25,10 +25,10 @@
-
-
+
+
-
+
-
+
@@ -209,16 +209,16 @@
-
+
-
+
-
+
diff --git a/.project b/.project
index 085a4d5..f2c35b2 100644
--- a/.project
+++ b/.project
@@ -1,6 +1,6 @@
- zapp
+ little_disinfection_liquid_path_control
diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml
index 5e8ee27..34e6a9d 100644
--- a/.settings/language.settings.xml
+++ b/.settings/language.settings.xml
@@ -5,7 +5,7 @@
-
+
@@ -16,7 +16,7 @@
-
+
diff --git a/Core/Inc/stm32f4xx_it.h b/Core/Inc/stm32f4xx_it.h
index e4a252b..b38d2ee 100644
--- a/Core/Inc/stm32f4xx_it.h
+++ b/Core/Inc/stm32f4xx_it.h
@@ -59,6 +59,7 @@ void CAN1_TX_IRQHandler(void);
void CAN1_RX0_IRQHandler(void);
void CAN1_RX1_IRQHandler(void);
void CAN1_SCE_IRQHandler(void);
+void USART1_IRQHandler(void);
void USART3_IRQHandler(void);
/* USER CODE BEGIN EFP */
diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c
index e63d0ba..28d3e7e 100644
--- a/Core/Src/stm32f4xx_it.c
+++ b/Core/Src/stm32f4xx_it.c
@@ -56,6 +56,7 @@
/* External variables --------------------------------------------------------*/
extern CAN_HandleTypeDef hcan1;
+extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart3;
/* USER CODE BEGIN EV */
@@ -256,6 +257,20 @@ void CAN1_SCE_IRQHandler(void)
}
/**
+ * @brief This function handles USART1 global interrupt.
+ */
+void USART1_IRQHandler(void)
+{
+ /* USER CODE BEGIN USART1_IRQn 0 */
+
+ /* USER CODE END USART1_IRQn 0 */
+ HAL_UART_IRQHandler(&huart1);
+ /* USER CODE BEGIN USART1_IRQn 1 */
+
+ /* USER CODE END USART1_IRQn 1 */
+}
+
+/**
* @brief This function handles USART3 global interrupt.
*/
void USART3_IRQHandler(void)
diff --git a/Core/Src/usart.c b/Core/Src/usart.c
index 635107c..d606e3c 100644
--- a/Core/Src/usart.c
+++ b/Core/Src/usart.c
@@ -70,7 +70,7 @@ void MX_USART2_UART_Init(void)
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
- huart2.Init.BaudRate = 9600;
+ huart2.Init.BaudRate = 115200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
@@ -140,6 +140,9 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+ /* USART1 interrupt Init */
+ HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
+ HAL_NVIC_EnableIRQ(USART1_IRQn);
/* USER CODE BEGIN USART1_MspInit 1 */
/* USER CODE END USART1_MspInit 1 */
@@ -214,6 +217,8 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle)
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
+ /* USART1 interrupt Deinit */
+ HAL_NVIC_DisableIRQ(USART1_IRQn);
/* USER CODE BEGIN USART1_MspDeInit 1 */
/* USER CODE END USART1_MspDeInit 1 */
diff --git a/little_disinfection_liquid_path_control Debug.cfg b/little_disinfection_liquid_path_control Debug.cfg
new file mode 100644
index 0000000..ef37116
--- /dev/null
+++ b/little_disinfection_liquid_path_control Debug.cfg
@@ -0,0 +1,44 @@
+# This is an genericBoard board with a single STM32F407VETx chip
+#
+# Generated by STM32CubeIDE
+# Take care that such file, as generated, may be overridden without any early notice. Please have a look to debug launch configuration setup(s)
+
+source [find interface/stlink-dap.cfg]
+
+
+set WORKAREASIZE 0x8000
+
+transport select "dapdirect_swd"
+
+set CHIPNAME STM32F407VETx
+set BOARDNAME genericBoard
+
+# Enable debug when in low power modes
+set ENABLE_LOW_POWER 1
+
+# Stop Watchdog counters when halt
+set STOP_WATCHDOG 1
+
+# STlink Debug clock frequency
+set CLOCK_FREQ 8000
+
+# Reset configuration
+# use hardware reset, connect under reset
+# connect_assert_srst needed if low power mode application running (WFI...)
+reset_config srst_only srst_nogate connect_assert_srst
+set CONNECT_UNDER_RESET 1
+set CORE_RESET 0
+
+# ACCESS PORT NUMBER
+set AP_NUM 0
+# GDB PORT
+set GDB_PORT 3333
+
+
+
+
+
+# BCTM CPU variables
+
+source [find target/stm32f4x.cfg]
+
diff --git a/little_disinfection_liquid_path_control Debug.launch b/little_disinfection_liquid_path_control Debug.launch
new file mode 100644
index 0000000..f5a5e19
--- /dev/null
+++ b/little_disinfection_liquid_path_control Debug.launch
@@ -0,0 +1,96 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/zapp.ioc b/little_disinfection_liquid_path_control.ioc
similarity index 97%
rename from zapp.ioc
rename to little_disinfection_liquid_path_control.ioc
index 680d564..116970b 100644
--- a/zapp.ioc
+++ b/little_disinfection_liquid_path_control.ioc
@@ -82,6 +82,7 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
+NVIC.USART1_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.USART3_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
PA10.Mode=Asynchronous
@@ -147,8 +148,8 @@ ProjectManager.MainLocation=Core/Src
ProjectManager.NoMain=false
ProjectManager.PreviousToolchain=STM32CubeIDE
ProjectManager.ProjectBuild=false
-ProjectManager.ProjectFileName=zapp.ioc
-ProjectManager.ProjectName=zapp
+ProjectManager.ProjectFileName=little_disinfection_liquid_path_control.ioc
+ProjectManager.ProjectName=little_disinfection_liquid_path_control
ProjectManager.ProjectStructure=
ProjectManager.RegisterCallBack=
ProjectManager.StackSize=0x1000
diff --git a/zapp.launch b/little_disinfection_liquid_path_control.launch
similarity index 94%
rename from zapp.launch
rename to little_disinfection_liquid_path_control.launch
index b284c63..71cb833 100644
--- a/zapp.launch
+++ b/little_disinfection_liquid_path_control.launch
@@ -12,7 +12,7 @@
-
+
@@ -46,7 +46,7 @@
-
+
@@ -80,13 +80,13 @@
-
-
+
+
-
+
diff --git a/sdk b/sdk
index 7a8a3c0..a223c66 160000
--- a/sdk
+++ b/sdk
@@ -1 +1 @@
-Subproject commit 7a8a3c0c76c859f725b97a668bd96d166b245d68
+Subproject commit a223c666e76044036e648ebcea3db8ec4aec59d3
diff --git a/usrc/hardware.cpp b/usrc/hardware.cpp
index a8677c3..d70ab9f 100644
--- a/usrc/hardware.cpp
+++ b/usrc/hardware.cpp
@@ -45,11 +45,11 @@ DP600PressureSensor m_dp600PressureSensor4;
ZGPIO IO_PD13_IN;
ZGPIO IO_PC7_IN;
-#define PROCESS_CMD(cmd, id) \
- if ((cmdheader->cmdid == (uint16_t)cmd) && (cmdheader->subcmdid == 0) && cmdheader->data[0] == id) { \
- matching = true; \
- } \
- if ((cmdheader->cmdid == (uint16_t)cmd) && (cmdheader->subcmdid == 0) && cmdheader->data[0] == id)
+#define PROCESS_CMD(cmd, _subcmdid, id) \
+ if ((cmdheader->cmdid == (uint16_t)cmd) && (cmdheader->subcmdid == _subcmdid) && cmdheader->data[0] == id) { \
+ matching = true; \
+ } \
+ if ((cmdheader->cmdid == (uint16_t)cmd) && (cmdheader->subcmdid == _subcmdid) && cmdheader->data[0] == id)
void setmotor(TMC5130 *motor, int16_t acc_rpm2, int16_t rpm, int16_t idlepower, int16_t power) {
int32_t ppm = rpm / 60.0 * 51200;
@@ -101,7 +101,7 @@ void Hardware::initialize(int deviceId) {
m_motor2.setAcceleration(300000);
m_motor2.setDeceleration(300000);
- // m_motor1.rotate(1000000);
+ // m_motor2.rotate(1000000);
}
triLight_R.initAsOutput(PD8, ZGPIO::kMode_nopull, false, false);
@@ -135,11 +135,12 @@ void packet_kcmd_read_huacheng_pressure_sensor_data(int id, DP600PressureSensor:
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;
+ printf("rx: cmdid:%d subcmdid:%d id:%d\n", cmdheader->cmdid, cmdheader->subcmdid, cmdheader->data[0]);
/**
* @brief Ping
*/
- PROCESS_CMD(kcmd_ping, m_device_id) {
+ PROCESS_CMD(kcmd_ping, 0, m_device_id) {
receipt[0] = cmdheader->data[0];
receiptsize = 1;
return 0;
@@ -148,7 +149,7 @@ int32_t Hardware::process_rx_packet(from_where_t fromwhere, uint8_t *packet, int
/**
* @brief 获取蒸发仓水浸状态
*/
- PROCESS_CMD(kcmd_proportional_read_water_immersion_sensor, 0) {
+ PROCESS_CMD(kcmd_proportional_read_water_immersion_sensor, 0, 0) {
((int32_t *)receipt)[0] = !IO_PC7_IN.getState();
receiptsize = 4;
return 0;
@@ -157,7 +158,7 @@ int32_t Hardware::process_rx_packet(from_where_t fromwhere, uint8_t *packet, int
/**
* @brief 获取设备底盘水浸传感器
*/
- PROCESS_CMD(kcmd_proportional_read_water_immersion_sensor, 1) {
+ PROCESS_CMD(kcmd_proportional_read_water_immersion_sensor, 0, 1) {
((int32_t *)receipt)[0] = !IO_PD13_IN.getState();
receiptsize = 4;
return 0;
@@ -166,12 +167,14 @@ int32_t Hardware::process_rx_packet(from_where_t fromwhere, uint8_t *packet, int
/**
* @brief 控制加液泵
*/
- PROCESS_CMD(kcmd_peristaltic_pump_ctl, 1) {
+ PROCESS_CMD(kcmd_peristaltic_pump_ctl, 0, 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;
@@ -181,11 +184,12 @@ int32_t Hardware::process_rx_packet(from_where_t fromwhere, uint8_t *packet, int
/**
* @brief 控制-喷液泵
*/
- PROCESS_CMD(kcmd_peristaltic_pump_ctl, 2) {
+ PROCESS_CMD(kcmd_peristaltic_pump_ctl, 0, 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];
@@ -196,7 +200,7 @@ int32_t Hardware::process_rx_packet(from_where_t fromwhere, uint8_t *packet, int
/**
* @brief 三色指示灯控制
*/
- PROCESS_CMD(kcmd_triple_warning_light_ctl, 1) {
+ PROCESS_CMD(kcmd_triple_warning_light_ctl, 0, 1) {
/**
* @brief 0:设置状态
* cmd:
@@ -228,7 +232,7 @@ int32_t Hardware::process_rx_packet(from_where_t fromwhere, uint8_t *packet, int
/**
* @brief 液位测量压力传感器
*/
- PROCESS_CMD(kcmd_read_huacheng_pressure_sensor, 1) {
+ PROCESS_CMD(kcmd_read_huacheng_pressure_sensor, 0, 1) {
static ModbusBlockHost modbusBlockHost;
modbusBlockHost.initialize(&huart3);
int16_t val[1] = {0};
@@ -248,7 +252,7 @@ int32_t Hardware::process_rx_packet(from_where_t fromwhere, uint8_t *packet, int
/**
* @brief 空压机压力传感器
*/
- PROCESS_CMD(kcmd_read_huacheng_pressure_sensor, 2) {
+ 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);
@@ -260,7 +264,7 @@ int32_t Hardware::process_rx_packet(from_where_t fromwhere, uint8_t *packet, int
/**
* @brief 加液蠕动泵压力传感器
*/
- PROCESS_CMD(kcmd_read_huacheng_pressure_sensor, 3) {
+ 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);
@@ -272,7 +276,7 @@ int32_t Hardware::process_rx_packet(from_where_t fromwhere, uint8_t *packet, int
/**
* @brief 喷射蠕动泵压力传感器
*/
- PROCESS_CMD(kcmd_read_huacheng_pressure_sensor, 4) {
+ 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);
@@ -281,5 +285,6 @@ int32_t Hardware::process_rx_packet(from_where_t fromwhere, uint8_t *packet, int
}
return 0;
}
+ return 0;
}
void Hardware::loop() {}
diff --git a/usrc/main.cpp b/usrc/main.cpp
index 099f7e2..02b6998 100644
--- a/usrc/main.cpp
+++ b/usrc/main.cpp
@@ -18,6 +18,7 @@
//
#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"
@@ -30,68 +31,6 @@ Main gmain;
using namespace iflytop;
-/*******************************************************************************
- * TOOLS *
- *******************************************************************************/
-static uint8_t *hex_str_to_bytes(char *data, int32_t len, int32_t &bytelen) {
- /**
- * @brief
- * data:
- * 12 34 56 78 90 ab cd ef
- *
- */
- static uint8_t bytes_cache[1024] = {0};
- static uint8_t data_cache[1024] = {0};
-
- int32_t data_len = 0;
-
- memset(bytes_cache, 0, sizeof(bytes_cache));
- memset(data_cache, 0, sizeof(data_cache));
-
- for (int32_t i = 0; i < len; i++) {
- if (data[i] == ' ') continue;
- if (data[i] == '\r' || data[i] == '\n') break;
- data_cache[i] = data[i];
- data_len++;
- }
-
- if (data_len % 2 != 0) {
- ZLOGE(TAG, "data_len %d", data_len);
- return NULL;
- }
-
- for (int32_t i = 0; i < data_len; i += 2) {
- char c1 = data_cache[i];
- char c2 = data_cache[i + 1];
- if (c1 >= '0' && c1 <= '9') {
- c1 = c1 - '0';
- } else if (c1 >= 'a' && c1 <= 'f') {
- c1 = c1 - 'a' + 10;
- } else if (c1 >= 'A' && c1 <= 'F') {
- c1 = c1 - 'A' + 10;
- } else {
- ZLOGE(TAG, "c1 %c", c1);
- return NULL;
- }
-
- if (c2 >= '0' && c2 <= '9') {
- c2 = c2 - '0';
- } else if (c2 >= 'a' && c2 <= 'f') {
- c2 = c2 - 'a' + 10;
- } else if (c2 >= 'A' && c2 <= 'F') {
- c2 = c2 - 'A' + 10;
- } else {
- ZLOGE(TAG, "c2 %c", c2);
- return NULL;
- }
-
- bytes_cache[i / 2] = (c1 << 4) | c2;
- }
-
- bytelen = data_len / 2;
- return bytes_cache;
-}
-
void dumphexdata(uint8_t *data, int32_t len) {
for (int32_t i = 0; i < len; i++) {
printf("%02X ", data[i]);
@@ -126,7 +65,7 @@ void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len)
if (ecode != 0) {
m_canReceiver.sendErrorAck(cmdheader, ecode);
} else {
- m_canReceiver.sendAck(cmdheader, rxdata, sizeof(rxdata));
+ m_canReceiver.sendAck(cmdheader, rxdata, sizeof(receipt_size));
}
}
}
@@ -139,16 +78,24 @@ static void processUartRX(uint8_t *packet, size_t len) {
bool match = false;
memset(rxdata, 0, sizeof(rxdata));
+ printf("processUartRX %d\n", len);
//
int32_t bytelen = 0;
- uint8_t *hexbytes = hex_str_to_bytes((char *)packet, len, bytelen);
+ 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);
-
- m_hardware.process_rx_packet(Hardware::kuart, packet, len, rxdata, receipt_size, match);
+ 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);
+ }
}
/*******************************************************************************
@@ -161,8 +108,7 @@ void Main::run() {
};
ZHALCORE::getInstance()->initialize(oscfg);
- ZLOGI(TAG, "zapp:%s", VERSION);
- printf("int32_t %d int %d longint %d\n", sizeof(int32_t), sizeof(int), sizeof(long int));
+ 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(); });
@@ -178,6 +124,7 @@ void Main::run() {
};
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);
@@ -187,5 +134,6 @@ void Main::run() {
while (1) {
ZHALCORE::getInstance()->loop();
m_hardware.loop();
+ uartreceiver.forceCchedule();
}
}
diff --git a/usrc/project.hpp b/usrc/project.hpp
index e2dfad5..5c48e57 100644
--- a/usrc/project.hpp
+++ b/usrc/project.hpp
@@ -1,6 +1,6 @@
#pragma once
-#define VERSION "v1.0"
+#define VERSION "v1.1"
// 设备ID
#define DEVICE_ID (2)
// 调试串口