| | |
| | | uint8_t phy_work_mode; /* PHY_TX / PHY_RX / PHT_TX|PHY_RX */ |
| | | struct UWB_CONFIG_T phy_cfg; |
| | | }; |
| | | |
| | | ///* Default communication configuration. */ |
| | | //static struct mk_uwb_configure config = {//原来的基站非110k代码 |
| | | // .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), |
| | | // .phy_cfg.ch_num = 5, /* Channel number. */ |
| | | // .phy_cfg.code_index = 9, /* TX preamble code. */ |
| | | // .phy_cfg.mean_prf = MEAN_PRF_64M, /* Data rate 6.8M */ |
| | | // .phy_cfg.data_bit_rate = DATA_BR_6M8, /* data rate 6.8M. */ |
| | | // .phy_cfg.sync_sym = PREAM_LEN_128, /* Preamble duration, length of preamble 128 */ |
| | | // .phy_cfg.sfd_sym = BPRF_NSFD2_8, /* Identifier for SFD sequence */ |
| | | // .phy_cfg.ranging_bit = 1, /* ranging bit set. */ |
| | | // .phy_cfg.trx_mode = TRX_MODE_15_4Z_BPRF, /* IEEE802.15.4z - BPRF mode */ |
| | | // .phy_cfg.sts_pkt_cfg = STS_PKT_CFG_0, /* SP0 Frame */ |
| | | // .phy_cfg.sts_segnum = STS_SEGNUM_BPRF_1, /* Number of STS segments in the frame */ |
| | | // .phy_cfg.sts_seglen = STS_SEGLEN_BPRF_64, /* Number of symbols in an STS segment */ |
| | | // .phy_cfg.rx_ant_id = UWB_RX_ANT_3, /* UWB RX antenna port */ |
| | | //}; |
| | | #ifdef DW1000 |
| | | extern uint8_t uwb_ch; |
| | | static struct mk_uwb_configure config = { |
| | | .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), |
| | | .phy_cfg.ch_num = 9, /* Channel number. */ |
| | | .phy_cfg.ch_num = 5, /* Channel number. */ |
| | | .phy_cfg.code_index = 9, /* TRX preamble code */ |
| | | .phy_cfg.mean_prf = MEAN_PRF_64M, /* Mean prf 64/128/256M */ |
| | | .phy_cfg.data_bit_rate = DATA_BR_6M8, /* Data rate 6.8M */ |
| | |
| | | .phy_cfg.sts_seglen = STS_SEGLEN_BPRF_64, /* Number of symbols in an STS segment */ |
| | | .phy_cfg.rx_ant_id = UWB_RX_ANT_3, /* UWB RX antenna port */ |
| | | }; |
| | | #elif defined STS_MODE |
| | | static struct mk_uwb_configure config = { |
| | | .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), |
| | | .phy_cfg.ch_num = 5, /* Channel number. */ |
| | | .phy_cfg.code_index = 9, /* TRX preamble code */ |
| | | .phy_cfg.mean_prf = MEAN_PRF_64M, /* Mean prf 64/128/256M */ |
| | | .phy_cfg.data_bit_rate = DATA_BR_6M8, /* Data rate 6.8M */ |
| | | .phy_cfg.sync_sym = PREAM_LEN_128, /* Preamble duration, length of preamble 128 */ |
| | | .phy_cfg.sfd_sym = BPRF_NSFD2_8, /* Identifier for SFD sequence */ |
| | | .phy_cfg.ranging_bit = 1, /* ranging bit set 1 */ |
| | | .phy_cfg.trx_mode = TRX_MODE_15_4Z_BPRF, /* IEEE802.15.4z - BPRF mode */ |
| | | .phy_cfg.sts_pkt_cfg = STS_PKT_CFG_1, /* SP1 Frame */ |
| | | .phy_cfg.sts_segnum = STS_SEGNUM_BPRF_1, /* Number of STS segments in the frame */ |
| | | .phy_cfg.sts_seglen = STS_SEGLEN_BPRF_64, /* Number of symbols in an STS segment */ |
| | | .phy_cfg.rx_ant_id = UWB_RX_ANT_3, /* UWB RX antenna port */ |
| | | }; |
| | | /* Use the default key and IV specified in the IEEE 802.15.4z attachment */ |
| | | static struct UWB_STS_KEY_CONFIG_T sts_iv_key = { |
| | | .sts_vcounter = 0x1F9A3DE4, |
| | | .sts_vupper0 = 0xD37EC3CA, |
| | | .sts_vupper1 = 0xC44FA8FB, |
| | | .sts_vupper2 = 0x362EEB34, |
| | | .sts_key0 = 0x14EB220F, |
| | | .sts_key1 = 0xF86050A8, |
| | | .sts_key2 = 0xD1D336AA, |
| | | .sts_key3 = 0x14148674, |
| | | }; |
| | | #elif defined MK_MODE |
| | | static struct mk_uwb_configure config = { |
| | | .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), |
| | | .phy_cfg.ch_num = 9, /* Channel number. */ |
| | | .phy_cfg.code_index = 9, /* TX preamble code. */ |
| | | .phy_cfg.mean_prf = MEAN_PRF_64M, /* Data rate 6.8M */ |
| | | .phy_cfg.data_bit_rate = DATA_BR_6M8, /* data rate 6.8M. */ |
| | | .phy_cfg.sync_sym = PREAM_LEN_128, /* Preamble duration, length of preamble 128 */ |
| | | .phy_cfg.sfd_sym = BPRF_NSFD2_8, /* Identifier for SFD sequence */ |
| | | .phy_cfg.ranging_bit = 1, /* ranging bit set. */ |
| | | .phy_cfg.trx_mode = TRX_MODE_15_4Z_BPRF, /* IEEE802.15.4z - BPRF mode */ |
| | | .phy_cfg.sts_pkt_cfg = STS_PKT_CFG_0, /* SP0 Frame */ |
| | | .phy_cfg.sts_segnum = STS_SEGNUM_BPRF_1, /* Number of STS segments in the frame */ |
| | | .phy_cfg.sts_seglen = STS_SEGLEN_BPRF_64, /* Number of symbols in an STS segment */ |
| | | .phy_cfg.rx_ant_id = UWB_RX_ANT_3, /* UWB RX antenna port */ |
| | | }; |
| | | #endif |
| | | |
| | | |
| | | static struct anchor_id_car{ |
| | | uint16_t anchor_new_id; |
| | |
| | | extern uint16_t mubiao_anchor_ID; |
| | | uint8_t Lora_qingqiu_flag; |
| | | extern uint16_t Lora_qingqiu_bao; |
| | | uint8_t shengji_flag; |
| | | extern uint8_t Dtu_shengji_jindu[20]; |
| | | static void rx_int_callback(struct MAC_HW_REPORT_T *rx_report) |
| | | { uint8_t valid_sts=0; |
| | | uint16_t checksum1 = 0,dest_id; |
| | |
| | | rssi = rx_report->rssi; |
| | | receive_flag=1; |
| | | // uart_send(UART_ID0, rx_buf,rx_length, NULL); |
| | | if(rx_buf[MESSAGE_TYPE_IDX]==MBX_POLL) |
| | | gpio_pin_toggle(IO_PIN_4); |
| | | if(rx_buf[MESSAGE_TYPE_IDX]==MBX_POLL&&!shengji_flag) |
| | | { |
| | | Anchor_App(); |
| | | } |
| | |
| | | { |
| | | if(!memcmp(&dev_id,&dest_id,2)/*||dest_id==0xffff||(dest_id==0xfffe&&get_channel==5)*/) |
| | | { |
| | | shengji_flag=1; |
| | | switch(rx_buf[MSG_TYPE_IDX]) |
| | | { |
| | | case LORA_MSGTYPE_UPDATE_CONFIRM: |
| | |
| | | break; |
| | | |
| | | case 0x99: |
| | | LOG_INFO(TRACE_MODULE_APP, "收到结束升级请求\r\n",Lora_qingqiu_bao); |
| | | delay_ms(500); |
| | | // LOG_INFO(TRACE_MODULE_APP, "收到结束升级请求\r\n",Lora_qingqiu_bao); |
| | | delay_ms(200); |
| | | Dtu_shengji_jindu[4]=100; |
| | | memcpy(&Dtu_shengji_jindu[5],&mubiao_anchor_ID,2); |
| | | uart_send(UART_ID0, Dtu_shengji_jindu,9, NULL); |
| | | |
| | | delay_ms(1000); |
| | | // Lora_upanc_flag=0; |
| | | Lora_qingqiu_flag=0; |
| | | NVIC_SystemReset(); |
| | |
| | | // } |
| | | } |
| | | } |
| | | |
| | | |
| | | #ifdef STS_MODE |
| | | valid_sts= sts_valid_check(); |
| | | if (valid_sts) |
| | |
| | | uint32_t start_receive_count,end_receive_count,poll_timeout,current_count,temp_resp; |
| | | int16_t anchordata_id[TAG_NUM_IN_SYS],anchordata_dist[TAG_NUM_IN_SYS]; |
| | | static uint8_t anchordata_bat[TAG_NUM_IN_SYS]; |
| | | static uint16_t anchordata_version[TAG_NUM_IN_SYS]; |
| | | uint8_t anchordata_num = 0; |
| | | static int32_t tagdist_list[TAG_NUM_IN_SYS]; |
| | | static int16_t tagdist_list[TAG_NUM_IN_SYS]; |
| | | uint16_t random_time; |
| | | //anchor |
| | | int32_t hist_dist; |
| | |
| | | { uint16_t i; |
| | | for(i=0; i<taglist_num; i++) |
| | | { |
| | | if(memcmp(&tagid,&anchordata_id[i],2)==0) |
| | | if(memcmp(&tagid,&tagid_list[i],2)==0) |
| | | break; |
| | | } |
| | | if(i==taglist_num) |
| | |
| | | //void TagListUpdate(void) |
| | | //{ |
| | | // uint8_t i,j=0; |
| | | // for(i=0; i<anchordata_num; i++) |
| | | // for(i=0; i<taglist_num; i++) |
| | | // { |
| | | // if(tagofflinetime[i]++<QUIT_SLOT_TIME) |
| | | // { |
| | |
| | | // tagofflinetime[j++]=tagofflinetime[i]; |
| | | // } |
| | | // } |
| | | // anchordata_num=j; |
| | | // taglist_num=j; |
| | | //} |
| | | void TagListUpdate(void) |
| | | { |
| | | uint16_t i,j=0,k=0; |
| | | for(i=0; i<taglist_num; i++) |
| | | { |
| | | if(tagofflinetime[i]++<TAG_KEEPTIMES) |
| | | if(tagofflinetime[i]++<10) |
| | | { |
| | | tagid_list[j]=tagid_list[i]; |
| | | tagdist_list[j] = tagdist_list[i]; |
| | | anchordata_bat[j]=anchordata_bat[i];//电量随之更新 |
| | | anchordata_bat[j]=anchordata_bat[i];//电量随之更新 |
| | | anchordata_version[j]=anchordata_version[i]; |
| | | tagofflinetime[j++]=tagofflinetime[i]; |
| | | } |
| | | } |
| | |
| | | //while(mac_is_busy()); |
| | | gpio_pin_clr(SCL_PIN); |
| | | cmd_flag=1; |
| | | if(send_buffer[RW_FLAG_IDX]==0x01) |
| | | { |
| | | delay_ms(100); |
| | | NVIC_SystemReset(); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | |
| | | if(uwb_losttimer>g_com_map[UWB_RNAGE_TIME]) |
| | | uwb_losttimer=g_com_map[UWB_RNAGE_TIME]+1;//防止溢出 |
| | | } |
| | | uint8_t uwbsend[200]; |
| | | uint8_t uwbsend[1000]; |
| | | |
| | | void UWBIdleTask(void) |
| | | { |
| | | |
| | | if(HIDO_TimerGetTick()-uwbtasktimer >=1) |
| | | { |
| | | |
| | | for(uint16_t i=0;i<taglist_num-1;i++) |
| | | { |
| | | for(uint16_t j=0;j<taglist_num-1-i;j++) |
| | | { |
| | | if(tagdist_list[j]>tagdist_list[j+1]) |
| | | { |
| | | uint16_t id,dist,version; |
| | | uint8_t bat; |
| | | id = tagid_list[j]; |
| | | dist = tagdist_list[j]; |
| | | version = anchordata_version[j]; |
| | | tagid_list[j] = tagid_list[j+1]; |
| | | tagdist_list[j] = tagdist_list[j+1]; |
| | | anchordata_version[j] = anchordata_version[j+1]; |
| | | tagid_list[j+1] = id; |
| | | tagdist_list[j+1] = dist; |
| | | anchordata_version[j+1] = version; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | // if(taglist_num>6) |
| | | // { |
| | | // taglist_num=6; |
| | | // } |
| | | uwbtasktimer = HIDO_TimerGetTick(); |
| | | UWBOneSecondTask(); |
| | | uwbsend[0]=0x55; |
| | |
| | | uwbsend[3]=taglist_num; |
| | | memcpy(&uwbsend[4],&tagid_list,taglist_num*2); |
| | | memcpy(&uwbsend[4+taglist_num*2],&tagdist_list,taglist_num*2); |
| | | uart_send(UART_ID0, uwbsend,taglist_num*4+4, NULL); |
| | | // for(int i=0;i<anchordata_num;i++) |
| | | // { |
| | | // LOG_INFO(TRACE_MODULE_APP,"当前测距基站ID:%x,距离:%d.\r\n",anchordata_id[i],anchordata_dist[i]); |
| | | // } |
| | | memcpy(&uwbsend[4+taglist_num*4],&anchordata_version,taglist_num*2); |
| | | // uart_send(UART_ID0, uwbsend,taglist_num*6+4, NULL); |
| | | // taglist_num=0; |
| | | LOG_INFO(TRACE_MODULE_APP,"当前测距基站数量%d.\r\n",taglist_num); |
| | | for(int i=0;i<taglist_num;i++) |
| | | { |
| | | LOG_INFO(TRACE_MODULE_APP,"当前测距基站ID:%x,距离:%d.\r\n",tagid_list[i],tagdist_list[i]); |
| | | } |
| | | } |
| | | } |
| | | int uwb_app_poll(void) |
| | | { |
| | | // switch(wltag_state) |
| | | // { |
| | | // case RANGE: |
| | | // if(HIDO_TimerGetTick()-wltag_uwbtimer>2&&uwb_rx_flag==0) |
| | | // { |
| | | // wltag_uwbtimer = HIDO_TimerGetTick(); |
| | | // OpenUWB(); |
| | | // } |
| | | // else if(HIDO_TimerGetTick()-wltag_uwbtimer>1&&uwb_rx_flag==1) |
| | | // { |
| | | // wltag_uwbtimer = HIDO_TimerGetTick(); |
| | | // CloseUWB(); |
| | | // } |
| | | // if(uwb_losttimer>g_com_map[UWB_RNAGE_TIME]) |
| | | // { |
| | | // wltag_statetimer = HIDO_TimerGetTick(); |
| | | // if(uwb_rx_flag==0)//若要切换到搜索模式时没有开启则开启UWB |
| | | // { |
| | | // OpenUWB(); |
| | | // } |
| | | // wltag_state = SEARCH; |
| | | // } |
| | | // break; |
| | | // case SEARCH: |
| | | // if(HIDO_TimerGetTick()-wltag_statetimer>1) |
| | | // { |
| | | // wltag_statetimer = HIDO_TimerGetTick(); |
| | | // wltag_state = CLOSE; |
| | | // CloseUWB(); |
| | | // } |
| | | // break; |
| | | // case CLOSE: |
| | | // if(HIDO_TimerGetTick()-wltag_statetimer>g_com_map[UWB_WAIT_TIME]) |
| | | // { |
| | | // wltag_statetimer = HIDO_TimerGetTick(); |
| | | // wltag_state = SEARCH; |
| | | // OpenUWB(); |
| | | // } |
| | | // break; |
| | | // } |
| | | UWBIdleTask(); |
| | | } |
| | | int Anchor_App(void) |
| | |
| | | Anchor_RecNearPoll(i); |
| | | tagdist_list[taglist_pos]=rec_ancdistlist[i]; |
| | | anchordata_bat[taglist_pos] = battary;//保存该基站电量 |
| | | // anchordata_version[taglist_pos] = battary;//保存该基站版本号 |
| | | memcpy(& anchordata_version[taglist_pos],&rx_buf[7],2); |
| | | if(taglist_pos==taglist_num)// taglist_pos==taglist_num 说明这个基站不在当前列表中 |
| | | { //tempid==dev_id 说明基站下发测距报文有这个标签的信息 |
| | | taglist_num++; //满足上述两种情况才会添加基站ID进入列表中,否则会出现标签不在基站列表中,标签也不响应的情况 |
| | |
| | | current_count=phy_timer_count_get(); |
| | | while(mac_is_busy()) |
| | | { |
| | | Calibration_Time(); |
| | | // Calibration_Time(); |
| | | IdleTask(); |
| | | current_count=phy_timer_count_get(); |
| | | if(current_count>end_receive_count&¤t_count<end_receive_count+HALF_SECOND_TIME) |
| | |
| | | phy_rx_ant_mode_set(RX_ANT_PORTS_COMBINATION); |
| | | #endif |
| | | // Set calibration parameters |
| | | // config.phy_cfg.ch_num=g_com_map[NEARBASE_ID1]; |
| | | uwb_calibration_params_set(config.phy_cfg.ch_num); |
| | | #ifndef STS_MODE |
| | | // set advanced parameters |