From 7d3477c256ef93ce3190c1d7740c90ee941311cd Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期四, 07 四月 2022 21:00:49 +0800
Subject: [PATCH] V1.70

---
 源码/核心板/Src/main.c |  168 +++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 113 insertions(+), 55 deletions(-)

diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c"
index f1c5bcf..eb5bba2 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c"
@@ -2,6 +2,7 @@
 #include "Rcc_Nvic_Systick.h"
 #include "Usart.h"
 #include "Spi.h"
+#include "Flash.h"
 #include "led.h"
 #include "beep.h"
 #include "dw_driver.h"
@@ -13,23 +14,6 @@
 
 //#define DEBUG_MODE
 /*
- * 设置 IWDG 的超时时间
- * Tout = prv/40 * rlv (s)
- *      prv可以是[4,8,16,32,64,128,256]
- * prv:预分频器值,取值如下:
- *     @arg IWDG_Prescaler_4: IWDG prescaler set to 4
- *     @arg IWDG_Prescaler_8: IWDG prescaler set to 8
- *     @arg IWDG_Prescaler_16: IWDG prescaler set to 16
- *     @arg IWDG_Prescaler_32: IWDG prescaler set to 32
- *     @arg IWDG_Prescaler_64: IWDG prescaler set to 64
- *     @arg IWDG_Prescaler_128: IWDG prescaler set to 128
- *     @arg IWDG_Prescaler_256: IWDG prescaler set to 256
- *
- *        独立看门狗使用LSI作为时钟。
- *        LSI 的频率一般在 30~60KHZ 之间,根据温度和工作场合会有一定的漂移,我
- *        们一般取 40KHZ,所以独立看门狗的定时时间并一定非常精确,只适用于对时间精度
- *        要求比较低的场合。
- *
  * rlv:重装载寄存器的值,取值范围为:0-0XFFF
  * 函数调用举例:
  * IWDG_Config(IWDG_Prescaler_64 ,625);  // IWDG 1s 超时溢出 
@@ -71,29 +55,50 @@
 	Uart1_Init();
 	Spi_Init();
 	ADC_Configuration();
-	IWDG_Config(IWDG_Prescaler_128 ,4095);   //10s
-    IWDG_Feed();
+//	IWDG_Config(IWDG_Prescaler_128 ,4095);   //10s
+//    IWDG_Feed();
 	GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
 }
 u8 anchor_type;
 u32 dev_id;
-u8 hbsend[16];
+u8 hbsend[26];
 void HeartBeatInit(void)
 {
 	u16 checksum;
 	hbsend[0]=0x55;
 	hbsend[1]=0xAA;
 	hbsend[2]=0x2;
-	hbsend[3]=0xc;
+	hbsend[3]=0x16;
 	memcpy(&hbsend[4],&g_com_map[DEV_ID],2);
-	checksum = Checksum_u16(&hbsend[2],12);
-	memcpy(&hbsend[14],&checksum,2);
 }
+
 uint16_t vel_factor,pos_factor;
-u16 tyncpoll_time,dist_threshold;
+u16 tyncpoll_time,dist_threshold,group_id;
 u16 slottime,max_slotpos;
 extern u8 module_power;
 extern u16 total_slotnum;
+void ComMapCheck(void)
+{
+
+    if(g_com_map[ANT_LENGTH]>10000)
+    {
+        g_com_map[ANT_LENGTH] = 0;
+    }
+    if(g_com_map[WAR_JDQ_TIME]>1000||g_com_map[WAR_JDQ_TIME]<0)
+    {
+        g_com_map[WAR_JDQ_TIME] = 1;
+    }
+    	if(g_com_map[COM_INTERVAL]==0)
+	{
+	  g_com_map[COM_INTERVAL]=100;
+	}
+    if(dist_threshold<300)
+		{dist_threshold = 300;}
+		if(dist_threshold>15000)
+		{dist_threshold = 15000;}
+}
+u16 JDQ_time;
+int16_t g_commap_antdelay;
 void Program_Init(void)
 {	float temp;
 	u16 temp2;
@@ -112,20 +117,40 @@
 	g_com_map[ANC_FLAG]=1;
 		save_com_map_to_flash();
 #endif
-	OUT485_ENABLE;
-	if(g_com_map[COM_INTERVAL]==0)
-	{
-	  g_com_map[COM_INTERVAL]=100;
-	}
+//    
+//    g_com_map[COM_INTERVAL]=100;
+//		g_com_map[MAX_REPORT_ANC_NUM]=10;
+//		g_com_map[GROUP_ID]=0;
+//		g_com_map[DIST_OFFSET]=-116;
 
-	g_com_map[VERSION] = 0x012b;
-dist_threshold = (g_com_map[SPEEDFILTER_THRES]*10)/(1000/g_com_map[COM_INTERVAL]);
-		if(dist_threshold<300)
-		{dist_threshold = 300;}
-		if(dist_threshold>15000)
-		{dist_threshold = 15000;}
+//			g_com_map[DEV_ROLE] =0x0;  //基站
+//	
+//		g_com_map[ANC_POLL]=1;
+//		g_com_map[ALARM_DEV] = 0;
+//		g_com_map[ALARM_DISTANCE1] = 0;	//默认报警距离50cm
+//		g_com_map[ALARM_DISTANCE2] = 900;	//默认报警距离50cm
+//		g_com_map[ALARM_DISTANCE3] = 1400;	//默认报警距离50cm
+//         g_com_map[RELAY2_DISTANCE1] = 0;	//默认报警距离50cm
+//		g_com_map[RELAY2_DISTANCE2] = 900;	//默认报警距离50cm
+//		g_com_map[RELAY2_DISTANCE3] = 1400;	//默认报警距离50cm
+//        g_com_map[WAR_JDQ_TIME] = 1; //1秒
+//		g_com_map[POWER]=30;
+//        g_com_map[SPEEDFILTER_THRES]=10000;
+//		g_com_map[FILTER_COEFFICIENT]=40;
+//        g_com_map[ANT_LENGTH]=0;
+//        g_com_map[NOMOVESLEEP_TIME]=728;
+      
+        
+	OUT485_ENABLE;
+		
+	g_com_map[VERSION] = (1<<8)|(70);
+	FLASH_Read(FLASH_HARDWARE_FLAG, (uint8_t*)&g_com_map[HARDWAREFLAG_INDEX], 16);
+	dist_threshold = (g_com_map[SPEEDFILTER_THRES]*10)/(1000/g_com_map[COM_INTERVAL]);
+	g_commap_antdelay = g_com_map[ANT_LENGTH];
+	JDQ_time = g_com_map[WAR_JDQ_TIME]*10;
 	g_com_map[SW_TYPE] = 	SW_FANGZHUANG;
 	dev_id = g_com_map[DEV_ID];
+	group_id=g_com_map[GROUP_ID];
 	slottime=ceil((double)g_com_map[MAX_REPORT_ANC_NUM]*SLOT_SCALE)+3;
 	max_slotpos=g_com_map[COM_INTERVAL]/slottime;
 	tyncpoll_time=(g_com_map[DEV_ID]%max_slotpos)*slottime;	
@@ -133,7 +158,7 @@
 	total_slotnum = 1000/g_com_map[COM_INTERVAL];
 			vel_factor=g_com_map[FILTER_COEFFICIENT];
 		pos_factor=g_com_map[FILTER_COEFFICIENT];
-
+ComMapCheck();
 		if(module_power>67)
 		{
 			module_power=67;
@@ -145,8 +170,7 @@
 //	printf("通讯间隔: %d ms.\r\n",g_com_map[COM_INTERVAL]);
 //	printf("单次通讯基站数量: %d个.\r\n",g_com_map[MAX_REPORT_ANC_NUM]);
 //	}else{
-//	
-//	anchor_type = dev_id%g_com_map[MAX_REPORT_ANC_NUM];
+//    anchor_type = dev_id%g_com_map[MAX_REPORT_ANC_NUM];
 //	printf("基站ID: %x .\r\n",dev_id);
 //	printf("基站类型: %c .\r\n",anchor_type+0x41);
 //	printf("单次通讯基站数量: %d个.\r\n",g_com_map[MAX_REPORT_ANC_NUM]);
@@ -158,7 +182,7 @@
 	
 	for(i=0;i<255;i++)
 	{
-		g_Tagdist[i]=0xffff;
+		g_Tagdist[i]=0x1ffff;
 	}
 }
 
@@ -171,9 +195,35 @@
  *
  * @return none
  */
