| | |
| | | |
| | | //#define _UWB_4G |
| | | |
| | | static dwt_config_t config = { |
| | | dwt_config_t config = { |
| | | #ifdef _UWB_4G |
| | | 2, /* Channel number. */ |
| | | #else |
| | |
| | | } |
| | | } |
| | | #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; |
| | | #define UWB 0 |
| | | #define LORA 1 |
| | | static uint8_t lora_sendbuffer[40]; |
| | | static uint16_t wg_report_id=0xffff; |
| | | uint8_t seq_num; |
| | | static u16 checksum; |
| | | #define SEQNUM_IDX 6 //标签报文序号 |
| | | #define BAT_IDX 7 //标签电量 |
| | | #define STATE_IDX 8 |
| | | #define ANCID_IDX 30 //校验在4*ancnum+ANCID_IDX 位置 |
| | | #define LORA5_CHANNEL_FRQ 478 |
| | | #define LORA5_CHANNEL_SF 7 |
| | | uint8_t poll_state; |
| | | void Lora_Poll(void) |
| | | { |
| | | |
| | | SwitchLoraSettings(LORA5_CHANNEL_FRQ,LORA5_CHANNEL_SF,22); |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_GPS; |
| | | lora_sendbuffer[MSG_LENGTH] = 30; |
| | | memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&g_com_map[DEV_ID],2); |
| | | memcpy(&lora_sendbuffer[DEST_ID_IDX],&wg_report_id,2); |
| | | lora_sendbuffer[SEQNUM_IDX] = seq_num++; |
| | | lora_sendbuffer[BAT_IDX] = bat_percent; |
| | | lora_sendbuffer[STATE_IDX] = 0; |
| | | // memcpy(&lora_sendbuffer[GPS_JINGDU_IDX],&gps_jingdu,8); |
| | | // memcpy(&lora_sendbuffer[GPS_WEIDU_IDX],&gps_jingdu,8); |
| | | // lora_sendbuffer[GPS_STATE_IDX] = gps_state; |
| | | // lora_sendbuffer[GPS_SATEL_NUM_IDX] = gps_satel_num; |
| | | // lora_sendbuffer[GPS_SPOWER_IDX] = gps_signalpower; |
| | | // lora_sendbuffer[GPS_CHAFENLINGQI] = gps_chafenlingqi; |
| | | // lora_sendbuffer[ANCNUM_IDX] = report_ancnum; |
| | | // memcpy(&lora_sendbuffer[ANCID_IDX],report_ancid,report_ancnum*2); |
| | | // memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*2],report_ancdist,report_ancnum*2); |
| | | checksum = Checksum_u16(lora_sendbuffer,4*0+ANCID_IDX); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+0*4],&checksum,2); |
| | | Radio.Send(lora_sendbuffer,ANCID_IDX+0*4+2); |
| | | } |
| | | nextpoll_enum next_poll_state; |
| | | extern uint8_t sync_lost_count; |
| | | extern uint8_t Lorahuifu_flag; |
| | | extern int16_t intheight; |
| | | extern u16 uwbdistance; |
| | | extern float bat_volt; |
| | | extern uint8_t shuzu[3]; |
| | | extern uint8_t datashuju[50]; |
| | | extern uint8_t datachangdu; |
| | | void Tag_App(void)//发送模式(TAG标签) |
| | | { |
| | | if(next_poll_state==Next_Poll_RANGE) |
| | | // SyncStateSwitch(); |
| | | if(poll_state==UWB) //读取本次的工作状态 测距还是同步 |
| | | { |
| | | poll_state=LORA; |
| | | 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; |
| | | } |
| | | } |
| | | // g_com_map[LORA_POWER]=22; |
| | | // g_com_map2[LORA_POWER]=22; |
| | | 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; |
| | | // next_poll_state = Next_Poll_LORASYNC; |
| | | }else{ |
| | | LoraSyncRecPoll(); |
| | | if(GetRangeState()) //获取当前测距状态,是否开启。如果开启下次为测距,否为同步 |
| | | poll_state=UWB; |
| | | Lora_Poll(); |
| | | if(intheight!=0) |
| | | { |
| | | next_poll_state = Next_Poll_RANGE; |
| | | }else{ |
| | | next_poll_state = Next_Poll_LORASYNC; |
| | | } |
| | | // printf("高度值:%d\r\n",intheight); |
| | | uartsend(6,intheight); |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t2.bco=2024"); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | } |
| | | if(uwbdistance!=0) |
| | | { |
| | | // printf("UWB测距值:%d\r\n",uwbdistance); |
| | | uartsend(4,uwbdistance); |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t0.bco=2024"); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | } |
| | | if(Lorahuifu_flag) |
| | | { |
| | | Lorahuifu_flag=0; |
| | | uartsend(5,0); |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t1.bco=2024"); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | } |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t7.txt=\"%.2f\"",bat_volt); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | if(bat_volt>0) |
| | | { |
| | | memset(datashuju,0,sizeof(datashuju)); |
| | | USART_puts(shuzu, 3);//开始结束都要发 |
| | | datachangdu=sprintf(datashuju,"t3.bco=2024"); |
| | | USART_puts(datashuju, datachangdu); |
| | | USART_puts(shuzu, 3); |
| | | } |
| | | // LoraSyncRecPoll(); |
| | | // if(GetRangeState()) //获取当前测距状态,是否开启。如果开启下次为测距,否为同步 |
| | | // { |
| | | // next_poll_state = Next_Poll_RANGE; |
| | | // }else{ |
| | | // next_poll_state = Next_Poll_LORASYNC; |
| | | // } |
| | | } |
| | | if(next_poll_state == Next_Poll_LORASYNC) |
| | | { |
| | | target_count = GetUwbPollCount()-4000/LPTIMER_LSB; //同步则提前4ms唤醒,如果在同步间隔内,则会快速进入休眠。 |
| | | if(target_count<0) |
| | | target_count+=32768; |
| | | __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count); |
| | | }else{ |
| | | // Radio.Sleep(); |
| | | // if(next_poll_state == Next_Poll_LORASYNC) //设定下一次的唤醒时间 |
| | | // { |
| | | //// 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; |
| | | __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count); |
| | | } |
| | | // target_count = GetUwbPollCount(); //测距提前2ms唤醒 |
| | | // __HAL_LPTIM_COMPARE_SET(&hlptim1, target_count); |
| | | // } |
| | | |
| | | } |