From 5f1696dcd80b5838eea5cf2a425d537fdfdd4b0f Mon Sep 17 00:00:00 2001
From: WXK <287788329@qq.com>
Date: 星期一, 20 三月 2023 10:44:37 +0800
Subject: [PATCH] 免布线基站v1.52-6.5g。

---
 Src/main.c |   86 ++++++++++++++++--------------------------
 1 files changed, 33 insertions(+), 53 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index 50d3684..b151144 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -115,10 +115,10 @@
 float motor_keeptime;
 void IdleTask(void)
 {u16 current_time;
-if(huart1.Instance->ISR&USART_ISR_FE)
-	{
-	SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
-	}	
+//if(huart1.Instance->ISR&USART_ISR_FE)
+//	{
+//	SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
+//	}	
 	if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
 	{
         	
@@ -145,38 +145,6 @@
 		LED_LG_OFF;
 //	}
 }
-	if(g_com_map[CNT_UPDATE]==1)
-	{
-	uint32_t result = 0;
-		uint16_t tmp = 0xAAAA;
-	__disable_irq();
-	result = FLASH_Prepare(0x8004A38, 128);
-	if(result)
-		result = FLASH_Write(0x8004A38, (const uint8_t*)&tmp, 2); 
-	__enable_irq();
-		printf("进入升级模式\r\n");
-	g_com_map[CNT_UPDATE]=0;
-	save_com_map_to_flash();
-	delay_ms(100);
-		//	STMFLASH_Write_NoCheck(0x8004A38,0xAAAA);
-		//	Delay_ms(100);
-			SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
-	}
-			if(g_com_map[CNT_REBOOT]==1)
-		{
-			g_com_map[CNT_REBOOT]=0;
-			g_com_map[MAP_SIGN_INDEX]=0;
-			save_com_map_to_flash();
-			delay_ms(100);
-			SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
-		}
-		if(g_com_map[CNT_RESTART]==1)
-		{
-			g_com_map[CNT_RESTART]=0;
-			save_com_map_to_flash();
-			delay_ms(100);
-				SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
-		}
 			if(g_com_map[MAP_SIGN_INDEX]!=0x55AA||g_com_map[COM_INTERVAL]==0)
 		{
 				SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
@@ -206,7 +174,7 @@
 //	{
 //	lpcount+=LPTIMER_1S_COUNT;
 //	}
-    lpcount = last_lpcount+g_com_map[COM_INTERVAL]*32.768;
+    lpcount = last_lpcount+32768/tag_frequency;
     while(lpcount>LPTIMER_1S_COUNT)
     {
         lpcount-=LPTIMER_1S_COUNT;
@@ -250,9 +218,18 @@
 	hardware_pici = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+2);
 	hardware_type = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+4);
 	//deca_sleep(1000);
-	g_com_map[VERSION] = (1<<8)|38;
+	g_com_map[VERSION] = (1<<8)|52;
+    
+    #ifdef DEBUG_MODE
+//    g_com_map[GROUP_ID]=21;
+//    		g_com_map[DEV_ID]=4;
+    //	g_com_map[COM_INTERVAL]=100;
+    //	g_com_map[MAX_REPORT_ANC_NUM]=1;
+    //	g_com_map[NOMOVESLEEP_TIME]=10;
+    #endif
+    
     active_flag = g_com_map[ACTIVE_INDEX];
-    	module_power = g_com_map[POWER];
+    module_power = g_com_map[POWER];
 	imu_enable=g_com_map[IMU_ENABLE];
 	motor_enable=g_com_map[MOTOR_ENABLE];
 	
@@ -271,13 +248,7 @@
 		imu_enable=1;
 		nomovesleeptime =10;		
 	}
-#ifdef DEBUG_MODE
-//	g_com_map[DEV_ROLE]=1;
-//		g_com_map[DEV_ID]=1;
-//	g_com_map[COM_INTERVAL]=100;
-//	g_com_map[MAX_REPORT_ANC_NUM]=1;
-//	g_com_map[NOMOVESLEEP_TIME]=10;
-#endif
+
  //   g_com_map[COM_INTERVAL]=100;
 		if(g_com_map[COM_INTERVAL]==0)
 	{
@@ -298,8 +269,7 @@
 	printf("标签ID: %d .\r\n",dev_id);
 	printf("通讯间隔: %d ms.\r\n",g_com_map[COM_INTERVAL]);
 	printf("单次通讯基站数量: %d个.\r\n",g_com_map[MAX_REPORT_ANC_NUM]);
-	
-
+	memcpy(g_com_map2,g_com_map,COM_MAP_SIZE);
 //	printf("DEVICE PAIRID: %d .\r\n",g_com_map[PAIR_ID]);
 //	printf("DEVICE ALARM DISTANCE: 1.%d 2.%d 3.%d .\r\n",g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],g_com_map[ALARM_DISTANCE3]);
 
@@ -426,7 +396,7 @@
     /* USER CODE END WHILE */
 
     /* USER CODE BEGIN 3 */
-		if(g_start_send_flag&&active_flag)
+		if(g_start_send_flag)
 	{ static uint16_t blink_count=0;
 		SystemClock_Config();
 		g_start_send_flag = 0;	
@@ -456,7 +426,11 @@
 			waitusart_timer--;
 		}
 			if(m_bEUARTTxEn==0&&waitusart_timer==0)
-			{	
+			{
+             if(memcmp(g_com_map2,g_com_map,200)!=0)
+             {
+                SCB->AIRCR = 0X05FA0000|(unsigned int)0x04;
+             }
 #ifndef DEBUG_MODE	
 if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))				
 				HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);  
@@ -908,21 +882,27 @@
 }
 extern uint8_t tx_near_msg[80],stationary_flag;
 float key_keeptime;
+extern float freqlost_count;
 void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
 {
 	static uint8_t i=0;
 	i++;
 	g_start_send_flag=1;
 	current_slotnum++;
+    freqlost_count+=1/(float)tag_frequency;
+    if(freqlost_count>FREQ_LOST_TIME)
+    {
+        tag_frequency = NOTAG_FREQ;
+    }
 	SetNextPollTime(tyncpoll_time);
-	nomove_count+=(float)g_com_map[COM_INTERVAL]/1000;
+	nomove_count+=1/(float)tag_frequency;
     if(motor_keeptime>0)
 	{	
-	motor_keeptime-=(float)g_com_map[COM_INTERVAL]/1000;
+        nomove_count+=1/(float)tag_frequency;
 	}
 	if(!GET_USERKEY)
 	{
-		key_keeptime+=(float)g_com_map[COM_INTERVAL]/1000;
+		key_keeptime+=1/(float)tag_frequency;
 		if(key_keeptime>=KEY_KEEPRESET_TIME)
 		{
             g_com_map[ACTIVE_INDEX]=!active_flag;

--
Gitblit v1.9.3