DWM1000 幀過濾代碼實現


幀過濾功能可以在同一個環境內組建多個網絡而不干擾(非頻段不同),可以通過PANID(網絡ID)區分不同網絡,不同網絡中的模塊無法直接通信, 再之,利用短地址,網絡中可以同時有多個模塊發送信息,而接收端會根據信息短地址不同而自動過濾。

1 發送端部分,組建發送結構體,按照MAC 數據結構組織。

    srd_msg_dsss msg_f ; // ranging message frame with 16-bit addresses
    int psduLength = 0;
    //set frame type (0-2), SEC (3), Pending (4), ACK (5), PanIDcomp(6)
    msg_f.frameCtrl[0] = 0x1 /*frame type 0x1 == data*/ | 0x40 /*PID comp*/;
    //source/dest addressing modes and frame version
        //msg_f.frameCtrl[0] = 0x41;
    msg_f.frameCtrl[1] = 0x8 /*dest extended address (16bits)*/ | 0x80 /*src extended address (16bits)*/;
    msg_f.panID[0] = 0xF0;
    msg_f.panID[1] = 0xF0;

    msg_f.seqNum = 0;
    msg_f.messageData[POLL_RNUM] = 3; //copy new range number
    msg_f.messageData[FCODE] = RTLS_DEMO_MSG_ANCH_POLL; //message function code (specifies if message is a poll, response or other...)
    psduLength = (TAG_POLL_MSG_LEN + FRAME_CRTL_AND_ADDRESS_S + FRAME_CRC);
    msg_f.seqNum = 0; //copy sequence number and then increment
    msg_f.sourceAddr[0] = 0x02; //copy the address
    msg_f.sourceAddr[1] =0x02; //copy the address
    msg_f.destAddr[0] = 0x01;  //set the destination address
    msg_f.destAddr[1] = 0x01;  //set the destination address 

其中數據結構 srd_msg_dsss 部分摘錄自官方源碼。模塊所在PANID = 0xF0F0, TX 本身短地址0x0202,RX本身短地址0x0101。-->接收端需要配置同樣的PANID以及RX本身地址

啟動發送代碼

   dwt_writetxdata(psduLength, (uint8 *)&msg_f, 0) ; // write the frame data
   dwt_writetxfctrl(psduLength, 0);
   /* Start transmission. */
   dwt_starttx(DWT_START_TX_IMMEDIATE);

2 RX 使能幀過濾功能以及配置PANID 和 短地址

   dwt_enableframefilter(DWT_FF_DATA_EN | DWT_FF_ACK_EN); 
   dwt_setpanid(0xF0F0);
   dwt_setaddress16(0x0101);

接收並打印信息

 if (status_reg & SYS_STATUS_RXFCG)
 {
            //printf("Step3!\r\n");
            /* A frame has been received, copy it to our local buffer. */
            frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFL_MASK_1023;
            if (frame_len <= FRAME_LEN_MAX)
            {
                dwt_readrxdata(rx_buffer, frame_len, 0);
                USART_puts(rx_buffer,frame_len);
                //printf("Y!\r\n");
            }
            /* Clear good RX frame event in the DW1000 status register. */
            dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG);
  }

按照上述代碼實現,RX端可以接收到TX發送的信息。

增加實驗:不論單獨修改TX/RX 任何一端的PANID 和 短地址,RX端均不能收到數據,說明幀過濾功能正常。

 

上述只有部分代碼實例,完整工程請到bphero.com.cn 下載學習


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM