| | |
| | | static uint8_t flag_syncbase,sync_seq,synclost_timer,temp_nearbaspos; |
| | | static uint16_t sync_timer; |
| | | static uint8_t send_buffer[150]; |
| | | static uint8_t frame_seq_nb2,battary,button,ancidlist_num; |
| | | static uint8_t battary,button,ancidlist_num; |
| | | uint8_t frame_seq_nb2; |
| | | uint8_t rec_nearbase_num; |
| | | static uint16_t ancidlist_rec[TAG_NUM_IN_SYS],ancidlist_send[TAG_NUM_IN_SYS],rec_ancidlist[TAG_NUM_IN_SYS],rec_ancdistlist[TAG_NUM_IN_SYS]; |
| | | static int16_t rec_antdelay; |
| | |
| | | { |
| | | |
| | | current_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | if(current_time>end_time/*||current_time<end_time+15000*/) |
| | | if(current_time>end_time+((32768/1000)*3)/*||current_time<end_time+15000*/) |
| | | { |
| | | // printf("debug2 timec:%d timee:%d\r\n",current_time,end_time); |
| | | break;} |
| | | // if(lp_time-uwb_timeout>2) |
| | | // break; |
| | | if(lp_time-uwb_timeout>2) |
| | | break; |
| | | }; |
| | | dwt_rxenable(0); |
| | | |
| | | } |
| | | uint8_t power_and_key=0; |
| | | |
| | | uint16_t target_tagid[12] = {0x1316,0x1394,0x1265,0x1318,0x1306,0x1304,0x1376,0x1312,0x1277,0x1388,0x1140,0x1392}; |
| | | uint16_t Lora_tx_ancid[50]; |
| | | uint16_t Lora_tx_ancdist[50]; |
| | | uint8_t Lora_tx_anc_electricity[50]; |
| | | uint8_t Lora_tx_ancnum=0; |
| | | uint8_t break_flag ; |
| | | uint16_t RX_TIMEOUTs_UWB; |
| | | void Anchor_App(void) |
| | | { |
| | | |
| | |
| | | u16 tempid; |
| | | uint32_t rec_syncid; |
| | | uint16_t checksum; |
| | | |
| | | uint8_t kk; |
| | | |
| | | dwt_setrxtimeout(0);//设定接收超时时间,0位没有超时时间 |
| | | dwt_rxenable(0);//打开接收 |
| | |
| | | |
| | | |
| | | start_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | end_time=start_time+((32768/1000)*20); |
| | | end_time=start_time+((32768/1000)*2); |
| | | if(end_time>=32768) |
| | | {end_time-=32768;} |
| | | current_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | |
| | | { |
| | | uint16_t tag_recv_interval; |
| | | float temp_tagpos; |
| | | |
| | | |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG | SYS_STATUS_TXFRS); |
| | | frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFL_MASK_1023;//获得接收数据长度 |
| | | recpoll_len = frame_len; |
| | |
| | | //将收到的tag_id分别写入各次通讯的包中,为多标签通讯服务,防止一次通讯中接收到不同ID标签的数据 |
| | | memcpy(&tag_id_recv,&rx_buffer[TAG_ID_IDX],2); |
| | | |
| | | |
| | | // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET); |
| | | // printf("ID %x\r\n",tag_id_recv); |
| | | switch(rx_buffer[MESSAGE_TYPE_IDX]) |
| | | {uint8_t target_tagi; |
| | |
| | | for(u8 i=0;i<rec_nearbase_num;i++) |
| | | { |
| | | if(rec_ancidlist[i] == dev_id) |
| | | { |
| | | // PushAnchorDataArray(tag_id_recv,rec_ancdistlist[i],-(int8_t)firstpath_power); |
| | | |
| | | // PushAnchorDataArray(tag_id_recv,rec_ancdistlist[i],battary); |
| | | } |
| | | { |
| | | for(kk=0;kk<Lora_tx_ancnum;kk++) |
| | | { |
| | | if(Lora_tx_ancid[kk]==tag_id_recv) |
| | | { |
| | | // Lora_tx_ancnum--; |
| | | Lora_tx_ancdist[kk]=rec_ancdistlist[i]; |
| | | Lora_tx_anc_electricity[kk]=battary; |
| | | break_flag=1; |
| | | break; |
| | | } |
| | | } |
| | | if(break_flag) |
| | | { |
| | | break_flag=0; |
| | | break; |
| | | } |
| | | Lora_tx_ancid[Lora_tx_ancnum]=tag_id_recv; |
| | | Lora_tx_ancdist[Lora_tx_ancnum]=rec_ancdistlist[i]; |
| | | Lora_tx_anc_electricity[Lora_tx_ancnum]=battary; |
| | | Lora_tx_ancnum++; |
| | | RX_TIMEOUTs_UWB++; |
| | | } |
| | | } |
| | | // #ifdef USART_ALL_OUTPUT |
| | | usart_send[2] = 0x12;//正常模式 |
| | | usart_send[3] = 8+rec_nearbase_num*4;//数据段长度 |
| | | memcpy(&usart_send[4],&tag_id_recv,2); |
| | | usart_send[6] = frame_seq_nb2;//包序 |
| | | power_and_key=battary<<1;//把按键跟电量2合1,发出去 |
| | | power_and_key=power_and_key+button; |
| | | memcpy(usart_send+7,&power_and_key,1); |
| | | |
| | | usart_send[8] = rec_nearbase_num;//lora等待应答位 |
| | | usart_send[9] = lora_yingda_flag; |
| | | memcpy(&usart_send[10],&rec_ancidlist,2*rec_nearbase_num); |
| | | memcpy(&usart_send[10+rec_nearbase_num*2],&rec_ancdistlist,2*rec_nearbase_num); |
| | | checksum = Checksum_u16(&usart_send[2],8+4*rec_nearbase_num); |
| | | memcpy(&usart_send[10+4*rec_nearbase_num],&checksum,2); |
| | | // UART_PushFrame(usart_send,12+rec_nearbase_num*4); |
| | | // #endif |
| | | //// #ifdef USART_ALL_OUTPUT |
| | | // usart_send[2] = 0x12;//正常模式 |
| | | // usart_send[3] = 8+rec_nearbase_num*4;//数据段长度 |
| | | // memcpy(&usart_send[4],&tag_id_recv,2); |
| | | // usart_send[6] = frame_seq_nb2;//包序 |
| | | // power_and_key=battary<<1;//把按键跟电量2合1,发出去 |
| | | // power_and_key=power_and_key+button; |
| | | // memcpy(usart_send+7,&power_and_key,1); |
| | | // usart_send[8] = lora_yingda_flag;//lora等待应答位 |
| | | // usart_send[9] = rec_nearbase_num;//lora等待应答位 |
| | | //// usart_send[9] = lora_yingda_flag; |
| | | // memcpy(&usart_send[10],&rec_ancidlist,2*rec_nearbase_num); |
| | | // memcpy(&usart_send[10+rec_nearbase_num*2],&rec_ancdistlist,2*rec_nearbase_num); |
| | | // checksum = Checksum_u16(&usart_send[2],8+4*rec_nearbase_num); |
| | | // memcpy(&usart_send[10+4*rec_nearbase_num],&checksum,2); |
| | | //// UART_PushFrame(usart_send,12+rec_nearbase_num*4); |
| | | //// #endif |
| | | |
| | | taglist_pos=CmpTagInList(tag_id_recv); |
| | | if(taglist_num>=TAG_NUM_IN_SYS) |