| | |
| | | u8 GetRandomSlotPos(uint32_t emptyslot) |
| | | { |
| | | u8 i,temp_value; |
| | | temp_value = GetRandomValue(); |
| | | temp_value = HAL_LPTIM_ReadCounter(&hlptim1);//GetRandomValue(); |
| | | for(i=temp_value%32;i<max_slotpos;i++) |
| | | { |
| | | if(((emptyslot>>i)&0x1)==0) |
| | |
| | | last_nearbase_num=next_nearbase_num; |
| | | nearbase_num=next_nearbase_num; |
| | | recbase_num=0; |
| | | motor_state=0; |
| | | |
| | | tx_near_msg[BATTARY_IDX] = Get_Battary(); |
| | | //tx_near_msg[BUTTON_IDX] = !READ_KEY0; |
| | |
| | | flag_getresponse=0; |
| | | start_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | recbase_num=0; |
| | | timeout=ceil((float)nearbase_num*0.6)+2; |
| | | timeout=ceil((float)nearbase_num*0.4)+2; |
| | | end_count=start_count+(timeout<<5); |
| | | if(end_count>=32768) |
| | | {end_count-=32768;} |
| | |
| | | exsistbase_list[rec_nearbasepos]=KEEP_TIMES; |
| | | memcpy(&temp_dist,&rx_buffer[DIST_IDX],4); |
| | | nearbase_distlist[rec_nearbasepos]=temp_dist; |
| | | motor_state=rx_buffer[MOTORSTATE_INDEX]&0xf; |
| | | if((rx_buffer[MOTORSTATE_INDEX]&0xf)!=3) |
| | | motor_state=rx_buffer[MOTORSTATE_INDEX]&0xf; |
| | | rec_remotepara_state=rx_buffer[MOTORSTATE_INDEX]>>4; |
| | | |
| | | mainbase_lost_count=0; |
| | |
| | | flag_getresponse=1; |
| | | memcpy(&rec_tagpos_binary,&rx_buffer[NEARMSG_EMPTYSLOTPOS_INDEX],4); |
| | | |
| | | tyncpoll_time=0; |
| | | |
| | | //时间同步 |
| | | ancsync_time=((sync_timer)*1000+tmp_time); |
| | | last_slotnum=current_slotnum; |
| | | current_slotnum=round((float)sync_timer/g_com_map[COM_INTERVAL])+1; |
| | | current_slotnum=((float)sync_timer/g_com_map[COM_INTERVAL])+1; |
| | | if(current_slotnum==last_slotnum-1) |
| | | {flag_getresponse=1;} |
| | | lastsync_timer=sync_timer; |
| | |
| | | memcpy(&temp_dist,&rx_buffer[DIST_IDX],4); |
| | | nearbase_distlist[rec_nearbasepos]=temp_dist; |
| | | |
| | | if(motor_state<rx_buffer[MOTORSTATE_INDEX]&&rx_buffer[MOTORSTATE_INDEX]!=3) |
| | | if(motor_state<(rx_buffer[MOTORSTATE_INDEX]&0xf)&&(rx_buffer[MOTORSTATE_INDEX]&0xf)!=3) |
| | | { |
| | | motor_state=rx_buffer[MOTORSTATE_INDEX]; |
| | | } |
| | |
| | | // } |
| | | tagslotpos=GetRandomSlotPos(rec_tagpos_binary); |
| | | tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; |
| | | // SetNextPollTime(tyncpoll_time); |
| | | SetNextPollTime(tyncpoll_time); |
| | | } |
| | | // tyncpoll_time=0; |
| | | next_nearbase_num=0; |
| | |
| | | tagslotpos=GetRandomSlotPos(rec_tagpos_binary); |
| | | //tagslotpos=rx_buffer[TAGSLOTPOS]; |
| | | memcpy(nearbaseid_list,&rx_buffer[NEARBASEID_INDEX],nearbase_num*2); |
| | | slottime=ceil((nearbase_num+2)*0.3)+1; |
| | | //slottime=ceil((nearbase_num+2)*0.3)+1; |
| | | tyncpoll_time=tagslotpos*slottime; |
| | | tag_state=NEARPOLL; |
| | | } |