From d3d530578cd646c83b6683439d08a80141205e46 Mon Sep 17 00:00:00 2001 From: WXK <287788329@qq.com> Date: 星期三, 29 十一月 2023 16:29:30 +0800 Subject: [PATCH] 1 --- Src/main.c | 137 ++++++++++++++++++++++++--------------------- 1 files changed, 73 insertions(+), 64 deletions(-) diff --git a/Src/main.c b/Src/main.c index ba855ad..044e478 100644 --- a/Src/main.c +++ b/Src/main.c @@ -35,10 +35,11 @@ #include "string.h" #include "stdio.h" #include "delay.h" +#include <stdlib.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 -----------------------------------------------------------*/ @@ -211,12 +212,13 @@ // { // lpcount+=LPTIMER_1S_COUNT; // } - lpcount = last_lpcount+32768/tag_frequency-time*LPTIMER_LSB; + last_lpcount=HAL_LPTIM_ReadCounter(&hlptim1); + lpcount = last_lpcount+32768+32.768*time; while(lpcount>LPTIMER_1S_COUNT) { lpcount-=LPTIMER_1S_COUNT; } - last_lpcount = lpcount; +// last_lpcount = lpcount; __HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount); } @@ -259,48 +261,50 @@ u8 active_flag,nomovesleeptime; void GetLoratx_frequency(void) { -if(g_com_map[NEARBASE_ID1]==0x470) -{Loratx_frequency=470000000;} -if(g_com_map[NEARBASE_ID1]==0x471) -{Loratx_frequency=471000000;} -if(g_com_map[NEARBASE_ID1]==0x472) -{Loratx_frequency=472000000;} -if(g_com_map[NEARBASE_ID1]==0x473) -{Loratx_frequency=473000000;} -if(g_com_map[NEARBASE_ID1]==0x474) -{Loratx_frequency=474000000;} -if(g_com_map[NEARBASE_ID1]==0x475) -{Loratx_frequency=475000000;} -if(g_com_map[NEARBASE_ID1]==0x476) -{Loratx_frequency=476000000;} -if(g_com_map[NEARBASE_ID1]==0x477) -{Loratx_frequency=477000000;} -if(g_com_map[NEARBASE_ID1]==0x478) -{Loratx_frequency=478000000;} -if(g_com_map[NEARBASE_ID1]==0x479) -{Loratx_frequency=479000000;} -if(g_com_map[NEARBASE_ID1]==0x480) -{Loratx_frequency=480000000;} -if(g_com_map[NEARBASE_ID1]==0x481) -{Loratx_frequency=481000000;} -if(g_com_map[NEARBASE_ID1]==0x482) -{Loratx_frequency=482000000;} -if(g_com_map[NEARBASE_ID1]==0x483) -{Loratx_frequency=483000000;} -if(g_com_map[NEARBASE_ID1]==0x484) -{Loratx_frequency=484000000;} -if(g_com_map[NEARBASE_ID1]==0x485) -{Loratx_frequency=485000000;} -if(g_com_map[NEARBASE_ID1]==0x486) -{Loratx_frequency=486000000;} -if(g_com_map[NEARBASE_ID1]==0x487) -{Loratx_frequency=487000000;} -if(g_com_map[NEARBASE_ID1]==0x488) -{Loratx_frequency=488000000;} -if(g_com_map[NEARBASE_ID1]==0x489) -{Loratx_frequency=489000000;} -if(g_com_map[NEARBASE_ID1]==0x490) -{Loratx_frequency=490000000;} +//if(g_com_map[NEARBASE_ID1]==0x470) +//{Loratx_frequency=470000000;} +//if(g_com_map[NEARBASE_ID1]==0x471) +//{Loratx_frequency=471000000;} +//if(g_com_map[NEARBASE_ID1]==0x472) +//{Loratx_frequency=472000000;} +//if(g_com_map[NEARBASE_ID1]==0x473) +//{Loratx_frequency=473000000;} +//if(g_com_map[NEARBASE_ID1]==0x474) +//{Loratx_frequency=474000000;} +//if(g_com_map[NEARBASE_ID1]==0x475) +//{Loratx_frequency=475000000;} +//if(g_com_map[NEARBASE_ID1]==0x476) +//{Loratx_frequency=476000000;} +//if(g_com_map[NEARBASE_ID1]==0x477) +//{Loratx_frequency=477000000;} +//if(g_com_map[NEARBASE_ID1]==0x478) +//{Loratx_frequency=478000000;} +//if(g_com_map[NEARBASE_ID1]==0x479) +//{Loratx_frequency=479000000;} +//if(g_com_map[NEARBASE_ID1]==0x480) +//{Loratx_frequency=480000000;} +//if(g_com_map[NEARBASE_ID1]==0x481) +//{Loratx_frequency=481000000;} +//if(g_com_map[NEARBASE_ID1]==0x482) +//{Loratx_frequency=482000000;} +//if(g_com_map[NEARBASE_ID1]==0x483) +//{Loratx_frequency=483000000;} +//if(g_com_map[NEARBASE_ID1]==0x484) +//{Loratx_frequency=484000000;} +//if(g_com_map[NEARBASE_ID1]==0x485) +//{Loratx_frequency=485000000;} +//if(g_com_map[NEARBASE_ID1]==0x486) +//{Loratx_frequency=486000000;} +//if(g_com_map[NEARBASE_ID1]==0x487) +//{Loratx_frequency=487000000;} +//if(g_com_map[NEARBASE_ID1]==0x488) +//{Loratx_frequency=488000000;} +//if(g_com_map[NEARBASE_ID1]==0x489) +//{Loratx_frequency=489000000;} +//if(g_com_map[NEARBASE_ID1]==0x490) +//{Loratx_frequency=490000000;} +srand(HAL_LPTIM_ReadCounter(&hlptim1)); + Loratx_frequency=((rand()%5)+470)*1000000; } void Program_Init(void) { float temp; @@ -321,14 +325,13 @@ // g_com_map[MAX_REPORT_ANC_NUM]=1; // g_com_map[NOMOVESLEEP_TIME]=10; #endif - g_com_map[GROUP_ID]=3; + g_com_map[GROUP_ID]=33; 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; imu_enable=g_com_map[IMU_ENABLE]; motor_enable=g_com_map[MOTOR_ENABLE]; -GetLoratx_frequency(); group_id=g_com_map[GROUP_ID]; dev_id = g_com_map[DEV_ID]; @@ -362,8 +365,9 @@ { Error_Handler(); } + //g_com_map[NOMOVESLEEP_TIME]=5; - printf("固件版本: 免布线基站 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff); + printf("固件版本: 免布线基站LORA版本 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff); memcpy(g_com_map2,g_com_map,COM_MAP_SIZE); // 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]); @@ -589,6 +593,8 @@ } Delay_Ms(2); // Uwb_Lora_Switch(0,1); +// Lora433rx_Init(); +// Lora47xrx_Init(); Lora_Init(); // Radio.Sleep( ); Delay_Ms(10); @@ -597,6 +603,7 @@ usart_send[0]=0x55; usart_send[1]=0xaa; bat_percent=Get_VDDVlotage(); + GetLoratx_frequency(); // mcu_sleep(); //LED0_BLINK; // SystemPower_Config(); @@ -611,7 +618,7 @@ /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ -Lora_rx_open(); +//Lora_rx_open(); Lora_Tx_Poll(); HAL_IWDG_Refresh(&hiwdg); @@ -1039,7 +1046,7 @@ extern uint8_t lora_yingda_flag; uint8_t lora_yingdatime; extern uint8_t lora_chongfuyingda_flag; -uint8_t no_data_chongqi_num; +uint16_t no_data_chongqi_num; uint16_t anchor_send_num; void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim) { @@ -1048,22 +1055,24 @@ anchor_send_num++; no_data_chongqi_num++; stationary_num++; - if( no_data_chongqi_num>60) + if( no_data_chongqi_num>600) {NVIC_SystemReset();} - 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 - {lora_tx_flag=1; + 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 +// { + lora_tx_flag=1; lora_txanchor_power_flag=0; - } +// } if(anchor_send_num>=600) {anchor_send_num=0; lora_txanchor_power_flag=1; -- Gitblit v1.9.3