zhyinch
2019-11-29 00485199097d2314a18da9f69fb7422a489064d6
Ô´Âë/ºËÐİå/Src/application/dw_app.c
@@ -21,7 +21,7 @@
static uint8_t tx_sync_msg[14] = {0};
static uint8_t tx_final_msg[60] = {0};
static uint8_t tx_resp_msg[22] = {0};
static uint8_t tx_near_msg[32] = {0};
static uint8_t tx_near_msg[80] = {0};
static uint32_t frame_seq_nb = 0;   
static uint32_t status_reg = 0;
@@ -326,8 +326,8 @@
   memcpy(&tx_near_msg[NEARBASEID_INDEX],&nearbaseid_list,nearbase_num*2);
   tx_near_msg[MESSAGE_TYPE_IDX] = NEAR_POLL;   
   memcpy(&tx_near_msg[ANCHOR_ID_IDX],&mainbase_id,2);   
   dwt_writetxdata(sizeof(tx_near_msg), tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去
   dwt_writetxfctrl(sizeof(tx_near_msg), 0);//设置超宽带发送数据长度
   dwt_writetxdata(24, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去
   dwt_writetxfctrl(24, 0);//设置超宽带发送数据长度
   dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置
   neartimout_timer=0;
@@ -336,7 +336,9 @@
         while(neartimout_timer<timeout&&recbase_num<nearbase_num+1)
         {
               while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到成功接收或者发生错误
               {
               {
                   if(neartimout_timer>timeout)
                        break;
               };
               if(status_reg==0xffffffff)
               {
@@ -347,13 +349,14 @@
                     dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG | SYS_STATUS_TXFRS);//清楚寄存器标志位
                     frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFLEN_MASK;   //获得接收到的数据长度
                     dwt_readrxdata(rx_buffer, frame_len, 0);   //读取接收数据
                     dwt_setrxtimeout(DELAY_BETWEEN_TWO_FRAME_UUS+100);//设定接收超时时间,0位没有超时时间
                     dwt_rxenable(0);//打开接收
                     if (rx_buffer[MESSAGE_TYPE_IDX] == NEAR_RESPONSE&&!memcmp(&rx_buffer[TAG_ID_IDX],&dev_id,2)) //判断接收到的数据是否是response数据
                     {   u16 rec_nearbaseid,rec_nearbasepos;
                        poll_tx_ts = get_tx_timestamp_u64();                              //获得POLL发送时间T1
                        resp_rx_ts = get_rx_timestamp_u64();                              //获得RESPONSE接收时间T4   
                        recbase_num++;
                        memcpy(&rec_nearbaseid,&rx_buffer[ANCHOR_ID_IDX],2);
                        rec_nearbasepos=FindNearBasePos(rec_nearbaseid);
                        if(rec_nearbaseid==mainbase_id)
                        {
                           //时间同步
@@ -378,30 +381,33 @@
                           dwt_setdelayedtrxtime(final_tx_time);//设置final包发送时间T5
                           final_tx_ts = (((uint64_t)(final_tx_time & 0xFFFFFFFE)) << 8) + TX_ANT_DLY;//final包实际发送时间是计算时间加上发送天线delay
                           final_msg_set_ts(&tx_near_msg[FINAL_MSG_POLL_TX_TS_IDX], poll_tx_ts);//将T1,T4,T5写入发送数据
                           final_msg_set_ts(&tx_near_msg[FINAL_MSG_RESP_RX_TS_IDX], resp_rx_ts);
                           final_msg_set_ts(&tx_near_msg[FINAL_MSG_RESP_RX_NEARBASE_IDX], resp_rx_ts);
                           final_msg_set_ts(&tx_near_msg[FINAL_MSG_FINAL_TX_TS_IDX], final_tx_ts);
                           tx_near_msg[MESSAGE_TYPE_IDX]=NEAR_FINAL;
                           dwt_writetxdata(sizeof(tx_near_msg), tx_near_msg, 0);//将发送数据写入DW1000
                           dwt_writetxfctrl(sizeof(tx_near_msg), 0);//设定发送数据长度
                           dwt_writetxdata(28+nearbase_num*4, tx_near_msg, 0);//将发送数据写入DW1000
                           dwt_writetxfctrl(28+nearbase_num*4, 0);//设定发送数据长度
                           result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送         
                        }else{
                           final_msg_set_ts(&tx_near_msg[FINAL_MSG_RESP_RX_NEARBASE_IDX+rec_nearbasepos*4], resp_rx_ts);
                           rec_nearbasepos=FindNearBasePos(rec_nearbaseid);
                           final_msg_set_ts(&tx_near_msg[FINAL_MSG_RESP_RX_NEARBASE_IDX+(rec_nearbasepos+1)*4], resp_rx_ts);
                           memcpy(&nearbase_distlist[rec_nearbasepos],&rx_buffer[DIST_IDX],4);
                           dwt_writetxdata(sizeof(tx_near_msg), tx_near_msg, 0);//将发送数据写入DW1000
                           dwt_writetxdata(28+nearbase_num*4, tx_near_msg, 0);//将发送数据写入DW1000
                           dwt_writetxfctrl(28+nearbase_num*4, 0);//设定发送数据长度
                           //dwt_writetxdata(4,&tx_near_msg[FINAL_MSG_RESP_RX_NEARBASE_IDX+(rec_nearbasepos+1)*4], FINAL_MSG_RESP_RX_NEARBASE_IDX+(rec_nearbasepos+1)*4);//将发送数据写入DW1000
                        }                        
                     }
                  }         
         }
            if(result==0)
         {while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))//不断查询芯片状态直到发送完成
         { };
   }
   else
   {
   dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR);
      random_delay_tim = DFT_RAND_DLY_TIM_MS;
   }
            dwt_forcetrxoff();
//            if(result==0)
//         {while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))//不断查询芯片状态直到发送完成
//         { };
//
//   }
//   else
//   {
//   dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR);
//   }
}
void NearAncSelect(void)
@@ -583,7 +589,7 @@
         }
}
void Anchor_RecNearPoll(u8 ancrec_nearbasepos)
void Anchor_RecNearPoll(u8 ancrec_nearbasepos) //0 mainbase  1 first near_base
{
         tmp_time=TIM3->CNT;
         memcpy(&tx_near_msg[ANCTIMEMS],&sync_timer,2);
@@ -599,8 +605,8 @@
         memcpy(&tx_near_msg[DIST_IDX], &tagdist_list[taglist_pos], 4);
         tx_near_msg[MESSAGE_TYPE_IDX]=NEAR_RESPONSE;
         dwt_writetxdata(sizeof(tx_near_msg), tx_near_msg, 0);//写入发送数据
         dwt_writetxfctrl(sizeof(tx_near_msg), 0);//设定发送长度
         dwt_writetxdata(17, tx_near_msg, 0);//写入发送数据
         dwt_writetxfctrl(17, 0);//设定发送长度
         result = dwt_starttx(DWT_START_TX_DELAYED | DWT_RESPONSE_EXPECTED);//延迟发送,等待接收
         battary = rx_buffer[BATTARY_IDX];
@@ -669,7 +675,7 @@
}
void Anchor_App(void)
{
   u8 send_len,nearbase_num,i;
   u8 send_len,i;
   u16 tempid;
   dwt_setrxtimeout(0);//设定接收超时时间,0位没有超时时间
   dwt_rxenable(0);//打开接收