From a05285d3b4ea5aa0609a2a23aa867c17c0611a38 Mon Sep 17 00:00:00 2001
From: yincheng.zhong <634916154@qq.com>
Date: 星期日, 18 二月 2024 10:17:57 +0800
Subject: [PATCH] 配合网关调试标签上传回复部分,测距部分已经调通

---
 Src/main.c |  202 ++++++++++----------------------------------------
 1 files changed, 41 insertions(+), 161 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index 37f878a..92e041b 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -37,10 +37,11 @@
 #include <stdlib.h>
 #include "WS2812.h"
 #include "syn6288.h"
+#include "dw_mbx_tag.h"
 #define NSH1 0x0001
 #define GP   0x0002
 #define FLASH_HARDWARE_VERSION_MAP		(uint32_t)0x08004F00    //硬件版本号和批次信息位置
-//#define DEBUG_MODE
+#define DEBUG_MODE
 uint8_t chongqi_flag;
 uint32_t uwbled,gpsled,loraled,powerled;
 UART_WakeUpTypeDef Selection;
@@ -204,20 +205,6 @@
 float motor_keeptime;
 void IdleTask(void)
 {
-//if(huart1.Instance->ISR&USART_ISR_FE)
-//	{
-//	SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
-////	}
-//    if(du_flag==1)
-//    {
-//    du_flag=0;
-//        
-//    }
-//    if(xie_flag==1)
-//    {
-//    xie_flag=0;
-//    memcpy((uint8_t*)&g_com_map + pack_index, mUsartReceivePack, pack_datalen);    
-//    }
 	if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))
 	{
         	
@@ -232,11 +219,10 @@
 		}
 		if(bat_percent>99)
 		{
-    powerled=GREEN;
-    Set4LEDColor(powerled,loraled,gpsled,uwbled);
+            powerled=GREEN;
+     
 		}else{
-    powerled=RED;
-    Set4LEDColor(powerled,loraled,gpsled,uwbled);
+            powerled=RED;           
 		}		
 	}else{
         if(state5v==1)
@@ -324,19 +310,9 @@
     return sum;
 }
     
-u32 Loratx_frequency;
+
 u8 active_flag,nomovesleeptime;
-void GetLoratx_frequency(void)
-{
-Loratx_frequency=470000000;
-srand(HAL_LPTIM_ReadCounter(&hlptim1));
-        Loratx_frequency=((rand()%5)+470)*1000000; 
-        if(470000000<=Loratx_frequency&&Loratx_frequency<480000000)
-        g_com_map[NEARBASE_ID1]=1136+(Loratx_frequency/1000000-470);
-        if(480000000<=Loratx_frequency&&Loratx_frequency<490000000)
-        g_com_map[NEARBASE_ID1]=1152+(Loratx_frequency/1000000-480);
-Loratx_frequency=470000000;
-}
+
 void Program_Init(void)
 {	float temp;
 	uint16_t temp2;
@@ -487,18 +463,11 @@
     }
     if(GPIO_Pin == GPIO_PIN_1)//按键
     {
-        SystemClock_Config();
       anjian_flag=1;
     }
     if(GPIO_Pin == GPIO_PIN_0)//加速度
     {
-        SystemClock_Config();
-     stationary_flag =0;
-        stationary_num=0;
-   if(chongqi_flag==1)
-   {
-   HAL_NVIC_SystemReset();
-   }
+        
     }
 }
 extern void Lora_tx_zubao( void );
@@ -508,9 +477,7 @@
 extern uint16_t lora_yingda_num;
 uint8_t lora_tx_flag;
 uint8_t lora_txanchor_power_flag;
-extern uint16_t Lora_tx_ancid[50];
-extern uint16_t Lora_tx_ancdist[50];
-extern uint8_t Lora_tx_anc_electricity[50];
+
 u8 lora_seq_nb1;
 static uint8_t send_frame1[EUART_RX_BUF_SIZE];
 uint8_t data_length1;
@@ -538,54 +505,11 @@
 uint8_t no_yingdaflag;
 extern  uint8_t GPS_GGAdate[200];
 uint8_t GPS_GGAdate111[200]="报警";
