zigbee协议栈一 zigbee协议栈有哪些

本文参考自jennic技术手册《JN-UG-3017-ZigBeeStackUserGuide-1v6》

Acronyms and Abbreviations缩略语
AES AdvancedEncryption Standard
AF Application Framework
AFDE AF sub-layer Data Entity
AFME AF sub-layer Management Entity
API Application Programming Interface
zigbee协议栈(一) zigbee协议栈有哪些
APS Application Support sub-layer
BOS Basic Operating System
BPSK Bipolar Phase-Shift Keying
DSSS Direct-Sequence-Spread-Spectrum
HCL Home Controls-Lighting
MAC Media Access Control

NWK Network layer
OEM Original Equipment Manufacturer
PAN Personal Area Network
PDU Protocol Data Unit
RF Radio Frequency
SAP Service Access Point
ZDO ZigBee Device Objects
ZDP ZigBee Device Profile(规约)


一、zigbee网络介绍

其实就是讲zigbee的有点,比如低功耗,组网快,一个节点可以与多个节点建立连接。去网上一搜一大堆。

其中zigbee协议栈里有一些知识讲一下:

1.profile

Profile:每一个ZigBee 的网络设备都应该使用一个Profile, Profile定义了设备的应用场景,WSN),另外定义了设备的类型还有设备之间的信息交换规范。以便不同的节点甚至是不同厂商生产的节点能够协作。

有两种profile,一种是stackprofile,一种是application profile

1)stack profile

stack profile决定了zigbeestack为网络结构提供什么样的资源(resource)——比如网络类型,拓扑,以及与application相适应的特征(如安全类型)。

zigbee联盟已经制定了多个常见的stackprofiles,应用在不同的场合如:Home Controls,Building

Automation,PlantControl

除此之外,用户可以自定义自己需要的私有应用程序规约(private application profile)

2)Application Profile

一个Application Profile 关联一个特定的stack profile,并制定一些applicationprofile自己特定的应用。

每一个Profile都有一个16位的标志。

Application Profiles可以分为PublicProfiles和Private Profiles

Public Profiles

zigbee联盟制定的profile就是PublicProfiles,制定它是为了实现不同厂商生产的设备在同一个应用中能够兼容

Private Profiles (also known as ‘non-public’profiles)

除了zigbee联盟制定的公有的profile,厂商还可以定义自己私有的profile,实现自己一些特定的应用。

二、zigbee结构与相关概念

1.zigbee结构

一个节点上的程序,它的结构可以认为分为3层次(level不是layer):PHY/LINK level,zigbeestack level,application level。

application level和applicationlayer是否是一个概念呢?文档没有说清楚

2.网络层次概念(Network LevelConcepts)

1)节点

节点角色:Co-ordinator(选择合适的信道,建立网络,网络初始化(网络ID等),允许节点加入)

Router(允许子节点通过它加入网络) End Device(不能转发消息)。

2)拓扑

星形(两个节点通信必须要经过coordinator),树形,网状

3)网络配置(Network Configuration)

网络配置的初始化是在coordinator上进行的。配置的内容包括:一个router可以连接的最多的节点个数,一个router可以连接的router的个数,从coordinator到最远节点的跳数,然后基于以上可以得到一个网络最多的节点个数。

配置内容:

The depth of a device is the number of nodes from the root ofthe network tree (the Co-ordinator) to the device. Themaximum network depth is then the maximum numberof hops to the most distant device in the network from theCo-ordinator. This is set at configuration timeand determines the overall diameter for the network. Note that aStar network has a network depth of 1.

Each Router in the network can have a numberof child devices attached to it. These may be either Routers or EndDevices. The Co-ordinator specifies the number of childdevices allowed per Router, and how many of these child devices canbe Routers.

Network addresses are allocated duringinitialisation of the network. The Co-ordinator allocates eachchild Router a block of consecutive addresses to allocate to itschildren. These address blocks provide each Router with enoughaddresses to allocate to all of its potential children, as definedby the maximum routers, maximum children and maximum depthparameters. In turn, the block of addresses given to a Router willbe subdivided amongst its child Routers and so on down the tree.Since the topology of a deployed network is not necessarily uniform(as many nodes may be needed in one geographic area and relativelyfewer in another), it is possible for one Router to have all of itsallocated addresses in use while those on another may beunused.(网络初始化的时候,coordinator会进行短地址分配,根据每个router子节点个数的最大值,分配给router一段地址,供它分配给其子节点。)

3)启动网络

