| | |
| | | #define FINAL_MSG_TS_LEN 4 |
| | | |
| | | #define STARTPOLL REGPOLL//#define SWITCHBASE_DIST |
| | | //#define SWITCHBASE_ZHUANDIAN |
| | | #define SWITCHBASE_ZHUANDIAN |
| | | #define SWITCHBASE_DIST |
| | | enum enumtagstate |
| | | { |
| | |
| | | dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS); |
| | | tag_succ_times = 0; |
| | | frame_seq_nb++; |
| | | intheight+=g_com_map[HEIGHTOFFEST_INDEX]; |
| | | for(singlepoll_i=0;singlepoll_i<SINGLEPOLL_BASENUM;singlepoll_i++) |
| | | { |
| | | /* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */ |
| | |
| | | tx_near_msg[NEARBASENUM_INDEX] = nearbase_num; |
| | | memcpy(&tx_near_msg[NEARBASEID_INDEX],&singlepoll_baseid,nearbase_num*2); |
| | | memcpy(&tx_near_msg[NEARBASEID_INDEX+nearbase_num*2],&singlepoll_basedist,nearbase_num*4+4); |
| | | intheight+=g_com_map[HEIGHTOFFEST_INDEX]; |
| | | |
| | | memcpy(&tx_near_msg[NEARBASEID_INDEX+nearbase_num*6],&intheight,2); |
| | | tx_near_msg[MESSAGE_TYPE_IDX] = SPOLL; |
| | | |
| | |
| | | void GetNearMsg(void) |
| | | { |
| | | u32 start_poll,frame_len; |
| | | |
| | | u8 nearmsg_i=0; |
| | | for(nearmsg_i=0;nearmsg_i<20;nearmsg_i++) |
| | | { |
| | | nearbase_distlist[nearmsg_i] = 0x1ffff; |
| | | } |
| | | //mainbase_id = 0x9724; |
| | | memcpy(&tx_near_msg[ANCHOR_ID_IDX],&mainbase_id,2); |
| | | memcpy(&tx_near_msg[TAG_ID_IDX],&dev_id,2); |
| | | tx_near_msg[MESSAGE_TYPE_IDX] = NEAR_MSG; |
| | | |
| | | |
| | | dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); //设置发送后开启接收,并设定延迟时间 |
| | | dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS); |
| | | dwt_writetxdata(12, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 |
| | |
| | | memcpy(&nearbase_switchdistlist[rec_nearbasepos],&rx_buffer[NR_NEARSWITCH_DISTANCE],2); |
| | | nearbase_distlist[rec_nearbasepos+1]=temp_dist; // nearbase_distlist[1]对应 rec_nearbaseid[0]的距离 |
| | | final_msg_set_ts(&tx_near_msg[FINAL_MSG_RESP_RX_NEARBASE_IDX+(rec_nearbasepos)*4], resp_rx_ts); |
| | | if(temp_dist<salvebase_mindist) |
| | | if(temp_dist<salvebase_mindist&&nearbase_switchdistlist[rec_nearbasepos]==1) |
| | | { |
| | | salvebase_mindist = temp_dist; |
| | | mindist_slavebaseid = rec_nearbaseid; |
| | | } |
| | | #ifdef SWITCHBASE_ZHUANDIAN |
| | | if(temp_dist<nearbase_switchdistlist[rec_nearbasepos]&&nearbase_switchdistlist[rec_nearbasepos]!=0&&temp_dist>0) |
| | | { |
| | | if(temp_dist<nearbase_switchdistlist[rec_nearbasepos]&&nearbase_switchdistlist[rec_nearbasepos]>1&&temp_dist>0) |
| | | { |
| | | mainbase_id = rec_nearbaseid; |
| | | tag_state = GETNEARMSG; |
| | | } |
| | |
| | | changemainbase_count = 0; |
| | | } |
| | | #endif |
| | | }else if(mainbase_lost_count>10*tag_frequency) |
| | | }else if(mainbase_lost_count>5*tag_frequency) |
| | | { |
| | | tag_state = STARTPOLL; |
| | | } |
| | |
| | | |
| | | //LED0_ON; |
| | | SPIx_CS_GPIO->BRR = SPIx_CS; |
| | | delay_us(700); |
| | | delay_us(2700); |
| | | GetPressAndHeight(); |
| | | intheight = Height*100; |
| | | SPIx_CS_GPIO->BSRR = SPIx_CS; |
| | |
| | | while (DWT_DEVICE_ID != id) |
| | | { |
| | | // Dw1000_Init(); |
| | | delay_us(700); |
| | | id = dwt_readdevid() ; |
| | | IdleTask(); |
| | | if(error_times++>20) |