-void Lora_Tx_Poll()
-{
 
-    if(lora_tx_flag)
-    {  
-        lora_tx_flag=0;
-//        SYN_FrameInfo(0,GPS_GGAdate111);
-//        while(1);
-       if(du_flag==1)
-       {    
-    Lora47X_Init();    
-    du_flag=0;
-    Radio.Send( send_frame1, data_length1);    
-        no_yingdaflag=1;
-       }
-       else
-       {
-        Lora47X_Init();
-        if(bat_percent>20)
-        {
-    loraled=BLUE;
-//    Set4LEDColor(powerled,loraled,gpsled,uwbled);
-        }
-        else
-        {
-    loraled=RED;
-//    Set4LEDColor(powerled,loraled,gpsled,uwbled);
-        }
-    lora_seq_nb2++;
-    Lora_tx_zubao();
-    Radio.Send( usart_send, 15+Lora_tx_ancnum*4+GPSchangdu);
-    Lora_tx_ancnum=0;    
-    GPSchangdu=0;
-    memset(Lora_tx_ancdist,0,sizeof(Lora_tx_ancdist));
-    memset(Lora_tx_ancid,0,sizeof(Lora_tx_ancid));
-    memset(GPS_GGAdate,0,sizeof(GPS_GGAdate));
-    anjian_flag=0;
-        //        delay_ms(10);
-//            loraled=LEDOFF;
-//    Set4LEDColor(powerled,loraled,gpsled,uwbled);
-//        HAL_UART_Transmit(&huart1,usart_send,15+Lora_tx_ancnum*4+GPSchangdu,3000);
-       }
-    }
-     
-}
+
 void MX_ADC1_Init()
 {
-MX_ADC_Init();
+    MX_ADC_Init();
 }
 void GPS_Close_Init()
 {
@@ -636,7 +560,7 @@
         else
         {
             gpsled=RED;
-//    Set4LEDColor(powerled,loraled,gpsled,uwbled);
+//    Set4LEDColor(powerled,loraled,gpsled,uwbled);z
         }
     }
     HAL_UART_Receive_IT(&hlpuart1, (uint8_t *)GPSRxBuffer, 1);
@@ -711,15 +635,15 @@
           }
       }
 }
-uint8_t usart5_state;
+uint8_t usart5_state,flag_onesecond;
 void Jingzhi_Poll(void)
 {
           powerled=LEDOFF;
           loraled=LEDOFF;
           gpsled=LEDOFF;
           uwbled=LEDOFF;
-      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); //GuanGPS and lora 电源
-      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); //guan uwb 电源
+          HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET); //GuanGPS and lora 电源
+          HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); //guan uwb 电源
           HAL_SPI_DeInit(&hspi1);
           HAL_GPIO_WritePin( RADIO_NSS_GPIO_Port, RADIO_NSS_Pin,GPIO_PIN_RESET);//lora  cs
           HAL_GPIO_WritePin( GPIOA, GPIO_PIN_4,GPIO_PIN_RESET);//uwb cs
@@ -727,13 +651,16 @@
           Usart5DeInit();
           LpusartDeInit();
           HAL_ADC_DeInit(&hadc);
-//          __HAL_RCC_GPIOA_CLK_DISABLE();
-//          __HAL_RCC_GPIOB_CLK_DISABLE();
-//          __HAL_RCC_GPIOC_CLK_DISABLE();
-//          __HAL_RCC_GPIOD_CLK_DISABLE();
-//          __HAL_RCC_GPIOE_CLK_DISABLE();
+
           Set4LEDColor_Off(); //关led总电源
           chongqi_flag=1;
+}
+void OneSecondTask(void)
+{
+    if(flag_onesecond==1)
+    {
+        flag_onesecond = 0;
+    }
 }
 /* USER CODE END 0 */
 
@@ -783,7 +710,6 @@
     Program_Init();
     LIS3DH_Data_Init();	
     Dw1000_Init();
-    Dw1000_App_Init();
     //	HardWareTypeDiffConfig();
     dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_CS | DWT_WAKE_WK| DWT_SLP_EN);
     dwt_entersleep();
