| | |
| | | static uint16_t ancidlist_rec[TAG_NUM_IN_SYS],ancidlist_send[TAG_NUM_IN_SYS],rec_ancidlist[TAG_NUM_IN_SYS]; |
| | | static int16_t rec_ancdistlist[TAG_NUM_IN_SYS]; |
| | | extern uint8_t group_id; |
| | | static uint16_t anc_id_recv,tag_id_recv; |
| | | static uint16_t anc_id_recv; |
| | | static uint32_t tag_id_recv; |
| | | static int16_t rec_antdelay; |
| | | extern uint32_t dev_id; |
| | | static uint16_t taglist_pos,tmp_time; |
| | | static uint32_t taglist_pos,tmp_time; |
| | | extern uint16_t tag_frequency; |
| | | extern uint16_t disoffset; |
| | | static uint8_t frame_len,recpoll_len,current_syncid,new_tagid,seize_anchor,result,g_start_sync_flag; |
| | |
| | | //resp函数 |
| | | void PushAnchorDataArray(uint16_t ancid,int16_t dist,uint8_t battary);//找到自己的id信息对应位置更新自己的交互信息 |
| | | static void resp_msg_set_ts(uint8_t *ts_field, int64_t ts);//用来对应位置放入时间戳 |
| | | static uint16_t tagid_list[TAG_NUM_IN_SYS]; |
| | | static uint32_t tagid_list[TAG_NUM_IN_SYS]; |
| | | uint32_t fliter_tagid_list[TAG_NUM_IN_SYS]; |
| | | uint16_t CmpTagInList(uint16_t tagid); |
| | | uint8_t Anchor_RecNearPoll(uint8_t ancrec_nearbasepos); |
| | | static uint8_t send_buffer[100]; |
| | |
| | | extern uint8_t recev_error_num; |
| | | uint8_t uwb_rx_flag; |
| | | extern Operation_step UWB_work_state; |
| | | void find_in_tag_id_authorization_list(uint32_t authorization_list_num); |
| | | extern int16_t first_search_flag; |
| | | typedef enum |
| | | { |
| | |
| | | #define RANGING_PERIOD_MS (1000) |
| | | |
| | | /* This is the delay from Frame RX POLL frame to send RESP Frame */ |
| | | #define POLL_RX_TO_RESP_TX_DLY_US 550U //yuan600 success 并且不卡busy |
| | | #define POLL_RX_TO_RESP_TX_DLY_US 550U //yuan550极限 |
| | | |
| | | #define RESP_TX_TO_FINAL_RX_DLY_US 500U |
| | | |
| | |
| | | /* RX window open in advance */ |
| | | #define RX_WIN_IN_ADVANCE_US (150) |
| | | |
| | | #define DELAY_BETWEEN_TWO_FRAME_UUS 300 //yuan1400 |
| | | #define DELAY_BETWEEN_TWO_FRAME_UUS 500 //yuan1400 |
| | | |
| | | /* Field index in frame */ |
| | | #define MSG_SEQ_NUM_IDX 2 |
| | |
| | | temp_count= phy_timer_count_get(); |
| | | memcpy(&rx_rpt, rx_report, sizeof(struct MAC_HW_REPORT_T)); |
| | | rx_length = 0; |
| | | OpenUWB();//再次开启UWB接收 |
| | | // OpenUWB();//再次开启UWB接收 |
| | | } |
| | | //OpenUWB();//再次开启UWB接收 |
| | | OpenUWB();//再次开启UWB接收 |
| | | } |
| | | |
| | | /* TX done process handler. */ |
| | |
| | | temp_count= phy_timer_count_get(); |
| | | temp_internal=temp_count; |
| | | resp_tx_num++; |
| | | OpenUWB();//再次开启UWB接收 |
| | | // OpenUWB();//再次开启UWB接收 |
| | | //LOG_INFO(TRACE_MODULE_APP, "poll_rx_num is %d,resp_tx_num is %d\r\n",poll_rx_num,resp_tx_num); |
| | | } |
| | | } |
| | | uint32_t start_receive_count,end_receive_count,poll_timeout,current_count,temp_resp; |
| | | uint16_t anchordata_id[TAG_NUM_IN_SYS],anchordata_dist[TAG_NUM_IN_SYS]; |
| | | extern uint32_t tag_id_authorization_list[1024]; |
| | | static uint8_t anchordata_bat[TAG_NUM_IN_SYS]; |
| | | uint8_t anchordata_num = 0; |
| | | static int32_t tagdist_list[TAG_NUM_IN_SYS]; |
| | |
| | | // } |
| | | |
| | | } |
| | | //uint16_t CmpTagInList(uint16_t tagid) |
| | | //{ uint16_t i; |
| | | // for(i=0; i<taglist_num; i++) |
| | | // { |
| | | // if(memcmp(&tagid,&anchordata_id[i],2)==0) |
| | | // break; |
| | | // } |
| | | // if(i==taglist_num) |
| | | // return taglist_num; |
| | | // //tagofflinetime[i] = 0; |
| | | // return i; |
| | | //}yuan |
| | | uint16_t CmpTagInList(uint16_t tagid) |
| | | { uint16_t i; |
| | | for(i=0; i<taglist_num; i++) |
| | | { |
| | | if(memcmp(&tagid,&anchordata_id[i],2)==0) |
| | | if(memcmp(&tagid,&tagid_list[i],2)==0) |
| | | break; |
| | | } |
| | | if(i==taglist_num) |
| | | return taglist_num; |
| | | //tagofflinetime[i] = 0; |
| | | return i; |
| | | } |
| | | uint16_t ExistInTagList(uint16_t tagid) |
| | | { uint16_t i; |
| | | for(i=0; i<taglist_num; i++) |
| | | { |
| | | if(memcmp(&tagid,&tagid_list[i],2)==0) |
| | | return 1; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | uint16_t CmpCarInExistList(uint16_t tagid) |
| | |
| | | ts2 >>= 8; |
| | | } |
| | | } |
| | | |
| | | void TagListUpdate(void) |
| | | uint8_t tt5=0; |
| | | //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 find_flag; |
| | | 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) |
| | | { |
| | | 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]; |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | anchordata_num=j; |
| | | } |
| | | 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; |
| | | for(i=0; i<taglist_num; i++) |
| | | { |
| | | if(tagofflinetime[i]++<TAG_KEEPTIMES) |
| | | { |
| | | tagid_list[j]=tagid_list[i]; |
| | | tagdist_list[j] = tagdist_list[i]; |
| | | anchordata_bat[j]=anchordata_bat[i];//电量随之更新 |
| | | tagofflinetime[j++]=tagofflinetime[i]; |
| | | } |
| | | } |
| | | 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; |
| | | uint8_t Anchor_RecNearPoll(uint8_t ancrec_nearbasepos)//根据自己是否为新基站定制消息去发送,根据是否抢占判断 |
| | | { |
| | | temp_count2=poll_rx_en_start_u32; |
| | | |
| | | memcpy(&send_buffer[GROUP_ID_IDX],&group_id,1);//组id |
| | | memcpy(&send_buffer[ANCHOR_ID_IDX],&dev_id,2);//自身id |
| | | memcpy(&send_buffer[TAG_ID_IDX],&tag_id_recv,2);//接受者id |
| | | memcpy(&send_buffer[TAG_ID_IDX],&tag_id_recv,4);//接受者id |
| | | send_buffer[MESSAGE_TYPE_IDX]=MBX_RESPONSE; |
| | | |
| | | // if(rec_nearbase_num == ancrec_nearbasepos)//抢占模式自己为新基站 |
| | |
| | | // resp_tx_en_start_u32 = phy_timer_count_get()+US_TO_PHY_TIMER_COUNT(20*rec_nearbase_num+POLL_RX_TO_RESP_TX_DLY_US+ancrec_nearbasepos*DELAY_BETWEEN_TWO_FRAME_UUS);//后面的需要根据已有基站数量进行更改,如果是抢占自己最后一个回复,要有底数 |
| | | // //这里应该有问题问一下钟工 |
| | | // }//此处设置绝对时间将poll u32改为phy_timer_count_get() |
| | | resp_tx_en_start_u32 = poll_rx_en_start_u32+US_TO_PHY_TIMER_COUNT(POLL_RX_TO_RESP_TX_DLY_US); |
| | | position=ancrec_nearbasepos; |
| | | resp_tx_en_start_u32 = poll_rx_en_start_u32+US_TO_PHY_TIMER_COUNT(POLL_RX_TO_RESP_TX_DLY_US)+ancrec_nearbasepos*US_TO_PHY_TIMER_COUNT(DELAY_BETWEEN_TWO_FRAME_UUS);//加入帧间隔 |
| | | resp_tx_ts_i64 = ranging_tx_time_correct(resp_tx_en_start_u32 + phy_shr_duration());//修正时间戳 |
| | | /* Write all timestamps in the final message. See NOTE 8 below. */ |
| | | 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&&tag_authorized_List[ancrec_nearbasepos]==1)//授权才改变频率否则不改变 |
| | | { |
| | | send_buffer[RESP_MSG_TAG_FREQUENCY]=tag_near_frequency;//新加入改变标签测距hz |
| | | } |
| | | else{ |
| | | send_buffer[RESP_MSG_TAG_FREQUENCY]=1;//新加入改变标签测距hz |
| | | } |
| | | temp_resp_i64=resp_tx_ts_i64; |
| | | temp_count3= phy_timer_count_get(); |
| | | flag_temp2=uwb_tx(send_buffer, 40,1 ,resp_tx_en_start_u32);//立即发送测试size大小 |
| | | tagofflinetime[taglist_pos] = 0;//更新标签通信 |
| | | // temp_count1=phy_timer_count_get(); |
| | | //while(mac_is_busy()); |
| | | gpio_pin_clr(SCL_PIN); |
| | | //gpio_pin_clr(SCL_PIN); |
| | | } |
| | | |
| | | uint16_t uwb_searchcount; |
| | |
| | | &&!((end_receive_count-current_count_calibration<=MS_TO_PHY_TIMER_COUNT(200))||(end_receive_count+(UINT32_MAX-current_count_calibration)<=MS_TO_PHY_TIMER_COUNT(200)))) |
| | | { |
| | | start_receive_count_calibration=current_count_calibration;//更新开始时间 |
| | | // MotorPoll(); |
| | | |
| | | |
| | | if(secondtask_search_count++%2==0) |
| | | { |
| | |
| | | { |
| | | uwb_rx_force_off(1); |
| | | uwb_rx_flag=0; |
| | | LOG_INFO(TRACE_MODULE_APP,"关闭uwb_rx\r\n"); |
| | | //LOG_INFO(TRACE_MODULE_APP,"关闭uwb_rx\r\n"); |
| | | } |
| | | void OpenUWB(void) |
| | | { |
| | | flag_temp1=uwb_rx(0, 0,range_timeout_us);//提交接收请求 |
| | | uwb_rx_flag=1; |
| | | LOG_INFO(TRACE_MODULE_APP,"打开uwb_rx\r\n"); |
| | | //LOG_INFO(TRACE_MODULE_APP,"打开uwb_rx\r\n"); |
| | | } |
| | | void UWBOneSecondTask(void) |
| | | { |
| | | TagListUpdate();//更新标签数 |
| | | uwb_losttimer++; |
| | | if(uwb_losttimer>g_com_map[UWB_RNAGE_TIME]) |
| | | uwb_losttimer=g_com_map[UWB_RNAGE_TIME]+1;//防止溢出 |
| | | if(uwb_losttimer>g_com_map[UWB_RNAGE_TIME]) |
| | | uwb_losttimer=g_com_map[UWB_RNAGE_TIME]+1;//防止溢出 |
| | | } |
| | | void UWBIdleTask(void) |
| | | { |
| | |
| | | } |
| | | int uwb_app_poll(void) |
| | | { |
| | | switch(wltag_state) |
| | | { |
| | | case RANGE: |
| | | if(HIDO_TimerGetTick()-wltag_uwbtimer>2&&uwb_rx_flag==0) |
| | | { |
| | | wltag_uwbtimer = HIDO_TimerGetTick(); |
| | | OpenUWB(); |
| | | } |
| | | else if(HIDO_TimerGetTick()-wltag_uwbtimer>1&&uwb_rx_flag==1) |
| | | { |
| | | wltag_uwbtimer = HIDO_TimerGetTick(); |
| | | CloseUWB(); |
| | | } |
| | | if(uwb_losttimer>g_com_map[UWB_RNAGE_TIME]) |
| | | { |
| | | wltag_statetimer = HIDO_TimerGetTick(); |
| | | if(uwb_rx_flag==0)//若要切换到搜索模式时没有开启则开启UWB |
| | | { |
| | | OpenUWB(); |
| | | } |
| | | wltag_state = SEARCH; |
| | | } |
| | | break; |
| | | case SEARCH: |
| | | if(HIDO_TimerGetTick()-wltag_statetimer>1) |
| | | { |
| | | wltag_statetimer = HIDO_TimerGetTick(); |
| | | wltag_state = CLOSE; |
| | | CloseUWB(); |
| | | } |
| | | break; |
| | | case CLOSE: |
| | | if(HIDO_TimerGetTick()-wltag_statetimer>g_com_map[UWB_WAIT_TIME]) |
| | | { |
| | | wltag_statetimer = HIDO_TimerGetTick(); |
| | | wltag_state = SEARCH; |
| | | OpenUWB(); |
| | | } |
| | | break; |
| | | } |
| | | // switch(wltag_state) |
| | | // { |
| | | // case RANGE: |
| | | // if(HIDO_TimerGetTick()-wltag_uwbtimer>2&&uwb_rx_flag==0) |
| | | // { |
| | | // wltag_uwbtimer = HIDO_TimerGetTick(); |
| | | // OpenUWB(); |
| | | // } |
| | | // else if(HIDO_TimerGetTick()-wltag_uwbtimer>1&&uwb_rx_flag==1) |
| | | // { |
| | | // wltag_uwbtimer = HIDO_TimerGetTick(); |
| | | // CloseUWB(); |
| | | // } |
| | | // if(uwb_losttimer>g_com_map[UWB_RNAGE_TIME]) |
| | | // { |
| | | // wltag_statetimer = HIDO_TimerGetTick(); |
| | | // if(uwb_rx_flag==0)//若要切换到搜索模式时没有开启则开启UWB |
| | | // { |
| | | // OpenUWB(); |
| | | // } |
| | | // wltag_state = SEARCH; |
| | | // } |
| | | // break; |
| | | // case SEARCH: |
| | | // if(HIDO_TimerGetTick()-wltag_statetimer>1) |
| | | // { |
| | | // wltag_statetimer = HIDO_TimerGetTick(); |
| | | // wltag_state = CLOSE; |
| | | // CloseUWB(); |
| | | // } |
| | | // break; |
| | | // case CLOSE: |
| | | // if(HIDO_TimerGetTick()-wltag_statetimer>g_com_map[UWB_WAIT_TIME]) |
| | | // { |
| | | // wltag_statetimer = HIDO_TimerGetTick(); |
| | | // wltag_state = SEARCH; |
| | | // OpenUWB(); |
| | | // } |
| | | // break; |
| | | // } |
| | | UWBIdleTask(); |
| | | } |
| | | |
| | | extern uint8_t bind_flag; |
| | | void bubble_sort(uint32_t *arr, uint32_t n) |
| | | { |
| | | if (n <= 1) return; // 无需排序 |
| | | |
| | | uint32_t i, j; |
| | | uint8_t swapped; // 标记是否发生交换 |
| | | |
| | | for (i = 0; i < n - 1; i++) { |
| | | swapped = 0; // 重置交换标记 |
| | | |
| | | // 每轮将最大元素"冒泡"到末尾 |
| | | for (j = 0; j < n - i - 1; j++) { |
| | | if (arr[j] > arr[j + 1]) { |
| | | // 交换相邻元素 |
| | | uint32_t temp = arr[j]; |
| | | arr[j] = arr[j + 1]; |
| | | arr[j + 1] = temp; |
| | | swapped = 1; // 标记发生了交换 |
| | | } |
| | | } |
| | | |
| | | // 优化:如果本轮未发生交换,说明数组已排序 |
| | | if (!swapped) break; |
| | | } |
| | | } |
| | | uint16_t tag_authorization_list_num_temp; |
| | | void fliter_tag_id_authorization_list(uint16_t*tag_authorization_list_real_num) |
| | | { |
| | | uint32_t filtered_count = 0; |
| | | |
| | | // 遍历所有标签,将距离小于阈值的ID存入结果数组 |
| | | for (uint32_t i = 0; i < taglist_num; i++) { |
| | | if (tagdist_list[i] < bind_distance&&tagid_list[i]!=0) { |
| | | fliter_tagid_list[filtered_count] = tagid_list[i]; |
| | | filtered_count++; |
| | | } |
| | | //fliter_tagid_list |
| | | } |
| | | *tag_authorization_list_real_num=filtered_count; |
| | | } |
| | | void copy_taglist_to_flash(void) |
| | | { |
| | | fliter_tag_id_authorization_list(&tag_authorization_list_num_temp);//过滤调id为0的标签和不满足绑定距离的标签 |
| | | memset(tag_id_authorization_list,0,sizeof(tag_id_authorization_list));//清空上一次数组防止重叠 |
| | | memcpy(&tag_id_authorization_list,&fliter_tagid_list,tag_authorization_list_num_temp*4);//复制满足条件数组 |
| | | bubble_sort(&tag_id_authorization_list,tag_authorization_list_num_temp);//进行排序后存入,为二分法做基础 |
| | | save_taglist_map_to_flash();//存入flash |
| | | } |
| | | |
| | | void find_in_tag_id_authorization_list(uint32_t authorization_list_num) |
| | | { |
| | | // for (uint32_t i = 0; i < taglist_num; i++) { |
| | | // uint32_t target = tagid_list[i]; |
| | | // uint32_t left = 0; |
| | | // uint32_t right = authorization_list_num - 1; // 授权列表的最大索引 |
| | | // uint8_t found = 0; |
| | | // |
| | | // // 二分查找循环 |
| | | // while (left <= right) { |
| | | // uint32_t mid = left + ((right - left) >> 1); // 防止整数溢出 |
| | | // uint32_t mid_val = tag_id_authorization_list[mid]; |
| | | // |
| | | // if (mid_val == target) { |
| | | // found = 1; |
| | | // break; // 找到目标值,立即退出循环 |
| | | // } else if (mid_val < target) { |
| | | // left = mid + 1; |
| | | // } else { |
| | | // right = mid - 1; |
| | | // } |
| | | // LOG_INFO(TRACE_MODULE_APP, "DEBUG: i=%u, left=%d, right=%d, found=%u\n", i, left, right, found); |
| | | // } |
| | | //// |
| | | //// // 存储查找结果 |
| | | //// tag_authorized_List[i] = found; |
| | | // } |
| | | { |
| | | // 如果授权列表为空,直接全部标记为0 |
| | | if (authorization_list_num == 0) { |
| | | for (int i = 0; i < taglist_num; i++) { |
| | | tag_authorized_List[i] = 0; |
| | | } |
| | | return; |
| | | } |
| | | |
| | | // 遍历需要查找的每个ID |
| | | for (int i = 0; i < taglist_num; i++) { |
| | | int key = tagid_list[i]; |
| | | int low = 0; |
| | | int high = authorization_list_num - 1; |
| | | int found = 0; // 标记是否找到 |
| | | |
| | | // 在授权列表中执行二分查找 |
| | | while (low <= high) { |
| | | int mid = low + (high - low) / 2; // 防止整数溢出 |
| | | |
| | | if (tag_id_authorization_list[mid] == key) { |
| | | found = 1; // 找到匹配项 |
| | | break; |
| | | } else if (tag_id_authorization_list[mid] < key) { |
| | | low = mid + 1; // 在右半部分继续查找 |
| | | } else { |
| | | high = mid - 1; // 在左半部分继续查找 |
| | | } |
| | | } |
| | | |
| | | // 根据查找结果设置输出列表 |
| | | tag_authorized_List[i] = found ? 1 : 0; |
| | | } |
| | | } |
| | | } |
| | | |
| | | int Anchor_App(void) |
| | | { |
| | | 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(); |
| | |
| | | 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(&tag_id_recv,&rx_buf[TAG_ID_IDX],4); |
| | | 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) |
| | | { temp_recdist_before_offset=rec_ancdistlist[i]; |
| | | rec_ancdistlist[i]+=(int16_t)g_com_map[DIST_OFFSET]; |
| | | 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; |
| | | } |
| | | } |
| | | // for(i=0; i<rec_nearbase_num; i++) |
| | | // { |
| | | // if(rec_ancidlist[i] == dev_id) |
| | | // { temp_recdist_before_offset=rec_ancdistlist[i]; |
| | | // rec_ancdistlist[i]+=(int16_t)g_com_map[DIST_OFFSET]; |
| | | // 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); |
| | | } |
| | | }else{ |
| | | OpenUWB();//接收到不是自己的包再次开启UWB接收 |
| | | // if(i==rec_nearbase_num) |
| | | // { |
| | | // seize_anchor=1; //抢占anchor |
| | | // Anchor_RecNearPoll(i); |
| | | // } |
| | | |
| | | taglist_pos=CmpTagInList(tag_id_recv); |
| | | if(taglist_num>=ANC_MAX_NUM) |
| | | return 0; |
| | | for(i=0; i<rec_nearbase_num; i++) |
| | | { |
| | | memcpy(&tempid,&rx_buf[FZ_NEARBASEID_INDEX+i*2],2); |
| | | if(tempid==dev_id) |
| | | { |
| | | |
| | | 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(taglist_pos==taglist_num)// taglist_pos==taglist_num 说明这个基站不在当前列表中 |
| | | { //tempid==dev_id 说明基站下发测距报文有这个标签的信息 |
| | | taglist_num++; //满足上述两种情况才会添加基站ID进入列表中,否则会出现标签不在基站列表中,标签也不响应的情况 |
| | | tagid_list[taglist_pos] = tag_id_recv;//新增基站 |
| | | find_flag=1; |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if((i==rec_nearbase_num&&taglist_pos==taglist_num)||(rec_nearbase_num==0&&!ExistInTagList(tag_id_recv)))//当基站不在标签列表中,标签也不在基站列表中时,随机找个时间片回复基站。 |
| | | { |
| | | Anchor_RecNearPoll(rec_nearbase_num); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | int UwbRange(void) |
| | | { |