| | |
| | | } |
| | | return i; |
| | | } |
| | | extern uint8_t gps_state; |
| | | uint32_t temp231; |
| | | extern uint32_t uwbled,gpsled,loraled,powerled; |
| | | uint32_t uwbdezhuangtai; |
| | | void MbxTagUwbRec(void) |
| | | { |
| | | |
| | |
| | | uint32_t rec_syncid,status_reg; |
| | | uint16_t checksum; |
| | | uint8_t kk; |
| | | |
| | | dwt_setrxtimeout(3000);//设定接收超时时间,0位没有超时时间 |
| | | dwt_rxenable(0);//打开接收 |
| | | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET); |
| | | // HAL_GPIO_WritePin(GPIOC, GPIO_PIN_5, GPIO_PIN_SET); |
| | | // printf("成功接收LORA\r\n"); |
| | | temp231 = dwt_read32bitreg(CHAN_CTRL_ID) ; |
| | | start_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | timeout=100; //单位0.1ms |
| | |
| | | if(current_time>=end_time&¤t_time<end_time+15000) |
| | | break; |
| | | }; |
| | | |
| | | uwbdezhuangtai=status_reg; |
| | | // printf("UWB״̬:%x\r\n",uwbdezhuangtai); |
| | | if (status_reg & SYS_STATUS_RXFCG && status_reg!=0xffffffff)//成功接收 |
| | | { |
| | | uint16_t tag_recv_interval; |
| | |
| | | dwt_readrxdata(rx_buffer, frame_len, 0);//读取接收数据 |
| | | memcpy(&anc_id_recv,&rx_buffer[ANCHOR_ID_IDX],2); |
| | | //将收到的tag_id分别写入各次通讯的包中,为多标签通讯服务,防止一次通讯中接收到不同ID标签的数据 |
| | | memcpy(&tag_id_recv,&rx_buffer[TAG_ID_IDX],2); |
| | | memcpy(&tag_id_recv,&rx_buffer[TAG_ID_IDX],2); |
| | | //gps_state=tag_id_recv; |
| | | switch(rx_buffer[MESSAGE_TYPE_IDX]) |
| | | {uint8_t target_tagi; |
| | | case MBX_REG: |
| | |
| | | |
| | | dwt_forcetrxoff(); |
| | | dwt_entersleep(); |
| | | |
| | | //printf("UWB״̬:%x\r\n",uwbdezhuangtai); |
| | | //printf("ID:%x\r\n",tag_id_recv); |
| | | //printf("测距:%x\r\n",rec_ancdistlist[0]); |
| | | //uwbdezhuangtai=0; |
| | | //tag_id_recv=0; |
| | | } |
| | | wg_state_enum wg_state = WG_Lost; |
| | | uint8_t lora_sendbuffer[200]; |
| | |
| | | extern u8 wg_lost_count; |
| | | uint16_t wg_report_freq,wg_report_id; |
| | | #define WG_LOST_SWITCH_THRES 3 |
| | | #define WG_LOST_NOUWB_COUNT 30 |
| | | u8 closeuwb_flag; |
| | | #define WG_LOST_NOUWB_COUNT 60 |
| | | #define DEFAULT_WG_ID 0xFFFF |
| | | u8 lora_jianting_flag = 1; |
| | | void LoraReportFreqPoll(void) |
| | | { |
| | | if(wg_lost_count++>WG_LOST_NOUWB_COUNT) |
| | | { |
| | | closeuwb_flag = 1; |
| | | }else{ |
| | | closeuwb_flag = 0; |
| | | lora_jianting_flag = 0; |
| | | } else { |
| | | lora_jianting_flag = 1; |
| | | } |
| | | if(wg_state==WG_Lost) |
| | | { |
| | | wg_report_id = 0xffff; |
| | | wg_report_id = DEFAULT_WG_ID; |
| | | wg_report_freq = REPORT_MANGE_CHANNEL_FRQ; //如果丢失链接就进入WG管理信道。 |
| | | }else{ |
| | | if(wg_lost_count>WG_LOST_SWITCH_THRES) |
| | | { |
| | | wg_state = WG_Lost; |
| | | } |
| | | } else { |
| | | if(wg_lost_count>WG_LOST_SWITCH_THRES) |
| | | { |
| | | wg_state = WG_Lost; |
| | | } |
| | | } |
| | | } |
| | | static u16 checksum; |
| | |
| | | void LoraReportPoll(void) |
| | | { |
| | | // delay_ms(100); |
| | | #ifdef _USE_BAR |
| | | GetPressAndHeight(); |
| | | intheight = Height*100; |
| | | #endif |
| | | #ifdef _SMT_TEST |
| | | printf("气压值:%d",intheight); |
| | | #endif |
| | | |
| | | //#ifdef _USE_BAR |
| | | // GetPressAndHeight(); |
| | | // intheight = Height*100; |
| | | //#endif |
| | | // #ifdef _SMT_TEST |
| | | // printf("气压值:%d",intheight); |
| | | // #endif |
| | | // printf("LORA发送\r\n"); |
| | | if(sendcount++>0) |
| | | TagListUpdate(); |
| | | |
| | |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG; |
| | | lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+ANCID_IDX; |
| | | #endif |
| | | |
| | | // 2000f026 02020002 //000220200 |
| | | memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&g_com_map[DEV_ID],2); |
| | | memcpy(&lora_sendbuffer[DEST_ID_IDX],&wg_report_id,2); |
| | | lora_sendbuffer[SEQNUM_IDX] = seq_num++; |
| | |
| | | lora_sendbuffer[GPS_SPOWER_IDX] = gps_signalpower; |
| | | lora_sendbuffer[GPS_CHAFENLINGQI] = gps_chafenlingqi; |
| | | #endif |
| | | for(u16 i=0; i<report_ancnum-1; i++) |
| | | { |
| | | for(u16 j=0; j<report_ancnum-1-i; j++) |
| | | { |
| | | if(report_ancdist[j]>report_ancdist[j+1]) |
| | | { |
| | | u16 id,dist; |
| | | u8 bat; |
| | | id = report_ancid[j]; |
| | | dist = report_ancdist[j]; |
| | | report_ancid[j] = report_ancid[j+1]; |
| | | report_ancdist[j] = report_ancdist[j+1]; |
| | | report_ancid[j+1] = id; |
| | | report_ancdist[j+1] = dist; |
| | | } |
| | | } |
| | | } |
| | | memcpy(&lora_sendbuffer[BAR_HEIGHT_IDX],&intheight,2); |
| | | lora_sendbuffer[ANCNUM_IDX] = report_ancnum; |
| | | memcpy(&lora_sendbuffer[ANCID_IDX],report_ancid,report_ancnum*2); |
| | |
| | | |
| | | // LED_TB_ON; |
| | | bat_percent=Get_Battary(); |
| | | #ifdef _USE_BAR_ |
| | | //if(taglist_total_num>0) |
| | | { |
| | | // #ifdef _USE_BAR_ |
| | | // //if(taglist_total_num>0) |
| | | // { |
| | | GetPressAndHeight(); |
| | | intheight = Height*100; |
| | | } |
| | | #endif |
| | | // } |
| | | //#endif |
| | | } |