| | |
| | | #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 |
| | | |
| | |
| | | } |
| | | 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 |
| | | end_time=start_time+(timeout<<2); |
| | |
| | | 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: |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | 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 60 |
| | | #define DEFAULT_WG_ID 0xFFFF |
| | | u8 lora_jianting_flag = 1; |
| | | void LoraReportFreqPoll(void) |
| | | { |
| | | if(wg_lost_count++>WG_LOST_NOUWB_COUNT) |
| | | { |
| | | 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; |
| | | u8 gps_state,gps_chafenlingqi,gps_satel_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 = 590; |
| | | int16_t intheight; |
| | | #define HEATBEAT_UPDATE_TIME 600 |
| | | extern float Height; |
| | | void LoraReportPoll(void) |
| | | { |
| | | |
| | | // delay_ms(100); |
| | | //#ifdef _USE_BAR |
| | | // GetPressAndHeight(); |
| | | // intheight = Height*100; |
| | | //#endif |
| | | // #ifdef _SMT_TEST |
| | | // printf("气压值:%d",intheight); |
| | | // #endif |
| | | // printf("LORA发送\r\n"); |
| | | if(sendcount++>0) |
| | | TagListUpdate(); |
| | | |
| | | LoraReportFreqPoll(); |
| | | |
| | | 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*report_ancnum+30; |
| | | lora_sendbuffer[MSG_LENGTH] = 4*report_ancnum+ANCID_IDX; |
| | | #else |
| | | 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[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_WEIDU_IDX],&gps_weidu,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; |
| | | #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); |
| | | 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); |
| | | bat_percent=Get_Battary(); |
| | | |
| | | } |
| | | //delay_ms(100); |
| | | // LED_TB_ON; |
| | | // bat_percent=Get_Battary(); |
| | | // #ifdef _USE_BAR_ |
| | | // //if(taglist_total_num>0) |
| | | // { |
| | | GetPressAndHeight(); |
| | | intheight = Height*100; |
| | | // } |
| | | //#endif |
| | | } |