From 58bf13b0569714d03afe101a3abb4d2419ec9e30 Mon Sep 17 00:00:00 2001
From: yincheng.zhong <634916154@qq.com>
Date: 星期日, 25 二月 2024 19:04:38 +0800
Subject: [PATCH] Merge branch '免布线基站-lora' of http://47.108.70.204:60062/r/XRange_Tag into 免布线基站-lora

---
 Src/main.c |  130 +++++++++++++------------------------------
 1 files changed, 40 insertions(+), 90 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index d24a257..b463e5c 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -34,6 +34,8 @@
 #include "string.h"
 #include "stdio.h"
 #include "delay.h"
+#include "lora.h"
+#include "dw_mbx_anc.h"
 #define NSH1 0x0001
 #define GP   0x0002
 #define FLASH_HARDWARE_VERSION_MAP		(uint32_t)0x08004F00    //硬件版本号和批次信息位置
@@ -146,7 +148,7 @@
 uint8_t state5v = 1;
 float motor_keeptime;
 void IdleTask(void)
-{u16 current_time;
+{
 //if(huart1.Instance->ISR&USART_ISR_FE)
 //	{
 //	SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
@@ -188,13 +190,25 @@
 
 	}
 
-
+void delay_us(uint32_t nTimer)  
+{  
+    uint32_t i=0;  
+    for(i=0;i<nTimer;i++){  
+        __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
+		__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
+		__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();  
+        __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
+		__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
+		__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();  
+        __NOP();__NOP();__NOP();__NOP(); 
+    }  
+}
 u16 total_slotnum,current_slotnum;
 extern int32_t offsettimeus;
 u16 last_lpcount = 0;
 void SetNextPollTime(u16 time)
 {
-  int32_t lpcount,lptime,target_time;
+  int32_t lpcount;
 
 //	if(current_slotnum>=total_slotnum)
 //		current_slotnum-=total_slotnum;
@@ -222,17 +236,15 @@
 
 u8 active_flag,nomovesleeptime;
 void Program_Init(void)
-{	float temp;
-	uint16_t temp2;
-	uint16_t i;
+{	
 	Usart1ParseDataCallback = UsartParseDataHandler;
 	parameter_init();
     hardware_version = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP);
 	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] = (1<<8)|0;
-    testprogram();
+	g_com_map[VERSION] = (3<<8)|0;
+ //   testprogram();
 //    g_com_map[DEV_ID]=0x6777;
     #ifdef DEBUG_MODE
    // g_com_map[GROUP_ID]=21;
@@ -241,7 +253,9 @@
     //	g_com_map[MAX_REPORT_ANC_NUM]=1;
     //	g_com_map[NOMOVESLEEP_TIME]=10;
     #endif
-//    g_com_map[GROUP_ID]=33;
+    g_com_map[ACTIVE_INDEX] = 1;
+    g_com_map[GROUP_ID]=5;
+    g_com_map[UWBPOLLTIME_MS_IDX] = 520;
     g_com_map[COM_INTERVAL] = 1000;
     if(g_com_map[COM_INTERVAL]<1000)
     {g_com_map[COM_INTERVAL] = 1000;}
@@ -264,8 +278,7 @@
     nomovesleeptime = g_com_map[NOMOVESLEEP_TIME];
 	if(active_flag==0)
 	{   
-		imu_enable=1;
-		nomovesleeptime =10;		
+        
 	}
 
  //   g_com_map[COM_INTERVAL]=100;
@@ -275,8 +288,6 @@
 	}
 	 if(module_power>67)
 		{module_power=67;}
-		if(module_power<0)
-		{module_power=0;}
 
 	current_slotnum=1;
 	current_time=GetLPTime();
@@ -290,15 +301,6 @@
 //	printf("DEVICE PAIRID: %d .\r\n",g_com_map[PAIR_ID]);
 //	printf("DEVICE ALARM DISTANCE: 1.%d 2.%d 3.%d .\r\n",g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],g_com_map[ALARM_DISTANCE3]);
 
-}
-
-static void SystemPower_Config(void)
-{
-  /* Enable Ultra low power mode */
-  HAL_PWREx_EnableUltraLowPower();
-  
-  /* Enable the fast wake up from Ultra low power mode */
-  HAL_PWREx_EnableFastWakeUp();
 }
 void mcu_sleep(void);
 uint32_t temp;
