update modbus
This commit is contained in:
+64
-20
@@ -91,33 +91,41 @@ Mcu.Package=LQFP100
|
||||
Mcu.Pin0=PH0-OSC_IN
|
||||
Mcu.Pin1=PH1-OSC_OUT
|
||||
Mcu.Pin10=PC5
|
||||
Mcu.Pin11=PE11
|
||||
Mcu.Pin12=PB10
|
||||
Mcu.Pin13=PB11
|
||||
Mcu.Pin14=PB12
|
||||
Mcu.Pin15=PB13
|
||||
Mcu.Pin16=PB14
|
||||
Mcu.Pin17=PB15
|
||||
Mcu.Pin18=PC6
|
||||
Mcu.Pin19=PC7
|
||||
Mcu.Pin11=PB0
|
||||
Mcu.Pin12=PB1
|
||||
Mcu.Pin13=PB2
|
||||
Mcu.Pin14=PE7
|
||||
Mcu.Pin15=PE9
|
||||
Mcu.Pin16=PE10
|
||||
Mcu.Pin17=PE11
|
||||
Mcu.Pin18=PB10
|
||||
Mcu.Pin19=PB11
|
||||
Mcu.Pin2=PA0-WKUP
|
||||
Mcu.Pin20=PA13
|
||||
Mcu.Pin21=PA14
|
||||
Mcu.Pin22=PD3
|
||||
Mcu.Pin23=PD4
|
||||
Mcu.Pin24=PD5
|
||||
Mcu.Pin25=PB6
|
||||
Mcu.Pin26=PB7
|
||||
Mcu.Pin27=PB8
|
||||
Mcu.Pin28=VP_SYS_VS_Systick
|
||||
Mcu.Pin20=PB12
|
||||
Mcu.Pin21=PB13
|
||||
Mcu.Pin22=PB14
|
||||
Mcu.Pin23=PB15
|
||||
Mcu.Pin24=PC6
|
||||
Mcu.Pin25=PC7
|
||||
Mcu.Pin26=PA12
|
||||
Mcu.Pin27=PA13
|
||||
Mcu.Pin28=PA14
|
||||
Mcu.Pin29=PD3
|
||||
Mcu.Pin3=PA1
|
||||
Mcu.Pin30=PD4
|
||||
Mcu.Pin31=PD5
|
||||
Mcu.Pin32=PB5
|
||||
Mcu.Pin33=PB6
|
||||
Mcu.Pin34=PB7
|
||||
Mcu.Pin35=PB8
|
||||
Mcu.Pin36=VP_SYS_VS_Systick
|
||||
Mcu.Pin4=PA2
|
||||
Mcu.Pin5=PA3
|
||||
Mcu.Pin6=PA5
|
||||
Mcu.Pin7=PA6
|
||||
Mcu.Pin8=PA7
|
||||
Mcu.Pin9=PC4
|
||||
Mcu.PinsNb=29
|
||||
Mcu.PinsNb=37
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32F407VGTx
|
||||
@@ -149,6 +157,10 @@ PA0-WKUP.Signal=UART4_TX
|
||||
PA1.Locked=true
|
||||
PA1.Mode=Asynchronous
|
||||
PA1.Signal=UART4_RX
|
||||
PA12.GPIOParameters=GPIO_Label
|
||||
PA12.GPIO_Label=LED
|
||||
PA12.Locked=true
|
||||
PA12.Signal=GPIO_Output
|
||||
PA13.Mode=Serial_Wire
|
||||
PA13.Signal=SYS_JTMS-SWDIO
|
||||
PA14.Mode=Serial_Wire
|
||||
@@ -168,6 +180,14 @@ PA6.Signal=SPI1_MISO
|
||||
PA7.Locked=true
|
||||
PA7.Mode=Full_Duplex_Master
|
||||
PA7.Signal=SPI1_MOSI
|
||||
PB0.GPIOParameters=GPIO_Label
|
||||
PB0.GPIO_Label=RS485_1_EN
|
||||
PB0.Locked=true
|
||||
PB0.Signal=GPIO_Output
|
||||
PB1.GPIOParameters=GPIO_Label
|
||||
PB1.GPIO_Label=RS485_2_EN
|
||||
PB1.Locked=true
|
||||
PB1.Signal=GPIO_Output
|
||||
PB10.Locked=true
|
||||
PB10.Mode=Asynchronous
|
||||
PB10.Signal=USART3_TX
|
||||
@@ -187,6 +207,15 @@ PB14.Signal=SPI2_MISO
|
||||
PB15.Locked=true
|
||||
PB15.Mode=Full_Duplex_Master
|
||||
PB15.Signal=SPI2_MOSI
|
||||
PB2.GPIOParameters=GPIO_Label
|
||||
PB2.GPIO_Label=RS485_3_EN
|
||||
PB2.Locked=true
|
||||
PB2.Signal=GPIO_Output
|
||||
PB5.GPIOParameters=GPIO_PuPd,GPIO_Label
|
||||
PB5.GPIO_Label=JK4
|
||||
PB5.GPIO_PuPd=GPIO_PULLUP
|
||||
PB5.Locked=true
|
||||
PB5.Signal=GPIO_Output
|
||||
PB6.Locked=true
|
||||
PB6.Mode=Asynchronous
|
||||
PB6.Signal=USART1_TX
|
||||
@@ -223,10 +252,25 @@ PD5.GPIOParameters=GPIO_Label
|
||||
PD5.GPIO_Label=DS1302_RST
|
||||
PD5.Locked=true
|
||||
PD5.Signal=GPIO_Output
|
||||
PE11.GPIOParameters=GPIO_Label
|
||||
PE10.GPIOParameters=GPIO_PuPd,GPIO_Label
|
||||
PE10.GPIO_Label=JK3
|
||||
PE10.GPIO_PuPd=GPIO_PULLUP
|
||||
PE10.Locked=true
|
||||
PE10.Signal=GPIO_Output
|
||||
PE11.GPIOParameters=GPIO_PuPd,GPIO_Label
|
||||
PE11.GPIO_Label=W5500_SPI1_CS
|
||||
PE11.GPIO_PuPd=GPIO_NOPULL
|
||||
PE11.Locked=true
|
||||
PE11.Signal=GPIO_Output
|
||||
PE7.GPIOParameters=GPIO_Label
|
||||
PE7.GPIO_Label=RS485_4_EN
|
||||
PE7.Locked=true
|
||||
PE7.Signal=GPIO_Output
|
||||
PE9.GPIOParameters=GPIO_PuPd,GPIO_Label
|
||||
PE9.GPIO_Label=JK2
|
||||
PE9.GPIO_PuPd=GPIO_PULLUP
|
||||
PE9.Locked=true
|
||||
PE9.Signal=GPIO_Output
|
||||
PH0-OSC_IN.Mode=HSE-External-Oscillator
|
||||
PH0-OSC_IN.Signal=RCC_OSC_IN
|
||||
PH1-OSC_OUT.Mode=HSE-External-Oscillator
|
||||
|
||||
@@ -61,16 +61,32 @@ void Error_Handler(void);
|
||||
#define W5500_RST_GPIO_Port GPIOC
|
||||
#define W5500_INT_Pin GPIO_PIN_5
|
||||
#define W5500_INT_GPIO_Port GPIOC
|
||||
#define RS485_1_EN_Pin GPIO_PIN_0
|
||||
#define RS485_1_EN_GPIO_Port GPIOB
|
||||
#define RS485_2_EN_Pin GPIO_PIN_1
|
||||
#define RS485_2_EN_GPIO_Port GPIOB
|
||||
#define RS485_3_EN_Pin GPIO_PIN_2
|
||||
#define RS485_3_EN_GPIO_Port GPIOB
|
||||
#define RS485_4_EN_Pin GPIO_PIN_7
|
||||
#define RS485_4_EN_GPIO_Port GPIOE
|
||||
#define JK2_Pin GPIO_PIN_9
|
||||
#define JK2_GPIO_Port GPIOE
|
||||
#define JK3_Pin GPIO_PIN_10
|
||||
#define JK3_GPIO_Port GPIOE
|
||||
#define W5500_SPI1_CS_Pin GPIO_PIN_11
|
||||
#define W5500_SPI1_CS_GPIO_Port GPIOE
|
||||
#define SPI2_CS_Pin GPIO_PIN_12
|
||||
#define SPI2_CS_GPIO_Port GPIOB
|
||||
#define LED_Pin GPIO_PIN_12
|
||||
#define LED_GPIO_Port GPIOA
|
||||
#define DS1302_CLK_Pin GPIO_PIN_3
|
||||
#define DS1302_CLK_GPIO_Port GPIOD
|
||||
#define DS1302_DIO_Pin GPIO_PIN_4
|
||||
#define DS1302_DIO_GPIO_Port GPIOD
|
||||
#define DS1302_RST_Pin GPIO_PIN_5
|
||||
#define DS1302_RST_GPIO_Port GPIOD
|
||||
#define JK4_Pin GPIO_PIN_5
|
||||
#define JK4_GPIO_Port GPIOB
|
||||
#define RS485_EN_Pin GPIO_PIN_8
|
||||
#define RS485_EN_GPIO_Port GPIOB
|
||||
|
||||
|
||||
+39
-12
@@ -48,18 +48,22 @@ void MX_GPIO_Init(void)
|
||||
__HAL_RCC_GPIOH_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOC, W5500_RST_Pin|W5500_INT_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(W5500_SPI1_CS_GPIO_Port, W5500_SPI1_CS_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOB, RS485_1_EN_Pin|RS485_2_EN_Pin|RS485_3_EN_Pin|SPI2_CS_Pin
|
||||
|JK4_Pin|RS485_EN_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, SPI2_CS_Pin|RS485_EN_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOE, RS485_4_EN_Pin|JK2_Pin|JK3_Pin|W5500_SPI1_CS_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOD, DS1302_CLK_Pin|DS1302_DIO_Pin|DS1302_RST_Pin, GPIO_PIN_RESET);
|
||||
@@ -71,20 +75,36 @@ void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = W5500_SPI1_CS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(W5500_SPI1_CS_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PBPin PBPin */
|
||||
GPIO_InitStruct.Pin = SPI2_CS_Pin|RS485_EN_Pin;
|
||||
/*Configure GPIO pins : PBPin PBPin PBPin PBPin
|
||||
PBPin */
|
||||
GPIO_InitStruct.Pin = RS485_1_EN_Pin|RS485_2_EN_Pin|RS485_3_EN_Pin|SPI2_CS_Pin
|
||||
|RS485_EN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PEPin PEPin */
|
||||
GPIO_InitStruct.Pin = RS485_4_EN_Pin|W5500_SPI1_CS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PEPin PEPin */
|
||||
GPIO_InitStruct.Pin = JK2_Pin|JK3_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = LED_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PDPin PDPin PDPin */
|
||||
GPIO_InitStruct.Pin = DS1302_CLK_Pin|DS1302_DIO_Pin|DS1302_RST_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
@@ -92,6 +112,13 @@ void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = JK4_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(JK4_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
@@ -98,6 +98,7 @@ int main(void)
|
||||
MX_USART6_UART_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
app_init();
|
||||
//HAL_GPIO_WritePin(JK1_GPIO_Port,JK1_Pin,GPIO_PIN_SET);
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -117,10 +117,6 @@
|
||||
<pMon>Segger\JL2CM3.dll</pMon>
|
||||
</DebugOpt>
|
||||
<TargetDriverDllRegistry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>DLGUARM</Key>
|
||||
</SetRegEntry>
|
||||
<SetRegEntry>
|
||||
<Number>0</Number>
|
||||
<Key>ARMRTXEVENTFLAGS</Key>
|
||||
@@ -154,14 +150,81 @@
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>id</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>1</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>IP_Addr</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>2</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>W5500,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>3</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>W5500,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>4</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>leakage,0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>5</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>DS1302</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>6</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>p_data</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<WatchWindow2>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
<WinNumber>2</WinNumber>
|
||||
<ItemText>leakage</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>1</count>
|
||||
<WinNumber>2</WinNumber>
|
||||
<ItemText>hmi_tx_buffer</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>2</count>
|
||||
<WinNumber>2</WinNumber>
|
||||
<ItemText>p_leakage</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>3</count>
|
||||
<WinNumber>2</WinNumber>
|
||||
<ItemText>history_record</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>4</count>
|
||||
<WinNumber>2</WinNumber>
|
||||
<ItemText>p_tjc_hmi</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>5</count>
|
||||
<WinNumber>2</WinNumber>
|
||||
<ItemText>p_sensor_sys</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>6</count>
|
||||
<WinNumber>2</WinNumber>
|
||||
<ItemText>p_data</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow2>
|
||||
<Tracepoint>
|
||||
<THDelay>0</THDelay>
|
||||
</Tracepoint>
|
||||
<DebugFlag>
|
||||
<trace>0</trace>
|
||||
<periodic>0</periodic>
|
||||
<aLwin>1</aLwin>
|
||||
<aLwin>0</aLwin>
|
||||
<aCover>0</aCover>
|
||||
<aSer1>0</aSer1>
|
||||
<aSer2>0</aSer2>
|
||||
@@ -209,7 +272,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>Application/MDK-ARM</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
@@ -229,7 +292,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>Application/User/Core</GroupName>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
|
||||
@@ -188,7 +188,7 @@
|
||||
<hadIRAM2>1</hadIRAM2>
|
||||
<hadIROM2>0</hadIROM2>
|
||||
<StupSel>8</StupSel>
|
||||
<useUlib>0</useUlib>
|
||||
<useUlib>1</useUlib>
|
||||
<EndSel>0</EndSel>
|
||||
<uLtcg>0</uLtcg>
|
||||
<nSecure>0</nSecure>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,10 @@
|
||||
#include "bsp_Led.h"
|
||||
#include "bsp_74HC4067.h"
|
||||
#include "bsp_Flash.h"
|
||||
#include "bsp_W5500.h"
|
||||
#include "bsp_w25q.h"
|
||||
#include "bsp_DS1302.h"
|
||||
#include "app_leakage.h"
|
||||
|
||||
#include "proto_modbus_master_tdlas.h"
|
||||
#include "proto_modbus_slave_ex.h"
|
||||
@@ -60,7 +63,10 @@ void app_init(void)
|
||||
UartCH_Config.init();
|
||||
|
||||
app_timer.init(APP_TIMER_TASK_NUM,app_timer_task); /*分时复用,时间片轮询*/
|
||||
W5500.Init();
|
||||
tjc_hmi.init();
|
||||
DS1302.Init();
|
||||
tdlas.init();
|
||||
led.init();
|
||||
|
||||
//Wdg.Init();
|
||||
@@ -77,6 +83,7 @@ void app_task(void)
|
||||
{
|
||||
app_timer.task();
|
||||
task_idle();
|
||||
W5500.Task();
|
||||
}
|
||||
/*空闲执行的函数*/
|
||||
void task_idle(void)
|
||||
@@ -108,12 +115,14 @@ void task_200ms(void)
|
||||
void task_500ms(void)
|
||||
{
|
||||
led.task();
|
||||
tdlas.tx_task();
|
||||
}
|
||||
|
||||
|
||||
void task_1s(void)
|
||||
{
|
||||
|
||||
p_leakage->task();
|
||||
DS1302.Task();
|
||||
}
|
||||
|
||||
void task_2s(void)
|
||||
|
||||
@@ -1,17 +1,31 @@
|
||||
#include "app_leakage.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "bsp_w25q.h"
|
||||
|
||||
|
||||
static void history_clear_all(void);
|
||||
static u8 history_read_record(u32 record_index, app_leakage_history_alarm_t *record);
|
||||
static void history_init(void);
|
||||
static void history_save_metadata(void);
|
||||
|
||||
app_leakage_t leakage =
|
||||
{
|
||||
|
||||
.region_num = 0,
|
||||
.sub_device_num = 0,
|
||||
.init = NULL,
|
||||
.task = app_leakage_task
|
||||
};
|
||||
app_leakage_t *p_leakage = &leakage;
|
||||
|
||||
app_hitory_t history =
|
||||
{
|
||||
.read_history = history_read_record,
|
||||
.clean_history = history_clear_all,
|
||||
.init_history = history_init
|
||||
};
|
||||
|
||||
/*区域分类,将同一区域名的设备划分到一起*/
|
||||
static void app_leakage_region_classify(void)
|
||||
void app_leakage_region_classify(void)
|
||||
{
|
||||
u16 i,j;
|
||||
u8 add_region_flag;
|
||||
@@ -36,7 +50,7 @@ static void app_leakage_region_classify(void)
|
||||
{
|
||||
/*添加子设备*/
|
||||
p_leakage->region_data[j].sub_device_index[p_leakage->region_data[j].leakage_num] = i;/*绑定子设备索引*/
|
||||
p_leakage->region_data[j].leakage_num++; /*区域中子系统数据++*/
|
||||
p_leakage->region_data[j].sub_device_num++; /*区域中子系统数据++*/
|
||||
add_region_flag = 0;/*不添加新区域*/
|
||||
break;
|
||||
}
|
||||
@@ -48,7 +62,7 @@ static void app_leakage_region_classify(void)
|
||||
/*复制名称*/
|
||||
memcpy(p_leakage->region_data[p_leakage->region_num].name,p_leakage->sub_device_data[i].flash_data.region_name, APP_LEAKAGE_STRING_NANE_LEN);
|
||||
p_leakage->region_data[p_leakage->region_num].sub_device_index[p_leakage->region_data[p_leakage->region_num].leakage_num] = i;/*绑定子设备索引*/
|
||||
p_leakage->region_data[p_leakage->region_num].leakage_num++; /*区域中子系统数据++*/
|
||||
p_leakage->region_data[p_leakage->region_num].sub_device_num++; /*区域中子系统数据++*/
|
||||
p_leakage->region_num++; /*区域数量++*/
|
||||
}
|
||||
}
|
||||
@@ -58,43 +72,285 @@ static void app_leakage_region_classify(void)
|
||||
/*异常状态设备数量统计*/
|
||||
void app_leakage_task(void)
|
||||
{
|
||||
u16 i,j,k,sub_device_index;
|
||||
/*计算异常设备数量*/
|
||||
/*遍历区域*/
|
||||
for(i=0;i<p_leakage->region_num;i++)
|
||||
static u16 prev_ch_state[APP_LEAKAGE_SUB_DEVICE_NUM][APP_LEAKAGE_SUB_DEVICE_CH_NUM] = {0};
|
||||
u16 i, j, k, sub_device_index;
|
||||
static u8 initialized = 0;
|
||||
|
||||
/* 初始化历史模块 */
|
||||
if(!initialized)
|
||||
{
|
||||
history.init_history();
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
/* 初始化区域异常统计 */
|
||||
for(i = 0; i < p_leakage->region_num; i++)
|
||||
{
|
||||
/*清除设备*/
|
||||
p_leakage->region_data[i].leakage_num = 0;
|
||||
p_leakage->region_data[i].open_num = 0;
|
||||
p_leakage->region_data[i].time_out_num = 0;
|
||||
/*遍历区域里面的设备*/
|
||||
for(j=0;j<p_leakage->region_data[i].leakage_num;j++)
|
||||
}
|
||||
|
||||
/* 检测状态变化并统计异常数量 */
|
||||
for(i = 0; i < p_leakage->region_num; i++)
|
||||
{
|
||||
for(j = 0; j < p_leakage->region_data[i].sub_device_num; j++)
|
||||
{
|
||||
/*记录索引*/
|
||||
sub_device_index = p_leakage->region_data[i].sub_device_index[j];
|
||||
|
||||
/*遍历通道*/
|
||||
for(k=0;k<APP_LEAKAGE_SUB_DEVICE_CH_NUM;k++)
|
||||
/* 检查设备是否启用 */
|
||||
if(p_leakage->sub_device_data[sub_device_index].flash_data.state != ENABLE)
|
||||
{
|
||||
/*通讯超时*/
|
||||
if(p_leakage->sub_device_data[sub_device_index].ch_data[k].state & APP_LEAKAGE_SUB_DEVICE_STATE_TIME_OUT)
|
||||
continue;
|
||||
}
|
||||
|
||||
for(k = 0; k < APP_LEAKAGE_SUB_DEVICE_CH_NUM; k++)
|
||||
{
|
||||
u16 current_state = p_leakage->sub_device_data[sub_device_index].ch_data[k].state;
|
||||
u16 prev_state = prev_ch_state[sub_device_index][k];
|
||||
u16 leak_distance = p_leakage->sub_device_data[sub_device_index].ch_data[k].distance;
|
||||
|
||||
/* 检测状态变化并记录历史报警 */
|
||||
if((current_state & APP_LEAKAGE_SUB_DEVICE_STATE_LEAKAGE) &&
|
||||
!(prev_state & APP_LEAKAGE_SUB_DEVICE_STATE_LEAKAGE))
|
||||
{
|
||||
/* 漏液报警开始 - 记录历史报警 */
|
||||
history_add_alarm_record(i, sub_device_index, k, APP_LEAKAGE_SUB_DEVICE_STATE_LEAKAGE, leak_distance);
|
||||
}
|
||||
|
||||
if((current_state & APP_LEAKAGE_SUB_DEVICE_STATE_OPEN) &&
|
||||
!(prev_state & APP_LEAKAGE_SUB_DEVICE_STATE_OPEN))
|
||||
{
|
||||
/* 断带报警开始 - 记录历史报警 */
|
||||
history_add_alarm_record(i, sub_device_index, k, APP_LEAKAGE_SUB_DEVICE_STATE_OPEN, 0);
|
||||
}
|
||||
|
||||
if((current_state & APP_LEAKAGE_SUB_DEVICE_STATE_TIME_OUT) &&
|
||||
!(prev_state & APP_LEAKAGE_SUB_DEVICE_STATE_TIME_OUT))
|
||||
{
|
||||
/* 通讯超时报警开始 - 记录历史报警 */
|
||||
history_add_alarm_record(i, sub_device_index, k, APP_LEAKAGE_SUB_DEVICE_STATE_TIME_OUT, 0);
|
||||
}
|
||||
|
||||
/* 更新历史状态 */
|
||||
prev_ch_state[sub_device_index][k] = current_state;
|
||||
}
|
||||
|
||||
/* 统计区域异常设备数量 - 按设备统计 */
|
||||
|
||||
for(k = 0; k < APP_LEAKAGE_SUB_DEVICE_CH_NUM; k++)
|
||||
{
|
||||
u16 current_state = p_leakage->sub_device_data[sub_device_index].ch_data[k].state;
|
||||
|
||||
if(current_state & APP_LEAKAGE_SUB_DEVICE_STATE_TIME_OUT)
|
||||
{
|
||||
p_leakage->region_data[i].time_out_num++;
|
||||
break;
|
||||
continue; /* 通讯超时,设备已离线,不再检查其他异常 */
|
||||
}
|
||||
/*断带*/
|
||||
else if(p_leakage->sub_device_data[sub_device_index].ch_data[k].state & APP_LEAKAGE_SUB_DEVICE_STATE_OPEN)
|
||||
if(current_state & APP_LEAKAGE_SUB_DEVICE_STATE_OPEN)
|
||||
{
|
||||
|
||||
p_leakage->region_data[i].open_num++;
|
||||
break;
|
||||
}
|
||||
/*漏液*/
|
||||
else if(p_leakage->sub_device_data[sub_device_index].ch_data[k].state & APP_LEAKAGE_SUB_DEVICE_STATE_LEAKAGE)
|
||||
if(current_state & APP_LEAKAGE_SUB_DEVICE_STATE_LEAKAGE)
|
||||
{
|
||||
p_leakage->region_data[i].leakage_num++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 获取当前时间 */
|
||||
static void get_current_time(u8 *time_buffer)
|
||||
{
|
||||
// RTC_TimeTypeDef sTime;
|
||||
// RTC_DateTypeDef sDate;
|
||||
//
|
||||
// /* 获取RTC时间 */
|
||||
// HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
|
||||
// HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
|
||||
//
|
||||
// /* 年: 2字节 (例如: 2024 -> 0x07 0xE8) */
|
||||
// uint16_t year = 2000 + sDate.Year; /* RTC年份通常从2000开始 */
|
||||
// time_buffer[0] = (year >> 8) & 0xFF; /* 高字节 */
|
||||
// time_buffer[1] = year & 0xFF; /* 低字节 */
|
||||
// time_buffer[2] = sDate.Month; /* 月 */
|
||||
// time_buffer[3] = sDate.Date; /* 日 */
|
||||
// time_buffer[4] = sTime.Hours; /* 时 */
|
||||
// time_buffer[5] = sTime.Minutes; /* 分 */
|
||||
}
|
||||
|
||||
/* 从Flash读取历史报警元数据 */
|
||||
static void history_read_metadata(void)
|
||||
{
|
||||
app_leakage_history_metadata_t temp_metadata;
|
||||
|
||||
w25q32.read(W25Q32_HISTORY_ALARM_METADATA_ADDR,
|
||||
(uint8_t*)&temp_metadata,
|
||||
sizeof(app_leakage_history_metadata_t));
|
||||
|
||||
|
||||
if(temp_metadata.total_records <= temp_metadata.max_records &&
|
||||
temp_metadata.write_index < temp_metadata.max_records)
|
||||
{
|
||||
/* 数据有效,复制到全局变量 */
|
||||
memcpy(&leakage.history_metadata, &temp_metadata, sizeof(app_leakage_history_metadata_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 数据无效,初始化 */
|
||||
memset(&leakage.history_metadata, 0, sizeof(app_leakage_history_metadata_t));
|
||||
leakage.history_metadata.max_records = MAX_HISTORY_ALARM_RECORDS;
|
||||
|
||||
/* 保存到Flash */
|
||||
history_save_metadata();
|
||||
}
|
||||
}
|
||||
|
||||
/* 保存历史报警元数据到Flash */
|
||||
static void history_save_metadata(void)
|
||||
{
|
||||
/* 擦除元数据扇区 */
|
||||
w25q32_sector_erase(W25Q32_HISTORY_ALARM_METADATA_ADDR);
|
||||
|
||||
/* 写入元数据 */
|
||||
w25q32.write(W25Q32_HISTORY_ALARM_METADATA_ADDR,
|
||||
(uint8_t*)&leakage.history_metadata,
|
||||
sizeof(app_leakage_history_metadata_t));
|
||||
}
|
||||
|
||||
/* 计算记录在Flash中的地址 */
|
||||
static uint32_t history_calc_record_addr(u32 record_index)
|
||||
{
|
||||
return W25Q32_HISTORY_ALARM_DATA_ADDR +
|
||||
(record_index * HISTORY_ALARM_RECORD_SIZE);
|
||||
}
|
||||
|
||||
/* 获取记录所在的扇区地址 */
|
||||
static uint32_t history_calc_sector_addr(u32 record_index)
|
||||
{
|
||||
uint32_t record_addr = history_calc_record_addr(record_index);
|
||||
return record_addr & ~(W25Q32_SECTOR_SIZE - 1); /* 4K对齐 */
|
||||
}
|
||||
|
||||
/* 添加历史报警记录 */
|
||||
void history_add_alarm_record(u8 region_idx, u8 device_idx, u8 channel, u16 alarm_type, u16 leak_distance)
|
||||
{
|
||||
app_leakage_history_alarm_t new_alarm;
|
||||
uint32_t write_addr;
|
||||
|
||||
/* 填充报警记录 */
|
||||
memset(&new_alarm, 0, sizeof(app_leakage_history_alarm_t));
|
||||
|
||||
/* 区域名 */
|
||||
if(region_idx < leakage.region_num)
|
||||
{
|
||||
memcpy(new_alarm.region_name, leakage.region_data[region_idx].name,
|
||||
APP_LEAKAGE_STRING_NANE_LEN);
|
||||
}
|
||||
|
||||
/* 设备ID和名称 */
|
||||
if(device_idx < APP_LEAKAGE_SUB_DEVICE_NUM)
|
||||
{
|
||||
new_alarm.device_id = leakage.sub_device_data[device_idx].flash_data.modbus_id;
|
||||
memcpy(new_alarm.device_name, leakage.sub_device_data[device_idx].flash_data.device_name,
|
||||
APP_LEAKAGE_STRING_NANE_LEN);
|
||||
}
|
||||
|
||||
/* 报警类型、通道和漏液距离 */
|
||||
new_alarm.alarm_type = alarm_type;
|
||||
new_alarm.channel = channel;
|
||||
new_alarm.leak_distance = leak_distance;
|
||||
|
||||
/* 开始时间 */
|
||||
get_current_time(new_alarm.start_time);
|
||||
|
||||
/* 计算写入地址 */
|
||||
write_addr = history_calc_record_addr(leakage.history_metadata.write_index);
|
||||
|
||||
/* 检查是否需要擦除新扇区 */
|
||||
uint32_t current_sector = history_calc_sector_addr(leakage.history_metadata.write_index);
|
||||
uint32_t prev_sector = history_calc_sector_addr(
|
||||
(leakage.history_metadata.write_index == 0) ?
|
||||
leakage.history_metadata.max_records - 1 :
|
||||
leakage.history_metadata.write_index - 1);
|
||||
|
||||
/* 如果切换到新扇区,需要擦除 */
|
||||
if(current_sector != prev_sector)
|
||||
{
|
||||
w25q32_sector_erase(current_sector);
|
||||
}
|
||||
|
||||
/* 写入记录 */
|
||||
w25q32.write(write_addr, (uint8_t*)&new_alarm, HISTORY_ALARM_RECORD_SIZE);
|
||||
|
||||
/* 更新元数据 */
|
||||
leakage.history_metadata.write_index++;
|
||||
if(leakage.history_metadata.write_index >= leakage.history_metadata.max_records)
|
||||
{
|
||||
leakage.history_metadata.write_index = 0;
|
||||
}
|
||||
|
||||
if(leakage.history_metadata.total_records < leakage.history_metadata.max_records)
|
||||
{
|
||||
leakage.history_metadata.total_records++;
|
||||
}
|
||||
|
||||
/* 保存元数据 */
|
||||
history_save_metadata();
|
||||
}
|
||||
|
||||
/* 读取历史报警记录 */
|
||||
static u8 history_read_record(u32 record_index, app_leakage_history_alarm_t *record)
|
||||
{
|
||||
if(record_index >= leakage.history_metadata.total_records)
|
||||
{
|
||||
return 0; /* 记录索引无效 */
|
||||
}
|
||||
|
||||
/* 计算实际存储索引(考虑循环队列) */
|
||||
uint32_t actual_index;
|
||||
if(leakage.history_metadata.total_records == leakage.history_metadata.max_records)
|
||||
{
|
||||
/* 缓冲区已满,计算相对索引 */
|
||||
actual_index = (leakage.history_metadata.write_index + record_index) %
|
||||
leakage.history_metadata.max_records;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 缓冲区未满,直接读取 */
|
||||
actual_index = record_index;
|
||||
}
|
||||
|
||||
uint32_t read_addr = history_calc_record_addr(actual_index);
|
||||
w25q32.read(read_addr, (uint8_t*)record, HISTORY_ALARM_RECORD_SIZE);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 清空所有历史报警记录 */
|
||||
static void history_clear_all(void)
|
||||
{
|
||||
/* 重置元数据 */
|
||||
memset(&leakage.history_metadata, 0, sizeof(app_leakage_history_metadata_t));
|
||||
leakage.history_metadata.max_records = MAX_HISTORY_ALARM_RECORDS;
|
||||
|
||||
/* 保存元数据 */
|
||||
history_save_metadata();
|
||||
|
||||
/* 擦除所有数据扇区(可选) */
|
||||
for(uint32_t i = 0; i < HISTORY_ALARM_SECTORS_NEEDED; i++)
|
||||
{
|
||||
uint32_t sector_addr = W25Q32_HISTORY_ALARM_DATA_ADDR + i * W25Q32_SECTOR_SIZE;
|
||||
w25q32_sector_erase(sector_addr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 初始化历史报警模块 */
|
||||
static void history_init(void)
|
||||
{
|
||||
/* 读取元数据 */
|
||||
history_read_metadata();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,11 @@
|
||||
#define APP_LEAKAGE_SUB_DEVICE_NUM (32)
|
||||
#define APP_LEAKAGE_SUB_DEVICE_CH_NUM (4)
|
||||
|
||||
void app_leakage_task(void);
|
||||
void app_leakage_region_classify(void);
|
||||
void history_add_alarm_record(u8 region_idx, u8 device_idx, u8 channel, u16 alarm_type, u16 leak_distance);
|
||||
|
||||
|
||||
/*子设备存储的参数*/
|
||||
typedef struct
|
||||
{
|
||||
@@ -33,6 +38,8 @@ typedef struct
|
||||
u16 state; /*状态*/
|
||||
u16 distance; /*漏液距离*/
|
||||
}ch_data[APP_LEAKAGE_SUB_DEVICE_CH_NUM]; /*通道数据*/
|
||||
u8 heartbeat; /*心跳包,0-59循环*/
|
||||
u8 test_mode; /*测试模式,0=正常,1-4=测试对应通道*/
|
||||
}app_leakage_sub_device_class_t;
|
||||
|
||||
|
||||
@@ -47,6 +54,27 @@ typedef struct
|
||||
u8 sub_device_index[APP_LEAKAGE_SUB_DEVICE_NUM]; /*设备的索引*/
|
||||
}app_leakage_region_data_class_t;
|
||||
|
||||
/* 历史报警记录结构 */
|
||||
typedef struct
|
||||
{
|
||||
u8 region_name[APP_LEAKAGE_STRING_NANE_LEN]; /* 区域名 */
|
||||
u8 device_id; /* 设备ID */
|
||||
u8 device_name[APP_LEAKAGE_STRING_NANE_LEN]; /* 设备名称 */
|
||||
u16 alarm_type; /* 报警类型 */
|
||||
u8 start_time[6]; /* 开始时间: 年(2字节)月日时分 */
|
||||
u16 leak_distance; /* 漏液距离 (0表示非漏液报警) */
|
||||
u8 channel; /* 通道号 (0-3) */
|
||||
} app_leakage_history_alarm_t;
|
||||
|
||||
/* 历史报警管理结构 */
|
||||
typedef struct
|
||||
{
|
||||
u32 total_records; /* 总记录数 */
|
||||
u32 write_index; /* 写指针 */
|
||||
u32 read_index; /* 读指针 */
|
||||
u32 max_records; /* 最大记录数 */
|
||||
} app_leakage_history_metadata_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 region_num;
|
||||
@@ -54,9 +82,20 @@ typedef struct
|
||||
app_leakage_region_data_class_t region_data[APP_LEAKAGE_SUB_DEVICE_NUM];
|
||||
app_leakage_sub_device_class_t sub_device_data[APP_LEAKAGE_SUB_DEVICE_NUM];
|
||||
|
||||
app_leakage_history_metadata_t history_metadata;
|
||||
|
||||
void (*init)(void); /*初始化*/
|
||||
void (*task)(void); /*执行任务*/
|
||||
}app_leakage_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u8 (*read_history)(u32, app_leakage_history_alarm_t *);
|
||||
void (*clean_history)(void);
|
||||
void (*init_history)(void);
|
||||
}app_hitory_t;
|
||||
|
||||
extern app_leakage_t leakage;
|
||||
extern app_leakage_t *p_leakage;
|
||||
extern app_hitory_t history;
|
||||
#endif
|
||||
@@ -236,7 +236,7 @@ static void bsp_DS1302Init(void)
|
||||
if ((pDS1302->Time.Year > 99) || (pDS1302->Time.Month > 12) || (pDS1302->Time.Day > 31) ||
|
||||
(pDS1302->Time.Hour > 23) || (pDS1302->Time.Minute > 59) || (pDS1302->Time.Second > 59))
|
||||
{
|
||||
pDS1302->Time.Year = 25;
|
||||
pDS1302->Time.Year = 26;
|
||||
pDS1302->Time.Month = 1;
|
||||
pDS1302->Time.Day = 1;
|
||||
pDS1302->Time.Hour = 0;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "bsp_Led.h"
|
||||
#include "app_timer.h"
|
||||
|
||||
//#define LED1_ON HAL_GPIO_WritePin (LED1_GPIO_Port, LED1_Pin, GPIO_PIN_RESET)
|
||||
//#define LED1_OFF HAL_GPIO_WritePin (LED1_GPIO_Port, LED1_Pin, GPIO_PIN_SET)
|
||||
//#define LED1_TOGGLE HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin)
|
||||
#define LED_ON HAL_GPIO_WritePin (LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET)
|
||||
#define LED_OFF HAL_GPIO_WritePin (LED_GPIO_Port, LED_Pin, GPIO_PIN_SET)
|
||||
#define LED_TOGGLE HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin)
|
||||
|
||||
//#define LED2_ON HAL_GPIO_WritePin (LED2_GPIO_Port, LED2_Pin, GPIO_PIN_RESET)
|
||||
//#define LED2_OFF HAL_GPIO_WritePin (LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET)
|
||||
@@ -28,11 +28,11 @@ static void bsp_led_init(void)
|
||||
for(u8 i = 0;i < 20;i++)
|
||||
{
|
||||
delay_ms(50);
|
||||
// HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
|
||||
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
|
||||
}
|
||||
}
|
||||
|
||||
static void bsp_led_task(void)
|
||||
{
|
||||
// HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
|
||||
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
|
||||
}
|
||||
|
||||
@@ -42,11 +42,11 @@ static void Write_SOCK_Data_Buffer(bsp_W5500_Class_t *pW5500_Class, u8 *dat_ptr,
|
||||
bsp_W5500_t W5500 =
|
||||
{
|
||||
.Gateway_IP = {192,168,1,1},
|
||||
.Sub_Mask = {255,255,255,0},
|
||||
.Sub_Mask = {255,255,255,0},/*子网掩码*/
|
||||
.Phy_Addr = {0x0c,0x29,0xab,0x7c,0x00,0x01},
|
||||
|
||||
//.IP_Addr = {169,254,107,101},
|
||||
.IP_Addr = {192,168,1,101},
|
||||
.IP_Addr = {192,168,100,101},
|
||||
|
||||
.Interrupt_Process = bsp_W5500_Interrupt_Process,
|
||||
|
||||
@@ -61,7 +61,7 @@ bsp_W5500_t W5500 =
|
||||
.ConfigData.Sub_Mask = {255,255,255,0},
|
||||
.ConfigData.Phy_Addr = {0x0c,0x29,0xab,0x7c,0x00,0x01},
|
||||
|
||||
.ConfigData.IP_Addr = {192,168,1,101},
|
||||
.ConfigData.IP_Addr = {192,168,100,101},
|
||||
.ConfigData.Port = {0x13,0x88},
|
||||
|
||||
// .ConfigData.DIP = {192,168,1,32},
|
||||
@@ -776,7 +776,7 @@ static void bsp_W5500_Init()
|
||||
{
|
||||
bsp_W5500_Socket_Init(&pW5500->W5500_Class[i]);
|
||||
pW5500->W5500_Class[i].Run_State = 0; /*复位状态*/
|
||||
//bsp_W5500_Socket_Set(&pW5500->W5500_Class[i]); /*W5500端口初始化配置*/
|
||||
// bsp_W5500_Socket_Set(&pW5500->W5500_Class[i]); /*W5500端口初始化配置*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -205,14 +205,14 @@
|
||||
#define S_TX_SIZE 2048 /*定义Socket发送缓冲区的大小,可以根据W5500_TMSR的设置修改 */
|
||||
|
||||
/***************----- W5500 GPIO定义 -----***************/
|
||||
#define W5500_SCS GPIO_PIN_0 // 定义W5500的CS引脚
|
||||
#define W5500_SCS_PORT GPIOB
|
||||
#define W5500_SCS W5500_SPI1_CS_Pin // 定义W5500的CS引脚
|
||||
#define W5500_SCS_PORT W5500_SPI1_CS_GPIO_Port
|
||||
|
||||
#define W5500_RST GPIO_PIN_4 // 定义W5500的RST引脚
|
||||
#define W5500_RST_PORT GPIOA
|
||||
#define W5500_RST W5500_RST_Pin // 定义W5500的RST引脚
|
||||
#define W5500_RST_PORT W5500_RST_GPIO_Port
|
||||
|
||||
#define W5500_INT GPIO_PIN_1 // 定义W5500的INT引脚
|
||||
#define W5500_INT_PORT GPIOA
|
||||
#define W5500_INT W5500_INT_Pin // 定义W5500的INT引脚
|
||||
#define W5500_INT_PORT W5500_INT_GPIO_Port
|
||||
|
||||
///***************----- 网络参数变量定义 -----***************/
|
||||
//extern u8 Gateway_IP[4]; // 网关IP地址
|
||||
|
||||
@@ -2,8 +2,14 @@
|
||||
#include "string.h"
|
||||
|
||||
/* RS485控制宏定义 */
|
||||
#define RS485_RX HAL_GPIO_WritePin(RS485_EN_GPIO_Port, RS485_EN_Pin, GPIO_PIN_SET)
|
||||
#define RS485_TX HAL_GPIO_WritePin(RS485_EN_GPIO_Port, RS485_EN_Pin, GPIO_PIN_SET)
|
||||
#define RS485_1_RX HAL_GPIO_WritePin(RS485_1_EN_GPIO_Port, RS485_1_EN_Pin, GPIO_PIN_RESET)
|
||||
#define RS485_1_TX HAL_GPIO_WritePin(RS485_1_EN_GPIO_Port, RS485_1_EN_Pin, GPIO_PIN_SET)
|
||||
#define RS485_2_RX HAL_GPIO_WritePin(RS485_2_EN_GPIO_Port, RS485_2_EN_Pin, GPIO_PIN_RESET)
|
||||
#define RS485_2_TX HAL_GPIO_WritePin(RS485_2_EN_GPIO_Port, RS485_2_EN_Pin, GPIO_PIN_SET)
|
||||
#define RS485_3_RX HAL_GPIO_WritePin(RS485_3_EN_GPIO_Port, RS485_3_EN_Pin, GPIO_PIN_RESET)
|
||||
#define RS485_3_TX HAL_GPIO_WritePin(RS485_3_EN_GPIO_Port, RS485_3_EN_Pin, GPIO_PIN_SET)
|
||||
#define RS485_4_RX HAL_GPIO_WritePin(RS485_4_EN_GPIO_Port, RS485_4_EN_Pin, GPIO_PIN_RESET)
|
||||
#define RS485_4_TX HAL_GPIO_WritePin(RS485_4_EN_GPIO_Port, RS485_4_EN_Pin, GPIO_PIN_SET)
|
||||
|
||||
/* 缓冲收发区大小 */
|
||||
#define RX_TEMP_BUFF_NUM (3000U)
|
||||
@@ -181,6 +187,14 @@ static void bsp_uart_dma_send(bsp_uart_t *p_uart, u8 *p_data, u16 len)
|
||||
{
|
||||
u32 tick_start, tick;
|
||||
|
||||
if(p_uart == &com_uart4)
|
||||
{
|
||||
RS485_1_TX;
|
||||
}else if(p_uart == &com_uart2)
|
||||
{
|
||||
RS485_2_TX;
|
||||
}
|
||||
|
||||
p_uart->tx_dma_complete_flag = 0;
|
||||
|
||||
/* 如果请求发送的长度大于缓冲区长度,则截断 */
|
||||
@@ -221,7 +235,12 @@ static void bsp_uart_send(bsp_uart_t *p_uart, u8 *p_data, u16 len)
|
||||
|
||||
/* RS485切换到发送模式 */
|
||||
if(p_uart == &com_uart4)
|
||||
RS485_TX;
|
||||
{
|
||||
RS485_1_TX;
|
||||
}else if(p_uart == &com_uart2)
|
||||
{
|
||||
RS485_2_TX;
|
||||
}
|
||||
|
||||
/* 计算需要发送的次数 */
|
||||
send_num = len / p_uart->tx_dma_len;
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include "main.h"
|
||||
|
||||
/* spi flash 片选引脚 - pb12 */
|
||||
#define W25Q32_CS_LOW() HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET)
|
||||
#define W25Q32_CS_HIGH() HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET)
|
||||
#define W25Q32_CS_LOW() HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_RESET)
|
||||
#define W25Q32_CS_HIGH() HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_SET)
|
||||
|
||||
/* spi 传输函数 */
|
||||
static void w25q32_spi_transmit(uint8_t *data, uint16_t size) {
|
||||
@@ -30,7 +30,6 @@ static void w25q32_write_enable(void);
|
||||
static void w25q32_write_disable(void);
|
||||
static uint8_t w25q32_read_status_reg(void);
|
||||
static void w25q32_wait_for_write_end(void);
|
||||
static void w25q32_sector_erase(uint32_t sector_addr);
|
||||
static void w25q32_block_erase(uint32_t block_addr);
|
||||
static void w25q32_page_write(uint32_t addr, uint8_t *data, uint16_t len);
|
||||
static uint8_t w25q32_read_id(void);
|
||||
@@ -43,6 +42,7 @@ w25q32_t w25q32 = {
|
||||
.read = w25q32_read,
|
||||
.write = w25q32_write,
|
||||
.chip_erase = w25q32_chip_erase,
|
||||
.sector_erase = w25q32_sector_erase,
|
||||
};
|
||||
|
||||
|
||||
@@ -106,7 +106,8 @@ static void w25q32_wait_for_write_end(void) {
|
||||
}
|
||||
|
||||
/* 扇区擦除 (4kb) */
|
||||
static void w25q32_sector_erase(uint32_t sector_addr) {
|
||||
void w25q32_sector_erase(uint32_t sector_addr)
|
||||
{
|
||||
uint8_t cmd[4];
|
||||
|
||||
/* 确保地址是4k对齐 */
|
||||
|
||||
@@ -31,6 +31,8 @@ extern "C" {
|
||||
#define W25Q32_MANUFACTURER_ID 0x90
|
||||
#define W25Q32_JEDEC_ID 0x9F
|
||||
|
||||
void w25q32_sector_erase(uint32_t sector_addr);
|
||||
|
||||
/* 状态寄存器位 */
|
||||
#define W25Q32_STATUS_BUSY (1 << 0)
|
||||
#define W25Q32_STATUS_WRITE_EN (1 << 1)
|
||||
@@ -39,12 +41,25 @@ extern "C" {
|
||||
#define W25Q32_USER_DATA_ADDR 0x000000 /* 用户数据存储起始地址 */
|
||||
#define W25Q32_USER_DATA_SIZE 0x100000 /* 大约1mb空间用于用户数据 */
|
||||
|
||||
#define W25Q32_DEVICE_INFO_ADDR (0x001000) /* 设备信息存储地址 - 扇区1,4K对齐 */
|
||||
#define DEVICE_INFO_STORAGE_SIZE (APP_LEAKAGE_SUB_DEVICE_NUM * sizeof(app_leakage_sub_device_flash_data_t)) /*设备信息存储大小*/
|
||||
|
||||
/* 历史报警存储地址和大小 */
|
||||
#define W25Q32_HISTORY_ALARM_METADATA_ADDR 0x002000 /* 历史报警元数据存储地址 - 扇区2 */
|
||||
#define W25Q32_HISTORY_ALARM_DATA_ADDR 0x003000 /* 历史报警数据存储地址 - 从扇区3开始 */
|
||||
|
||||
#define HISTORY_ALARM_RECORD_SIZE (sizeof(app_leakage_history_alarm_t)) /* 每条记录大小 */
|
||||
#define HISTORY_ALARM_RECORDS_PER_SECTOR (W25Q32_SECTOR_SIZE / HISTORY_ALARM_RECORD_SIZE) /* 每扇区记录数 */
|
||||
#define MAX_HISTORY_ALARM_RECORDS (1000) /* 最大历史报警记录数 */
|
||||
#define HISTORY_ALARM_SECTORS_NEEDED ((MAX_HISTORY_ALARM_RECORDS * HISTORY_ALARM_RECORD_SIZE + W25Q32_SECTOR_SIZE - 1) / W25Q32_SECTOR_SIZE)
|
||||
|
||||
/* w25q32 对象结构体 */
|
||||
typedef struct {
|
||||
void (*init)(void);
|
||||
void (*read)(uint32_t addr, uint8_t *data, uint32_t len);
|
||||
void (*write)(uint32_t addr, uint8_t *data, uint32_t len);
|
||||
void (*chip_erase)(void);
|
||||
void (*sector_erase)(uint32_t sector_addr);
|
||||
} w25q32_t;
|
||||
|
||||
/* 全局对象 */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -10,11 +10,14 @@ typedef struct
|
||||
u8 deliniter_main_index;/*主界面选中区域的全局索引*/
|
||||
u8 real_alarm_index;/*实时报警界面页码*/
|
||||
u8 detail_main_index;/*区域详情界面页码*/
|
||||
u8 device_config_index;/*设备配置界面页码*/
|
||||
u8 history_alarm_index;/*历史报警界面页码*/
|
||||
}gui_tjc_hmi_page_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gui_tjc_hmi_page_t page;
|
||||
u8 password[4];
|
||||
void (*init)(void);
|
||||
}gui_tjc_hmi_t;
|
||||
|
||||
|
||||
@@ -12,20 +12,16 @@
|
||||
**************************************************/
|
||||
u16 modbus_lib_crc16(u8 *p_data, u16 len)
|
||||
{
|
||||
u16 crc16 = 0xffff;
|
||||
u16 i;
|
||||
while(len--)
|
||||
{
|
||||
crc16 = crc16^(*p_data++);
|
||||
for(i=0; i++<8; )
|
||||
{
|
||||
if(crc16&0x0001)
|
||||
{
|
||||
crc16 = (crc16>>1)^0xa001;
|
||||
}
|
||||
else
|
||||
{
|
||||
crc16>>=1;
|
||||
u16 crc16 = 0xFFFF;
|
||||
u16 i, j;
|
||||
for (i = 0; i < len; i++) {
|
||||
crc16 ^= p_data[i];
|
||||
for (j = 0; j < 8; j++) {
|
||||
if (crc16 & 0x0001) {
|
||||
crc16 >>= 1;
|
||||
crc16 ^= 0xA001;
|
||||
} else {
|
||||
crc16 >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,7 +193,7 @@ void modbus_lib_data_read(u8 id,u16 addr,u16 num,void (*send)(u8 *,u16 ))
|
||||
u8 tx[8];
|
||||
u16 crc16;
|
||||
tx[0] = id;
|
||||
tx[1] = 0x41;//0x03;
|
||||
tx[1] = 0x03;//0x03;
|
||||
tx[2] = (addr >> 8) & 0xff;
|
||||
tx[3] = addr & 0xff;
|
||||
tx[4] = (num >> 8) & 0xff;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "bsp_Uart.h"
|
||||
#include "bsp_74HC4067.h"
|
||||
#include "bsp_Flash.h"
|
||||
#include "app_leakage.h"
|
||||
|
||||
#include "proto_print.h"
|
||||
#include "proto_modbus_lib.h"
|
||||
@@ -15,7 +16,8 @@
|
||||
#define TDLAS_MODBUS_ID (0xe8)
|
||||
#define TDLAS_DATA_ENDIAN (LITTLE_ENDIAN) /*配置大小端序*/
|
||||
|
||||
#define PROTO_TDLAS_GET_CURR_DATA_START_ADDR (20000)
|
||||
#define PROTO_LEAKAGE_READ_DATA_NUM (14) /*读取一个设备寄存器数量*/
|
||||
#define PROTO_TDLAS_GET_CURR_DATA_START_ADDR (0x0000)
|
||||
#define PROTO_TDLAS_SET_ZERO_CALIB_START_ADDR (12)
|
||||
#define PROTO_TDLAS_SET_SPAN_CALIB_START_ADDR (13)
|
||||
#define PROTO_TDLAS_GET_RESET_START_ADDR (0x0000)
|
||||
@@ -147,7 +149,7 @@ static void proto_tdlas_control_fac_calib_data_get(u8 ch)
|
||||
static void proto_tdlas_tx_curr_data_get(void)
|
||||
{
|
||||
u16 addr = PROTO_TDLAS_GET_CURR_DATA_START_ADDR;
|
||||
u8 len = Usr_Flash.FlashData.modbus_read_reg_num;
|
||||
u8 len = PROTO_LEAKAGE_READ_DATA_NUM;
|
||||
modbus_lib_data_read(p_sensor->modbus_id,addr,len,proto_tdlas_send);
|
||||
}
|
||||
|
||||
@@ -316,8 +318,8 @@ static void proto_tdlas_rx_task(u8 *p_data,u16 len,void *other_data)
|
||||
u8 modbus_id,cmd;
|
||||
u16 check_crc16,modbus_crc16;
|
||||
u16 *p_u16_temp;
|
||||
u16 i;
|
||||
u8 *p_rx_valid;
|
||||
u16 i,ch;
|
||||
u8 *p_rx_valid,temp_value;
|
||||
|
||||
proto_tdlas_sys_t *p_sensor_sys;
|
||||
p_sensor_sys = &p_sensor->sys[p_sensor->sensor_index];
|
||||
@@ -337,7 +339,7 @@ static void proto_tdlas_rx_task(u8 *p_data,u16 len,void *other_data)
|
||||
check_crc16 = p_data[len-2] << 8 | p_data[len-1];
|
||||
|
||||
if(modbus_id != p_sensor->modbus_id) return ;
|
||||
if(cmd != 0x04 && cmd != 0x06 && cmd != 0x10 && cmd != 0x41) return ;
|
||||
if(cmd != 0x03 && cmd != 0x06 && cmd != 0x10 && cmd != 0x41) return ;
|
||||
|
||||
modbus_crc16 = modbus_lib_crc16(p_data,len-2);
|
||||
modbus_crc16 = (modbus_crc16 >> 8) | (modbus_crc16 << 8);
|
||||
@@ -348,6 +350,10 @@ static void proto_tdlas_rx_task(u8 *p_data,u16 len,void *other_data)
|
||||
{
|
||||
p_rx_valid = &p_data[6];
|
||||
}
|
||||
|
||||
u8 byte_count = p_data[3];
|
||||
p_rx_valid = &p_data[3];
|
||||
|
||||
rx_uart = (bsp_uart_t *)other_data;
|
||||
|
||||
p_sensor_sys->tx_time_out_count = 0;
|
||||
@@ -361,10 +367,97 @@ static void proto_tdlas_rx_task(u8 *p_data,u16 len,void *other_data)
|
||||
}break;
|
||||
case PROTO_TDLAS_SYS_STATE_CURR_DATA_GET:
|
||||
{
|
||||
p_u16_temp = (u16 *)&(gas_data[p_sensor->sensor_index]);
|
||||
for(i=0;i<Usr_Flash.FlashData.modbus_read_reg_num;i++)
|
||||
/*计算当前设备索引*/
|
||||
u8 device_global_idx = p_sensor->sensor_index;
|
||||
|
||||
if(device_global_idx >= APP_LEAKAGE_SUB_DEVICE_NUM)
|
||||
{
|
||||
p_u16_temp[i] = p_rx_valid[i * 2] << 8 | p_rx_valid[i * 2 + 1];
|
||||
break;
|
||||
}
|
||||
|
||||
/*通道数据重置*/
|
||||
for(ch = 0;ch < APP_LEAKAGE_SUB_DEVICE_CH_NUM;ch++)
|
||||
{
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].state = 0;
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].state = 0;
|
||||
}
|
||||
|
||||
if(byte_count >=28)
|
||||
{
|
||||
ch = 0;
|
||||
temp_value = (p_rx_valid[0] << 8) | p_rx_valid[1];
|
||||
if(temp_value == 1) {
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].state |=
|
||||
APP_LEAKAGE_SUB_DEVICE_STATE_LEAKAGE;
|
||||
}
|
||||
|
||||
temp_value = (p_rx_valid[2] << 8) | p_rx_valid[3];
|
||||
if(temp_value == 1) {
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].state |=
|
||||
APP_LEAKAGE_SUB_DEVICE_STATE_OPEN;
|
||||
}
|
||||
|
||||
temp_value = (p_rx_valid[4] << 8) | p_rx_valid[5];
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].distance = temp_value *0.01;
|
||||
|
||||
/* 心跳包:0x0003*/
|
||||
temp_value = (p_rx_valid[6] << 8) | p_rx_valid[7];
|
||||
p_leakage->sub_device_data[device_global_idx].heartbeat = temp_value & 0xFF;
|
||||
|
||||
/*通道2:0x0004-0x0006*/
|
||||
ch = 1;
|
||||
temp_value = (p_rx_valid[8] << 8) | p_rx_valid[9];
|
||||
if(temp_value == 1) {
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].state |=
|
||||
APP_LEAKAGE_SUB_DEVICE_STATE_LEAKAGE;
|
||||
}
|
||||
|
||||
temp_value = (p_rx_valid[10] << 8) | p_rx_valid[11];
|
||||
if(temp_value == 1) {
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].state |=
|
||||
APP_LEAKAGE_SUB_DEVICE_STATE_OPEN;
|
||||
}
|
||||
|
||||
temp_value = (p_rx_valid[12] << 8) | p_rx_valid[13];
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].distance = temp_value *0.01;
|
||||
|
||||
/*测试模式:0x0007*/
|
||||
temp_value = (p_rx_valid[14] << 8) | p_rx_valid[15];
|
||||
p_leakage->sub_device_data[device_global_idx].test_mode = temp_value & 0xFF;
|
||||
|
||||
/*通道3:0x0008-0x000A*/
|
||||
ch = 2;
|
||||
temp_value = (p_rx_valid[16] << 8) | p_rx_valid[17];
|
||||
if(temp_value == 1) {
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].state |=
|
||||
APP_LEAKAGE_SUB_DEVICE_STATE_LEAKAGE;
|
||||
}
|
||||
|
||||
temp_value = (p_rx_valid[18] << 8) | p_rx_valid[19];
|
||||
if(temp_value == 1) {
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].state |=
|
||||
APP_LEAKAGE_SUB_DEVICE_STATE_OPEN;
|
||||
}
|
||||
|
||||
temp_value = (p_rx_valid[20] << 8) | p_rx_valid[21];
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].distance = temp_value *0.01;
|
||||
|
||||
/* 通道4:0x000B-0x000D*/
|
||||
ch = 3;
|
||||
temp_value = (p_rx_valid[22] << 8) | p_rx_valid[23];
|
||||
if(temp_value == 1) {
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].state |=
|
||||
APP_LEAKAGE_SUB_DEVICE_STATE_LEAKAGE;
|
||||
}
|
||||
|
||||
temp_value = (p_rx_valid[24] << 8) | p_rx_valid[25];
|
||||
if(temp_value == 1) {
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].state |=
|
||||
APP_LEAKAGE_SUB_DEVICE_STATE_OPEN;
|
||||
}
|
||||
|
||||
temp_value = (p_rx_valid[26] << 8) | p_rx_valid[27];
|
||||
p_leakage->sub_device_data[device_global_idx].ch_data[ch].distance = temp_value *0.01;
|
||||
}
|
||||
}break;
|
||||
case PROTO_TDLAS_SYS_STATE_ZERO_CALIB:
|
||||
|
||||
Reference in New Issue
Block a user