主要内容

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

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

背景

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

ZigBee的应用层包括多个子层组成:(我)应用支持子层(APS),和金宝app(2)ZigBee集群库(ZCL)。APS子层遵循所有应用程序概要文件和ZigBee集群通用的格式(参见[2])。的ZCL遵循所有集群通用的格式(参见[4.])。的ZCL有效载荷仅由一些集群使用,并且遵循特定于集群的格式。

集群和帧捕获

出所有的家庭自动化应用简档中使用的簇,该实施例中的解码,并产生帧为:(我)开/关集群(用于照明设备),以及(2)入侵者警报系统(IAS)区域簇(由运动传感器使用)[4.]。开/关群集不使用一个ZCL有效载荷,但IAS园区集群一样。

这些集群的框架已经从商业ZigBee射频实现家庭自动化捕获,使用USRP®B200迷你收音机和通讯工具箱支持包USRP®无线电金宝app.ZigBee可以在网络或应用层采用安全性。捕获的帧在网络层使用了安全性,随后被解密。这个示例解码解密的net层有效负载的应用层。

负载zigbeeAPPCaptures

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

一种无线个域网。一种PSFrameConfig配置对象用于生成和解码ZigBee APS帧。这些对象描述了一个aps层框架,并指定了它的框架类型和所有适用的属性。这无线个域网。一种PSFrameDecoder函数接受一个以字节为单位的APS协议数据单元(APDU)并输出一个zigbee。对象描述帧,也可能是一个以字节为单位的ZCL帧。第2.2.5.1条2]表示APS帧格式。

接下来,对捕获的IAS Zone帧的APS子层进行解码:

[apsConfig, apsPayload] = zigbee.APSFrameDecoder(motionDetectedFrame);apsConfig
apsConfig = APSFrameConfig与属性:帧类型: '数据' APSCounter:230 AcknowledgmentRequest:1寻址:DeliveryMode: '单播' DestinationEndpoint: '01' 丛集编号: '0500' 的简档: '0104' SourceEndpoint: '01' 的扩展报头:ExtendedHeader:0安全性:安全性:0

解码家用自动化ZigBee无线电的ZCL报头

一种无线个域网。ZCLFrameConfig配置对象中生成和解码的ZigBee ZCL头使用两者。这样的对象描述ZCL层帧并指定其帧类型和所有适用的性质。

zigbee.ZCLFrameDecoder函数接受以字节为单位的ZCL帧并输出zigbee。ZCLFrameConfigobject describing the header and possibly a ZCL payload in bytes. Clause 2.4.1 in [4.]描述了ZCL头帧格式。注意,ZCL头既可以指定“库宽”或“群集特定”命令类型。在后一种情况下,zigbee.ZCLFrameDecoder也需要集群ID,这是存在于APS头,以簇特定命令ID解码成命令类型。例如,下一个命令所捕获的IAS区帧的报头ZCL解码。

[zclConfig,zclPayload] = zigbee.ZCLFrameDecoder(apsPayload,apsConfig.ClusterID);zclConfig
zclConfig = ZCLFrameConfig with properties: FrameType: 'Cluster-specific' CommandType: 'Zone Status Change Notification' SequenceNumber: 9 manufacercommand: 0 Direction: 'Downlink' DisableDefaultResponse: 0

解码ZigBee无线电的IAS区域帧ZCL有效载荷

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

iasZoneConfig = zigbee.IASZoneFrameDecoder(zclPayload)
iasZoneConfig = IASZoneFrameConfig with properties: CommandType: 'Zone Status Change Notification' ZoneID: 0 Alarm1: 'Not alert ' Alarm2: ' alert ' Tampered: 0 LowBattery: 0 PeriodicReports: 0 RestoreReports: 1 Trouble: 0 ACFault: 0 BatteryDefect: 0 TestMode: 0 Delay: 0

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”;如果〜的isEmpty(zclPayload)&&的strcmp(apsConfig.ClusterID,iasZoneClusterID)IASConfig目录= zigbee.IASZoneFrameDecoder(zclPayload)如果任何(strcmp (“警告”, {iasConfig。一种larm1, iasConfig.Alarm2})) fprintf(“运动检测。\ n”);其他的fprintf中('运动停止。\ 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有效载荷

无线个域网。IASZoneFrameGenerator函数接受描述IAS区有效载荷的zigbee.IASZoneFrameConfig对象,并输出以字节为单位的有效负载。下面的代码创建用于该簇指示入侵具有或尚未检测到两个ZCL有效载荷。

iasConfigIntrusion =无线个域网。IASZoneFrameConfig (“Alarm2”“警告”);zclPayloadIntrusion = zigbee.IASZoneFrameGenerator (iasConfigIntrusion);iasConfigNoIntrusion =无线个域网。IASZoneFrameConfig (“Alarm2”“不担心”);zclPayloadNoIntrusion = zigbee.IASZoneFrameGenerator (iasConfigNoIntrusion);

生成ZCL帧

zigbee.ZCLFrameGenerator函数接受zigbee。ZCLFrameConfigobject describing the frame, and optionally a ZCL payload in bytes (two-characters), and outputs the ZCL frame in bytes. The following code generates ZCL frames for the On/Off cluster (no payload) and the IAS Zone cluster (payload needed).

% IAS区域集群zclConfigIntrusion =无线个域网。ZCLFrameConfig (“FrameType”提供集群范围内的......'的CommandType'“区域状态更改通知”......'序列号'1,“方向”“下行”);zclFrameIntrusion =无线个域网。ZCLFrameGenerator (zclConfigIntrusion zclPayloadIntrusion);%开/关集群zclConfigOn =无线个域网。ZCLFrameConfig (“FrameType”提供集群范围内的......'的CommandType''在'......'序列号'2,“方向”“上行”);zclFrameOn = zigbee.ZCLFrameGenerator (zclConfigOn);

生成APS帧

无线个域网。一种PSFrameGenerator函数接受描述所述帧中的对象zigbee.APSFrameConfig,和任选地在字节(2个字符)一个APS有效载荷(ZCL层帧),并输出在字节APS帧。下面的代码说明如何生成前一节中创建的帧ZCL APS帧。

% IAS区域集群apsConfigIntrusion = zigbee.APSFrameConfig(“FrameType”“数据”......“群ID”iasZoneClusterID,......“简档”,zigbee.profileID(“家庭自动化”),......“APSCounter”1,......'AcknowledgmentRequest',真正的);apsFrameIntrusion =无线个域网。APSFrameGenerator(apsConfigIntrusion, zclFrameIntrusion);%开/关集群apsConfigOn =无线个域网。APSFrameConfig (“FrameType”“数据”......“群ID”onOffClusterID,......“简档”,zigbee.profileID(“家庭自动化”),......“APSCounter”2,......'AcknowledgmentRequest',真正的);apsFrameOn = zigbee.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月。