| | |
| | | #include "dw_mbx_tag.h" |
| | | |
| | | #define DELAY_BETWEEN_TWO_FRAME_UUS 300 |
| | | #define DELAY_BETWEEN_TWO_FRAME_UUS 400 |
| | | #define POLL_RX_TO_RESP_TX_DLY_UUS 470 |
| | | #define UUS_TO_DWT_TIME 65536 |
| | | |
| | |
| | | #define TAG_NUM_IN_SYS 25 |
| | | |
| | | #define TAG_KEEPTIMES 30 |
| | | #define REPORT_TAG_KEEPTIMES 3 |
| | | static uint16_t ancidlist_rec[TAG_NUM_IN_SYS],ancidlist_send[TAG_NUM_IN_SYS],rec_ancidlist[TAG_NUM_IN_SYS],rec_ancdistlist[TAG_NUM_IN_SYS]; |
| | | static u8 frame_seq_nb2,battary,button,uwb_losttimer,taglist_pos; |
| | | |
| | |
| | | // delay_ms(10); |
| | | } |
| | | uint8_t report_ancnum; |
| | | uint16_t report_ancdist[ANC_MAX_NUM],report_ancid[ANC_MAX_NUM]; |
| | | void TagListUpdate(void) |
| | | { |
| | | uint16_t i,j=0,temp[TAG_NUM_IN_SYS]; |
| | | uint16_t i,j=0,k=0,temp[TAG_NUM_IN_SYS]; |
| | | for(i=0;i<taglist_num;i++) |
| | | { |
| | | if(tagofflinetime[i]++<REPORT_TAG_KEEPTIMES) |
| | | { |
| | | report_ancid[k]=tagid_list[i]; |
| | | report_ancdist[k++]=tagdist_list[i]; |
| | | } |
| | | if(tagofflinetime[i]++<TAG_KEEPTIMES) |
| | | { |
| | | tagid_list[j]=tagid_list[i]; |
| | | tagdist_list[j] = tagdist_list[i]; |
| | | tagofflinetime[j++]=tagofflinetime[i]; |
| | | } |
| | | } |
| | | report_ancnum = k; |
| | | taglist_num=j; |
| | | } |
| | | uint16_t CmpTagInList(uint16_t tagid) |
| | |
| | | } |
| | | if(i==rec_nearbase_num&&taglist_pos==taglist_num)//当基站不在标签列表中,标签也不在基站列表中时,随机找个时间片回复基站。 |
| | | { |
| | | Anchor_RecNearPoll(rec_nearbase_num+start_time%5); |
| | | //Anchor_RecNearPoll(rec_nearbase_num+start_time%2); |
| | | Anchor_RecNearPoll(rec_nearbase_num); |
| | | } |
| | | } |
| | | |
| | |
| | | extern u8 wg_lost_count; |
| | | uint16_t wg_report_freq,wg_report_id; |
| | | #define WG_LOST_SWITCH_THRES 3 |
| | | #define WG_LOST_NOUWB_COUNT 30 |
| | | u8 closeuwb_flag; |
| | | void LoraReportFreqPoll(void) |
| | | { |
| | | if(wg_lost_count++>WG_LOST_NOUWB_COUNT) |
| | | { |
| | | closeuwb_flag = 1; |
| | | }else{ |
| | | closeuwb_flag = 0; |
| | | } |
| | | if(wg_state==WG_Lost) |
| | | { |
| | | wg_report_id = 0xffff; |
| | | wg_report_freq = REPORT_MANGE_CHANNEL_FRQ; //如果丢失链接就进入WG管理信道。 |
| | | }else{ |
| | | if(wg_lost_count++>WG_LOST_SWITCH_THRES) |
| | | if(wg_lost_count>WG_LOST_SWITCH_THRES) |
| | | { |
| | | wg_state = WG_Lost; |
| | | wg_state = WG_Lost; |
| | | } |
| | | } |
| | | } |
| | | static u16 checksum; |
| | | u8 gps_state,gps_chafenlingqi,gps_satel_num; |
| | | u8 gps_state,gps_chafenlingqi,gps_satel_num,gps_signalpower; |
| | | double gps_jingdu,gps_weidu; |
| | | extern u8 bat_percent,stationary_flag; |
| | | int16_t sendcount = 0,tp1; |
| | | u8 flag_getwgresp; |
| | | void LoraReportPoll(void) |
| | | { |
| | | |
| | |
| | | TagListUpdate(); |
| | | |
| | | LoraReportFreqPoll(); |
| | | |
| | | flag_getwgresp = 0; |
| | | SwitchLoraSettings(wg_report_freq,REPORT_CHANNEL_SF,g_com_map[LORA_POWER]); |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_GPS; |
| | | lora_sendbuffer[MSG_LENGTH] = 4*taglist_num+30; |
| | | lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+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++; |
| | |
| | | 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] = taglist_num; |
| | | memcpy(&lora_sendbuffer[ANCID_IDX],tagid_list,taglist_num*2); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+taglist_num*2],tagdist_list,taglist_num*2); |
| | | checksum = Checksum_u16(lora_sendbuffer,4*taglist_num+ANCID_IDX); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+taglist_num*4],&checksum,2); |
| | | Radio.Send(lora_sendbuffer,ANCID_IDX+taglist_num*4+2); |
| | | 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*report_ancnum+ANCID_IDX); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*4],&checksum,2); |
| | | Radio.Send(lora_sendbuffer,ANCID_IDX+report_ancnum*4+2); |
| | | LED_TB_ON; |
| | | // bat_percent=Get_Battary(); |
| | | |
| | | } |