主要内容

ZigBee家庭自动化帧生成和解码

这个示例演示了如何为家庭自动化应用程序配置文件生成和解码应用层框架[1]ZigBee®规范[2使用用于ZigBee和UWB的通信工具箱™库。

背景

ZigBee标准[2]指定用于低速率无线个人局域网的网络(NET或NWK)层和应用程序(APP或APL)层。这些网络和应用程序层规范建立在IEEE®802.15.4™的PHY和MAC规范之上[3.].ZigBee设备应用于家庭自动化和传感器网络,与物联网(IoT)趋势高度相关。

ZigBee应用层由多个子层组成:(我)APS (Application金宝app Support Sublayer)(ii)zigbee群集库(zcl)。APS Sublayer遵循对所有应用程序配置文件和ZigBee集群常见的格式(参见[2])。ZCL.标题遵循对所有群集常见的格式(参见[4])。ZCL.有效载荷仅由某些集群使用,它遵循特定于群集的格式。

集群和帧捕获

在家庭自动化应用程序概要文件中使用的所有集群中,这个示例解码并生成以下帧:(我)开/关群集(由灯设备使用),以及(ii)入侵者警报系统(IAS)区域集群(由运动传感器使用)[4].On/Off集群不使用ZCL有效负载,但是IAS Zone集群使用。

这些集群的帧是从支持家庭自动化的商用ZigBee无线电中捕获的,使用USRP®B200-mini无线电和通讯工具箱支持包的USRP®无线电金宝app.ZigBee可以在网络或应用层中使用安全性。捕获的帧在网络层采用安全性,并稍后在解密。此示例对解密的Net-Layer载荷的应用层进行解码。

负载zigbeeAPPCaptures

家庭自动化ZigBee无线电APS帧解码

一个zigbee.apsframeconfig配置对象在生成和解码ZigBee APS帧中使用。这些对象描述了APS层框架并指定其帧类型和所有适用的属性。的ZigBee.apsfrawerCoder.函数接受一个以字节为单位的APS协议数据单元(APDU)并输出一个zigbee。对象描述帧,也可能是一个以字节为单位的ZCL帧。第2.2.5.1条2]描述APS帧格式。

接下来,解码捕获的IAS区域帧的APS子层:

[apsconfig,apspayload] = zigbee.apsframedecoder(motionDetectedFrame);apsconfig.
apsConfig = APSFrameConfig带有属性:FrameType: 'Data' APSCounter: 230鸣信请求:1寻址:DeliveryMode: 'Unicast' DestinationEndpoint: '01' ClusterID: '0500' ProfileID: '0104' SourceEndpoint: '01'扩展头:ExtendedHeader: 0安全:安全:0

解码家庭自动化ZigBee Roiro的ZCL标题

一个zigbee.zclframeconfig配置对象用于生成和解码ZigBee ZCL报头。这些对象描述一个zcl层框架,并指定它的框架类型和所有适用的属性。

