diff --git a/.cproject b/.cproject
index 7bff557..f7b9e24 100644
--- a/.cproject
+++ b/.cproject
@@ -25,8 +25,8 @@
-
-
+
+
diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml
index 089a477..6d9848e 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 cdee066..b8d88d6 100644
--- a/Core/Inc/stm32f4xx_it.h
+++ b/Core/Inc/stm32f4xx_it.h
@@ -60,6 +60,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/Inc/usart.h b/Core/Inc/usart.h
index 7b84d11..600bc69 100644
--- a/Core/Inc/usart.h
+++ b/Core/Inc/usart.h
@@ -34,6 +34,8 @@ extern "C" {
extern UART_HandleTypeDef huart1;
+extern UART_HandleTypeDef huart2;
+
extern UART_HandleTypeDef huart3;
/* USER CODE BEGIN Private defines */
@@ -41,6 +43,7 @@ extern UART_HandleTypeDef huart3;
/* USER CODE END Private defines */
void MX_USART1_UART_Init(void);
+void MX_USART2_UART_Init(void);
void MX_USART3_UART_Init(void);
/* USER CODE BEGIN Prototypes */
diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c
index e0d4c01..f2689fe 100644
--- a/Core/Src/gpio.c
+++ b/Core/Src/gpio.c
@@ -106,11 +106,11 @@ void MX_GPIO_Init(void)
/*Configure GPIO pins : PD8 PD9 PD10 PD11
PD12 PD13 PD14 PD15
PD0 PD1 PD2 PD3
- PD4 PD5 PD6 PD7 */
+ PD4 PD7 */
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15
|GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
- |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
+ |GPIO_PIN_4|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
diff --git a/Core/Src/main.c b/Core/Src/main.c
index 8539c80..2cbd722 100644
--- a/Core/Src/main.c
+++ b/Core/Src/main.c
@@ -104,6 +104,7 @@ int main(void)
MX_CAN1_Init();
MX_USART3_UART_Init();
MX_ADC1_Init();
+ MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
extern void umain();
diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c
index 4042caf..b5e63fa 100644
--- a/Core/Src/stm32f4xx_it.c
+++ b/Core/Src/stm32f4xx_it.c
@@ -57,6 +57,7 @@
/* External variables --------------------------------------------------------*/
extern ADC_HandleTypeDef hadc1;
extern CAN_HandleTypeDef hcan1;
+extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart3;
/* USER CODE BEGIN EV */
@@ -271,6 +272,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 b34f79f..9aeb692 100644
--- a/Core/Src/usart.c
+++ b/Core/Src/usart.c
@@ -25,6 +25,7 @@
/* USER CODE END 0 */
UART_HandleTypeDef huart1;
+UART_HandleTypeDef huart2;
UART_HandleTypeDef huart3;
/* USART1 init function */
@@ -56,6 +57,35 @@ void MX_USART1_UART_Init(void)
/* USER CODE END USART1_Init 2 */
}
+/* USART2 init function */
+
+void MX_USART2_UART_Init(void)
+{
+
+ /* USER CODE BEGIN USART2_Init 0 */
+
+ /* USER CODE END USART2_Init 0 */
+
+ /* USER CODE BEGIN USART2_Init 1 */
+
+ /* USER CODE END USART2_Init 1 */
+ huart2.Instance = USART2;
+ huart2.Init.BaudRate = 9600;
+ huart2.Init.WordLength = UART_WORDLENGTH_8B;
+ huart2.Init.StopBits = UART_STOPBITS_1;
+ huart2.Init.Parity = UART_PARITY_NONE;
+ huart2.Init.Mode = UART_MODE_TX_RX;
+ huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
+ huart2.Init.OverSampling = UART_OVERSAMPLING_16;
+ if (HAL_UART_Init(&huart2) != HAL_OK)
+ {
+ Error_Handler();
+ }
+ /* USER CODE BEGIN USART2_Init 2 */
+
+ /* USER CODE END USART2_Init 2 */
+
+}
/* USART3 init function */
void MX_USART3_UART_Init(void)
@@ -110,10 +140,37 @@ 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 */
}
+ else if(uartHandle->Instance==USART2)
+ {
+ /* USER CODE BEGIN USART2_MspInit 0 */
+
+ /* USER CODE END USART2_MspInit 0 */
+ /* USART2 clock enable */
+ __HAL_RCC_USART2_CLK_ENABLE();
+
+ __HAL_RCC_GPIOD_CLK_ENABLE();
+ /**USART2 GPIO Configuration
+ PD5 ------> USART2_TX
+ PD6 ------> USART2_RX
+ */
+ GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
+ HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
+
+ /* USER CODE BEGIN USART2_MspInit 1 */
+
+ /* USER CODE END USART2_MspInit 1 */
+ }
else if(uartHandle->Instance==USART3)
{
/* USER CODE BEGIN USART3_MspInit 0 */
@@ -160,10 +217,30 @@ 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 */
}
+ else if(uartHandle->Instance==USART2)
+ {
+ /* USER CODE BEGIN USART2_MspDeInit 0 */
+
+ /* USER CODE END USART2_MspDeInit 0 */
+ /* Peripheral clock disable */
+ __HAL_RCC_USART2_CLK_DISABLE();
+
+ /**USART2 GPIO Configuration
+ PD5 ------> USART2_TX
+ PD6 ------> USART2_RX
+ */
+ HAL_GPIO_DeInit(GPIOD, GPIO_PIN_5|GPIO_PIN_6);
+
+ /* USER CODE BEGIN USART2_MspDeInit 1 */
+
+ /* USER CODE END USART2_MspDeInit 1 */
+ }
else if(uartHandle->Instance==USART3)
{
/* USER CODE BEGIN USART3_MspDeInit 0 */
diff --git a/README.md b/README.md
index d7110fa..9614c7d 100644
--- a/README.md
+++ b/README.md
@@ -13,11 +13,14 @@
3. 空压机,风机,加热片安全继电器控制
-writeio 0 1
-writeio 1 1
-writeio 2 1
-writeio 3 1
-writeio 4 1
-writeio 5 1
+
+writeio 0 1
+writeio 1 1
+
+writeio 2 1
+writeio 3 1
+
+writeio 4 1
+writeio 5 1
```
\ No newline at end of file
diff --git a/pipeline_disinfection_high_power_ctrl_prj (1).launch b/pipeline_disinfection_high_power_ctrl_prj (1).launch
new file mode 100644
index 0000000..6eec842
--- /dev/null
+++ b/pipeline_disinfection_high_power_ctrl_prj (1).launch
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/zapp.ioc b/pipeline_disinfection_high_power_ctrl_prj.ioc
similarity index 92%
rename from zapp.ioc
rename to pipeline_disinfection_high_power_ctrl_prj.ioc
index b9e80d4..ef76b52 100644
--- a/zapp.ioc
+++ b/pipeline_disinfection_high_power_ctrl_prj.ioc
@@ -32,7 +32,8 @@ Mcu.IP0=ADC1
Mcu.IP1=CAN1
Mcu.IP10=TIM7
Mcu.IP11=USART1
-Mcu.IP12=USART3
+Mcu.IP12=USART2
+Mcu.IP13=USART3
Mcu.IP2=CRC
Mcu.IP3=NVIC
Mcu.IP4=RCC
@@ -41,7 +42,7 @@ Mcu.IP6=SYS
Mcu.IP7=TIM1
Mcu.IP8=TIM3
Mcu.IP9=TIM6
-Mcu.IPNb=13
+Mcu.IPNb=14
Mcu.Name=STM32F407V(E-G)Tx
Mcu.Package=LQFP100
Mcu.Pin0=PH0-OSC_IN
@@ -54,14 +55,16 @@ Mcu.Pin14=PA11
Mcu.Pin15=PA12
Mcu.Pin16=PA13
Mcu.Pin17=PA14
-Mcu.Pin18=VP_CRC_VS_CRC
-Mcu.Pin19=VP_RNG_VS_RNG
+Mcu.Pin18=PD5
+Mcu.Pin19=PD6
Mcu.Pin2=PC0
-Mcu.Pin20=VP_SYS_VS_Systick
-Mcu.Pin21=VP_TIM1_VS_ClockSourceINT
-Mcu.Pin22=VP_TIM3_VS_ClockSourceINT
-Mcu.Pin23=VP_TIM6_VS_ClockSourceINT
-Mcu.Pin24=VP_TIM7_VS_ClockSourceINT
+Mcu.Pin20=VP_CRC_VS_CRC
+Mcu.Pin21=VP_RNG_VS_RNG
+Mcu.Pin22=VP_SYS_VS_Systick
+Mcu.Pin23=VP_TIM1_VS_ClockSourceINT
+Mcu.Pin24=VP_TIM3_VS_ClockSourceINT
+Mcu.Pin25=VP_TIM6_VS_ClockSourceINT
+Mcu.Pin26=VP_TIM7_VS_ClockSourceINT
Mcu.Pin3=PA0-WKUP
Mcu.Pin4=PA1
Mcu.Pin5=PA2
@@ -69,7 +72,7 @@ Mcu.Pin6=PA3
Mcu.Pin7=PB0
Mcu.Pin8=PB1
Mcu.Pin9=PB10
-Mcu.PinsNb=25
+Mcu.PinsNb=27
Mcu.ThirdPartyNb=0
Mcu.UserConstants=
Mcu.UserName=STM32F407VETx
@@ -90,6 +93,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
PA0-WKUP.Locked=true
@@ -127,6 +131,10 @@ PC0.Signal=GPXTI0
PC9.Locked=true
PC9.Mode=Clock-out-2
PC9.Signal=RCC_MCO_2
+PD5.Mode=Asynchronous
+PD5.Signal=USART2_TX
+PD6.Mode=Asynchronous
+PD6.Signal=USART2_RX
PH0-OSC_IN.Mode=HSE-External-Oscillator
PH0-OSC_IN.Signal=RCC_OSC_IN
PH1-OSC_OUT.Mode=HSE-External-Oscillator
@@ -152,8 +160,8 @@ ProjectManager.MainLocation=Core/Src
ProjectManager.NoMain=false
ProjectManager.PreviousToolchain=STM32CubeIDE
ProjectManager.ProjectBuild=false
-ProjectManager.ProjectFileName=zapp.ioc
-ProjectManager.ProjectName=zapp
+ProjectManager.ProjectFileName=pipeline_disinfection_high_power_ctrl_prj.ioc
+ProjectManager.ProjectName=pipeline_disinfection_high_power_ctrl_prj
ProjectManager.ProjectStructure=
ProjectManager.RegisterCallBack=
ProjectManager.StackSize=0x1000
@@ -229,6 +237,9 @@ TIM7.IPParameters=Prescaler
TIM7.Prescaler=81
USART1.IPParameters=VirtualMode
USART1.VirtualMode=VM_ASYNC
+USART2.BaudRate=9600
+USART2.IPParameters=VirtualMode,BaudRate
+USART2.VirtualMode=VM_ASYNC
USART3.BaudRate=19200
USART3.IPParameters=VirtualMode,BaudRate,StopBits
USART3.StopBits=STOPBITS_2
diff --git a/zapp.launch b/pipeline_disinfection_high_power_ctrl_prj.launch
similarity index 100%
rename from zapp.launch
rename to pipeline_disinfection_high_power_ctrl_prj.launch
diff --git a/sdk b/sdk
index eb85daa..49cd7f7 160000
--- a/sdk
+++ b/sdk
@@ -1 +1 @@
-Subproject commit eb85daa5183b6d045c4ba701ce8bac065e923cda
+Subproject commit 49cd7f76f44ac0dce2b426cd8cf1af29bdeb7c19
diff --git a/usrc/main.cpp b/usrc/main.cpp
index 84af837..daddbeb 100644
--- a/usrc/main.cpp
+++ b/usrc/main.cpp
@@ -22,9 +22,15 @@
#include "sdk\components\zcan_module\zcan_pump_ctrl_module.hpp"
#include "sdk\components\zcan_module\zcan_trigle_warning_light_ctl_module.hpp"
//
+#include
+
#include "adc.h"
+#include "sdk\components\cmdscheduler\cmd_scheduler_v2.hpp"
+#include "sdk\components\modbus\modbus_block_host.hpp"
#include "sdk\components\zcan_module\zcan_high_power_electrical_ctl_module.hpp"
#include "sdk\components\zcan_module\zcan_m211887_module_manager.hpp"
+#include "sdk\hal\zuart.hpp"
+
#define TAG "main"
namespace iflytop {
Main gmain;
@@ -56,6 +62,8 @@ ZCanBasicOrderModule m_basicOrderModule;
ZCanHighPowerElectricalCtlModule m_highPowerElectricalCtlModule;
ZCanM211887ModuleManager m_m211887ModuleManager;
+ModbusBlockHost m_blowserModbusBlockHost;
+
// ch(1-6Chnnal),times(读取次数)
uint32_t ADC_Get_Average(uint8_t ch, uint8_t times) {
ADC_ChannelConfTypeDef sConfig; // 通道初始化
@@ -93,6 +101,12 @@ uint32_t ADC_Get_Average(uint8_t ch, uint8_t times) {
}
return value_sum / times; // 返回平均值
}
+
+static void setblowser(bool state) {
+ // AirBlowerCtrl1.setState(state);
+ // AirBlowerCtrl2.setState(state);
+}
+
void Main::onRceivePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) {
printf("can rx from %d %d,", rxbuf->id, len);
for (size_t i = 0; i < len; i++) {
@@ -153,11 +167,15 @@ void Main::run() {
return true;
}
if (id == 2) {
- AirBlowerCtrl1.setState(val);
+ if (val) {
+ m_blowserModbusBlockHost.writeReg06(1, 0x2000, 1, 100);
+ } else {
+ m_blowserModbusBlockHost.writeReg06(1, 0x2000, 6, 100);
+ }
return true;
}
if (id == 3) {
- AirBlowerCtrl2.setState(val);
+ // AirBlowerCtrl2.setState(val);
return true;
}
if (id == 4) {
@@ -178,6 +196,15 @@ void Main::run() {
return true;
}
+ if (id == 10) {
+ AirBlowerCtrl1.setState(val);
+ return true;
+ }
+ if (id == 11) {
+ AirBlowerCtrl2.setState(val);
+ return true;
+ }
+
return false;
});
@@ -212,14 +239,81 @@ void Main::run() {
m_m211887ModuleManager.initialize(&m_canReceiver);
m_m211887ModuleManager.regSubmodule(1, &huart3, 0xf0);
+ m_blowserModbusBlockHost.initialize(&huart2);
+
// while(true){
// uint8_t buf[10] ={1,2,3,4,5,6,7,8,9,10};
// HAL_UART_Transmit(&huart3,buf,10,1000);
// HAL_Delay(10);
// }
+ /*******************************************************************************
+ * 调试方法初始化 *
+ *******************************************************************************/
+ static ZUART uartreceiver;
+ static CmdSchedulerV2 cmdScheduler;
+ static ZUART::cfg_t uartreceiver_cfg = {
+ .name = "uartreceiver",
+ .huart = &DEBUG_UART,
+ .rxbuffersize = 512,
+ .rxovertime_ms = 30,
+ };
+ uartreceiver.initialize(&uartreceiver_cfg);
+ cmdScheduler.initialize(&uartreceiver);
+ // write_io
+ // read_adc
+
+ cmdScheduler.regCMD("writeio", "(id,val)", 2, //
+ [](int32_t paramN, const char **paraV, ICmdParserACK *ack) {
+ m_basicOrderModule.write_io(atoi(paraV[0]), atoi(paraV[1]));
+ ack->setNoneAck(0);
+ });
+
+ cmdScheduler.regCMD("readadc", "(id)", 1, //
+ [](int32_t paramN, const char **paraV, ICmdParserACK *ack) {
+ int32_t val = m_basicOrderModule.read_adc(atoi(paraV[0]));
+ ack->setInt32Ack(0, val);
+ });
+
+ cmdScheduler.regCMD("hpp272_read_c1000", "(id)", 1, //
+ [](int32_t paramN, const char **paraV, ICmdParserACK *ack) {
+ // int32_t val = m_basicOrderModule.read_adc(atoi(paraV[0]));
+ // uint16_t hydrogen_peroxide_volume; // ppm 0x0100
+ // uint16_t h2o_h2o2_rs; // %RS * 100
+ // uint16_t temperature1; // °C * 100
+ // uint16_t relative_humidity; // %RH * 100
+ // uint16_t absolute_hydrogen_peroxide; // mg/m3
+ // uint16_t h2o_h2o2dew_point_temperature; // °C * 100
+ // uint16_t reserved1; //
+ // uint16_t water_volume; // ppm
+ // uint16_t water_vapor_pressure; // hpa
+ // uint16_t absolute_humidity; // g/m3
+ // uint16_t water_vapor_saturation_pressure_h2o; // hpa
+ // uint16_t temperature2; // °C * 100
+ // uint16_t h2o2_vapor_pressure; // hpa
+ // uint16_t water_vapor_saturation_pressure_h2o_h2o2; // hpa
+
+ auto *sensordata = m_m211887ModuleManager.readSensor(atoi(paraV[0]));
+ // ZLOGI(TAG, "hpp272_read_c1000 %d", sensordata->pressure);
+ ZLOGI(TAG, "hydrogen_peroxide_volume :%d", sensordata->hydrogen_peroxide_volume);
+ ZLOGI(TAG, "h2o_h2o2_rs :%d", sensordata->h2o_h2o2_rs);
+ ZLOGI(TAG, "temperature1 :%d", sensordata->temperature1);
+ ZLOGI(TAG, "relative_humidity :%d", sensordata->relative_humidity);
+ ZLOGI(TAG, "absolute_hydrogen_peroxide :%d", sensordata->absolute_hydrogen_peroxide);
+ ZLOGI(TAG, "h2o_h2o2dew_point_temperature :%d", sensordata->h2o_h2o2dew_point_temperature);
+ ZLOGI(TAG, "reserved1 :%d", sensordata->reserved1);
+ ZLOGI(TAG, "water_volume :%d", sensordata->water_volume);
+ ZLOGI(TAG, "water_vapor_pressure :%d", sensordata->water_vapor_pressure);
+ ZLOGI(TAG, "absolute_humidity :%d", sensordata->absolute_humidity);
+ ZLOGI(TAG, "water_vapor_saturation_pressure_h2o :%d", sensordata->water_vapor_saturation_pressure_h2o);
+ ZLOGI(TAG, "temperature2 :%d", sensordata->temperature2);
+ ZLOGI(TAG, "h2o2_vapor_pressure :%d", sensordata->h2o2_vapor_pressure);
+ ZLOGI(TAG, "water_vapor_saturation_pressure_h2o_h2o2 :%d", sensordata->water_vapor_saturation_pressure_h2o_h2o2);
+ ack->setInt32Ack(0, 0);
+ });
ZLOGI(TAG, "init done");
while (1) {
+ cmdScheduler.schedule();
ZHALCORE::getInstance()->loop();
}
}