@@ -791,19 +717,13 @@
     {
      Error_Handler();
     }
-    Delay_Ms(2);
-    Delay_Ms(10);
-    bat_percent=Get_VDDVlotage();
-    GetLoratx_frequency();
-    delay_ms(2000);
-    GPS_Close_Init();    
-
     HAL_UART_Receive_IT(&hlpuart1, (uint8_t *)GPSRxBuffer, 1);
-    Set4LEDColor(RED,RED,RED,RED);
+    Set4LEDColor(GREEN,RED,RED,RED);
     HAL_Delay(500);
-    Set4LEDColor(GREEN,GREEN,GREEN,GREEN);
+    Set4LEDColor(GREEN,GREEN,GREEN,RED);
     HAL_Delay(500);
     Set4LEDColor_Off();
+    LoraInit();
 //    Lora47X_Init();
 //    Radio.Sleep();
   /* USER CODE END 2 */
@@ -815,27 +735,10 @@
     /* USER CODE END WHILE */
 
     /* USER CODE BEGIN 3 */
-//Lora_rx_open();
-//      Lora_Tx_Poll();
-      if(stationary_flag==1)
-      {
-          Jingzhi_Poll();
-          HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
-      }
-      else
-      {
-      Lora_Tx_Poll();    
-          IdleTask();	
-      TTSchaxun_Busy();
+      OneSecondTask();
+      IdleTask();	
       PowerDownDetect();
       
-//      Ble_rx_Poll();
-//    HAL_IWDG_Refresh(&hiwdg);
-
-//      Lora_rece_error=0;
-//	Radio.IrqProcess( ); // Process Radio IRQ
-//     Anchor_App();
-
     #ifndef DEBUG_MODE	
     if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))	
   {      
@@ -856,7 +759,7 @@
           }
   }
     #endif
-    }
+    
   }
   /* USER CODE END 3 */
 }
@@ -1378,23 +1281,20 @@
 uint8_t lora_yingdatime;
 extern uint8_t lora_chongfuyingda_flag;
 uint16_t no_data_chongqi_num;
-uint16_t anchor_send_num;
+
 uint8_t no_yingdatime;
 void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
 {
 //    uint8_t pinlv;
     SystemClock_Config();
+    Set4LEDColor(uwbled,gpsled,loraled,powerled);
+    LoraReportPoll();
     lp_time++;
-    anchor_send_num++;
+
     no_data_chongqi_num++;
     stationary_num++;
-    Set4LEDColor(powerled,loraled,gpsled,uwbled);
-//    if(Beepchixutime>0)
-//    {
-//        Beepchixutime--;
-//        if(Beepchixutime==0)
-//        {Beep_Off();}
-//    }
+
+    flag_onesecond = 1;
     if(no_yingdaflag==1)
     {
     no_yingdatime++;
@@ -1408,30 +1308,10 @@
     if( no_data_chongqi_num>600)
     {NVIC_SystemReset();}
     SetNextPollTime(0);
-//    if(lora_yingda_flag)
-//    {
-//    lora_yingdatime++;
-//        if(lora_yingdatime>=2)
-//        {lora_yingdatime=0;
-//        lora_yingda_flag=0;            
-//          Lora_tx_mode();
-//            Radio.Send( usart_send, 2);
-//        }
-//    }
-//    else
-//    {
-//    pinlv=g_com_map[COM_MAP_SIZE]/1000;
+ 
     if(lp_time%(g_com_map[COM_INTERVAL]/1000)==0)
     {
-    lora_tx_flag=1;
-    lora_txanchor_power_flag=0;
-//    }
-    if(anchor_send_num>=3600)
-    {anchor_send_num=0;
-    lora_txanchor_power_flag=1;
-        lora_tx_flag=0;
-        bat_percent=Get_VDDVlotage();
-    }
+        lora_txanchor_power_flag=0;
     }
 
     if(stationary_num>=30)
@@ -1441,10 +1321,10 @@
     yuyinzidongguan_time++;
     if(yuyinzidongguan_time>10)
     {
-    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;
+        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;
     }
 }
 /* USER CODE END 4 */

--
Gitblit v1.9.3