coordinator负责启动网络,首先他选择一个合适的频道,接着启动网络,生成PANID,然后响应其他节点加入网络的请求

4)加入网络步骤

coordinator和router都有让其他节点加入网络的能力。加入网络过程如下:

The newnode first scans the available channels to find operating networksand identifies which one it should join. Multiple networks mayoperate in the same channel and are differentiated by their PANIDs.(一个节点周围有多个PAN时该选择哪个?)
Thenode may be able to ‘see’ multiple Routers and a Co-ordinator fromthe same network, in which case it selects which one it shouldconnect to. Usually, this is the one with the bestsignal.(一个节点周围既有coordinator又有router时通常根据信号的好坏选择跟谁建立连接)
Thenode then sends a message to the Router asking to join thenetwork.(节点请求加入网络)
TheRouter decides whether the node is a permitteddevice, whether the Router is currently allowingdevices to join and whether it has addressspace available. If all these criteria are satisfied, theRouter will then allow the device to join and allocate it anaddress.(router考察能否让节点加入网络)

5)Stack Profiles

一个StackProfiles规定了网络的depth,网络拓扑,子节点个数等。zigbee联盟已经针对特定应用定义了一些stackprofile。对于一些特定的应用中,标准stack profile不适用,这是stack参数由设计者指定。

6)短地址

短地址为16位,由父节点分配,两个PAN中的节点可能有相同的ID.

7)消息传播(Message Propagation)

消息里需要包括两种地址才能保证到达目标节点:

目标节点地址和下一跳节点的地址。

在mesh网络中,当节点在目标节点通信范围内的时候,消息只需要目标节点的地址。

当节点不在目标节点通信范围内的时候,消息需要包含下一跳地址(下一跳需要在到目标节点的路由上)。

注意:对于节点上的应用程序来说,并不知道要传递的消息和消息的内容,转发机制(relayingmechanism)是由zigbee stack管理的(除非是在路由发现的情况下)。

8)消息路由和路由发现

ZigBee stack network layer支持路由发现(routediscovery),通过路由发现网络可以找到到达目标节点的最佳路由,路由发现有三种选择:

下面是两个end device之间的路由发现机制(如果用简单的DTN路由协议不会用到它,如果稍微有点难度的协议,就会需要使用转发机制,但是这里的路由发现协议显然不适合DTN转发协议,目前来看,转发机制在stack的网络层,好像是不能修改的。):

• A route discovery broadcast is sent by the parent Router ofthe source End Device, containing the target destination End Devicenetwork address.
All routers will eventually receive thebroadcast, one of which is the parent of the destination EndDevice
• The parent Router of the destination node sends back a replyaddressed to the parent router of the source.
• As the reply travels back through the network, the hop count anda signal quality measure for each hop are recorded. Each Router inthe path can build a routing table entry containing the best pathto the destination End Device
The choice of best path is usually the one with the least number ofhops, although if a hop on the most direct route has a poor signalquality (and hence a greater chance that retries will be needed), aroute with more hops may be chosen.
• Eventually each Router in the path will have a routing tableentry and the route from source to destination End Device isestablished. Note that the corresponding route from destination tosource is not known – the route discovered is unidirectional.

透明路由(RoutingTransparency)

通常情况下路由对于应用程序是透明的,但是在mesh网络拓扑中,当节点要发送信息时,如果没有可用的路由,在发消息之前,在Co-ordinator or Router的application level(我怀疑只是调用stack里的函数进行初始化,而真正的路由发现机制的程序代码是无法修改的,或者说想添加自己的DTN转发机制是很难得,就我目前的理解来看)会初始化并完成路由发现。我的理解是,mesh网络中如果没有可用路由,而是任信息在网络中转发的话,由于router很多,会造成网络业务增加,相比之下,有一条路由更可靠,而移动DTN就像一个router之间时而连接时而断开的mesh网络,用路由发现的方法寻找消息传播最佳路径是不可能的,使用路由转发机制才靠谱,但问题是,jennic是够给予我们增加转发机制的API。Messagerouting is normally performed automatically by theZigBee stack, without any intervention from theapplications running on the Router or Co-ordinator.Therefore, routing is usually, but not always, transparent to theapplications.
Routing is not transparent in a Mesh topology when a direct orindirect message is sent to a destination address for which a routehas not already been discovered (and route discovery is active). Inthis case, the Co-ordinator or Router must initiate and complete aroute discovery (at application level) before sending themessage.

3.应用程序层次概念(Application Level Concepts)

1)多应用程序和端点(Multiple Applications andEndpoints)

