| | |
| | | uint16_t bind_distance,button_determinate_distance,change_by_frequency_distance; |
| | | uint8_t tag_near_frequency; |
| | | extern uint32_t tag_id_authorization_list_num; |
| | | void sort_tag_lists(void) |
| | | { |
| | | if (taglist_num <= 1) { |
| | | return; // 无需排序 |
| | | } |
| | | // 使用冒泡排序(稳定排序,实现简单) |
| | | for (size_t i = 0; i < taglist_num - 1; i++) { |
| | | for (size_t j = 0; j < taglist_num - i - 1; j++) { |
| | | if (tagdist_list[j] > tagdist_list[j + 1]) { |
| | | // 交换距离值 |
| | | uint16_t temp_dist = tagdist_list[j]; |
| | | tagdist_list[j] = tagdist_list[j + 1]; |
| | | tagdist_list[j + 1] = temp_dist; |
| | | |
| | | // 同步交换标签ID |
| | | uint32_t temp_id = tagid_list[j]; |
| | | tagid_list[j] = tagid_list[j + 1]; |
| | | tagid_list[j + 1] = temp_id; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | uint8_t tag_authorized_List[TAG_NUM_IN_SYS]; |
| | | void change_button_state(void) |
| | | { |
| | | if(tag_authorized_List[0]==1&&taglist_num>=1)//只有在有效判定范围内有授权的标签才会开启,否则都是关闭 |
| | | { |
| | | if(tagdist_list[0]<button_determinate_distance) |
| | | { |
| | | gpio_pin_set(BUTTON_PIN); |
| | | }else{ |
| | | gpio_pin_clr(BUTTON_PIN); |
| | | } |
| | | }else{ |
| | | gpio_pin_clr(BUTTON_PIN); |
| | | } |
| | | } |
| | | void TagListUpdate(void) |
| | | { |
| | | uint16_t i,j=0,k=0; |
| | |
| | | } |
| | | } |
| | | taglist_num=j; |
| | | sort_tag_lists();//增加距离小的排到前面逻辑 |
| | | if(find_flag) |
| | | { |
| | | //if(tt5) |
| | | find_in_tag_id_authorization_list(tag_id_authorization_list_num); |
| | | find_flag=0; |
| | | } |
| | | change_button_state(); |
| | | } |
| | | |
| | | uint8_t position; |
| | |
| | | resp_msg_set_ts(&send_buffer[RESP_MSG_POLL_RX_TS_IDX], poll_rx_ts_i64); |
| | | resp_msg_set_ts(&send_buffer[RESP_MSG_RESP_TX_TS_IDX], resp_tx_ts_i64);//此处时间戳int64直接转换为uint64不知道会不会有错误 |
| | | memcpy(&send_buffer[RESP_MSG_ANC_DISTOFFSET],&disoffset,2);//差个修正offset,修正有符号但是这个com表为无符号的,传过去直接赋给Int16_t相当于还原了 |
| | | if(tagdist_list[ancrec_nearbasepos]<=change_by_frequency_distance) |
| | | if(tagdist_list[ancrec_nearbasepos]<=change_by_frequency_distance&&tag_authorized_List[ancrec_nearbasepos]==1)//授权才改变频率否则不改变 |
| | | { |
| | | send_buffer[RESP_MSG_TAG_FREQUENCY]=tag_near_frequency;//新加入改变标签测距hz |
| | | } |
| | |
| | | // } |
| | | UWBIdleTask(); |
| | | } |
| | | uint8_t tag_authorized_List[TAG_NUM_IN_SYS]; |
| | | |
| | | extern uint8_t bind_flag; |
| | | void bubble_sort(uint32_t *arr, uint32_t n) |
| | | { |
| | |
| | | uint8_t i; |
| | | uint16_t tempid; |
| | | if(group_id==rx_buf[GROUP_ID_IDX]&&rx_buf[MESSAGE_TYPE_IDX] == MBX_POLL)//判断是否是和自己是同一组通讯的且为poll包 |
| | | { flag_recsuccess = 1; |
| | | { |
| | | flag_recsuccess = 1; |
| | | wltag_state=RANGE;//成功后从search切换为range |
| | | memcpy(&g_com_receive_id,&rx_buf[TAG_ID_IDX],2); |
| | | //temp_count2=phy_timer_count_get(); |
| | |
| | | // seize_anchor=1; //抢占anchor |
| | | // Anchor_RecNearPoll(i); |
| | | // } |
| | | |
| | | taglist_pos=CmpTagInList(tag_id_recv); |
| | | if(taglist_num>=ANC_MAX_NUM) |
| | | return 0; |
| | |
| | | Anchor_RecNearPoll(i); |
| | | tagdist_list[taglist_pos]=rec_ancdistlist[i]; |
| | | anchordata_bat[taglist_pos] = battary;//保存该基站电量 |
| | | if(tag_authorized_List[taglist_pos]==1) |
| | | { |
| | | if(tagdist_list[taglist_pos]<button_determinate_distance) |
| | | { |
| | | gpio_pin_set(BUTTON_PIN); |
| | | }else{ |
| | | gpio_pin_clr(BUTTON_PIN); |
| | | } |
| | | } |
| | | // if(tag_authorized_List[taglist_pos]==1) |
| | | // { |
| | | // if(tagdist_list[taglist_pos]<button_determinate_distance) |
| | | // { |
| | | // gpio_pin_set(BUTTON_PIN); |
| | | // }else{ |
| | | // gpio_pin_clr(BUTTON_PIN); |
| | | // } |
| | | // } |
| | | if(taglist_pos==taglist_num)// taglist_pos==taglist_num 说明这个基站不在当前列表中 |
| | | { //tempid==dev_id 说明基站下发测距报文有这个标签的信息 |
| | | taglist_num++; //满足上述两种情况才会添加基站ID进入列表中,否则会出现标签不在基站列表中,标签也不响应的情况 |
| | |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if((i==rec_nearbase_num&&taglist_pos==taglist_num)||(rec_nearbase_num==0&&!ExistInTagList(tag_id_recv)))//当基站不在标签列表中,标签也不在基站列表中时,随机找个时间片回复基站。 |
| | | { |
| | | Anchor_RecNearPoll(rec_nearbase_num); |
| | | { |
| | | Anchor_RecNearPoll(rec_nearbase_num); |
| | | } |
| | | } |
| | | |