| | |
| | | #include "dw_mbx_tag.h" |
| | | |
| | | #define DELAY_BETWEEN_TWO_FRAME_UUS 300 |
| | | //#include "dps310.h" |
| | | #include "WS2812.h" |
| | | #include "syn6288.h" |
| | | #define DELAY_BETWEEN_TWO_FRAME_UUS 400 |
| | | #define POLL_RX_TO_RESP_TX_DLY_UUS 470 |
| | | #define UUS_TO_DWT_TIME 65536 |
| | | |
| | |
| | | #define TAG_NUM_IN_SYS 25 |
| | | |
| | | #define TAG_KEEPTIMES 30 |
| | | #define REPORT_TAG_KEEPTIMES 3 |
| | | 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 u8 frame_seq_nb2,battary,button,uwb_losttimer,taglist_pos; |
| | | |
| | |
| | | // delay_ms(10); |
| | | } |
| | | uint8_t report_ancnum; |
| | | uint16_t report_ancdist[ANC_MAX_NUM],report_ancid[ANC_MAX_NUM]; |
| | | void TagListUpdate(void) |
| | | { |
| | | uint16_t i,j=0,temp[TAG_NUM_IN_SYS]; |
| | | uint16_t i,j=0,k=0,temp[TAG_NUM_IN_SYS]; |
| | | for(i=0;i<taglist_num;i++) |
| | | { |
| | | if(tagofflinetime[i]++<REPORT_TAG_KEEPTIMES) |
| | | { |
| | | report_ancid[k]=tagid_list[i]; |
| | | report_ancdist[k++]=tagdist_list[i]; |
| | | } |
| | | if(tagofflinetime[i]++<TAG_KEEPTIMES) |
| | | { |
| | | tagid_list[j]=tagid_list[i]; |
| | | tagdist_list[j] = tagdist_list[i]; |
| | | tagofflinetime[j++]=tagofflinetime[i]; |
| | | } |
| | | } |
| | | report_ancnum = k; |
| | | taglist_num=j; |
| | | } |
| | | uint16_t CmpTagInList(uint16_t tagid) |
| | |
| | | } |
| | | return i; |
| | | } |
| | | |
| | | uint32_t temp231; |
| | | extern uint32_t uwbled,gpsled,loraled,powerled; |
| | | void MbxTagUwbRec(void) |
| | | { |
| | | |
| | |
| | | dwt_setrxtimeout(3000);//设定接收超时时间,0位没有超时时间 |
| | | dwt_rxenable(0);//打开接收 |
| | | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET); |
| | | |
| | | temp231 = dwt_read32bitreg(CHAN_CTRL_ID) ; |
| | | start_time=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | timeout=100; //单位0.1ms |
| | | end_time=start_time+(timeout<<2); |
| | |
| | | memcpy(&rec_ancdistlist,&rx_buffer[FZ_NEARBASEID_INDEX+2*rec_nearbase_num],2*rec_nearbase_num); |
| | | // memcpy(&rec_antdelay,&rx_buffer[FZ_NEARBASEID_INDEX+rec_nearbase_num*4],2); |
| | | uwb_losttimer = 0; |
| | | |
| | | uwbled=GREEN; |
| | | taglist_pos=CmpTagInList(tag_id_recv); |
| | | if(taglist_num>=ANC_MAX_NUM) |
| | | break; |
| | |
| | | } |
| | | if(i==rec_nearbase_num&&taglist_pos==taglist_num)//当基站不在标签列表中,标签也不在基站列表中时,随机找个时间片回复基站。 |
| | | { |
| | | Anchor_RecNearPoll(rec_nearbase_num+start_time%5); |
| | | //Anchor_RecNearPoll(rec_nearbase_num+start_time%2); |
| | | Anchor_RecNearPoll(rec_nearbase_num); |
| | | } |
| | | } |
| | | |
| | |
| | | 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; |
| | | void LoraReportFreqPoll(void) |
| | | { |
| | | if(wg_lost_count++>WG_LOST_NOUWB_COUNT) |
| | | { |
| | | closeuwb_flag = 1; |
| | | }else{ |
| | | closeuwb_flag = 0; |
| | | } |
| | | if(wg_state==WG_Lost) |
| | | { |
| | | wg_report_id = 0xffff; |
| | | wg_report_freq = REPORT_MANGE_CHANNEL_FRQ; //如果丢失链接就进入WG管理信道。 |
| | | }else{ |
| | | if(wg_lost_count++>WG_LOST_SWITCH_THRES) |
| | | if(wg_lost_count>WG_LOST_SWITCH_THRES) |
| | | { |
| | | wg_state = WG_Lost; |
| | | wg_state = WG_Lost; |
| | | } |
| | | } |
| | | } |
| | | static u16 checksum; |
| | | u8 gps_state,gps_chafenlingqi,gps_satel_num,test_num; |
| | | u8 gps_state,gps_chafenlingqi,gps_satel_num,gps_signalpower; |
| | | double gps_jingdu,gps_weidu; |
| | | float gps_height; |
| | | extern u8 bat_percent,stationary_flag; |
| | | int16_t sendcount = 0,tp1; |
| | | int16_t sendcount = 0,tp1,bar_height; |
| | | u8 flag_getwgresp; |
| | | void LoraHeartBeartPoll(void) |
| | | { |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGHEARTBEAT; |
| | | lora_sendbuffer[MSG_LENGTH] = 14; |
| | | memcpy(&lora_sendbuffer[SOURCE_ID_IDX],&g_com_map[DEV_ID],2); |
| | | memcpy(&lora_sendbuffer[DEST_ID_IDX],&wg_report_id,2); |
| | | memcpy(&lora_sendbuffer[HB_VERSION_IDX],&g_com_map[VERSION],2); |
| | | lora_sendbuffer[HB_UWBPOWER_IDX] = g_com_map[POWER]; |
| | | lora_sendbuffer[HB_LORAPOWER_IDX] = g_com_map[LORA_POWER]; |
| | | checksum = Checksum_u16(lora_sendbuffer,14); |
| | | memcpy(&lora_sendbuffer[14],&checksum,2); |
| | | Radio.Send(lora_sendbuffer,16); |
| | | } |
| | | uint16_t heatbeat_count = 3600; |
| | | int16_t intheight; |
| | | #define HEATBEAT_UPDATE_TIME 3600 |
| | | extern float Height; |
| | | void LoraReportPoll(void) |
| | | { |
| | | |
| | | // delay_ms(100); |
| | | #ifdef _USE_BAR |
| | | GetPressAndHeight(); |
| | | intheight = Height*100; |
| | | #endif |
| | | #ifdef _SMT_TEST |
| | | printf("气压值:%d",intheight); |
| | | #endif |
| | | |
| | | if(sendcount++>0) |
| | | TagListUpdate(); |
| | | |
| | | LoraReportFreqPoll(); |
| | | taglist_num = test_num; |
| | | flag_getwgresp = 0; |
| | | // wg_report_freq = REPORT_MANGE_CHANNEL_FRQ; |
| | | SwitchLoraSettings(wg_report_freq,REPORT_CHANNEL_SF,g_com_map[LORA_POWER]); |
| | | if(heatbeat_count++>HEATBEAT_UPDATE_TIME && WG_Connected == wg_state) //如果心跳包到达上传时间,并且网关处于链接状态,就上传心跳包 |
| | | { |
| | | heatbeat_count = 0; |
| | | LoraHeartBeartPoll(); |
| | | return; |
| | | } |
| | | #ifdef USE_GPS |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG_GPS; |
| | | lora_sendbuffer[MSG_LENGTH] = 4*taglist_num+30; |
| | | lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+30; |
| | | #else |
| | | lora_sendbuffer[MSG_TYPE_IDX] = LORA_MSGTYPE_TAGMSGTOWG; |
| | | lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+ANCID_IDX; |
| | | #endif |
| | | |
| | | 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[BAT_IDX] = bat_percent; |
| | | lora_sendbuffer[STATE_IDX] = !GET_USERKEY|stationary_flag<<1;; |
| | | lora_sendbuffer[STATE_IDX] = !GET_USERKEY|stationary_flag<<1; |
| | | #ifdef USE_GPS |
| | | memcpy(&lora_sendbuffer[GPS_JINGDU_IDX],&gps_jingdu,8); |
| | | memcpy(&lora_sendbuffer[GPS_WEIDU_IDX],&gps_jingdu,8); |
| | | memcpy(&lora_sendbuffer[GPS_HEIGHT_IDX],&gps_height,8); |
| | | lora_sendbuffer[GPS_STATE_IDX] = gps_state; |
| | | lora_sendbuffer[GPS_SATEL_NUM_IDX] = gps_satel_num; |
| | | lora_sendbuffer[GPS_SPOWER_IDX] = gps_signalpower; |
| | | lora_sendbuffer[GPS_CHAFENLINGQI] = gps_chafenlingqi; |
| | | lora_sendbuffer[ANCNUM_IDX] = taglist_num; |
| | | memcpy(&lora_sendbuffer[ANCID_IDX],tagid_list,taglist_num*2); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+taglist_num*2],tagdist_list,taglist_num*2); |
| | | checksum = Checksum_u16(lora_sendbuffer,4*taglist_num+ANCID_IDX); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+taglist_num*4],&checksum,2); |
| | | Radio.Send(lora_sendbuffer,ANCID_IDX+taglist_num*4+2); |
| | | #endif |
| | | memcpy(&lora_sendbuffer[BAR_HEIGHT_IDX],&intheight,2); |
| | | lora_sendbuffer[ANCNUM_IDX] = report_ancnum; |
| | | memcpy(&lora_sendbuffer[ANCID_IDX],report_ancid,report_ancnum*2); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*2],report_ancdist,report_ancnum*2); |
| | | checksum = Checksum_u16(lora_sendbuffer,4*report_ancnum+ANCID_IDX); |
| | | memcpy(&lora_sendbuffer[ANCID_IDX+report_ancnum*4],&checksum,2); |
| | | Radio.Send(lora_sendbuffer,ANCID_IDX+report_ancnum*4+2); |
| | | |
| | | // LED_TB_ON; |
| | | bat_percent=Get_Battary(); |
| | | |
| | | } |
| | | #ifdef _USE_BAR_ |
| | | //if(taglist_total_num>0) |
| | | { |
| | | GetPressAndHeight(); |
| | | intheight = Height*100; |
| | | } |
| | | #endif |
| | | } |