一个节点可以有多个应用程序运行,比如监测温度和监测湿度的两个应用程序,然后每个应用程序对应一个端点,类似套接字里的端口。Endpointaddresses for user applications are numbered from 1 to 240.Endpoint255 is the broadcast endpoint address; the same data can be sent toall applications on a node by sending the message to thataddress.所以两个节点的程序通信的时候,一个节点不仅要知道dest节点的地址,还要知道那个程序对应的endpoint

2)Application Profiles

The ZigBee Alliance has defined a number ofstandard profiles for ZigBee devices. A profilerelates to a particular application and/or marketand contains descriptions of the types of devices andinterfaces which are needed for that particularapplication.

Within each Application Profile, a number of Device Descriptionsare defined, describing the types of devices the profilesupports.在ApplicationProfile里描述了特定应用中会用到的节点上的设备(如开关,led,一些控制器。节点上的device很多,在某一个应用中不是所有的devices都会用的上),每个设备在ApplicationProfile里对应一个device ID

profile定义了:device的类型(厂商型号等),device产生的信息时作为输出还是输入,信息的格式。

属性包括:信息的分段划分(individual pieces是帧格式吗?),可能的值,格式与类型。

多个属性组成了簇(clusters)。下面会详细讲。

As well as defining the devices types supported, the profilealso specifies the information that a device can generate as outputand can use as input, together with the format this informationtakes. The individual pieces of information are called attributes,and their possible values and format or type (e.g. 8- or 16-bitinteger, time value etc) are defined as part of the DeviceDescriptions in the profile. Attributes aregrouped together into“clusters” for the device, which can be either inputs or outputs.Clusters and attributes are described in detail below.

3)属性和簇

A given ZigBee device profile has associated “attributes” and“clusters” which define the type of data that adevice with this profile may exchange with other ZigBeedevices.

Each data item that passes betweendevices of a ZigBee network is called an attribute. Eachattribute has its own unique identifier. For example, a switchdevice can have an attribute with identifier OnOff whose valuerepresents the action to be performed: On (0xFF), Off (0x00),Toggle (0xF0).

A number of attributes are grouped into a“cluster”, where each cluster has its own uniqueidentifier. For example, for an HCL Switch Remote Control(SRC) device, there is a cluster with identifier OnOffSRCcontaining the attribute OnOff. Clusters may be mandatory oroptional for a device to support.

A cluster may contain several attributes.A profile canhave several associated clusters.



The Application Profile defines which clusters aremandatory(强制的) and which clusters are optional forthe device. The clusters supported by a device determine the otherdevices with which it cancommunicate.比如,温度传感器读取得clusters和温度控制的clusters的格式应该是兼容的(compatible)。

4)发现(Discovery)

zigbeespecification是设备容易了解网络中其他节点的能力(capacity),如他们的地址(MAC地址或短地址)点上运行的应用程序类型,他们的供电,休眠行为。这些信息存储在节点的Descriptors中,查询节点(enquiringnode )用它来调整自己的行为来适应网络的需要。(This information isstored in descriptors (see below) on each node, and is used by theenquiring node to tailor its behaviour to the requirements of thenetwork.)Discovery的典型应用是在被介绍进一个用户定义网络(如一个安全或者灯控制系统)中时使用。为了让节点加入网络,用户可能需要按某个按钮,打开某个开关等行为;首先节点需要找到是否有合适的节点进行对话。比如在HCL(灯控制系统)中,一个节点要适应HCLprofile,它需要尝试找到一个controller节点——好把自己的开关状态信息发送过去。(Fora device implementing the switch conforming to the HCL profile, ittries to find devices containing HCL load controllers to which itwould make sense to send its switch state information.)

Device Discovery returns information about theaddresses of a network node. The retrievedinformation返回信息 can be the MAC (IEEE) address of the nodewith a given network address, or the network address of a node witha given MACaddress.对于router和coordinator除了返回自己的地址之外,还会有选择的返回与之相关的节点的地址。. Inthis way, it is possible to discover all the devices in a networkby requesting this information from the Co-ordinator (networkaddress 0) and then using the list of addresses corresponding tothe children of the Co-ordinator to launch other queries abouttheir child nodes.

Service Discovery allows a node to request informationfrom a remote node about the remote node’s capabilities.This information is stored in a number ofdescriptors (see below) on the remote node, andincludes:
• The device type and capabilities of the node
• The power characteristics of the node
• Information about each application running on the node
• Optional information such as serial numbers
• Other user-defined information; forexample, easily understandable names such as“MtgRoomLight”.
Requests for thesedescriptors are made by a device as part of thediscovery process that is typically part of the device’sconfiguration and integration into a ZigBee network.

