| | |
| | | #include "stdio.h" |
| | | #include "delay.h" |
| | | #include "lora.h" |
| | | #include "dps310.h" |
| | | #include "dw_mbx_anc.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 -----------------------------------------------------------*/ |
| | |
| | | /* USER CODE BEGIN 0 */ |
| | | #define DIANLIANG_TIME 3600 |
| | | uint8_t Anchor_Vcc_Flag; |
| | | uint16_t Anchor_Vcc_time=DIANLIANG_TIME-2; |
| | | uint16_t Anchor_Vcc_time=DIANLIANG_TIME+1; |
| | | uint32_t dev_id; |
| | | uint16_t heartbeat_timer,poll_timer,sync_timer; |
| | | uint8_t aRxBuffer[1],group_id; |
| | |
| | | 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] = (6<<8)|0; |
| | | g_com_map[VERSION] = (1<<8)|16; |
| | | // testprogram(); |
| | | // g_com_map[DEV_ID]=0x6777; |
| | | #ifdef DEBUG_MODE |
| | |
| | | // g_com_map[NOMOVESLEEP_TIME]=10; |
| | | #endif |
| | | g_com_map[ACTIVE_INDEX] = 1; |
| | | g_com_map[GROUP_ID]=5; |
| | | g_com_map[UWBPOLLTIME_MS_IDX] = 520; |
| | | g_com_map[GROUP_ID]=0; |
| | | |
| | | g_com_map[COM_INTERVAL] = 1000; |
| | | if(g_com_map[COM_INTERVAL]<1000) |
| | | {g_com_map[COM_INTERVAL] = 1000;} |
| | | active_flag = g_com_map[ACTIVE_INDEX]; |
| | | g_com_map[POWER]=0; |
| | | if(g_com_map[UWBPOLLTIME_MS_IDX]<10) //如果uwbpoll 时间小于10,随机生成一个小于一千的数。 |
| | | {g_com_map[UWBPOLLTIME_MS_IDX] = GetRandomValue()%1000+10;} |
| | | |
| | | if(g_com_map[UWBPOLLTIME_MS_IDX]>1000) |
| | | { |
| | | g_com_map[UWBPOLLTIME_MS_IDX] = GetRandomValue()%1000+10; |
| | | } |
| | | |
| | | 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]; |
| | | |
| | | |
| | | group_id=g_com_map[GROUP_ID]; |
| | | dev_id = g_com_map[DEV_ID]; |
| | | slottime=ceil((double)g_com_map[MAX_REPORT_ANC_NUM]*SLOT_SCALE)+3; |
| | | max_slotpos=g_com_map[COM_INTERVAL]/slottime; |
| | | tyncpoll_time=(g_com_map[DEV_ID]%max_slotpos)*slottime; |
| | | slot_startcount=tyncpoll_time*1000/LPTIMER_LSB; |
| | | lastpoll_time=tyncpoll_time; |
| | | tag_frequency = 1000/g_com_map[COM_INTERVAL]; |
| | | total_slotnum = 1000/g_com_map[COM_INTERVAL]; |
| | | nomovesleeptime = g_com_map[NOMOVESLEEP_TIME]; |
| | | if(active_flag==0) |
| | | { |
| | | |
| | | } |
| | | |
| | | // g_com_map[COM_INTERVAL]=100; |
| | | if(g_com_map[COM_INTERVAL]==0) |
| | | { |
| | | g_com_map[COM_INTERVAL]=1000; |
| | | } |
| | | if(module_power>67) |
| | | {module_power=67;} |
| | | |
| | | current_slotnum=1; |
| | | current_time=GetLPTime(); |
| | | |
| | | if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, slot_startcount) != HAL_OK) //system time is 1010ms 1 puls=30.518us |
| | | { |
| | | Error_Handler(); |
| | |
| | | MX_USART1_UART_Init(); |
| | | MX_IWDG_Init(); |
| | | /* USER CODE BEGIN 2 */ |
| | | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| | | /*Configure GPIO pin Output Level */ |
| | | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET); |
| | | /*Configure GPIO pins : SCL_Pin SDA_Pin */ |
| | | GPIO_InitStruct.Pin = GPIO_PIN_14; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| | | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| | | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
| | | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | LED_LG_ON; |
| | | Program_Init(); |
| | | // LIS3DH_Data_Init(); |
| | |
| | | MbxInit(); |
| | | // SwitchLoraSettingstest(UWB_CHANNEL_FRQ,UWB_CHANNEL_SF); |
| | | Delay_Ms(10); |
| | | #ifdef _USE_BAR_ |
| | | BarInit(); |
| | | #endif |
| | | // HAL_ADC_Start_DMA(&hadc,(uint32_t*)&AD_value,sizeof(AD_value)); |
| | | /* USER CODE END 2 */ |
| | | |
| | |
| | | // Send_Anchor_Vcc_Poll(); |
| | | if(g_start_send_flag&&g_com_map[ACTIVE_INDEX]) |
| | | { |
| | | SystemClock_Config(); |
| | | |
| | | g_start_send_flag = 0; |
| | | HAL_IWDG_Refresh(&hiwdg); |
| | | if(bat_percent>15) |
| | |
| | | extern uint8_t tx_near_msg[80],stationary_flag; |
| | | float key_keeptime; |
| | | extern float freqlost_count,range_lost_time; |
| | | uint8_t g_start_send_time; |
| | | void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim) |
| | | { |
| | | static uint8_t i=0; |
| | | SystemClock_Config(); |
| | | i++; |
| | | Anchor_Vcc_time++; |
| | | if(Anchor_Vcc_time>DIANLIANG_TIME) |
| | | if(Anchor_Vcc_time++>DIANLIANG_TIME) |
| | | { |
| | | Anchor_Vcc_Flag=1; |
| | | Anchor_Vcc_time=0; |