From c2802ee207528de2d06403061405f0faadffb922 Mon Sep 17 00:00:00 2001
From: WXK <287788329@qq.com>
Date: 星期二, 05 三月 2024 18:03:36 +0800
Subject: [PATCH] 初步修改完成,跟工卡相似,gps采用外包代码

---
 Src/main.c |  162 +++++++++++++++++++++++++++++++++--------------------
 1 files changed, 101 insertions(+), 61 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index 80fa0e2..d92495c 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -38,6 +38,7 @@
 #include "WS2812.h"
 #include "syn6288.h"
 #include "dw_mbx_tag.h"
+#include "GPS.h"
 #define NSH1 0x0001
 #define GP   0x0002
 #define FLASH_HARDWARE_VERSION_MAP		(uint32_t)0x08004F00    //硬件版本号和批次信息位置
@@ -220,7 +221,6 @@
 		if(bat_percent>99)
 		{
             powerled=GREEN;
-     
 		}else{
             powerled=RED;           
 		}		
@@ -230,11 +230,6 @@
             state5v=0;
             UsartDeInit();
         }
-//    powerled=LEDOFF;
-//    Set4LEDColor(powerled,loraled,gpsled,uwbled);
-//    gpsled=LEDOFF;
-//    Set4LEDColor(powerled,loraled,gpsled,uwbled);    
-//	}
 }
         if(g_com_map[MAP_SIGN_INDEX]!=0x55AA||g_com_map[COM_INTERVAL]==0)
 		{
@@ -305,13 +300,13 @@
 //    //	g_com_map[MAX_REPORT_ANC_NUM]=1;
 //    //	g_com_map[NOMOVESLEEP_TIME]=10;
 //    #endif
-    g_com_map[GROUP_ID]=5;
+    g_com_map[GROUP_ID]=1;
 //    g_com_map[COM_INTERVAL] = 1000;
     if(g_com_map[COM_INTERVAL]<1000)
     {g_com_map[COM_INTERVAL] = 1000;}
     active_flag = g_com_map[ACTIVE_INDEX];
     module_power = g_com_map[POWER];
-    g_com_map[IMU_ENABLE] = 0;
+//    g_com_map[IMU_ENABLE] = 0;
 	imu_enable=g_com_map[IMU_ENABLE];
 	motor_enable=g_com_map[MOTOR_ENABLE];
 
@@ -325,11 +320,11 @@
     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;		
-	}
+//	if(active_flag==0)
+//	{   
+//		imu_enable=1;
+//		nomovesleeptime =10;		
+//	}
 
  //   g_com_map[COM_INTERVAL]=100;
 		if(g_com_map[COM_INTERVAL]==0)
@@ -343,10 +338,6 @@
 
 	current_slotnum=1;
 //	current_time=GetLPTime();
-if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, 0) != HAL_OK)  //system time is 1010ms   1 puls=30.518us
-  {
-    Error_Handler();
-  }
 //  		if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, slot_startcount) != HAL_OK)  //system time is 1010ms   1 puls=30.518us
 //  {
 //    Error_Handler();
@@ -436,11 +427,17 @@
     }
     if(GPIO_Pin == GPIO_PIN_1)//按键
     {
+         SystemClock_Config();
       anjian_flag=1;
     }
     if(GPIO_Pin == GPIO_PIN_0)//加速度
     {
-        
+         SystemClock_Config();
+        if(chongqi_flag==1)
+        {
+        HAL_NVIC_SystemReset();
+        }
+      nomove_count = 0;
     }
 }
 extern void Lora_tx_zubao( void );
@@ -484,35 +481,33 @@
 uint8_t aRxBuffer[1],group_id,GPSRxBuffer[BleRxBufferSize];
 uint8_t ble_rx_success_flag;
 uint8_t fangzhijinrushuimian_flag;
-uint8_t GPS_zhongzhuandate[200];
-uint8_t GPS_zhongzhuannum;
 uint8_t GPSchangdu;
 uint8_t GPS_GGAdate[200]={1,2,3,4,5,6,7,8,9};
 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) 
 {
     {
-    GPS_zhongzhuandate[GPS_zhongzhuannum]=GPSRxBuffer[0];
-    GPS_zhongzhuannum++;
-    if(GPS_zhongzhuandate[GPS_zhongzhuannum-1]==0x0A&&GPS_zhongzhuandate[GPS_zhongzhuannum-2]==0x0D)
-    {
-//        HAL_UART_Transmit(&hlpuart1,ble_rxdate,5,1000);
-    memcpy(GPS_GGAdate,GPS_zhongzhuandate,GPS_zhongzhuannum);
-    GPSchangdu= GPS_zhongzhuannum;
-    memset(GPS_zhongzhuandate,0,sizeof(GPS_zhongzhuandate));
-        GPS_zhongzhuannum=0;
-        fangzhijinrushuimian_flag=0;
-        ble_rx_success_flag=1;
-        if(GPSchangdu>40)
-        {
-            gpsled=BLUE;
-//    Set4LEDColor(powerled,loraled,gpsled,uwbled);
-        }
-        else
-        {
-            gpsled=RED;
-//    Set4LEDColor(powerled,loraled,gpsled,uwbled);z
-        }
-    }
+//        GPS_RecvFsm(GPSRxBuffer[0]);
+        GPS_Recv_Poll(GPSRxBuffer[0]);
+//    GPS_zhongzhuandate[GPS_zhongzhuannum]=GPSRxBuffer[0];
+//    GPS_zhongzhuannum++;
+//    if(GPS_zhongzhuandate[GPS_zhongzhuannum-1]==0x0A&&GPS_zhongzhuandate[GPS_zhongzhuannum-2]==0x0D)
+//    {
+////        HAL_UART_Transmit(&hlpuart1,ble_rxdate,5,1000);
+//    memcpy(GPS_GGAdate,GPS_zhongzhuandate,GPS_zhongzhuannum);
+//    GPSchangdu= GPS_zhongzhuannum;
+//    memset(GPS_zhongzhuandate,0,sizeof(GPS_zhongzhuandate));
+//        GPS_zhongzhuannum=0;
+//        fangzhijinrushuimian_flag=0;
+//        ble_rx_success_flag=1;
+//        if(GPSchangdu>40)
+//        {
+//            gpsled=BLUE;
+//        }
+//        else
+//        {
+//            gpsled=RED;
+//        }
+//    }
     HAL_UART_Receive_IT(&hlpuart1, (uint8_t *)GPSRxBuffer, 1);
     }
 }
