From b660ffcc47c00bdf00a40a2c8b7fcb60e6fc794e Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期日, 19 九月 2021 18:05:08 +0800
Subject: [PATCH] V1.66 修改继电器触发延迟BUG

---
 源码/核心板/Src/main.c |   67 +++++++++++++++++----------------
 1 files changed, 35 insertions(+), 32 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..2be0a88 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 超时溢出 
@@ -89,11 +73,34 @@
 	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;
+u16 g_commap_antdelay;
 void Program_Init(void)
 {	float temp;
 	u16 temp2;
@@ -113,19 +120,15 @@
 		save_com_map_to_flash();
 #endif
 	OUT485_ENABLE;
-	if(g_com_map[COM_INTERVAL]==0)
-	{
-	  g_com_map[COM_INTERVAL]=100;
-	}
-
-	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;}
+	ComMapCheck();	
+	g_com_map[VERSION] = 0x0138;
+    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 = (float)g_com_map[ANT_LENGTH]*5.8;
+    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;	
@@ -202,7 +205,7 @@
 	if(heartbeat_timer>1000)
 	{
 		heartbeat_timer=0;
-		if(g_com_map[HEARTBEAT]&&g_com_map[DEV_ROLE]==0)
+		if(g_com_map[HEARTBEAT])
 		HeatBeat();
 	}
 	if(flag_newsecond)
@@ -262,7 +265,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 +285,7 @@
 int main(void)
 {
  
-	Device_Init();
+ 	Device_Init();
 	//StartUpTest();
 	Program_Init();
 	Dw1000_Init();

--
Gitblit v1.9.3