@@ -321,7 +323,7 @@
 {
     static uint8_t first = 1;
     static float last_value = 100;   
-    static uint16_t bat_count = 0;
+    
     //if(bat_count++%600==0)
     {
 	temp2=dwt_readtempvbat(1);
@@ -402,7 +404,7 @@
       
   }
 }
-uint16_t tmp111=0x55AA;
+u8 flag_entersleep = 1;
 /* USER CODE END 0 */
 
 /**
@@ -457,9 +459,9 @@
      Error_Handler();
     }
     HAL_Delay(1500);
-
-//    Lora_Init();
-SwitchLoraSettingstest(469000000,7);
+    Lora_Init();
+    MbxInit();
+  //  SwitchLoraSettingstest(UWB_CHANNEL_FRQ,UWB_CHANNEL_SF);
     Delay_Ms(10);
     
   /* USER CODE END 2 */
@@ -479,38 +481,23 @@
 
     /* USER CODE BEGIN 3 */
     //  Send_Anchor_Vcc_Poll();
-		if(g_start_send_flag)
-	{ static uint16_t blink_count=0;
+    if(g_start_send_flag&&g_com_map[ACTIVE_INDEX])
+	{ 
 		SystemClock_Config();
 		g_start_send_flag = 0;	
-		HAL_IWDG_Refresh(&hiwdg);
-
-
-       
-//        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
-
-	   
-//        HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
-//         Radio.Send( &TX_Buffer, 4);
-//        UWB_Wkup();
-//        delay_us(700);
+//		HAL_IWDG_Refresh(&hiwdg);
 		if(bat_percent>15)
 		{	
           LED_TB_ON;
-//			Tag_App();
+			Tag_App();
 			LED_TB_OFF;
 		}else{
 			LED_TR_ON;
-//			Tag_App();
+			Tag_App();
 			LED_TR_OFF;		
 		}
-        test1();
-//    __disable_irq();
-//    if(testflag==1)
-//    FLASH_Prepare(0X8012800, 128); 
-           
-//    FLASH_Write(0X8012800, (const uint8_t*)&tmp111, 2);    
-//    __enable_irq();      
+//        test1();
+        
 		//LED0_BLINK;		
 		IdleTask();	
 		if(waitusart_timer>0)
@@ -529,7 +516,7 @@
 //         if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))				
 //                    HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);  
     #ifndef DEBUG_MODE	
-    if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))				
+    if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)&&flag_entersleep)				
                     HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);  
     #endif
     }
@@ -950,51 +937,14 @@
 extern float freqlost_count,range_lost_time;
 void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
 {
-	static uint8_t i=0,lost_jumpcount=0;
+	static uint8_t i=0;
 	i++;
+    
 	Anchor_Vcc_time++;
 	current_slotnum++;
     freqlost_count+=1/(float)tag_frequency;
     range_lost_time +=1/(float)tag_frequency;
-//    g_start_send_flag=1;
-//    if(freqlost_count>FREQ_LOST_TIME)
-//    {
-//        tag_frequency = NOTAG_FREQ;
-//        if(lost_jumpcount++>=0) //无测距情况下,每5秒发一次;
-//        {
-//            lost_jumpcount = 0;
-//            g_start_send_flag=1;
-//        }
-//    }else{
-        g_start_send_flag=1;
-//    }
-    if(range_lost_time<1||freqlost_count>FREQ_LOST_TIME)
-    {
-        SetNextPollTime(0);
-    }else{
-        SetNextPollTime(5);
-    }
-    
-//	nomove_count+=1/(float)tag_frequency;
-//    if(motor_keeptime>0)
-//	{	
-//        nomove_count+=1/(float)tag_frequency;
-//	}
-//	if(!GET_USERKEY)
-//	{
-//		key_keeptime+=1/(float)tag_frequency;
-//		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{
-//		key_keeptime=0;
-//	}
-
+    g_start_send_flag=1;
 }
 /* USER CODE END 4 */
 

--
Gitblit v1.9.3