From 8961dfd8d31587ce62667e4f1941d92c5c685ef5 Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期一, 01 八月 2022 11:00:26 +0800
Subject: [PATCH] V1.33 修改基站功耗大BUG

---
 Src/main.c |   65 ++++++++++++++++++++------------
 1 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index ac12441..b53adef 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -136,7 +136,7 @@
 //		g_com_map[MOTOR_ONTIME]--;
 //		motor_state = 1;
 //	}
-if(g_com_map[MOTOR_ENABLE])
+if(0)//g_com_map[MOTOR_ENABLE])
 {
     
 
@@ -188,6 +188,7 @@
 	if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
 	{
 		nomove_count = 0;
+        bat_percent=Get_Battary();
 		if(state5v==0)
 		{
 			state5v=1;
@@ -295,6 +296,7 @@
 			break;
 		}
 }
+u8 active_flag,nomovesleeptime;
 void Program_Init(void)
 {	float temp;
 	uint16_t temp2;
@@ -305,23 +307,9 @@
 	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] = 0x0116;
-#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
-		if(g_com_map[COM_INTERVAL]==0)
-	{
-	  g_com_map[COM_INTERVAL]=100;
-	}
-	 if(module_power>67)
-		{module_power=67;}
-		if(module_power<0)
-		{module_power=0;}
-	module_power = g_com_map[POWER];
+	g_com_map[VERSION] = (1<<8)|33;
+    active_flag = g_com_map[ACTIVE_INDEX];
+    	module_power = g_com_map[POWER];
 	imu_enable=g_com_map[IMU_ENABLE];
 	motor_enable=g_com_map[MOTOR_ENABLE];
 	
@@ -332,8 +320,30 @@
 	tyncpoll_time=(g_com_map[DEV_ID]%max_slotpos)*slottime;	
 	slot_startcount=tyncpoll_time*1000/LPTIMER_LSB;
 	lastpoll_time=tyncpoll_time;
-  tag_frequency = 1000/g_com_map[COM_INTERVAL];
+    tag_frequency = 1000/g_com_map[COM_INTERVAL];
 	total_slotnum = 1000/g_com_map[COM_INTERVAL];
+    nomovesleeptime = g_com_map[NOMOVESLEEP_TIME];
+	if(active_flag==0)
+	{   
+		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
+		if(g_com_map[COM_INTERVAL]==0)
+	{
+	  g_com_map[COM_INTERVAL]=100;
+	}
+	 if(module_power>67)
+		{module_power=67;}
+		if(module_power<0)
+		{module_power=0;}
+
 	current_slotnum=1;
 	current_time=GetLPTime();
 		if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, slot_startcount) != HAL_OK)  //system time is 1010ms   1 puls=30.518us
@@ -405,10 +415,11 @@
   /* Initialize all configured peripherals */
   MX_GPIO_Init();
   MX_LPTIM1_Init();
+   MX_DMA_Init();
   MX_USART1_UART_Init();
   MX_SPI1_Init();
   MX_ADC_Init();
-  MX_DMA_Init();
+ 
 //  MX_TIM2_Init();
   /* USER CODE BEGIN 2 */
 	LED_LG_ON;
@@ -439,7 +450,7 @@
     /* USER CODE END WHILE */
 
     /* USER CODE BEGIN 3 */
-		if(g_start_send_flag)
+		if(g_start_send_flag&&active_flag)
 	{ static uint16_t blink_count=0;
 		SystemClock_Config();
 		g_start_send_flag = 0;	
@@ -450,7 +461,7 @@
 //		}else{
 //		HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_RESET);
 //		}
-//		LED_TR_BLINK;
+//		LED_TR_BLINK;s
 		
 			bat_percent=Get_Battary();
 		if(bat_percent>15)
@@ -468,7 +479,7 @@
 		{
 			waitusart_timer--;
 		}
-			if(m_bEUARTTxEn==0&&waitusart_timer==0&&(motor_state==0||motor_state==3))
+			if(m_bEUARTTxEn==0&&waitusart_timer==0)
 			{	
 #ifndef DEBUG_MODE	
 if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))				
@@ -932,6 +943,10 @@
 		key_keeptime+=(float)g_com_map[COM_INTERVAL]/1000;
 		if(key_keeptime>=KEY_KEEPRESET_TIME)
 		{
+            g_com_map[ACTIVE_INDEX]=!active_flag;
+            save_com_map_to_flash();
+            MOTOR_ON;
+            HAL_Delay(2000);
 			SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; 
 		}
 	}else{
@@ -943,11 +958,11 @@
 	}else{
 		stationary_flag = 0;
 	}
-if(nomove_count>=g_com_map[NOMOVESLEEP_TIME]-1&&imu_enable)
+if(nomove_count>=nomovesleeptime-1&&imu_enable)
 	{
 		tx_near_msg[TAGSTATE] = tx_near_msg[TAGSTATE]|GOINGSLEEPBIT;
 	}
-	if(nomove_count>g_com_map[NOMOVESLEEP_TIME]&&imu_enable)
+	if(nomove_count>nomovesleeptime&&imu_enable)
 	{
 		mcu_sleep();
 	}

--
Gitblit v1.9.3