无线个域网。ZCLFrameDecoder函数以字节为单位接受zcl帧,并输出描述标题的zigbee.zclframeConfig对象,并以字节为单位zcl有效载荷。第2.4.1条[4描述ZCL报头帧格式。注意,ZCL头可以指定“库范围”或“集群特定”命令类型。在后一种情况下,zigbee。ZCLFrameDecoderalso needs the cluster ID, which is present in the APS header, in order to decode the cluster-specific command ID into a command type. For example, the next command decodes the ZCL header of a captured IAS Zone frame.

[zclConfig, zclPayload] = zigbee。ZCLFrameDecoder(apsPayload, apsConfig.ClusterID); zclConfig
zclconfig = zclframeconfig与属性:frameType:'特定于群集的'commandtype:'区域状态更改通知'semencenumber:9制造商:0方向:'下行链路'disaverefaultresponse:0

解码ZigBee Radio的IAS区帧的ZCL有效载荷

与开/关集群相比,IAS Zone集群在ZCL头之外指定了一个ZCL负载。一个无线个域网。IASZoneFrameConfig配置对象用于生成和解码IAS Zone ZCL有效负载。这些对象描述了一个IAS区域有效载荷和所有适用的属性。的无线个域网。IASZoneFrameDecoder函数接受一个以字节为单位的IAS区域有效负载并输出一个zigbee。对象IASZoneFrameConfig,描述IAZ区域有效负载。

iasZoneConfig = zigbee.IASZoneFrameDecoder (zclPayload)
IASZONECONFIG = IASZONEFRAMECONFIG具有属性:'ZONE状态更改通知'ZOOMID:0 ALARM1:'没有警告'ALARM2:'警报'篡改:0低划分:0级别恢复器:1麻烦:0 ACFAULT:0电压件:0 TestMode:0延迟:0

解码ZigBee Radios的运动触发照明自动化

已经为商用家庭自动化ZigBee无线电建立了照明自动化,其帧已被捕获并解码。具体来说,一旦运动传感器检测到运动,它就会向ZigBee集线器发送信号,ZigBee集线器再向灯泡发送信号,灯泡就会打开。当运动传感器检测到运动已经停止(例如,在10秒钟没有运动后),它会向ZigBee集线器发送一个信号,然后通过无线方式触发灯泡关闭。下面的视频演示了照明自动化。

helperPlaybackVideo ('LightingAutomation.mp4', 2/5);

以下代码对ZigBee无线电之间传输的实际帧进行解码。使用USRP®设备捕获这些(在视频中显示)。

apsFrames = {motionDetectedFrame;turnOnFrame;motionStoppedFrame;turnOffFrame};idx = 1:长度(apsFrames)%APS解码:[apsConfig, apsPayload] = zigbee.APSFrameDecoder(apsFrames{idx});% ZCL头解码:[zclConfig, zclPayload] = zigbee。ZCLFrameDecoder(apsPayload, apsConfig.ClusterID); zclConfig%开关群集(没有ZCL有效载荷)onOffClusterID =“0006”如果比较字符串(apsConfig。ClusterID onOffClusterID)流(['转动灯泡'低(zclConfig.CommandType)”。\ n”]);结束%入侵者警报系统(IAS)区域集群有ZCL有效负载:iaszoneclusterid ='0500'如果& & strcmp (apsConfig ~ isempty (zclPayload)。iasConfig = zigbee.IASZoneFrameDecoder(zclPayload)如果任何(Strcmp(“警告”, {iasConfig。一个larm1, iasConfig.Alarm2})) fprintf(“运动检测。\ n”);其他的流(“运动停止。\ n”);结束结束结束
zclConfig = ZCLFrameConfig with properties: FrameType: 'Cluster-specific' CommandType: 'Zone Status Change Notification' SequenceNumber: 9 ManufacturerCommand: 0 Direction: 'Downlink' DisableDefaultResponse: 0 iasConfig = IASZoneFrameConfig with properties: CommandType: 'Zone Status Change Notification' ZoneID: 0 Alarm1: 'Not alert ' Alarm2:'告警' Tampered: 0 LowBattery: 0 PeriodicReports: 0 RestoreReports: 1 Trouble: 0 ACFault: 0 BatteryDefect: 0 TestMode: 0 Delay: 0 Motion detected。zclConfig = ZCLFrameConfig with properties: FrameType: 'Cluster-specific' CommandType: 'On' SequenceNumber: 64 ManufacturerCommand: 0 Direction: 'Uplink' DisableDefaultResponse: 0打开灯泡。zclConfig = ZCLFrameConfig with properties: FrameType: 'Cluster-specific' CommandType: 'Zone Status Change Notification' SequenceNumber: 10 ManufacturerCommand: 0 Direction: 'Downlink' DisableDefaultResponse: 0 iasConfig = IASZoneFrameConfig with properties: CommandType: 'Zone Status Change Notification' ZoneID: 0 Alarm1: 'Not alert ' Alarm2:'Not alert ' Tampered: 0 LowBattery: 0 PeriodicReports: 0 RestoreReports: 1 Trouble: 0 ACFault: 0 BatteryDefect: 0 TestMode: 0 Delay: 0 Motion stopped。zclConfig = ZCLFrameConfig with properties: FrameType: 'Cluster-specific' CommandType: 'Off' SequenceNumber: 70 manufacercommand: 0 Direction: 'Uplink' DisableDefaultResponse: 0 Turn light bulb Off . zclConfig = ZCLFrameConfig with properties: FrameType: 'Cluster-specific' CommandType: 'Off' SequenceNumber: 70 manufacercommand: 0 Direction: 'Uplink' DisableDefaultResponse: 0 Turn light bulb Off。

生成IAS区域ZCL有效载荷

zigbee.iaszoneFrameGenerator.函数接受zigbee。IASZoneFrameConfigobject describing the IAS Zone payload and outputs the payload in bytes. The following code creates two ZCL payloads for this cluster indicating that intrusion has or has not been detected.

IASConfigintrusion = ZigBee.iaszoneFrameConfig('armar2'“警告”);zclpayloadInctrusion = zigbee.iaszoneFrameGenerator(IASConfigintrusion);IASCONFignOineRusion = ZigBee.IaszoneFrameConfig('armar2''没有惊慌');zclPayloadNoIntrusion = zigbee.IASZoneFrameGenerator (iasConfigNoIntrusion);

生成ZCL帧

无线个域网。ZCLFrameGenerator函数接受zigbee。对象描述帧,并可选地使用字节(两个字符)表示ZCL有效负载,并输出以字节为单位的ZCL帧。下面的代码为开/关集群(没有有效负载)和IAS Zone集群(需要有效负载)生成ZCL帧。

%IAS区域集群zclconfigintrusion = zigbee.zclframeConfig(“FrameType”'特定于集群'...“CommandType”'区域状态更改通知'...“SequenceNumber”, 1“方向”'下行');zclframeintrusion = zigbee.zclframegenerator(zclconfigintrusion,zclpayloadintrusion);%开/关集群zclconfigon = zigbee.zclframeConfig(“FrameType”'特定于集群'...“CommandType”“上”...“SequenceNumber”2,“方向”“上行”);zclFrameOn = zigbee.ZCLFrameGenerator (zclConfigOn);

生成APS帧

无线个域网。一个PSFrameGenerator函数接受zigbee。一个PSFrameConfig object describing the frame, and optionally a APS payload (ZCL-layer frame) in bytes (two-characters), and outputs the APS frame in bytes. The following code illustrates how to generate APS frames for the ZCL frames created in the previous section.

%IAS区域集群apsConfigIntrusion =无线个域网。APSFrameConfig (“FrameType”'数据'...“ClusterID”iasZoneClusterID,...“ProfileID”zigbee.profileID ('家庭自动化'),...'apscounter', 1...“AcknowledgmentRequest”,真正的);apsFrameIntrusion =无线个域网。APSFrameGenerator(apsConfigIntrusion, zclFrameIntrusion);%开/关群集apsConfigOn =无线个域网。APSFrameConfig (“FrameType”'数据'...“ClusterID”onOffClusterID,...“ProfileID”zigbee.profileID ('家庭自动化'),...'apscounter'2,...“AcknowledgmentRequest”,真正的);apsFrameOn =无线个域网。APSFrameGenerator(apsConfigOn, zclFrameOn);

进一步的探索

您可以进一步探索以下生成器和解码功能,以及配置对象:

选定的参考书目

  1. ZigBee联盟,ZigBee家庭自动化公共应用简介,修订29,v. 1.2, 2013年6月。

  2. ZigBee联盟,ZigBee规范文件053474r17, 2007

  3. IEEE 802.15.4-2011 IEEE局域网和城域网标准第15.4部分:低速率无线个人区域网(rr - wpan)

  4. ZigBee联盟,ZigBee集群库规范,修订版6,2016年1月。