@@ -535,13 +530,6 @@
     HAL_UART_Receive_IT(&hlpuart1, (uint8_t *)GPSRxBuffer, 1);
 //    HAL_UART_Transmit(&hlpuart1,ble_rxdate,2,1000);
 }
-//void GPS_rx_Poll()
-//{
-//  if(ble_rx_success_flag)
-//  {
-//  ble_rx_success_flag=0;
-//  }
-//}
 extern uint8_t  yuyin_no_sleep_flag;
 extern uint8_t yuyin_sendflag;
 extern uint8_t xiafayuyin_data[200];
@@ -585,6 +573,7 @@
           }
       }
 }
+uint8_t gotosleep_flag;
 uint8_t usart5_state,flag_onesecond;
 void Jingzhi_Poll(void)
 {
@@ -611,6 +600,21 @@
     {
         flag_onesecond = 0;
     }
+}
+uint8_t Lora_send_flag;
+void Lora_Send_Poll(void)
+{
+        if(Lora_send_flag)
+        {
+        Lora_send_flag=0;    
+//        LedTask();
+            loraled=BLUE;
+        LoraReportPoll();
+        flag_onesecond = 1;
+        
+Set4LEDColor_Off(); 
+        }
+
 }
 /* USER CODE END 0 */
 
@@ -667,13 +671,25 @@
     {
      Error_Handler();
     }
+    delay_ms(1000);
+    GPS_Close_Init();
     HAL_UART_Receive_IT(&hlpuart1, (uint8_t *)GPSRxBuffer, 1);
-    Set4LEDColor(GREEN,RED,RED,RED);
+
+    Set4LEDColor(RED,RED,RED,RED);
     HAL_Delay(500);
-    Set4LEDColor(GREEN,GREEN,GREEN,RED);
+    Set4LEDColor(GREEN,GREEN,GREEN,GREEN);
     HAL_Delay(500);
     Set4LEDColor_Off();
+    HAL_Delay(500);
     LoraInit();
+    
+#ifdef _USE_BAR
+BarInit();
+#endif 
+    if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, 0) != HAL_OK)  //system time is 1010ms   1 puls=30.518us
+  {
+    Error_Handler();
+  }
 //    Lora47X_Init();
 //    Radio.Sleep();
   /* USER CODE END 2 */
@@ -685,10 +701,17 @@
     /* USER CODE END WHILE */
 
     /* USER CODE BEGIN 3 */
+      if(gotosleep_flag==1)
+      {
+          Jingzhi_Poll();
+          HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
+      }
+      else
+      {
       OneSecondTask();
       IdleTask();	
       PowerDownDetect();
-      
+      Lora_Send_Poll();
     #ifndef DEBUG_MODE	
     if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))	
   {      
@@ -704,12 +727,12 @@
     HAL_UARTEx_EnableStopMode( &hlpuart1 );
     HAL_UARTEx_StopModeWakeUpSourceConfig( &hlpuart1, Selection );
     __HAL_UART_ENABLE_IT(&hlpuart1, UART_IT_WUF);   
-    Set4LEDColor_Off();              
+//    Set4LEDColor_Off();              
     HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);  
           }
   }
     #endif
-    
+      }
   }
   /* USER CODE END 3 */
 }
@@ -1231,18 +1254,35 @@
 uint8_t lora_yingdatime;
 extern uint8_t lora_chongfuyingda_flag;
 uint16_t no_data_chongqi_num;
-
 uint8_t no_yingdatime;
+#define YUYINSTOP_TIME 10
 void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
 {
 //    uint8_t pinlv;
     SystemClock_Config();
-    uwbled = BLUE;
-    Set4LEDColor(uwbled,gpsled,loraled,powerled);
-    LoraReportPoll();
-    flag_onesecond = 1;
-    uwbled = LEDOFF;
-    Set4LEDColor(uwbled,gpsled,loraled,powerled);
+    HAL_IWDG_Refresh(&hiwdg);
+Set4LEDColor(powerled,loraled,gpsled,uwbled);
+    yuyinzidongguan_time++;
+    if(yuyinzidongguan_time>YUYINSTOP_TIME)
+    {
+    yuyinzidongguan_time=0;
+    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
+    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_RESET); 
+    yuyin_no_sleep_flag=0;
+    }
+    Lora_send_flag=1;
+    if(nomove_count++>g_com_map[STATIONARY_TIME])
+    {
+        stationary_flag = 1;
+    } else {
+        stationary_flag = 0;
+    }
+    if(nomove_count>=g_com_map[NOMOVESLEEP_TIME]-1&&imu_enable)
+    {
+        gotosleep_flag=1;
+    } else {
+        gotosleep_flag=0;
+    }
 }
 /* USER CODE END 4 */
 

--
Gitblit v1.9.3