| | |
| | | #define FINAL_MSG_FINAL_TX_TS_IDX 18 |
| | | #define FINAL_MSG_TS_LEN 4 |
| | | |
| | | //#define _UWB_4G |
| | | #define _UWB_4G |
| | | |
| | | static dwt_config_t config = { |
| | | #ifdef _UWB_4G |
| | |
| | | } |
| | | } |
| | | #include "radio.h" |
| | | #include "dw_mbx_anc.h" |
| | | u8 lora_start_poll_buff[4] = {LORA_MSGTYPE_RANGEPOLL,'I','N','G'}; |
| | | |
| | | uint16_t current_count,target_count; |
| | | typedef enum{ Next_Poll_RANGE, |
| | | Next_Poll_LORASYNC, |
| | | }nextpoll_enum; |
| | | nextpoll_enum next_poll_state; |
| | | extern uint8_t sync_lost_count; |
| | | void Tag_App(void)//发送模式(TAG标签) |
| | | { |
| | | if(next_poll_state==Next_Poll_RANGE) |
| | | SyncStateSwitch(); |
| | | if(next_poll_state==Next_Poll_RANGE) //读取本次的工作状态 测距还是同步 |
| | | { |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | target_count = GetUwbPollCount(); |
| | | SwitchLoraSettings(UWB_CHANNEL_FRQ,5); //切换lora接收频点 |
| | | while(current_count<target_count||current_count>target_count+16384) |
| | | { |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | if(current_count<target_count-300) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | SwitchLoraSettings(UWB_CHANNEL_FRQ+g_com_map[GROUP_ID],5,g_com_map[LORA_POWER]); //切换lora接收频点 |
| | | |
| | | memcpy(&lora_start_poll_buff[ANC_ID_IDX],&g_com_map[DEV_ID],2); |
| | | Radio.Send(lora_start_poll_buff, 4); |
| | | UWB_Wkup(); |
| | | UWB_Wkup(); |
| | | delay_us(700); |
| | | MBXANCPoll(); |
| | | dwt_entersleep(); |
| | | bat_percent=Get_VDDVlotage(); |
| | | next_poll_state = Next_Poll_LORASYNC; |
| | | }else{ |
| | | LoraSyncRecPoll(); |
| | |
| | | next_poll_state = Next_Poll_LORASYNC; |
| | | } |
| | | } |
| | | if(next_poll_state == Next_Poll_LORASYNC) |
| | | Radio.Sleep(); |
| | | if(next_poll_state == Next_Poll_LORASYNC) //设定下一次的唤醒时间 |
| | | { |
| | | target_count = GetUwbPollCount()-4000/LPTIMER_LSB; //同步则提前4ms唤醒,如果在同步间隔内,则会快速进入休眠。 |
| | | // if(sync_state==Sync_Lost) |
| | | // { |
| | | // target_count = GetLoraSyncCount()-(18000)/LPTIMER_LSB+sync_lost_count*1000; |
| | | // }else |
| | | { |
| | | target_count = GetLoraSyncCount()-(18000)/LPTIMER_LSB; //比上次收到的lora提前17ms唤醒(lora接收大概17ms),如果在同步间隔内,则会快速进入休眠。 |
| | | } |
| | | if(target_count<0) |
| | | target_count+=32768; |
| | | __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count); |
| | | }else{ |
| | | |
| | | target_count = GetUwbPollCount()-2000/LPTIMER_LSB; //测距提前4ms唤醒 |
| | | |
| | | if(target_count<0) |
| | | target_count+=32768; |
| | | target_count = GetUwbPollCount(); //测距提前2ms唤醒 |
| | | __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count); |
| | | } |
| | | |
| | | } |