| | |
| | | poll_rx_num++; |
| | | receive_flag=1; |
| | | recev_error_num=0; |
| | | sleep_timer_start(__MS_TO_32K_CNT(SLEEP_TIMER_NUM));//测试 |
| | | sleep_timer_start(__MS_TO_32K_CNT(SLEEP_TIMER_NUM));//测试 |
| | | } |
| | | else |
| | | { |
| | |
| | | anchordata_id[i] = ancid;//与之通信的标签id存入当前表中 |
| | | anchordata_dist[i] = dist; |
| | | anchordata_bat[i] = battary; |
| | | tagofflinetime[i]=0;//不断更新当前TAG对应离线时间 |
| | | distance=dist; |
| | | tagofflinetime[i]=0;//不断更新当前TAG对应离线时间 |
| | | distance=dist; |
| | | } |
| | | uint16_t CmpTagInList(uint16_t tagid) |
| | | { uint16_t i; |
| | |
| | | |
| | | void TagListUpdate(void) |
| | | { |
| | | uint8_t i,j=0; |
| | | for(i=0;i<anchordata_num;i++) |
| | | { |
| | | if(tagofflinetime[i]++<QUIT_SLOT_TIME) |
| | | { |
| | | anchordata_id[j]=anchordata_id[i]; |
| | | tagofflinetime[j++]=tagofflinetime[i]; |
| | | } |
| | | } |
| | | anchordata_num=j; |
| | | uint8_t i,j=0; |
| | | for(i=0; i<anchordata_num; i++) |
| | | { |
| | | if(tagofflinetime[i]++<QUIT_SLOT_TIME) |
| | | { |
| | | anchordata_id[j]=anchordata_id[i]; |
| | | tagofflinetime[j++]=tagofflinetime[i]; |
| | | } |
| | | } |
| | | anchordata_num=j; |
| | | } |
| | | uint8_t Anchor_RecNearPoll(uint8_t ancrec_nearbasepos)//根据自己是否为新基站定制消息去发送,根据是否抢占判断 |
| | | { |
| | |
| | | temp_flag=uwb_tx(send_buffer, 40,1 ,resp_tx_en_start_u32);//立即发送测试size大小 |
| | | temp_count1=phy_timer_count_get(); |
| | | while(mac_is_busy()); |
| | | gpio_pin_clr(SCL_PIN); |
| | | gpio_pin_clr(SCL_PIN); |
| | | } |
| | | int simple_main(void) |
| | | { |
| | |
| | | |
| | | // uwb configure |
| | | uwb_configure(config.phy_work_mode, board_param.tx_power_fcc[CALIB_CH(config.phy_cfg.ch_num)], &config.phy_cfg); |
| | | |
| | | |
| | | ranging_frame_type_set(config.phy_cfg.sts_pkt_cfg); |
| | | |
| | | // Register rx interrupt callback function |
| | |
| | | uint8_t i; |
| | | uint16_t tempid; |
| | | temp_count3=phy_timer_count_get(); |
| | | gpio_pin_set(SCL_PIN); |
| | | gpio_pin_set(SCL_PIN); |
| | | uwb_rx(0, 0, RX_SYNC_WIN_US);//开启接收 |
| | | while(mac_is_busy()); |
| | | while(mac_is_busy()); |
| | | temp_count2=phy_timer_count_get(); |
| | | // start_receive_count=phy_timer_count_get(); |
| | | // poll_timeout=rec_nearbase_num*US_TO_PHY_TIMER_COUNT(DELAY_BETWEEN_TWO_FRAME_UUS)+US_TO_PHY_TIMER_COUNT(DELAY_DEFAULT);//多一个多0.4ms默认0.4ms计算为0.125*4*100000,默认开启1mss |
| | |
| | | // { |
| | | if(receive_flag==1)//成功接收 |
| | | { |
| | | |
| | | |
| | | if(group_id==rx_buf[GROUP_ID_IDX]&&rx_buf[MESSAGE_TYPE_IDX] == MBX_POLL)//判断是否是和自己是同一组通讯的且为poll包 |
| | | { temp_count2=phy_timer_count_get(); |
| | | frame_seq_nb2 = rx_buf[SEQUENCE_IDX];//获取包序 |
| | |
| | | // while(mac_is_busy()); |
| | | } |
| | | //receive_flag=0; |
| | | gpio_pin_clr(SCL_PIN); |
| | | gpio_pin_clr(SCL_PIN); |
| | | } |
| | | |
| | | |
| | |
| | | uint8_t i; |
| | | uint16_t tempid; |
| | | temp_count3=phy_timer_count_get(); |
| | | gpio_pin_set(SCL_PIN); |
| | | gpio_pin_set(SCL_PIN); |
| | | uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//开启接收 |
| | | start_receive_count=phy_timer_count_get(); |
| | | poll_timeout=rec_nearbase_num*US_TO_PHY_TIMER_COUNT(DELAY_BETWEEN_TWO_FRAME_UUS)+US_TO_PHY_TIMER_COUNT(DELAY_DEFAULT);//多一个多0.4ms默认0.4ms计算为0.125*4*100000,默认开启1mss |
| | | end_receive_count=start_receive_count+poll_timeout; |
| | | if(end_receive_count>=UINT32_MAX) |
| | | {end_receive_count-=UINT32_MAX;} |
| | | current_count=phy_timer_count_get(); |
| | | while(current_count<end_receive_count||current_count>end_receive_count+HALF_SECOND_TIME)//循环接受包体,若为124.8K则是+62400000 |
| | | { |
| | | while(mac_is_busy()); |
| | | |
| | | temp_count2=phy_timer_count_get(); |
| | | if(receive_flag==1)//成功接收 |
| | | start_receive_count=phy_timer_count_get(); |
| | | poll_timeout=rec_nearbase_num*US_TO_PHY_TIMER_COUNT(DELAY_BETWEEN_TWO_FRAME_UUS)+US_TO_PHY_TIMER_COUNT(DELAY_DEFAULT);//多一个多0.4ms默认0.4ms计算为0.125*4*100000,默认开启1mss |
| | | end_receive_count=start_receive_count+poll_timeout; |
| | | if(end_receive_count>=UINT32_MAX) |
| | | { |
| | | if(group_id==rx_buf[GROUP_ID_IDX]&&rx_buf[MESSAGE_TYPE_IDX] == MBX_POLL)//判断是否是和自己是同一组通讯的且为poll包 |
| | | { temp_count2=phy_timer_count_get(); |
| | | frame_seq_nb2 = rx_buf[SEQUENCE_IDX];//获取包序 |
| | | battary = rx_buf[BATTARY_IDX]; |
| | | rec_nearbase_num=rx_buf[FZ_NEARBASENUM_INDEX]; //标签传过来的他与基站交互的基站id数目 |
| | | memcpy(&tag_id_recv,&rx_buf[TAG_ID_IDX],2); |
| | | memcpy(rec_ancidlist,&rx_buf[FZ_NEARBASEID_INDEX],2*rec_nearbase_num); |
| | | memcpy(rec_ancdistlist,&rx_buf[FZ_NEARBASEID_INDEX+2*rec_nearbase_num],2*rec_nearbase_num); |
| | | memcpy(&rec_antdelay,&rx_buf[FZ_NEARBASEID_INDEX+rec_nearbase_num*4],2); |
| | | for(i=0; i<rec_nearbase_num; i++) |
| | | { |
| | | if(rec_ancidlist[i] == dev_id) |
| | | { |
| | | PushAnchorDataArray(tag_id_recv,rec_ancdistlist[i],battary); |
| | | } |
| | | } |
| | | for(i=0; i<rec_nearbase_num; i++) |
| | | { |
| | | memcpy(&tempid,&rx_buf[FZ_NEARBASEID_INDEX+i*2],2); |
| | | if(tempid==dev_id)//也是比id如果有就更新没有就抢占 |
| | | { |
| | | seize_anchor=0; //非抢占。已存在列表中 |
| | | Anchor_RecNearPoll(i); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if(i==rec_nearbase_num) |
| | | { |
| | | seize_anchor=1; //抢占anchor |
| | | Anchor_RecNearPoll(i); |
| | | } |
| | | |
| | | } |
| | | gpio_pin_clr(SCL_PIN);//测试 |
| | | return 1;//返回发送成功标志 |
| | | } else if (receive_flag==2)//接受失败 |
| | | { |
| | | uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//再次开启接收 |
| | | end_receive_count-=UINT32_MAX; |
| | | } |
| | | //receive_flag=0; |
| | | } |
| | | gpio_pin_clr(SCL_PIN);//测试 |
| | | return 0;//返回绑定失败标志 |
| | | current_count=phy_timer_count_get(); |
| | | while(current_count<end_receive_count||current_count>end_receive_count+HALF_SECOND_TIME)//循环接受包体,若为124.8K则是+62400000 |
| | | { |
| | | while(mac_is_busy()); |
| | | |
| | | temp_count2=phy_timer_count_get(); |
| | | if(receive_flag==1)//成功接收 |
| | | { |
| | | if(group_id==rx_buf[GROUP_ID_IDX]&&rx_buf[MESSAGE_TYPE_IDX] == MBX_POLL)//判断是否是和自己是同一组通讯的且为poll包 |
| | | { temp_count2=phy_timer_count_get(); |
| | | frame_seq_nb2 = rx_buf[SEQUENCE_IDX];//获取包序 |
| | | battary = rx_buf[BATTARY_IDX]; |
| | | rec_nearbase_num=rx_buf[FZ_NEARBASENUM_INDEX]; //标签传过来的他与基站交互的基站id数目 |
| | | memcpy(&tag_id_recv,&rx_buf[TAG_ID_IDX],2); |
| | | memcpy(rec_ancidlist,&rx_buf[FZ_NEARBASEID_INDEX],2*rec_nearbase_num); |
| | | memcpy(rec_ancdistlist,&rx_buf[FZ_NEARBASEID_INDEX+2*rec_nearbase_num],2*rec_nearbase_num); |
| | | memcpy(&rec_antdelay,&rx_buf[FZ_NEARBASEID_INDEX+rec_nearbase_num*4],2); |
| | | for(i=0; i<rec_nearbase_num; i++) |
| | | { |
| | | if(rec_ancidlist[i] == dev_id) |
| | | { |
| | | PushAnchorDataArray(tag_id_recv,rec_ancdistlist[i],battary); |
| | | } |
| | | } |
| | | for(i=0; i<rec_nearbase_num; i++) |
| | | { |
| | | memcpy(&tempid,&rx_buf[FZ_NEARBASEID_INDEX+i*2],2); |
| | | if(tempid==dev_id)//也是比id如果有就更新没有就抢占 |
| | | { |
| | | seize_anchor=0; //非抢占。已存在列表中 |
| | | Anchor_RecNearPoll(i); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if(i==rec_nearbase_num) |
| | | { |
| | | seize_anchor=1; //抢占anchor |
| | | Anchor_RecNearPoll(i); |
| | | } |
| | | |
| | | } |
| | | gpio_pin_clr(SCL_PIN);//测试 |
| | | return 1;//返回发送成功标志 |
| | | } else if (receive_flag==2)//接受失败 |
| | | { |
| | | uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//再次开启接收 |
| | | } |
| | | //receive_flag=0; |
| | | } |
| | | gpio_pin_clr(SCL_PIN);//测试 |
| | | return 0;//返回绑定失败标志 |
| | | } |
| | | //} |
| | | #endif |