From a6c4135e127ac1d14023101eb364d61fac7e9166 Mon Sep 17 00:00:00 2001 From: yincheng.zhong <634916154@qq.com> Date: 星期二, 06 二月 2024 11:54:15 +0800 Subject: [PATCH] 开发未完成 --- Src/main.c | 102 ++++++++++++++++---------------------------------- 1 files changed, 33 insertions(+), 69 deletions(-) diff --git a/Src/main.c b/Src/main.c index 51401ce..c93ed0a 100644 --- a/Src/main.c +++ b/Src/main.c @@ -34,10 +34,11 @@ #include "string.h" #include "stdio.h" #include "delay.h" +#include "lora.h" #define NSH1 0x0001 #define GP 0x0002 #define FLASH_HARDWARE_VERSION_MAP (uint32_t)0x08004F00 //硬件版本号和批次信息位置 -#define DEBUG_MODE +//#define DEBUG_MODE /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -146,7 +147,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 +189,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,9 +235,7 @@ 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); @@ -232,7 +243,7 @@ hardware_type = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+4); //deca_sleep(1000); g_com_map[VERSION] = (1<<8)|0; - testprogram(); + // testprogram(); // g_com_map[DEV_ID]=0x6777; #ifdef DEBUG_MODE // g_com_map[GROUP_ID]=21; @@ -242,6 +253,7 @@ // g_com_map[NOMOVESLEEP_TIME]=10; #endif // g_com_map[GROUP_ID]=33; + g_com_map[UWBPOLLTIME_MS_IDX] = 100; g_com_map[COM_INTERVAL] = 1000; if(g_com_map[COM_INTERVAL]<1000) {g_com_map[COM_INTERVAL] = 1000;} @@ -275,8 +287,6 @@ } if(module_power>67) {module_power=67;} - if(module_power<0) - {module_power=0;} current_slotnum=1; current_time=GetLPTime(); @@ -290,15 +300,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 +322,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,6 +403,7 @@ } } +u8 flag_entersleep = 1; /* USER CODE END 0 */ /** @@ -437,7 +439,7 @@ MX_LPTIM1_Init(); MX_SPI1_Init(); MX_USART1_UART_Init(); -// MX_IWDG_Init(); + MX_IWDG_Init(); /* USER CODE BEGIN 2 */ LED_LG_ON; Program_Init(); @@ -456,9 +458,8 @@ Error_Handler(); } HAL_Delay(1500); - -// Lora_Init(); -SwitchLoraSettingstest(469000000,7); + Lora_Init(); + // SwitchLoraSettingstest(UWB_CHANNEL_FRQ,UWB_CHANNEL_SF); Delay_Ms(10); /* USER CODE END 2 */ @@ -471,7 +472,7 @@ /* USER CODE BEGIN 3 */ // Send_Anchor_Vcc_Poll(); if(g_start_send_flag) - { static uint16_t blink_count=0; + { SystemClock_Config(); g_start_send_flag = 0; HAL_IWDG_Refresh(&hiwdg); @@ -488,14 +489,14 @@ 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(); +// test1(); //LED0_BLINK; IdleTask(); @@ -515,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 } @@ -936,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