5)描述(Descriptors)

节点中存储了3个强制的描述(descriptors )和两个可选择的描述。其中3个强制描述是Node, Node Powerand Simple descriptors。可选择的两个描述是the Complex and User descriptors。

For each node, there is only one Nodeand Node Power descriptor. For eachapplication running on an endpoint, thereis a Simple descriptor and theremay also be Complex and User descriptors in thedevice.

The Node, Power Node and Simple descriptors are outlined below.For full details of descriptors, refer to the ZigBeeApplication Framework API ReferenceManual(在这里我不得不抱怨一下,jennic的中文参考资料少的可怜,只能读英文手册,蛋疼无比).

The Node descriptor contains information on thecapabilities of the node, including:
Type (End Device, Router or Co-ordinator)
• Frequency band in use (868 MHz, 902 MHz or 2400 MHz)
• MAC capabilities – that is, whether:
􀁹 the device can be a PAN Co-ordinator
􀁹 the node implements a Full-Function or Reduced-Function IEEE802.15.4 device
􀁹 the device is mains powered
􀁹 the device is capable of using MAC security
􀁹 the receiver stays on during idle periods
•Manufacturer code
Maximum buffer size (the largestdata packet that can be sent by an application in oneoperation)

This Node Power descriptor contains information on how the nodeis powered:
• Power mode – whether the device receiver is on all the time,wakes up periodically as determined by the network or only when anapplication requires (e.g. button press or periodmeasurement)
• Available power sources – indicates whether mains, rechargeableor disposable batteries (or any combination) can be used to powerthe device
• Current power sources - indicates which power source (from mains,rechargeable or disposable batteries) is currently being used topower the device
• Current power source level – indicates the level of charge of thecurrent power source

The Simple descriptor for an application includes:
• The endpoint in the device that the application resides on
• The Application Profile that it implements
• The Application Profile device identifier and version
• Whether there are corresponding Complex and Userdescriptors
• Lists of input and output clusters (see Section 2.3.3) that theapplication uses and provides, respectively

6)ZDO(ZigBee DeviceObjects)

ZDO是一个应用程序,管理各种被描述过的进程(processes),它在应用层,对应endpoint 0,扮演一下角色。

• Defines the type of network device: Co-ordinator, Router orEnd Device.
• Initialises the node to allow applications to be run
Performs the Device and Service Discoveryprocess
• Implements the processes needed to allow aCo-ordinator to create a network, and Routers and End Devices tojoin and leave a network
Initiates and responds to binding requests (seeSection 2.4.2)
• Provides security services which allow secure relationships to beestablished between applications
Allows remote nodes to retrieve information from thenode, such as routing andbinding tables, and to perform remote management of thenode, such as instructing it to leave thenetwork。

ZDO功能的实现是基于stack提供的服务,ZDO通过zigbeedevice profile和clustermechanism(应用程序之间用来进行交互)种方式使得用户程序可以使用(access)stack服务

4.节点间建立通信

这一节是关于一些进程(processes)使网络设备之间交换信息和执行(perform)有用的功能(functions)。为此,一个设备必须能够找到网络中其他设备,连个设备要通信,他们的交互的数据格式应该是兼容的。可以使用servicediscovery实现两点兼容

The Service Discovery and Binding mechanisms are described inthe subsections below.

1)service Discovery

一个节点通过servicediscovery寻找和选择跟哪个节点通信,节点通过广播消息获得其他节点的服务请求,有需求的节点会单播进行回复。意味着节点可能受到不止一个回复。

在回复的信息里包含了romote node的网络地址,节点会存储下来romote节点的网络地址,以备以后再与之通信。

2)Bingding

一种节点之间进行绑定,绑定之后通信更方便,但是绑定关系被存放在coordinator中,我的毕设不需要这个功能。

5.软件详细结构

前面简单的把程序分为三层,下面介绍详细分层:



1)软件分层

The above diagram shows (from bottom to top):

This consists of the IEEE 802.15.4 PHY and MAC layers, describedin Section 2.1.

This includes:
• Network (NWK) layer: The NWK layer handles network addressing androuting by invoking actions in the MAC layer. Its tasksinclude:
􀁹 Starting the network and assigning network addresses(Co-ordinator only)
􀁹 Adding devices to and removing them from the network
􀁹 Routing messages to their intended destinations
􀁹 Applying security to outgoing messages
􀁹 Implementing Route Discovery inMesh topologies and storing routing tableinformation
• Security plane: If implemented (notavailable in the Jennic ZigBee stack), this plane spans the NWK andAPS layers (see below), and provides security services; forexample, security key management, datastream encryption anddecryption. It may use hardware functions provided in the node toperform the encode and decode functions efficiently.

