| | |
| | | #define STARTPOLL REGPOLL//#define SWITCHBASE_DIST |
| | | #define SWITCHBASE_ZHUANDIAN |
| | | #define SWITCHBASE_DIST |
| | | void GetNearMsg(void); |
| | | enum enumtagstate |
| | | { |
| | | REGPOLL, |
| | |
| | | } |
| | | |
| | | u16 tag_time_recv[TAG_NUM_IN_SYS]; |
| | | u8 usart_send[25]; |
| | | u8 usart_send[125]; |
| | | u8 battary,button; |
| | | extern uint8_t g_pairstart; |
| | | void tag_sleep_configuraion(void) |
| | |
| | | tmp_time-=999; |
| | | sync_timer++; |
| | | if(sync_timer>=1010) |
| | | {sync_timer=0;} |
| | | { |
| | | sync_timer=0; |
| | | } |
| | | } |
| | | // TIM3->CNT=tmp_time; |
| | | } |
| | |
| | | tmp_time-=999; |
| | | sync_timer++; |
| | | if(sync_timer>=1010) |
| | | {sync_timer=0;} |
| | | { |
| | | sync_timer=0; |
| | | } |
| | | } |
| | | |
| | | //offsettimeus=ancsync_time-current_count*LPTIMER_LSB+offset; |
| | |
| | | trygetnearmsg_times = 0; |
| | | tag_state = GETNEARMSG; |
| | | mainbase_id = mindist_ancid; |
| | | GetNearMsg(); |
| | | } |
| | | |
| | | if(getsync_flag==0) |
| | |
| | | // tyncpoll_time = (tagslotpos--%max_slotpos)*slottime; |
| | | } |
| | | } |
| | | void SendHuiZongData(void) |
| | | { |
| | | usart_send[2] = 0x0c;//正常模式 |
| | | usart_send[3] = 15+8*(nearbase_num+1);//数据段长度 |
| | | memcpy(&usart_send[4],&dev_id,2); |
| | | usart_send[6] = frame_seq_nb; |
| | | usart_send[7] = frame_seq_nb>>8; |
| | | usart_send[8] = bat_percent; |
| | | usart_send[9] = tx_near_msg[BUTTON_IDX]; |
| | | //void SendHuiZongData(void) |
| | | //{ |
| | | // usart_send[2] = 0x0c;//正常模式 |
| | | // usart_send[3] = 15+8*(nearbase_num+1);//数据段长度 |
| | | // memcpy(&usart_send[4],&dev_id,2); |
| | | // usart_send[6] = frame_seq_nb; |
| | | // usart_send[7] = frame_seq_nb>>8; |
| | | // usart_send[8] = bat_percent; |
| | | // usart_send[9] = tx_near_msg[BUTTON_IDX]; |
| | | |
| | | memcpy(&usart_send[10],&intheight,2); |
| | | usart_send[12] = tag_frequency; |
| | | usart_send[13] = tagslotpos; |
| | | usart_send[14] = 0; |
| | | usart_send[15] = 0; |
| | | usart_send[16] = nearbase_num+1; |
| | | memcpy(&usart_send[17],&mainbase_id,2); |
| | | memcpy(&usart_send[19],&nearbaseid_list,2*nearbase_num); |
| | | memcpy(&usart_send[19+nearbase_num*2],&nearbase_distlist,4*nearbase_num+4); |
| | | memcpy(&usart_send[19+nearbase_num*6+4],&rec_anc_signalpower,2*nearbase_num+2); |
| | | // memcpy(&usart_send[10],&intheight,2); |
| | | // usart_send[12] = tag_frequency; |
| | | // usart_send[13] = tagslotpos; |
| | | // usart_send[14] = 0; |
| | | // usart_send[15] = 0; |
| | | // usart_send[16] = nearbase_num+1; |
| | | // memcpy(&usart_send[17],&mainbase_id,2); |
| | | // memcpy(&usart_send[19],&nearbaseid_list,2*nearbase_num); |
| | | // memcpy(&usart_send[19+nearbase_num*2],&nearbase_distlist,4*nearbase_num+4); |
| | | // memcpy(&usart_send[19+nearbase_num*6+4],&rec_anc_signalpower,2*nearbase_num+2); |
| | | |
| | | checksum = Checksum_u16(&usart_send[2],23+8*nearbase_num); |
| | | memcpy(&usart_send[25+8*nearbase_num],&checksum,2); |
| | | USART_puts(usart_send,27+8*nearbase_num); |
| | | //HexToAsciiSendUDP(usart_send,27+8*nearbase_num); |
| | | } |
| | | // checksum = Checksum_u16(&usart_send[2],23+8*nearbase_num); |
| | | // memcpy(&usart_send[25+8*nearbase_num],&checksum,2); |
| | | // USART_puts(usart_send,27+8*nearbase_num); |
| | | // //HexToAsciiSendUDP(usart_send,27+8*nearbase_num); |
| | | //} |
| | | uint8_t pack_length = 0,pack_index = 0,pack_msgtype = 0; |
| | | uint8_t motor_flag; |
| | | void NearPoll(void) |
| | |
| | | next_nearbase_num = MAX_NEARBASE_NUM-1; |
| | | } |
| | | if(nearbase_num>10) |
| | | {nearbase_num = 10;} |
| | | { |
| | | nearbase_num = 10; |
| | | } |
| | | // HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_SET); |
| | | |
| | | recbase_num=0; |
| | |
| | | timeout=ceil((float)nearbase_num*SLOT_SCALE)+3; |
| | | end_count=start_count+(timeout<<5); |
| | | if(end_count>=32768) |
| | | {end_count-=32768;} |
| | | { |
| | | end_count-=32768; |
| | | } |
| | | mainbase_dist=100000; |
| | | mainbase_lost_count++; |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | |
| | | tmp_time-=999; |
| | | sync_timer++; |
| | | if(sync_timer>=1000) |
| | | {sync_timer=0;} |
| | | { |
| | | sync_timer=0; |
| | | } |
| | | } |
| | | ancsync_time=((sync_timer)*1000+tmp_time); |
| | | SetLPTimer(ancsync_time); |
| | | if(result==0) |
| | | {while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))//不断查询芯片状态直到发送完成 |
| | | { };} |
| | | { }; |
| | | } |
| | | //HAL_GPIO_WritePin(LED1_G_GPIO_Port, LED1_G_Pin, GPIO_PIN_RESET); |
| | | break; |
| | | }else{ |
| | |
| | | mainbase_id = rec_nearbaseid; |
| | | tag_state = GETNEARMSG; |
| | | trygetnearmsg_times = 0; |
| | | GetNearMsg(); |
| | | } |
| | | #endif |
| | | |
| | |
| | | }else{ |
| | | dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | if(recbase_num!=nearbase_num+1) |
| | | {dwt_rxenable(0); } |
| | | { |
| | | dwt_rxenable(0); |
| | | } |
| | | // if(flag_rxon) |
| | | // { |
| | | // dwt_rxenable(0); |
| | |
| | | // dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | } |
| | | if(flag_finalsend!=1) |
| | | {flag_finalsend = 2;} |
| | | { |
| | | flag_finalsend = 2; |
| | | } |
| | | dwt_forcetrxoff(); |
| | | dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | // HAL_GPIO_WritePin(LED1_G_GPIO_Port, LED1_G_Pin, GPIO_PIN_SET); |
| | |
| | | if(salvebase_mindist<mainbase_dist- THRESHOLD_CHANGE_MAINBASE_DIST ) |
| | | { |
| | | changemainbase_count++; |
| | | if(changemainbase_count>tag_frequency*2) |
| | | if(changemainbase_count>=3) |
| | | { |
| | | mainbase_id = mindist_slavebaseid; |
| | | tag_state = GETNEARMSG; |
| | | trygetnearmsg_times = 0; |
| | | GetNearMsg(); |
| | | } |
| | | }else{ |
| | | changemainbase_count = 0; |
| | | } |
| | | #endif |
| | | }else if(mainbase_lost_count>5*tag_frequency) |
| | | } else if(mainbase_lost_count>3*tag_frequency) |
| | | { |
| | | tag_state = DISCPOLL; |
| | | } |
| | |
| | | tmp_time-=999; |
| | | sync_timer++; |
| | | if(sync_timer>=1010) |
| | | {sync_timer=0;} |
| | | { |
| | | sync_timer=0; |
| | | } |
| | | } |
| | | ancsync_time=((sync_timer)*1000+tmp_time); |
| | | SetLPTimer(ancsync_time); |
| | |
| | | // Poll(); |
| | | break; |
| | | } |
| | | FZNearPoll(); |
| | | userkey_state = !GET_USERKEY; |
| | | dwt_entersleep(); |
| | | } |