From 3836c31d5f4c9908f7b288f20742dfc87e858e2f Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期五, 29 四月 2022 19:42:08 +0800
Subject: [PATCH] 1

---
 Src/main.c |   58 +++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index e9843db..f0b9ad5 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -92,7 +92,7 @@
 uint16_t tyncpoll_time,lpsettime;
 uint16_t slottime,max_slotpos;
 uint16_t lastpoll_count,interval_count,slot_startcount,tag_frequency,lastpoll_time,current_time;
-extern uint8_t module_power;
+uint8_t module_power;
 extern float nomove_count;
 uint8_t imu_enable,motor_enable;	
 u16 GetLPTime(void)
@@ -295,6 +295,7 @@
 			break;
 		}
 }
+u8 active_flag,nomovesleeptime;
 void Program_Init(void)
 {	float temp;
 	uint16_t temp2;
@@ -305,7 +306,27 @@
 	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;
+	g_com_map[VERSION] = 0x011a;
+    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];
+	
+	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;
+	max_slotpos=g_com_map[COM_INTERVAL]/slottime;
+	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];
+	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;
@@ -321,19 +342,7 @@
 		{module_power=67;}
 		if(module_power<0)
 		{module_power=0;}
-	module_power = g_com_map[POWER];
-	imu_enable=g_com_map[IMU_ENABLE];
-	motor_enable=g_com_map[MOTOR_ENABLE];
-	
-	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;
-	max_slotpos=g_com_map[COM_INTERVAL]/slottime;
-	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];
-	total_slotnum = 1000/g_com_map[COM_INTERVAL];
+
 	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
@@ -404,7 +413,7 @@
 
   /* Initialize all configured peripherals */
   MX_GPIO_Init();
-  MX_LPTIM1_Init();
+  //MX_LPTIM1_Init();
    MX_DMA_Init();
   MX_USART1_UART_Init();
   MX_SPI1_Init();
@@ -417,15 +426,18 @@
 	LIS3DH_Data_Init();	
 	Dw1000_Init();
 	Dw1000_App_Init();
+    dwt_setrxtimeout(0);//设定接收超时时间,0位没有超时时间
+	dwt_rxenable(0);//打开接收
+    while(1);
+   //   NearPoll();
 	HardWareTypeDiffConfig();
-	dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_CS | DWT_WAKE_WK| DWT_SLP_EN);
-	dwt_entersleep();
 	waitusart_timer=tag_frequency*USART_KEEPWAKE_TIME;;
 	DW_DISABLE;
 	 if(HAL_UART_Receive_DMA(&huart1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE))
 	{
 	 Error_Handler();
 	}
+  
 //	HAL_Delay(2000);
 //	mcu_sleep();
 	//LED0_BLINK;		
@@ -440,7 +452,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;	
@@ -933,6 +945,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,11 +960,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