This includes:
• Applications: Up to 240 application instances are supported on asingle ZigBee node. Each application instance is a network endpointand is numbered between 1 and 240 (note that endpoint 0 is reservedfor the ZigBee Device Objects of the node).
• Application Framework (AF): The AF facilitatesinteraction between the applications andthe APS layer (see below) through aninterface known as a Service AccessPoint or SAP (see Section 2.5.2). All applicationinstances are contained inside this framework.(是否可以理解为,AF由一系列SAP构成
plication Support sub-layer (APS): The APS layeris responsible for:
􀁹 Communicating with the relevantapplication; for example, when a message arrives toilluminate an LED, the APS layer relays this instruction to theresponsible application using the endpoint information in themessage. The message is passed through the ServiceAccess Point which exists between the APS layer and eachapplication (endpoint).
􀁹 Maintaining binding tables(see Section 2.4.2) and sending messages between bound nodes.

• ZigBee Device Objects (ZDO): The ZDOrepresents the ZigBee node type of the device(Co-ordinator, Router or End Device) and has a number ofcommunication roles. The ZDO is an endpoint, numbered 0. For moreinformation, refer to Section 2.3.6.
ZDO Management plane: This plane spansthe NWK and APS layers, and allows the ZigBee Device Objects (ZDO) to communicatewith these layers when performing its internaltasks. It also allowsthe ZDO to deal with requests from applications fornetwork access andsecurity functions using ZigBeeDevice Profile messages.

2)ervice Access Points
A Service AccessPoint or SAP implements a set of operations to pass information and commands betweenlayers. There are usually four types of operation implemented by aSAP:
Request: Typically,a layer using the services of another layer generates a Request to the lowerlayer.

对于请求的回复分为两种:confirm和response
Confirm: In general,the lower layer responds with a Confirm, which indicateswhether it has accepted or rejected the request. Arejection could occur if the Request is invalid or the layer doesnot implement the operation concerned (the operation could bedefined as optional).
Response: Normally,Requests result in some sort of Response from the lower layer. Thismay be a simple status message indicating that the Requesthas been performed, or may contain furtherinformation that the Request has asked for. Responsescan be immediate ordelayed:
􀁹 Synchronous Response: Responses may be generated immediatelyafter the Request has been issued; for instance, if the informationor command is available on the local node.
􀁹 Asynchronous Response: A Request may require messages to be sentover the network to a remote node, in which casethere will be a delay between issuing the Request and the arrivalof the Response.
The SAP mechanism allows both types of Response to be handled anddelivered to the higher layer.
Indication: AnIndication is generated when the lower layer hasunsolicited(主动提供的) information or commands to bedelivered to the higher layer, possibly as a result of aRequest for information local to the node from aremote node.如当底层接到远端节点发来的请求时会向上层主动提供信息

  

爱华网本文地址 » http://www.aihuau.com/a/25101018/371391.html

更多阅读

喝红茶的好处有哪些 枸杞一天吃几颗最合适

喝红茶的好处有哪些——简介秋季天气转凉,人体的生理机能也开始减退,很多女性会出现体寒、手脚冰凉等症状。想要增强身体对气候的适应能力,不妨多喝红茶,既可以御寒暖身,还可以养胃助消化、预防感冒等疾病。喝红茶的好处有哪些——方法/

家有一老一小 家有一老如有一宝作文

俗话说“家有一老,如有一宝”,前几年来说,的确如此。跟我们住一起的“老”不是匡的爷爷奶奶,也不是外公外婆,而是姑婆,是匡爸的姑妈。再确切点,是匡爷爷的同母异父的姐姐。姑婆曾经带过匡爸,自己没有生过孩子,只有一个养女,养女不能算个有情

天下第一泉有哪些 天下第一泉到底是那个

我国有着第一泉的泉水有很多,各有各的道理。下面我们就来说一说天下第一泉有哪些?中泠泉:又名南泠泉。在江苏镇江市金山西觫。其"天下第一泉"之称始自唐代。唐元和年间,刘伯刍把此泉列为宜于煮茶泉水的第一等,故名。水帘洞泉:在湖南衡山县

声明:《zigbee协议栈一 zigbee协议栈有哪些》为网友偽善的男人分享!如侵犯到您的合法权益请联系我们删除