From 5739481744a7d26671190f6f327726e23843dd6d Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期一, 02 十一月 2020 15:34:13 +0800
Subject: [PATCH] Merge branch '定位-临近' into 定位临近_工卡

---
 Src/main.c |   80 +++++++++++++++++++++++++--------------
 1 files changed, 51 insertions(+), 29 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index 2b180a1..fde37e5 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -123,9 +123,9 @@
 //	LED_TR_OFF;
 	current_time=GetLPTime();
 	//motor_state=2;
-		if(g_com_map[MOTOR_ONTIME]>0)
+		if(g_com_map[MOTOR_ONTIME_INDEX]>0)
 	{
-		g_com_map[MOTOR_ONTIME]--;
+		g_com_map[MOTOR_ONTIME_INDEX]--;
 		motor_state = 1;
 	}
 	switch(motor_state)
@@ -210,17 +210,28 @@
 	}
 
 
-u16 total_slotnum,current_slotnum;
+u16 current_slotnum;
 extern int32_t offsettimeus;
-
-void SetNextPollTime(u16 time)
+#define FIXSLOT
+#define FIXSLOTPOS  3
+u16 slotpos_intoatl;
+uint16_t bigslot_num;
+uint8_t fix_slotpos =FIXSLOTPOS; 
+int32_t lpcount,lptime,target_time;
+void SetNextPollTime(u16 slotpos)
 {
-  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;
+#ifdef FIXSLOT
+	slotpos = fix_slotpos;
+#endif
+
+	if(current_slotnum>=tag_frequency)
+		current_slotnum-=tag_frequency;
+	slotpos_intoatl = current_slotnum*bigslot_num+slotpos;
+
+	if(current_slotnum==19)
+	{slotpos_intoatl = current_slotnum*bigslot_num+slotpos;}
+	target_time=(slotpos_intoatl*SLOTTIME_MS+100)*100;
 	//if(target_time<90000)
 	{
 		lptime=target_time-offsettimeus;
@@ -241,22 +252,24 @@
 	Usart1ParseDataCallback = UsartParseDataHandler;
 	parameter_init();
 	//deca_sleep(1000);
-	g_com_map[VERSION] = 0x0110;
+	g_com_map[VERSION] = 0x0205;
 #ifdef DEBUG_MODE
 //	g_com_map[DEV_ROLE]=1;
-//		g_com_map[DEV_ID]=1;
-	g_com_map[COM_INTERVAL]=100;
+//		g_com_map[DEV_ID]=0x123;
+//	g_com_map[COM_INTERVAL]=100;
 //	g_com_map[MAX_REPORT_ANC_NUM]=1;
-	g_com_map[NOMOVESLEEP_TIME]=10;
+//	g_com_map[NOMOVESLEEP_TIME]=10;
+			g_com_map[IMU_ENABLE]=0;
+	g_com_map[COM_INTERVAL]=100;
 #endif
-		g_com_map[IMU_ENABLE]=0;
-	 g_com_map[COM_INTERVAL]=100;
+//g_com_map[NOMOVESLEEP_TIME]=10;
+	// 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>MAX_RFPOWER)
+		{module_power=MAX_RFPOWER;}
 		if(module_power<0)
 		{module_power=0;}
 	module_power = g_com_map[POWER];
@@ -272,7 +285,7 @@
 	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];
+	bigslot_num = TOTAL_SLOTNUM/tag_frequency;
 	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
@@ -302,6 +315,7 @@
 uint32_t temp;
 extern uint8_t sleep_flag,m_bEUARTTxEn;
 uint16_t waitusart_timer;
+extern double pressure,temperature; 
 //void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
 //{
 //  /* Set transmission flag: trasfer complete*/
@@ -353,6 +367,7 @@
 	LED_LG_ON;
 	Program_Init();
 	LIS3DH_Data_Init();	
+	BarInit();
 	Dw1000_Init();
 	Dw1000_App_Init();
 	
@@ -378,11 +393,15 @@
     /* USER CODE END WHILE */
 
     /* USER CODE BEGIN 3 */
+//				while(1)
+//		{
+//		MODBUS_Poll();
+//		}
 		if(g_start_send_flag)
 	{ static uint16_t blink_count=0;
 		SystemClock_Config();
 		g_start_send_flag = 0;	
-		
+		 GetPressAndTemp();
 //		if(current_count>slot_startcount&&current_count<slot_startcount+interval_count)
 //		{
 //		HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_SET);
@@ -640,12 +659,12 @@
     Error_Handler();
   }
   /* USER CODE BEGIN USART1_Init 2 */
-	    GPIO_InitStruct.Pin = GPIO_PIN_10;
-    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-    GPIO_InitStruct.Pull = GPIO_PULLUP;
-    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
-    GPIO_InitStruct.Alternate = GPIO_AF4_USART1;
-    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+//	    GPIO_InitStruct.Pin = GPIO_PIN_9;
+//    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+//    GPIO_InitStruct.Pull = GPIO_PULLUP;
+//    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
+//    GPIO_InitStruct.Alternate = GPIO_AF4_USART1;
+//    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 //  if(HAL_UART_Receive_IT(&huart1, (uint8_t *)aRxBuffer, 1) != HAL_OK)
 //  {
 //    Error_Handler();
@@ -796,7 +815,8 @@
   /*Enter the Standby mode*/
   HAL_PWR_EnterSTANDBYMode();	
 }
-extern uint8_t tx_near_msg[80],stationary_flag;
+extern u16 tagslotpos;
+extern uint8_t tx_near_msg[80],stationary_flag,gotosleep_flag;
 float key_keeptime;
 void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
 {
@@ -804,7 +824,7 @@
 	i++;
 	g_start_send_flag=1;
 	current_slotnum++;
-	SetNextPollTime(tyncpoll_time);
+	SetNextPollTime(tagslotpos);
 	nomove_count+=(float)g_com_map[COM_INTERVAL]/1000;
 	if(!GET_USERKEY)
 	{
@@ -824,7 +844,9 @@
 	}
 if(nomove_count>=g_com_map[NOMOVESLEEP_TIME]-1&&imu_enable)
 	{
-		tx_near_msg[TAGSTATE] = tx_near_msg[TAGSTATE]|GOINGSLEEPBIT;
+		gotosleep_flag=1;
+	}else{
+		gotosleep_flag=0;
 	}
 	if(nomove_count>g_com_map[NOMOVESLEEP_TIME]&&imu_enable)
 	{

--
Gitblit v1.9.3