| | |
| | | }; |
| | | uint32_t dev_id; |
| | | uint8_t group_id; |
| | | |
| | | #ifdef DW1000 |
| | | /* Default communication configuration. */ |
| | | static struct mk_uwb_configure config = {//yuan |
| | | struct mk_uwb_configure config = {//yuan |
| | | .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX), |
| | | .phy_cfg.ch_num = 9, /* Channel number. */ |
| | | .phy_cfg.ch_num = UWB_CH_NUM, /* 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_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 */ |
| | | .phy_cfg.rx_main_ant = UWB_RX_ANT_3, /* UWB RX main antenna port */ |
| | | .phy_cfg.rx_ant_mode = RX_ANT_PORTS_COMBINATION, /* UWB RX antenna mode */ |
| | | .phy_cfg.pulse_shape = 0x2, /* 0x0: CCC pulse, 0x2: FiRa pulse */ |
| | | }; |
| | | #elif defined STS_MODE |
| | | static struct mk_uwb_configure config = { |
| | |
| | | .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 */ |
| | | .phy_cfg.rx_main_ant = UWB_RX_ANT_3, /* UWB RX main antenna port */ |
| | | .phy_cfg.rx_ant_mode = RX_ANT_PORTS_COMBINATION, /* UWB RX antenna mode */ |
| | | .phy_cfg.pulse_shape = 0x2, /* 0x0: CCC pulse, 0x2: FiRa pulse */ |
| | | }; |
| | | /* 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 STS_MODE_SQUARE |
| | | 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, /* 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_main_ant = UWB_RX_ANT_3, /* UWB RX main antenna port */ |
| | | .phy_cfg.rx_ant_mode = RX_ANT_PORTS_COMBINATION, /* UWB RX antenna mode */ |
| | | .phy_cfg.pulse_shape = 0x2, /* 0x0: CCC pulse, 0x2: FiRa pulse */ |
| | | }; |
| | | /* Use the default key and IV specified in the IEEE 802.15.4z attachment */ |
| | | static struct UWB_STS_KEY_CONFIG_T sts_iv_key = { |
| | |
| | | .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 */ |
| | | .phy_cfg.rx_main_ant = UWB_RX_ANT_3, /* UWB RX main antenna port */ |
| | | .phy_cfg.rx_ant_mode = RX_ANT_PORTS_COMBINATION, /* UWB RX antenna mode */ |
| | | .phy_cfg.pulse_shape = 0x2, /* 0x0: CCC pulse, 0x2: FiRa pulse */ |
| | | }; |
| | | #endif |
| | | ///* Default communication configuration. */ |
| | |
| | | // .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 */ |
| | | // .phy_cfg.rx_main_ant = UWB_RX_ANT_3, /* UWB RX main antenna port */ |
| | | // .phy_cfg.rx_ant_mode = RX_ANT_PORTS_COMBINATION, /* UWB RX antenna mode */ |
| | | // .phy_cfg.pulse_shape = 0x2, /* 0x0: CCC pulse, 0x2: FiRa pulse */ |
| | | //}; |
| | | /* Buffer to store received frame */ |
| | | static uint8_t rx_buf[150]; |
| | |
| | | extern double distance; |
| | | extern uint8_t bat_percent; |
| | | uint32_t count1,count2; |
| | | extern uint32_t reboot_num; |
| | | enum SIMPLE_FSM_T |
| | | { |
| | | SIMPLE_IDLE = 0, |
| | |
| | | { |
| | | tag_num_tosend = SEND_GROUP_MAX_NUM; |
| | | } |
| | | memcpy(&uwb_sendbuffer[7],&g_com_map[VERSION],2); |
| | | uwb_sendbuffer[GROUP_ID_IDX] = group_id; |
| | | memcpy(&uwb_sendbuffer[TAG_ID_IDX],&dev_id,2); |
| | | uwb_sendbuffer[BATTARY_IDX] = bat_percent; |
| | |
| | | memcpy(&uwb_sendbuffer[NEARBASEID_INDEX+tag_num_tosend*2],&taglist_dist[taglist_current_index],tag_num_tosend*2); |
| | | uwb_sendbuffer[MESSAGE_TYPE_IDX] = MBX_POLL; |
| | | memcpy(&uwb_sendbuffer[ANCHOR_ID_IDX],&mainbase_id,2); |
| | | |
| | | } |
| | | |
| | | static enum SIMPLE_FSM_T state = SIMPLE_IDLE; |
| | |
| | | int64_t tx_timestamp = ranging_tx_time(timestamp); |
| | | |
| | | // correct antenna delay (TX using the same antenna as RX) |
| | | tx_timestamp += ranging_ant_delays_get(config.phy_cfg.rx_ant_id) / 2; |
| | | tx_timestamp += ranging_ant_delays_get(config.phy_cfg.rx_main_ant) / 2; |
| | | |
| | | return tx_timestamp; |
| | | } |
| | |
| | | int64_t rx_timestamp = ranging_rx_time(ind); |
| | | |
| | | // correct antenna delay |
| | | rx_timestamp -= ranging_ant_delays_get(config.phy_cfg.rx_ant_id) / 2; |
| | | rx_timestamp -= ranging_ant_delays_get(config.phy_cfg.rx_main_ant) / 2; |
| | | |
| | | return rx_timestamp; |
| | | } |
| | |
| | | #if (defined STS_MODE) || (defined MK_MODE) |
| | | ranging_lib_init(); |
| | | #endif |
| | | ranging_frame_type_set(config.phy_cfg.sts_pkt_cfg); |
| | | //ranging_frame_type_set(config.phy_cfg.sts_pkt_cfg); |
| | | ranging_lib_init(config.phy_cfg.sts_pkt_cfg, CE_AUX_CH_PWR_NLOS_FOM); |
| | | } |
| | | void Anchor_uwb_aoa_square_init(void) |
| | | { |
| | | // Set calibration parameters |
| | | uwb_calibration_params_set(config.phy_cfg.ch_num); |
| | | |
| | | // set advanced parameters |
| | | struct PHY_ADV_CONFIG_T adv_config = |
| | | { |
| | | .thres_fap_detect = 40, |
| | | .nth_scale_factor = 1, |
| | | .ranging_performance_mode = 0, |
| | | #if RX_ANT_PORTS_NUM == 4 |
| | | .skip_weakest_port_en = 1, |
| | | #else |
| | | .skip_weakest_port_en = 0, |
| | | #endif |
| | | }; |
| | | phy_adv_params_configure(&adv_config); |
| | | |
| | | // uwb configure |
| | | uwb_configure(config.phy_work_mode, board_param.tx_power_fcc[CALIB_CH(config.phy_cfg.ch_num)], &config.phy_cfg); |
| | | |
| | | ranging_lib_init(config.phy_cfg.sts_pkt_cfg, CE_AUX_CH_PWR_NLOS_FOM); |
| | | |
| | | // Register rx interrupt callback function |
| | | mac_register_process_handler(tx_int_callback, rx_int_callback); |
| | | |
| | | // Reduce inter frame spacing (IFS) for non encrypted packets |
| | | mac_ifs_set(0, 0); |
| | | |
| | | sts_param_config(config.phy_cfg.sts_pkt_cfg, STS_AUX_ANT_IQ_RSSI, STS_BUF_NUM, STS_BUF_SIZE); |
| | | |
| | | // Set STS key and IV |
| | | phy_sts_key_configure(&sts_iv_key); |
| | | |
| | | phy_rx_sts_switch_mode_set(config.phy_cfg.sts_pkt_cfg, STS_NEVER_SWITCH, 0, 0); |
| | | |
| | | } |
| | | int sleep_time_step=SLEEP_COUNT; |
| | |
| | | uwb_poll_buffer_construct(); |
| | | temp_tag_num=0;//临时数量为0 |
| | | poll_tx_en_start_u32 = phy_timer_count_get()+US_TO_PHY_TIMER_COUNT(POLL_DELAY);//发送必须要延时发送才可以用于测距否则立即发送会获取时间戳不对,需要计算程序运行时间,避免设置过去时间 |
| | | tempflag=uwb_tx(uwb_sendbuffer,13+4*tag_num_tosend,1,poll_tx_en_start_u32);//立即发送 |
| | | //tempflag=uwb_tx(uwb_sendbuffer,13+4*tag_num_tosend,1,poll_tx_en_start_u32);//立即发送 |
| | | tempflag=uwb_tx(uwb_sendbuffer,sizeof(uwb_sendbuffer),1,poll_tx_en_start_u32);//立即发送 |
| | | #ifdef BOXING |
| | | gpio_pin_set(IO_PIN_5);//测试 |
| | | #endif |
| | |
| | | if(receive_flag==1)//成功接收数据 |
| | | { |
| | | receive_flag=0; |
| | | phy_update_sts_iv_counter(0x01, 0x00);//新增sts |
| | | tempflag=uwb_rx(0, 0, RESP_RX_TIMEOUT_US);//立即开启接受并设置0超时 |
| | | //接收成功则判断是否为同一组 |
| | | if(rx_buf[MESSAGE_TYPE_IDX] == MBX_POLL)//收到是其他的基站的POLL包 |
| | |
| | | sleep_timer_start(__MS_TO_32K_CNT(SLEEP_COUNT-rand_temp));//测试 |
| | | }else if (rx_buf[MESSAGE_TYPE_IDX] == MBX_RESPONSE&&!memcmp(&rx_buf[TAG_ID_IDX],&dev_id,2)&&rx_buf[GROUP_ID_IDX]==group_id) //判断接收到的数据是否是response数据 |
| | | { |
| | | reboot_num=0;//清0复位监测数值 |
| | | memcpy(&rec_nearbaseid,&rx_buf[ANCHOR_ID_IDX],2); |
| | | rec_tag_index = CmpTagInList(rec_nearbaseid);//当前新来的这包数据插入当前表中的位置索引 |
| | | //rec_nearbasepos=FindNearBasePos(rec_nearbaseid); |
| | |
| | | gpio_pin_clr(IO_PIN_5);//测试 |
| | | gpio_pin_set(IO_PIN_5);//测试 |
| | | #endif |
| | | phy_update_sts_iv_counter(0x00, sts_iv_key.sts_vcounter);//sts |
| | | } |
| | | // } |
| | | #ifdef BOXING |
| | |
| | | |
| | | return (crc&0xffffu); |
| | | } |
| | | void delay_ms(uint32_t nTimer) |
| | | { |
| | | uint32_t i=1000*nTimer; |
| | | delay_us(i); |
| | | } |
| | | //void delay_ms(uint32_t nTimer) |
| | | //{ |
| | | // uint32_t i=1000*nTimer; |
| | | // delay_us(i); |
| | | //} |
| | | uint8_t send_lora_data[250]; |
| | | uint16_t muqiandeshengjibao; |
| | | static uint16_t current_count1,target_count1,end_count1,start_count1; |