Z-Stack Home Developer's Guide—7.EZ-Mode中文翻译【Z-Stack Home 1.2.0的开发文档】
7. EZ-Mode
EZ-Mode提供了兩個設備正常交流的能力,無論這個2個設備是否在zigbee網絡中。它包括網絡控制、網絡發現和網絡綁定。EZ-Mode有如下特性:
- 網絡控制 - 找到第一個開放的網絡
- 發現和綁定 - 找到一個遠程節點(在網絡的任何地方) 并且初始化合適的綁定基于應用程序提供的有效集群列表
- 自動關閉 - 為了很多設備的快速綁定
- 應用程序回調 - 允許應用程序執行用戶提供的接口
- 任何回調函數 - 應用程序在調用EZ-Mode的時候將調用這些函數
舉一個簡單的例子,EZ-Mode允許電燈開關被綁定到電燈上,或者 溫度傳感器或加熱冷卻設備綁定到自動調溫器上。
EZ-Mode足夠智能,可以知道一個電燈開關不能被綁定到一個溫度傳感器上,或者不能綁定到另一個光開關上。
在樣例程序中,EZ-Mode在應用程序的HandleKeys函數(例如:zclSampleThermostat_HandleKeys)執行回調函數,對于所有的Home Automation中的樣例程序中。
由于zigbee路由器和zigbee終端設備無法自啟動,應用程序也能將節點加入到網路中, 此外,如果有合適的,將會綁定到其他的遠端設備上。
在zigbee網絡中的設備,如果EZ-Mode生效,這些設備將開放這個網絡(使其他設備能夠加入)。相互綁定的設備,他們一旦終止他們的綁定,EZ-Mode將關閉這個網絡。
每個設備只有一個EZ-Mode狀態。EZ-Mode調用函數(zcl_InvokeEZMode)是一個觸發函數。
如果EZ-Mode已經被啟動,再次調用將會取消這個設備上的EZ-Mode。
在理解EZ-Mode時,下面這些術語應該被知道:
- Opener - 已經在網絡中的節點并且EZ-Mode已經被調用
- Joiner - 沒有在網絡中的節點并且EZ-Mode已經被調用
- Initiator - 發起 加入某個設備功能網絡請求的節點(客戶端)
- Target - 接收到 來自某個設備功能加入網絡請求的節點(服務端)
- Active clusters - 設備的主要功能
如果要想網絡恢復可行,網絡配置信息要存儲到NV內存(非易失性內存)中。EZ-Mode沒有直接刪除綁定的方法,除了設備恢復出廠設置。
Home Automation樣例程序重置NV內存需要通過Shift-SW5(舉例:按住按鈕1然后按下操縱桿),這個功能只在SmartRF05 + CC2530中有效。
SmartRF06 + CC2538中將NV內存重置為工廠默認值,這個設備需要被重新編程。各種各樣的OTA在Zigbee調用中盡管顯得非常的復雜,但是EZ-Mode為連接在一起的設備提供了一個非常可靠的基礎線。
7.1 EZ-Mode 接口
EZ-Mode的所有接口可以在zcl_ezmode.h中找到。EZ-Mode應用程序接口被執行通過3個函數和一個單獨的應用程序回調函數:
- zcl_RegisterEZMode - 在EZ-Mode被使用前一定會被調用
- zcl_InvokeEZMode - 啟動或者取消EZ-Mode
- zcl_EZModeAction - 用于應用程序通知EZ-Mode的各種事件(比如加入網絡或者接收身份查詢命令)
應用程序必須支持Identify Cluster。EZ-Mode將繼續自我識別每隔EZMODE_TIME時間(默認是3分鐘)
7.2 EZ-Mode 圖解
EZ-Mode在以下狀態進行轉換:
- 建立/加入網絡(如果還沒有在網絡上)
- 打開網絡(通過允許加入請求)
- 標識本身
- 在EZ-Mode中找到一個遠程節點
- 匹配活動集群并綁定它們
- 在一段時間內自動關閉以允許在兩個方向上進行匹配
- 完成狀態碼
網絡控制、查找和綁定顯示在以下兩個流程圖中。
Figure 5 - EZ-Mode 網絡控制流程圖
網絡控制流程圖顯示,EZ-Mode是如何形成、連接、打開和關閉網絡的。這是假定只有一個開放網絡位于HA通道列表的區域內。一個網絡的正常狀態是關閉的。
Figure 6 – EZ-Mode 尋找和綁定流程圖
尋找和綁定流程圖顯示EZ-Mode在網絡中如何尋找和匹配另外一個設備。設備能夠被許多其他設備相連(在網狀網絡中)。看HA規格將知道那個設備是發起者,那個設備是目標。
7.3 EZ-Mode代碼
EZ-Mode的大部分代碼都是在zclezmode.c中找到的。
這包括完整的狀態機和用戶接口,應用程序必須提供一些功能,使EZ-Mode能夠通過各種狀態。
應用程序必須提供:
- 創建/加入網絡的通知
- 設備匹配的通知
- 進入/退出識別模式
- 2個事件(1個是狀態改變,一個是用于整個EZ-Mode超時)
下面的例子展示了SampleLight應用程序如何通知EZ-Mode整體超時,什么時候處理下一個狀態了
#ifdef ZCL_EZMODE if ( events & SAMPLELIGHT_EZMODE_NEXTSTATE_EVT ) { zcl_EZModeAction ( EZMODE_ACTION_PROCESS, NULL ); return ( events ^ SAMPLELIGHT_EZMODE_NEXTSTATE_EVT ); } if ( events & SAMPLELIGHT_EZMODE_TIMEOUT_EVT ) {zcl_EZModeAction ( EZMODE_ACTION_TIMED_OUT, NULL ); // EZ-Mode timed out return ( events ^ SAMPLELIGHT_EZMODE_TIMEOUT_EVT ); } #endif // ZCL_EZMODE通過使用ZCL_EZMODE標志可以啟用或禁用EZ-Mode。EZ-Mode需要標識族,所有也要確保使能ZCL_IDENTIFY。
如果EZ-Mode不生效,示例應用程序將使用終端設備綁定將應用程序綁定在一起。
如果EZ-Mode不生效,確保能夠實現自啟動 通過禁用HOLD_AUTO_START標志在編譯器的預定義中。或者這個節點不將加入網絡。
Figure 7 – 使用EZ-Mode不生效,讓ZCL_EZMODE和HOLD_AUTO_START兩個宏都不生效
對這個不生效的選項,在這個名字前面添加’x’。這種方式,可以通過刪除’x’讓該選項稍后可以啟用。(e.g. xHOLD_AUTO_START 意味著 hold auto start 失效的)。
英文原文
7 EZ-Mode
EZ-Mode provides an ability to easily bind (connect) two devices together for normal communication, whether the
devices are currently on a ZigBee network or not. It includes both the ability for network steering, and finding and
binding. EZ-Mode includes the following features:
? Network Steering – finds the first open network
? Finding and Binding – finds a remote node (anywhere in the network) and initiates appropriate bindings
based on an application supplied active output cluster list.
? Autoclose - for rapid binding of many pairs of devices
? Application Callbacks – allows the application to present an appropriate user interface
? Any Invoke Method – applications can be creative in the method they invoke EZ-Mode
As an example, EZ-Mode allows light switches to be bound to lights, or a temperature sensor or heating cooling unit
to a thermostat.
EZ-Mode is smart enough to know that a light switch cannot be bound to a temperature sensor, or to another light
switch.
In the sample applications, the EZ-Mode invoke call is performed in the application HandleKeys function (e.g.
zclSampleThermostat_HandleKeys), on switch 2 for all Home Automation Sample Applications. Since
ZRs and ZEDs do not autostart, this also puts the node on the network, then, if appropriate, will bind to the other
remote device.
Devices that are on the network will open up the network (enable joining) while EZ-Mode is in effect. EZ-Mode
will close the network as soon as both nodes in the pair have found each other and determined their bindings.
There is only 1 EZ-Mode state machine per device. The EZ-Mode Invoke function (zcl_InvokeEZMode) is a
toggle. That is, if EZ-Mode has already been started, invoke will cancel EZ-Mode on that device.
The following terms should be understood to understand EZ-Mode:
? Invoke – Initiate EZ-Mode on a device
? Opener – A node that is already on a network when EZ-Mode is invoked
? Joiner – A node that is not on a network when EZ-Mode is invoked
? Initiator – A node that initiates transactions (client) on the active clusters
? Target – A node that receives transactions (server) from active clusters
? Active clusters – The main functionality of a device (e.g OnOff for a light switch, or DoorLock for a
DoorLockController)
If NV_RESTORE is enabled, network configuration is stored in NV memory, EZ-Mode has no method for
removing bindings directly, other than to factory reset a device. The Home Automation sample applications reset
NV memory on Shift-SW5 (i.e. press and hold Button 1 and then press down the Joystick), this functionality is only
available in SmartRF05 + CC2530. To reset NV memory to factory defaults in SmartRF06 + CC2538, the device
should be reprogrammed.
While more sophisticated commissioning can be performed by various over-the-air ZigBee calls, EZ-Mode provides
a solid base-line for connecting the appropriate devices together.
7.1 EZ-Mode Interface
The EZ-Mode interface can be found in zcl_ezmode.h. The EZ-Mode application interface is performed through 3
functions and a single application callback:
? zcl_RegisterEZMode – Must be called before EZ-Mode can be used
Z-Stack Home Developer’s Guide SWRA441 Version 1.0
21 Copyright ? 2013 Texas Instruments, Inc. All rights reserved.
? zcl_InvokeEZMode – Used to invoke or cancel EZ-Mode
? zcl_EZModeAction – Used by the application to inform EZ-Mode of various events (such as when
joining the network or receiving and IdentifyQuery command).
The application must support the Identify Cluster. EZ-Mode will continue to identify itself for EZMODE_TIME
(which defaults to 3 minutes).
7.2 EZ-Mode Diagrams
EZ-Mode flows through the following states:
? Forming/Joining the network (if not yet on a network)
? Opening the network (through Permit Joining Request)
? Identifying Itself
? Finding a remote node in EZ-Mode
? Matching active output clusters and binding them
? AutoClose after a small period of time to allow Matching in both directions
? Finish up with status code
Network steering and Finding and Binding are shown in the following two flowchart diagrams.
Figure 5 - EZ-Mode Network Steering Flowchart
The Network Steering Flowchart indicates how EZ-Mode forms, joins, opens and closes the network. It is assumes
that only 1 open network is in the area on the list of HA channels. A network’s normal state is closed.
Z-Stack Home Developer’s Guide SWRA441 Version 1.0
22 Copyright ? 2013 Texas Instruments, Inc. All rights reserved.
Figure 6 – EZ-Mode Finding and Binding Flowchart
The Finding and Binding Flowchart shows how EZ-Mode finds and matches to another device in the network. The
devices can be many hops away (using mesh networking). See the HA specification for which devices are initiators
and which ones are targets.
7.3 EZ-Mode Code
The bulk of the code for EZ-Mode is found in zcl_ezmode.c. This includes the full state machine and the user
interface. In addition, the Application must supply some functionality to enable EZ-Mode to transition through
various states.
The application must supply:
? Notification of forming/joining
? Notification of cluster matching
? Enter/exit identify mode
? 2 Events (one for state changes, one for an overall EZ-Mode timeout)
The following example shows how the SampleLight application informs EZ-Mode to the overall timeout, and when
it’s time to process the next state.
#ifdef ZCL_EZMODE
if ( events & SAMPLELIGHT_EZMODE_NEXTSTATE_EVT )
{
zcl_EZModeAction ( EZMODE_ACTION_PROCESS, NULL );
return ( events ^ SAMPLELIGHT_EZMODE_NEXTSTATE_EVT );
}
if ( events & SAMPLELIGHT_EZMODE_TIMEOUT_EVT )
{
Z-Stack Home Developer’s Guide SWRA441 Version 1.0
23 Copyright ? 2013 Texas Instruments, Inc. All rights reserved.
zcl_EZModeAction ( EZMODE_ACTION_TIMED_OUT, NULL ); // EZ-Mode timed out
return ( events ^ SAMPLELIGHT_EZMODE_TIMEOUT_EVT );
}
#endif // ZCL_EZMODE
EZ-Mode may be enabled or disabled by the use of the ZCL_EZMODE flag. EZ-Mode requires the Identify cluster,
so make sure to also enable ZCL_IDENTIFY.
If EZ-Mode is disabled, the sample applications will use End Device Binding to bind applications together. If EZ-
Mode is disabled, make sure to also enable auto start by disabling the HOLD_AUTO_START flag in the Compiler’s
predefined compile-time flags, or the node won’t join the network.
Figure 7 – To Disable EZ-Mode, disable both ZCL_EZMODE and HOLD_AUTO_START
To disable an option, place an ‘x’ in front of the name. This way, the option can later be enabled by removing the
‘x’. (e.g. xHOLD_AUTO_START means hold auto start is disabled).
總結
以上是生活随笔為你收集整理的Z-Stack Home Developer's Guide—7.EZ-Mode中文翻译【Z-Stack Home 1.2.0的开发文档】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 判断文件夹或文件是否存在
- 下一篇: 12.IDA-虚函数和虚表(vf代表虚函