+u8 selftest[2];
 void HeatBeat(void)
 { 
-UART_PushFrame(hbsend,16);
+    u16 checksum;
+    selftest[0]=1;
+    selftest[1]=0;
+    memcpy(&hbsend[6],selftest,2);
+	memcpy(&hbsend[14],uartrec_userdata,10);
+	checksum = Checksum_u16(&hbsend[2],22);
+	memcpy(&hbsend[24],&checksum,2);
+    UART_PushFrame(hbsend,26);
+}
+void ClearUartUserData(void)
+{
+    u8 i;
+    for(i=0;i<USERDATA_MAXLEN;i++)
+    {
+      uartrec_userdata[i] = 0;  
+    }
+    usartrec_userdatalen = 0;
+}
+void ClearUWBUserData(void)
+{
+    u8 i;
+    for(i=0;i<USERDATA_MAXLEN;i++)
+    {
+      uwbrec_userdata[i] = 0;  
+    }
+    uwbrec_userdatalen = 0;
 }
 uint16_t temp;
 float dw_vbat;
@@ -198,13 +248,19 @@
 		
 			UART_CheckReceive();
 		UART_CheckSend();
-	
-	if(heartbeat_timer>1000)
-	{
-		heartbeat_timer=0;
-		if(g_com_map[HEARTBEAT]&&g_com_map[DEV_ROLE]==0)
-		HeatBeat();
-	}
+//	if(g_com_map[HEARTBEAT])
+//    {
+        if(heartbeat_timer>=200)
+        {
+            heartbeat_timer=0;
+            HeatBeat();
+        }
+        if(userdata_timer>=200)
+        {
+            userdata_timer = 0;
+            ClearUartUserData();
+        }
+//    }
 	if(flag_newsecond)
 	{
 		uint32_t temp23;
@@ -262,7 +318,7 @@
 		if(g_com_map[CNT_REBOOT]==1)
 		{
 			FactorySettings();
-			delay_ms(100);
+			
 			SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
 		}
 		if(g_com_map[CNT_RESTART]==1)
@@ -282,7 +338,7 @@
 int main(void)
 {
  
-	Device_Init();
+ 	Device_Init();
 	//StartUpTest();
 	Program_Init();
 	Dw1000_Init();
@@ -298,13 +354,15 @@
 	while(1)
 	{
 	g_start_sync_flag=0;
-	if(g_start_send_flag)
-	{
-		g_start_send_flag = 0;		
-		Tag_App();
-	}
+ 
+      if(g_start_send_flag)
+    {
+        g_start_send_flag = 0;		
+        Tag_App();
+    }
+  
 		IdleTask();		
-if(g_com_map[DEV_ROLE]==0)
+    if(g_com_map[DEV_ROLE]==0)
 		Anchor_App();
 
 	}

--
Gitblit v1.9.3