update modbus
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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); /*<2A><>ʱ<EFBFBD><CAB1><EFBFBD>ã<EFBFBD>ʱ<EFBFBD><CAB1>Ƭ<EFBFBD><C6AC>ѯ*/
|
||||
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();
|
||||
}
|
||||
/*<2A><><EFBFBD><EFBFBD>ִ<EFBFBD>еĺ<D0B5><C4BA><EFBFBD>*/
|
||||
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
|
||||
};
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>࣬<EFBFBD><E0A3AC>ͬһ<CDAC><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD>ֵ<EFBFBD>һ<EFBFBD><D2BB>*/
|
||||
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)
|
||||
{
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸*/
|
||||
p_leakage->region_data[j].sub_device_index[p_leakage->region_data[j].leakage_num] = i;/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>*/
|
||||
p_leakage->region_data[j].leakage_num++; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>++*/
|
||||
p_leakage->region_data[j].sub_device_num++; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>++*/
|
||||
add_region_flag = 0;/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
break;
|
||||
}
|
||||
@@ -48,7 +62,7 @@ static void app_leakage_region_classify(void)
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
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;/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>*/
|
||||
p_leakage->region_data[p_leakage->region_num].leakage_num++; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>++*/
|
||||
p_leakage->region_data[p_leakage->region_num].sub_device_num++; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>++*/
|
||||
p_leakage->region_num++; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>++*/
|
||||
}
|
||||
}
|
||||
@@ -58,43 +72,285 @@ static void app_leakage_region_classify(void)
|
||||
/*<2A>쳣״̬<D7B4>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3>*/
|
||||
void app_leakage_task(void)
|
||||
{
|
||||
static u16 prev_ch_state[APP_LEAKAGE_SUB_DEVICE_NUM][APP_LEAKAGE_SUB_DEVICE_CH_NUM] = {0};
|
||||
u16 i, j, k, sub_device_index;
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>*/
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
static u8 initialized = 0;
|
||||
|
||||
/* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ʷģ<CAB7><C4A3> */
|
||||
if(!initialized)
|
||||
{
|
||||
history.init_history();
|
||||
initialized = 1;
|
||||
}
|
||||
|
||||
/* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣ͳ<ECB3A3><CDB3> */
|
||||
for(i = 0; i < p_leakage->region_num; i++)
|
||||
{
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD>豸*/
|
||||
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;
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸*/
|
||||
for(j=0;j<p_leakage->region_data[i].leakage_num;j++)
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>״̬<D7B4>仯<EFBFBD><E4BBAF>ͳ<EFBFBD><CDB3><EFBFBD>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD> */
|
||||
for(i = 0; i < p_leakage->region_num; i++)
|
||||
{
|
||||
for(j = 0; j < p_leakage->region_data[i].sub_device_num; j++)
|
||||
{
|
||||
/*<2A><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>*/
|
||||
sub_device_index = p_leakage->region_data[i].sub_device_index[j];
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>*/
|
||||
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if(p_leakage->sub_device_data[sub_device_index].flash_data.state != ENABLE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for(k = 0; k < APP_LEAKAGE_SUB_DEVICE_CH_NUM; k++)
|
||||
{
|
||||
/*ͨѶ<CDA8><D1B6>ʱ*/
|
||||
if(p_leakage->sub_device_data[sub_device_index].ch_data[k].state & APP_LEAKAGE_SUB_DEVICE_STATE_TIME_OUT)
|
||||
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;
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>״̬<D7B4>仯<EFBFBD><E4BBAF><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD> */
|
||||
if((current_state & APP_LEAKAGE_SUB_DEVICE_STATE_LEAKAGE) &&
|
||||
!(prev_state & APP_LEAKAGE_SUB_DEVICE_STATE_LEAKAGE))
|
||||
{
|
||||
/* ©Һ<C2A9><D2BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ - <20><>¼<EFBFBD><C2BC>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD> */
|
||||
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))
|
||||
{
|
||||
/* <20>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ - <20><>¼<EFBFBD><C2BC>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD> */
|
||||
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))
|
||||
{
|
||||
/* ͨѶ<CDA8><D1B6>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ - <20><>¼<EFBFBD><C2BC>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD> */
|
||||
history_add_alarm_record(i, sub_device_index, k, APP_LEAKAGE_SUB_DEVICE_STATE_TIME_OUT, 0);
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ״̬ */
|
||||
prev_ch_state[sub_device_index][k] = current_state;
|
||||
}
|
||||
|
||||
/* ͳ<><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD> - <20><><EFBFBD>豸ͳ<E8B1B8><CDB3> */
|
||||
|
||||
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; /* ͨѶ<CDA8><D1B6>ʱ<EFBFBD><CAB1><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD><DFA3><EFBFBD><EFBFBD>ټ<EFBFBD><D9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣 */
|
||||
}
|
||||
/*<2A>ϴ<EFBFBD>*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* <20><>ȡ<EFBFBD><C8A1>ǰʱ<C7B0><CAB1> */
|
||||
static void get_current_time(u8 *time_buffer)
|
||||
{
|
||||
// RTC_TimeTypeDef sTime;
|
||||
// RTC_DateTypeDef sDate;
|
||||
//
|
||||
// /* <20><>ȡRTCʱ<43><CAB1> */
|
||||
// HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
|
||||
// HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
|
||||
//
|
||||
// /* <20><>: 2<>ֽ<EFBFBD> (<28><><EFBFBD><EFBFBD>: 2024 -> 0x07 0xE8) */
|
||||
// uint16_t year = 2000 + sDate.Year; /* RTC<54><43><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>2000<30><30>ʼ */
|
||||
// time_buffer[0] = (year >> 8) & 0xFF; /* <20><><EFBFBD>ֽ<EFBFBD> */
|
||||
// time_buffer[1] = year & 0xFF; /* <20><><EFBFBD>ֽ<EFBFBD> */
|
||||
// time_buffer[2] = sDate.Month; /* <20><> */
|
||||
// time_buffer[3] = sDate.Date; /* <20><> */
|
||||
// time_buffer[4] = sTime.Hours; /* ʱ */
|
||||
// time_buffer[5] = sTime.Minutes; /* <20><> */
|
||||
}
|
||||
|
||||
/* <20><>Flash<73><68>ȡ<EFBFBD><C8A1>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD> */
|
||||
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)
|
||||
{
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD> */
|
||||
memcpy(&leakage.history_metadata, &temp_metadata, sizeof(app_leakage_history_metadata_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC> */
|
||||
memset(&leakage.history_metadata, 0, sizeof(app_leakage_history_metadata_t));
|
||||
leakage.history_metadata.max_records = MAX_HISTORY_ALARM_RECORDS;
|
||||
|
||||
/* <20><><EFBFBD>浽Flash */
|
||||
history_save_metadata();
|
||||
}
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD>ݵ<EFBFBD>Flash */
|
||||
static void history_save_metadata(void)
|
||||
{
|
||||
/* <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
w25q32_sector_erase(W25Q32_HISTORY_ALARM_METADATA_ADDR);
|
||||
|
||||
/* д<><D0B4>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD> */
|
||||
w25q32.write(W25Q32_HISTORY_ALARM_METADATA_ADDR,
|
||||
(uint8_t*)&leakage.history_metadata,
|
||||
sizeof(app_leakage_history_metadata_t));
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>Flash<73>еĵ<D0B5>ַ */
|
||||
static uint32_t history_calc_record_addr(u32 record_index)
|
||||
{
|
||||
return W25Q32_HISTORY_ALARM_DATA_ADDR +
|
||||
(record_index * HISTORY_ALARM_RECORD_SIZE);
|
||||
}
|
||||
|
||||
/* <20><>ȡ<EFBFBD><C8A1>¼<EFBFBD><C2BC><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ */
|
||||
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<34><4B><EFBFBD><EFBFBD> */
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼ */
|
||||
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;
|
||||
|
||||
/* <20><><EFBFBD>䱨<EFBFBD><E4B1A8><EFBFBD><EFBFBD>¼ */
|
||||
memset(&new_alarm, 0, sizeof(app_leakage_history_alarm_t));
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
if(region_idx < leakage.region_num)
|
||||
{
|
||||
memcpy(new_alarm.region_name, leakage.region_data[region_idx].name,
|
||||
APP_LEAKAGE_STRING_NANE_LEN);
|
||||
}
|
||||
|
||||
/* <20>豸ID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
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);
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>©Һ<C2A9><D2BA><EFBFBD><EFBFBD> */
|
||||
new_alarm.alarm_type = alarm_type;
|
||||
new_alarm.channel = channel;
|
||||
new_alarm.leak_distance = leak_distance;
|
||||
|
||||
/* <20><>ʼʱ<CABC><CAB1> */
|
||||
get_current_time(new_alarm.start_time);
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ַ */
|
||||
write_addr = history_calc_record_addr(leakage.history_metadata.write_index);
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
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);
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD> */
|
||||
if(current_sector != prev_sector)
|
||||
{
|
||||
w25q32_sector_erase(current_sector);
|
||||
}
|
||||
|
||||
/* д<><D0B4><EFBFBD><EFBFBD>¼ */
|
||||
w25q32.write(write_addr, (uint8_t*)&new_alarm, HISTORY_ALARM_RECORD_SIZE);
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD> */
|
||||
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++;
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD> */
|
||||
history_save_metadata();
|
||||
}
|
||||
|
||||
/* <20><>ȡ<EFBFBD><C8A1>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼ */
|
||||
static u8 history_read_record(u32 record_index, app_leakage_history_alarm_t *record)
|
||||
{
|
||||
if(record_index >= leakage.history_metadata.total_records)
|
||||
{
|
||||
return 0; /* <20><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч */
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>ʵ<EFBFBD>ʴ洢<CAB4><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD> */
|
||||
uint32_t actual_index;
|
||||
if(leakage.history_metadata.total_records == leakage.history_metadata.max_records)
|
||||
{
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
actual_index = (leakage.history_metadata.write_index + record_index) %
|
||||
leakage.history_metadata.max_records;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>ֱ<EFBFBD>Ӷ<EFBFBD>ȡ */
|
||||
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;
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼ */
|
||||
static void history_clear_all(void)
|
||||
{
|
||||
/* <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD> */
|
||||
memset(&leakage.history_metadata, 0, sizeof(app_leakage_history_metadata_t));
|
||||
leakage.history_metadata.max_records = MAX_HISTORY_ALARM_RECORDS;
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD> */
|
||||
history_save_metadata();
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1> */
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3> */
|
||||
static void history_init(void)
|
||||
{
|
||||
/* <20><>ȡԪ<C8A1><D4AA><EFBFBD><EFBFBD> */
|
||||
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);
|
||||
|
||||
|
||||
/*<2A><><EFBFBD>豸<EFBFBD>洢<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>*/
|
||||
typedef struct
|
||||
{
|
||||
@@ -33,6 +38,8 @@ typedef struct
|
||||
u16 state; /*״̬*/
|
||||
u16 distance; /*©Һ<C2A9><D2BA><EFBFBD><EFBFBD>*/
|
||||
}ch_data[APP_LEAKAGE_SUB_DEVICE_CH_NUM]; /*ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
u8 heartbeat; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0-59ѭ<39><D1AD>*/
|
||||
u8 test_mode; /*<2A><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>0=<3D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1-4=<3D><><EFBFBD>Զ<EFBFBD>Ӧͨ<D3A6><CDA8>*/
|
||||
}app_leakage_sub_device_class_t;
|
||||
|
||||
|
||||
@@ -47,6 +54,27 @@ typedef struct
|
||||
u8 sub_device_index[APP_LEAKAGE_SUB_DEVICE_NUM]; /*<2A>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
}app_leakage_region_data_class_t;
|
||||
|
||||
/* <20><>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>ṹ */
|
||||
typedef struct
|
||||
{
|
||||
u8 region_name[APP_LEAKAGE_STRING_NANE_LEN]; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
u8 device_id; /* <20>豸ID */
|
||||
u8 device_name[APP_LEAKAGE_STRING_NANE_LEN]; /* <20>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD> */
|
||||
u16 alarm_type; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
u8 start_time[6]; /* <20><>ʼʱ<CABC><CAB1>: <20><>(2<>ֽ<EFBFBD>)<29><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
|
||||
u16 leak_distance; /* ©Һ<C2A9><D2BA><EFBFBD><EFBFBD> (0<><30>ʾ<EFBFBD><CABE>©Һ<C2A9><D2BA><EFBFBD><EFBFBD>) */
|
||||
u8 channel; /* ͨ<><CDA8><EFBFBD><EFBFBD> (0-3) */
|
||||
} app_leakage_history_alarm_t;
|
||||
|
||||
/* <20><>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ */
|
||||
typedef struct
|
||||
{
|
||||
u32 total_records; /* <20>ܼ<EFBFBD>¼<EFBFBD><C2BC> */
|
||||
u32 write_index; /* дָ<D0B4><D6B8> */
|
||||
u32 read_index; /* <20><>ָ<EFBFBD><D6B8> */
|
||||
u32 max_records; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC> */
|
||||
} 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); /*<2A><>ʼ<EFBFBD><CABC>*/
|
||||
void (*task)(void); /*ִ<><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
}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},/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
.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},
|
||||
|
||||
@@ -205,14 +205,14 @@
|
||||
#define S_TX_SIZE 2048 /*<2A><><EFBFBD><EFBFBD>Socket<65><74><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD>Ը<EFBFBD><D4B8><EFBFBD>W5500_TMSR<53><52><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
|
||||
/***************----- W5500 GPIO<49><4F><EFBFBD><EFBFBD> -----***************/
|
||||
#define W5500_SCS GPIO_PIN_0 // <20><><EFBFBD><EFBFBD>W5500<30><30>CS<43><53><EFBFBD><EFBFBD>
|
||||
#define W5500_SCS_PORT GPIOB
|
||||
#define W5500_SCS W5500_SPI1_CS_Pin // <20><><EFBFBD><EFBFBD>W5500<30><30>CS<43><53><EFBFBD><EFBFBD>
|
||||
#define W5500_SCS_PORT W5500_SPI1_CS_GPIO_Port
|
||||
|
||||
#define W5500_RST GPIO_PIN_4 // <20><><EFBFBD><EFBFBD>W5500<30><30>RST<53><54><EFBFBD><EFBFBD>
|
||||
#define W5500_RST_PORT GPIOA
|
||||
#define W5500_RST W5500_RST_Pin // <20><><EFBFBD><EFBFBD>W5500<30><30>RST<53><54><EFBFBD><EFBFBD>
|
||||
#define W5500_RST_PORT W5500_RST_GPIO_Port
|
||||
|
||||
#define W5500_INT GPIO_PIN_1 // <20><><EFBFBD><EFBFBD>W5500<30><30>INT<4E><54><EFBFBD><EFBFBD>
|
||||
#define W5500_INT_PORT GPIOA
|
||||
#define W5500_INT W5500_INT_Pin // <20><><EFBFBD><EFBFBD>W5500<30><30>INT<4E><54><EFBFBD><EFBFBD>
|
||||
#define W5500_INT_PORT W5500_INT_GPIO_Port
|
||||
|
||||
///***************----- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> -----***************/
|
||||
//extern u8 Gateway_IP[4]; // <20><><EFBFBD><EFBFBD>IP<49><50>ַ
|
||||
|
||||
@@ -2,8 +2,14 @@
|
||||
#include "string.h"
|
||||
|
||||
/* RS485<38><35><EFBFBD>ƺ궨<C6BA><EAB6A8> */
|
||||
#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)
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD>շ<EFBFBD><D5B7><EFBFBD><EFBFBD><EFBFBD>С */
|
||||
#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;
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵ij<CDB5><C4B3>ȴ<EFBFBD><C8B4>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD><C8A3><EFBFBD><EFBFBD>ض<EFBFBD> */
|
||||
@@ -221,7 +235,12 @@ static void bsp_uart_send(bsp_uart_t *p_uart, u8 *p_data, u16 len)
|
||||
|
||||
/* RS485<38>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ */
|
||||
if(p_uart == &com_uart4)
|
||||
RS485_TX;
|
||||
{
|
||||
RS485_1_TX;
|
||||
}else if(p_uart == &com_uart2)
|
||||
{
|
||||
RS485_2_TX;
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>͵Ĵ<CDB5><C4B4><EFBFBD> */
|
||||
send_num = len / p_uart->tx_dma_len;
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include "main.h"
|
||||
|
||||
/* spi flash Ƭѡ<C6AC><D1A1><EFBFBD><EFBFBD> - 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 <20><><EFBFBD>亯<EFBFBD><E4BAAF> */
|
||||
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) {
|
||||
}
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (4kb) */
|
||||
static void w25q32_sector_erase(uint32_t sector_addr) {
|
||||
void w25q32_sector_erase(uint32_t sector_addr)
|
||||
{
|
||||
uint8_t cmd[4];
|
||||
|
||||
/* ȷ<><C8B7><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>4k<34><6B><EFBFBD><EFBFBD> */
|
||||
|
||||
@@ -31,6 +31,8 @@ extern "C" {
|
||||
#define W25Q32_MANUFACTURER_ID 0x90
|
||||
#define W25Q32_JEDEC_ID 0x9F
|
||||
|
||||
void w25q32_sector_erase(uint32_t sector_addr);
|
||||
|
||||
/* ״̬<D7B4>Ĵ<EFBFBD><C4B4><EFBFBD>λ */
|
||||
#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 /* <20>û<EFBFBD><C3BB><EFBFBD><EFBFBD>ݴ洢<DDB4><E6B4A2>ʼ<EFBFBD><CABC>ַ */
|
||||
#define W25Q32_USER_DATA_SIZE 0x100000 /* <20><>Լ1mb<6D>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD> */
|
||||
|
||||
#define W25Q32_DEVICE_INFO_ADDR (0x001000) /* <20>豸<EFBFBD><E8B1B8>Ϣ<EFBFBD>洢<EFBFBD><E6B4A2>ַ - <20><><EFBFBD><EFBFBD>1<EFBFBD><31>4K<34><4B><EFBFBD><EFBFBD> */
|
||||
#define DEVICE_INFO_STORAGE_SIZE (APP_LEAKAGE_SUB_DEVICE_NUM * sizeof(app_leakage_sub_device_flash_data_t)) /*<2A>豸<EFBFBD><E8B1B8>Ϣ<EFBFBD>洢<EFBFBD><E6B4A2>С*/
|
||||
|
||||
/* <20><>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD>洢<EFBFBD><E6B4A2>ַ<EFBFBD>ʹ<EFBFBD>С */
|
||||
#define W25Q32_HISTORY_ALARM_METADATA_ADDR 0x002000 /* <20><>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD>ݴ洢<DDB4><E6B4A2>ַ - <20><><EFBFBD><EFBFBD>2 */
|
||||
#define W25Q32_HISTORY_ALARM_DATA_ADDR 0x003000 /* <20><>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ洢<DDB4><E6B4A2>ַ - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33>ʼ */
|
||||
|
||||
#define HISTORY_ALARM_RECORD_SIZE (sizeof(app_leakage_history_alarm_t)) /* ÿ<><C3BF><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>С */
|
||||
#define HISTORY_ALARM_RECORDS_PER_SECTOR (W25Q32_SECTOR_SIZE / HISTORY_ALARM_RECORD_SIZE) /* ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC> */
|
||||
#define MAX_HISTORY_ALARM_RECORDS (1000) /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC> */
|
||||
#define HISTORY_ALARM_SECTORS_NEEDED ((MAX_HISTORY_ALARM_RECORDS * HISTORY_ALARM_RECORD_SIZE + W25Q32_SECTOR_SIZE - 1) / W25Q32_SECTOR_SIZE)
|
||||
|
||||
/* w25q32 <20><><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD><E1B9B9> */
|
||||
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;
|
||||
|
||||
/* ȫ<>ֶ<EFBFBD><D6B6><EFBFBD> */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -10,11 +10,14 @@ typedef struct
|
||||
u8 deliniter_main_index;/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
u8 real_alarm_index;/*ʵʱ<CAB5><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>*/
|
||||
u8 detail_main_index;/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>*/
|
||||
u8 device_config_index;/*<2A>豸<EFBFBD><E8B1B8><EFBFBD>ý<EFBFBD><C3BD><EFBFBD>ҳ<EFBFBD><D2B3>*/
|
||||
u8 history_alarm_index;/*<2A><>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>*/
|
||||
}gui_tjc_hmi_page_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gui_tjc_hmi_page_t page;
|
||||
u8 password[4];
|
||||
void (*init)(void);
|
||||
}gui_tjc_hmi_t;
|
||||
|
||||
|
||||
@@ -12,19 +12,15 @@
|
||||
**************************************************/
|
||||
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
|
||||
{
|
||||
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) /*<2A><><EFBFBD>ô<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>*/
|
||||
|
||||
#define PROTO_TDLAS_GET_CURR_DATA_START_ADDR (20000)
|
||||
#define PROTO_LEAKAGE_READ_DATA_NUM (14) /*<2A><>ȡһ<C8A1><D2BB><EFBFBD>豸<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
#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++)
|
||||
/*<2A><><EFBFBD>㵱ǰ<E3B5B1>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>*/
|
||||
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;
|
||||
}
|
||||
|
||||
/*ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
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;
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0x0003*/
|
||||
temp_value = (p_rx_valid[6] << 8) | p_rx_valid[7];
|
||||
p_leakage->sub_device_data[device_global_idx].heartbeat = temp_value & 0xFF;
|
||||
|
||||
/*ͨ<><CDA8>2<EFBFBD><32>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;
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>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;
|
||||
|
||||
/*ͨ<><CDA8>3<EFBFBD><33>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;
|
||||
|
||||
/* ͨ<><CDA8>4<EFBFBD><34>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