| | |
| | | .sts_key2 = 0xD1D336AA, |
| | | .sts_key3 = 0x14148674, |
| | | }; |
| | | static struct anchor_id_car{ |
| | | uint16_t anchor_new_id; |
| | | uint16_t change_num; |
| | | }; |
| | | /* Buffer to store received frame */ |
| | | |
| | | /* Frames used in the ranging process |
| | |
| | | anchordata_num++; |
| | | } |
| | | anchordata_id[i] = ancid;//与之通信的标签id存入当前表中 |
| | | distance=dist*0.5+anchordata_dist[i]*0.5; |
| | | distance=dist*0.5+(int16_t)anchordata_dist[i]*0.5; |
| | | anchordata_dist[i] = dist; |
| | | anchordata_bat[i] = battary; |
| | | tagofflinetime[i]=0;//不断更新当前TAG对应离线时间 |
| | |
| | | } |
| | | if(i==taglist_num) |
| | | return taglist_num; |
| | | //tagofflinetime[i] = 0; |
| | | return i; |
| | | } |
| | | |
| | | uint16_t CmpCarInExistList(uint16_t tagid) |
| | | { uint16_t i; |
| | | for(i=0; i<anchordata_num; i++) |
| | | { |
| | | if(memcmp(&tagid,&anchordata_id[i],2)==0) |
| | | break; |
| | | } |
| | | if(i==anchordata_num) |
| | | return anchordata_num; |
| | | //tagofflinetime[i] = 0; |
| | | return i; |
| | | } |
| | |
| | | uint32_t start_receive_count_calibration; |
| | | uint32_t current_count_calibration; |
| | | uint32_t get_in_num,get_out_num; |
| | | struct anchor_id_car anchor_id_in_car[TAG_NUM_IN_SYS],anchor_id_out_car[TAG_NUM_IN_SYS]; |
| | | int16_t change_count[TAG_NUM_IN_SYS]; |
| | | uint16_t anchor_id_in[TAG_NUM_IN_SYS],anchor_id_out[TAG_NUM_IN_SYS]; |
| | | uint8_t secondtask_search_count,secondtask_search_flag; |
| | | extern uint8_t g_start_send_flag,search_open_flag = 1,link_success_flag,flag_secondtask; |
| | | uint16_t CmpCarInTable(uint16_t tagid) |
| | | { uint16_t i; |
| | | for(i=0; i<get_in_num; i++) |
| | | { |
| | | if(memcmp(&tagid,&anchor_id_in[i],2)==0) |
| | | break; |
| | | } |
| | | if(i==get_in_num) |
| | | return get_in_num; |
| | | //tagofflinetime[i] = 0; |
| | | return i; |
| | | } |
| | | void TagListUpdate_person_num(void) |
| | | { |
| | | uint8_t i,j=0; |
| | |
| | | anchordata_num=j; |
| | | |
| | | } |
| | | void in_table_log(void) |
| | | { |
| | | uint32_t u32LogLen,datalenth; |
| | | char acReadponse[200]; |
| | | u32LogLen = snprintf(acReadponse, sizeof(acReadponse), "车内:%d 人 ID:",get_in_num,get_out_num); |
| | | for(uint16_t i=0;i<get_in_num;i++) |
| | | { |
| | | datalenth = sprintf((char*)&acReadponse[u32LogLen],",%04X",anchor_id_in[i]); |
| | | u32LogLen += datalenth; |
| | | } |
| | | LOG_INFO(TRACE_MODULE_APP,"%s\r\n",acReadponse); |
| | | } |
| | | void TagListUpdate_person_num_car(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]; |
| | | }else{ |
| | | change_count[j]=0; |
| | | } |
| | | } |
| | | anchordata_num=j; |
| | | |
| | | } |
| | | void Calibration_Time(void) |
| | | { |
| | | current_count_calibration=phy_timer_count_get(); |
| | |
| | | } |
| | | } |
| | | uint16_t g_com_receive_id; |
| | | int Uwb_One_Shot(void) |
| | | int add_in_car_table(uint16_t position_anchor_in_table,uint16_t receive_success_id) |
| | | { |
| | | |
| | | if(position_anchor_in_table==get_in_num)//新增 |
| | | { |
| | | if(get_in_num<TAG_NUM_IN_SYS-1) |
| | | get_in_num++; |
| | | } |
| | | anchor_id_in[position_anchor_in_table]=receive_success_id; |
| | | } |
| | | int delete_in_car_table(uint16_t position_anchor_in_table) |
| | | { |
| | | if(position_anchor_in_table<get_in_num)//若在列表里 |
| | | { |
| | | for(int i=position_anchor_in_table+1;i<get_in_num;i++) |
| | | { |
| | | anchor_id_in[i-1]=anchor_id_in[i];//缺个数量-- |
| | | } |
| | | get_in_num--;//更新列表现存数 |
| | | } |
| | | } |
| | | void check_if_in_or_out(uint16_t receive_success_id,int32_t distance_from_tag,float rssi_ant0,float rssi_ant2) |
| | | { |
| | |
| | | } |
| | | anchor_id_out[get_out_num-1]=receive_success_id; |
| | | } |
| | | } |
| | | } |
| | | |
| | | void check_if_in_or_out_car(uint16_t receive_success_id,int32_t distance_from_tag,float rssi_ant0,float rssi_ant2) |
| | | { |
| | | uint8_t i; |
| | | uint16_t position_anchor_exist,position_anchor_in_table; |
| | | position_anchor_exist=CmpCarInExistList(receive_success_id); |
| | | if(rssi_ant0>rssi_ant2&&distance_from_tag<200) |
| | | { |
| | | change_count[position_anchor_exist]++; |
| | | if(change_count[position_anchor_exist]>=3) |
| | | { change_count[position_anchor_exist]=3; |
| | | position_anchor_in_table=CmpCarInTable(receive_success_id); |
| | | add_in_car_table(position_anchor_in_table,receive_success_id); |
| | | } |
| | | }else if(rssi_ant0<rssi_ant2&&distance_from_tag<200) |
| | | { |
| | | change_count[position_anchor_exist]--; |
| | | if(change_count[position_anchor_exist]<=-3) |
| | | {change_count[position_anchor_exist]=-3; |
| | | position_anchor_in_table=CmpCarInTable(receive_success_id); |
| | | delete_in_car_table(position_anchor_in_table); |
| | | } |
| | | } |
| | | } |
| | | int UwbRange(void) |
| | |
| | | recev_error_num=0; |
| | | //range_timeout_us=5000;//恢复为5000进入range后 |
| | | LOG_INFO(TRACE_MODULE_APP,"标签ID:%X,距离: %d 信号强度ANT0: %f,信号强度ANT2: %f\r\n",g_com_receive_id,distance,sts_rssi[0],sts_rssi[2]); |
| | | check_if_in_or_out(g_com_receive_id,distance,sts_rssi[0],sts_rssi[2]); |
| | | check_if_in_or_out_car(g_com_receive_id,distance,sts_rssi[0],sts_rssi[2]); |
| | | |
| | | |
| | | gpio_pin_clr(SCL_PIN); |