问题

 

如何使用Inter-Pan消息实现两个不同网络的设备之间的单跳通信?

答案

 

Inter-Pan消息可用于不同网络,同一信道的两个设备之间的单跳通信。Silicon Labs提供Inter-Pan Plugin,方便客户在此Plugin的基础上扩展,以在自己的应用中实现Inter-Pan消息的发送和接收。本文主要介绍如何搭建和测试Inter-Pan的功能,并以Z3Light sample(EmberZnet stack v5.10)为例,在WSTK+4151 无线板子上进行演示。

 

  1. Inter-Pan Plugin的源码位于协议栈的C:\SiliconLabs\SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\v1.1\protocol\zigbee_5.10\app\framework\plugin\interpan
  1. 在Z3Light sample中已经勾选该Inter-Pan Plugin。创建并编译该Z3Light sample,将固件以及对应的Bootloader烧录到两块WSTK 4151无线板。
  1. 两块无线板启动之后会自动扫描网络并加入Centralized,如果没有网络可以加入,最后会建立自己Distributed网络。在此实验中,每个板子分别建立自己的Distributed网络,确保它们处于同一个信道即可。如果比较难建立同一信道上的不同网络,也可以分别加入两个同一信道不同PANID的网络。如下所示,两个板子分别建立好自己的网络。
AppBuilder MFG Code: 0x1002
node [(>)000B57FFFE07F6E3] chan [20] pwr [3]
panID [0xF052] nodeID [0xCBD9] xpan [0x(>)0D03351F0A0587C6]
stack ver. [5.10.0 GA build 36]
nodeType [0x02]
Security level [05]
network state [02] Buffs: 74 / 75
AppBuilder MFG Code: 0x1002
node [(>)000B57FFFE07F6E2] chan [20] pwr [3]
panID [0x2923] nodeID [0x390E] xpan [0x(>)87461289F0783C2F]
stack ver. [5.10.0 GA build 36]
nodeType [0x02]
Security level [05]
network state [02] Buffs: 75 / 75
  1. 通过CLI命令测试Inter-Pan消息的发送和接收。在Simplicity Studio中,将两个设备对应的Console打开,在一个Console中输入如下命令:

plugin interpan fragment-test [panId:2] [eui64:8] [clusterId:2] [msgLen:2]

  • Sends a message of specified length of random values to target device over inter-PAN.
    • panId - INT16U - The PAN ID that the target is located on
    • eui64 - IEEE_ADDRESS - The target's EUI64 (big endian)
    • clusterId - INT16U - The cluster ID that the sample message should contain
    • msgLen - INT16U - The length of the randomly-filled message to be sent across inter-PAN

plugin interpan fragment-test 0xFFFF {000B57FFFE07F6E3}  0x0000 10

其中第一个参数是目的设备的PANID,可以设置为0xFFFF。

第二个参数是目的设备的EUI64,可以设置为NULL代表广播消息,否则为单播。

第三个参数是目的设备的Cluster。

第四个参数是发送的消息的Playload长度。

 

  1. 发送完上述命令,可在控制台中看到对应的输出信息:

发送端:

Z3LightSocV510MG1>Sending inter-PAN message of len 10 to (>)000B57FFFE07F6E3 with random values: T00000000:Inter-PAN TX (10) [A9 30 09 70 82 6D D1 A9 3B 14 ], 0x00
success (0x00)

接收端:

RX inter-PAN message (unicast):
  src pan id: 0x2923
  src long id: (>)000B57FFFE07F6E2
  profile id: 0x0109
  cluster id: 0x0000 (Basic)
ERR: Inter-PAN profile 0x0109, cluster 0x0000, command 0x09 not permitted

以上打印信息表明Inter-Pan消息发送成功。用户可根据自己的需求,构建自定义的消息。

 

  1. 函数流程分析:

发送流程:

当输入plugin interpan fragment-test,最调用如下函数:

void emAfInterpanFragmentTestCommand(void)

|-- emberAfSendInterPan()

|-- emberAfInterpanSendMessageCallback()

    |-- makeInterPanMessage()

    |-- emAfPluginInterpanSendRawMessage()

        |-- emberSendRawMessage()

最核心的函数是emberSendRawMessage(),其在raw-message.h中定义。

 

/** @brief Sends the given message over the air without higher layer
 * network headers.
 *
 * The first two bytes are interpreted as the 802.15.4 frame control field.
 * If the Ack Request bit is set, the packet will be retried as necessary.
 * Completion is reported via ::emberRawTransmitCompleteHandler().
 * Note that the sequence number specified in this packet is not taken into
 * account by the MAC layer. The MAC layer overwrites the sequence number field
 * with the next available sequence number.
 *
 * @param message  The message to transmit.
 *
 * @return ::EMBER_SUCCESS if the message was successfully submitted to
 * the transmit queue, and ::EMBER_ERR_FATAL otherwise.
 */
EmberStatus emberSendRawMessage(EmberMessageBuffer message);

 

如果想发送广播消息, 可将emberAfSendInterPan()的参数改为如下格式:

EmberStatus status = emberAfSendInterPan( OxFFFF,
                     NULL,
                     EMBER_NULL_NODE_ID,
                     0,      // mcast id - unused
                     clusterId,
                     SE_PROFILE_ID, // GBCS only
                     messageLen,
                     testMessage);

 

接收流程:

当接收到Inter-Pan消息时,emberMacPassthroughFilterHandler()会被调用,其在raw-message.h中定义。

 

/** @brief This function is called when the stack has received a raw MAC message that has
 *    matched one of the application's configured MAC filters.
 *
 * @param macFilterMatchStruct This is a pointer to a structure containing information
 *   about the matching message, including the index of the filter that was matched,
 *   and the actual data of the message.
 */
void emberMacFilterMatchMessageHandler(const EmberMacFilterMatchStruct* macFilterMatchStruct);

 

emberMacFilterMatchMessageHandler()

    |-- emAfPluginInterpanProcessMessage()

        |-- emberAfPluginInterpanPreMessageReceivedCallback()

 

以上就是Inter-Pan消息的测试过程以及发送和接收流程的源码分析,更多信息请参考Inter-Pan Plugin的源码。

  • Proprietary
  • Knowledge Base Articles
  • Wireless