From 5c6608fc16627430bcdbaf4917c608e61b7db77c Mon Sep 17 00:00:00 2001
From: yincheng.zhong <634916154@qq.com>
Date: 星期一, 24 四月 2023 10:26:57 +0800
Subject: [PATCH] 初步测试完成

---
 Src/main.c |  199 ++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 155 insertions(+), 44 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index e9843db..191cbc1 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -187,7 +187,8 @@
 }
 	if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
 	{
-		nomove_count = 0;
+		//nomove_count = 0;
+        bat_percent=Get_Battary();
 		if(state5v==0)
 		{
 			state5v=1;
@@ -196,9 +197,9 @@
 		if(bat_percent>99)
 		{
 			LED_LR_OFF;
-			LED_LG_ON;
+			//LED_LG_ON;
 		}else{
-			LED_LR_ON;
+		//	LED_LR_ON;
 			LED_LG_OFF;		
 		}		
 	}else{
@@ -249,19 +250,20 @@
 
 u16 total_slotnum,current_slotnum;
 extern int32_t offsettimeus;
-
+  int32_t lpcount,lptime,target_time;
 void SetNextPollTime(u16 time)
 {
-  int32_t lpcount,lptime,target_time;
 
-	if(current_slotnum>=total_slotnum)
-		current_slotnum-=total_slotnum;
-	
-	target_time=((current_slotnum*g_com_map[COM_INTERVAL])+time)*1000;
-	//if(target_time<90000)
-	{
-		lptime=target_time-offsettimeus;
-		lpcount = lptime/LPTIMER_LSB;
+
+//	if(current_slotnum>=total_slotnum)
+//		current_slotnum-=total_slotnum;
+//	
+//	target_time=((current_slotnum*g_com_map[COM_INTERVAL])+time)*1000;
+//	//if(target_time<90000)
+//	{
+//		lptime=target_time-offsettimeus;
+//		lpcount = lptime/LPTIMER_LSB;
+    lpcount+=g_com_map[COM_INTERVAL]*LPTIMER_LSB;
 	if(lpcount>LPTIMER_1S_COUNT)
 		lpcount-=LPTIMER_1S_COUNT;
 	if(lpcount<0)
@@ -269,7 +271,6 @@
 	lpcount+=LPTIMER_1S_COUNT;
 	}
 	__HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount);
-}
 }
 
 void HardWareTypeDiffConfig(void)
@@ -282,7 +283,7 @@
 		{
         case 1:
 	  
-		 HAL_GPIO_WritePin(GPIOB, MOTOR_Pin, GPIO_PIN_SET);
+  HAL_GPIO_WritePin(GPIOB, MOTOR_Pin, GPIO_PIN_SET);
   GPIO_InitStruct.Pin = MOTOR_Pin;
   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
   GPIO_InitStruct.Pull = GPIO_NOPULL;
@@ -295,6 +296,8 @@
 			break;
 		}
 }
+int16_t g_commap_antdelay;
+u8 active_flag,nomovesleeptime;
 void Program_Init(void)
 {	float temp;
 	uint16_t temp2;
@@ -305,26 +308,13 @@
 	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] = 0x0119;
-#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];
 	
+    g_com_map[GROUP_ID] = 98;
 	group_id=g_com_map[GROUP_ID];
 	dev_id = g_com_map[DEV_ID];
 	slottime=ceil((double)g_com_map[MAX_REPORT_ANC_NUM]*SLOT_SCALE)+3;
@@ -332,8 +322,36 @@
 	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
+    
+    g_com_map[COM_INTERVAL]=100;
+    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;}
+    if(g_com_map[ANT_LENGTH]>10000)
+    {
+        g_com_map[ANT_LENGTH] = 0;
+    }
+    g_commap_antdelay = -g_com_map[DIST_OFFSET];
 	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
@@ -341,9 +359,32 @@
     Error_Handler();
   }
 //g_com_map[NOMOVESLEEP_TIME]=5;
-	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]);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t0.bco=63488");
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t0.txt=\"等待串口通讯\"");  
+
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t1.bco=63488");
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t1.txt=\"等待测距\"");        
+  
+//          USART_putc(0xff);
+//        USART_putc(0xff);
+//        USART_putc(0xff);
+//        printf("t2.bco=2024");
+//        USART_putc(0xff);
+//        USART_putc(0xff);
+//        USART_putc(0xff);
+//        printf("t2.txt=\"无测距\"");   
 	
 
 //	printf("DEVICE PAIRID: %d .\r\n",g_com_map[PAIR_ID]);
@@ -374,6 +415,7 @@
 {
 		//SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
 }
+u8 flag_entersleep1=0,flag_entersleep2=0;
 /* USER CODE END 0 */
 
 /**
@@ -414,7 +456,7 @@
   /* USER CODE BEGIN 2 */
 	LED_LG_ON;
 	Program_Init();
-	LIS3DH_Data_Init();	
+	Accelerometer_Init();	
 	Dw1000_Init();
 	Dw1000_App_Init();
 	HardWareTypeDiffConfig();
@@ -472,7 +514,7 @@
 			if(m_bEUARTTxEn==0&&waitusart_timer==0&&(motor_state==0||motor_state==3))
 			{	
 #ifndef DEBUG_MODE	
-if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))				
+if(flag_entersleep1*flag_entersleep2==1)				
 				HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);  
 #endif
 			}
@@ -914,8 +956,67 @@
   /*Enter the Standby mode*/
   HAL_PWR_EnterSTANDBYMode();	
 }
+extern u8 flag_usartrecok,flag_uwbrange_ok;
+extern int32_t uwb_dist;
+void LCDPROCESS(void)
+{
+    if(flag_usartrecok)
+    {
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t0.bco=2024");
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t0.txt=\"串口通讯成功\"");   
+        flag_entersleep1 = 1;
+
+    }else{
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t0.bco=63488");
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t0.txt=\"等待串口通讯\"");        
+    }
+    if(flag_uwbrange_ok)
+    {
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t1.bco=2024");
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t1.txt=\"测距成功\"");   
+
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t2.bco=2024");
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t2.txt=\"距离:%d\"",uwb_dist); 
+        flag_entersleep2 = 1;        
+    }else{
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t1.bco=63488");
+        USART_putc(0xff);
+        USART_putc(0xff);
+        USART_putc(0xff);
+        printf("t1.txt=\"等待测距\"");        
+    }
+
+}
+float lcd_count=0;
 extern uint8_t tx_near_msg[80],stationary_flag;
-float key_keeptime;
+float key_keeptime,lcdtimer;
 void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
 {
 	static uint8_t i=0;
@@ -924,6 +1025,12 @@
 	current_slotnum++;
 	SetNextPollTime(tyncpoll_time);
 	nomove_count+=(float)g_com_map[COM_INTERVAL]/1000;
+    lcdtimer+=(float)g_com_map[COM_INTERVAL]/1000;
+    if(lcdtimer-lcd_count>0.5)
+    {   
+        lcd_count = lcdtimer;
+        LCDPROCESS();
+    }
     if(motor_keeptime>0)
 	{	
 	motor_keeptime-=(float)g_com_map[COM_INTERVAL]/1000;
@@ -933,6 +1040,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{
@@ -944,14 +1055,14 @@
 	}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)
-	{
-		mcu_sleep();
-	}
+//	if(nomove_count>nomovesleeptime&&imu_enable)
+//	{
+//		mcu_sleep();
+//	}
 }
 /* USER CODE END 4 */
 

--
Gitblit v1.9.3