From 15c798731ba5658fc0ecd9e3f47f662861c56b9c Mon Sep 17 00:00:00 2001 From: WXK <287788329@qq.com> Date: 星期五, 23 二月 2024 14:40:37 +0800 Subject: [PATCH] 加入lora升级。 --- Src/main.c | 127 +++++++++++++++--------------------------- 1 files changed, 46 insertions(+), 81 deletions(-) diff --git a/Src/main.c b/Src/main.c index 42937f3..f7c08cc 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,9 +236,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 +244,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; @@ -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] = 100; 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,6 +404,7 @@ } } +u8 flag_entersleep = 1; /* USER CODE END 0 */ /** @@ -437,7 +440,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,12 +459,20 @@ Error_Handler(); } HAL_Delay(1500); - Lora_Init(); - + MbxInit(); + // SwitchLoraSettingstest(UWB_CHANNEL_FRQ,UWB_CHANNEL_SF); Delay_Ms(10); + /* USER CODE END 2 */ - +//HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET); +//HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET); +// Delay_Ms(10); +// Delay_Ms(10); +//HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); +//HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET); +// Delay_Ms(10); +// Delay_Ms(10); /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) @@ -470,21 +481,11 @@ /* 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; @@ -495,7 +496,8 @@ Tag_App(); LED_TR_OFF; } - +// test1(); + //LED0_BLINK; IdleTask(); if(waitusart_timer>0) @@ -514,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 } @@ -935,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