[Ember Zigbee]Zigbee3.0设备入网流程

版权声明:Copyright © 2018 DesiLuo. All rights reserved. https://blog.csdn.net/up5201314/article/details/85322771

针对Simplicity Studio 4,EmberZNet协议栈Zigbee3.0设备入网流程

Platform:Simplicity Studio 4、EmberZNet SDK 6.4.1.0

【SPP】Content:

EmberZNet  Zigbee3.0设备入网流程
1、在.isc文件工程的Plugins添加a插件【必须】与b插件【可选】
                                              
2、调用EmberStatus emberAfPluginNetworkSteeringStart(void)函数启动Network Steering
                                 
此函数一调用最终执行扫描信道的状态机函数status = stateMachineRun();
3、进入status = stateMachineRun()函数
                                                     
由于在步骤2中line544得到emAfPluginNetworkSteeringState=EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_INSTALL_CODE,在状态机运行的时emAfPluginNetworkSteeringState在tryNextMethod()函数中是++的形式递增的,所以由上面的变量可知设备首次是以二维码扫描入网的方式开始入网,但我们工程配置是以集中式入网方式
                                                      
所以,
                                    
状态机前两次会执行a处,然后到return tryNextMethod()会直接返回,直到emAfPluginNetworkSteeringState=EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_CENTRALIZED,采用集中式策略入网,然后执行b处确定信道掩码方式,然后执行gotoNextChannel();进入信道扫描配置函数;
注:注意这里信道掩码分为两种:
a)    Primary:优先信道掩码,一般包含11、14、15、19、20、24、25,都是和蓝牙、WiFi信道重叠部分比较少的信道,减少干扰。
b)    Secondary:11-26,所有信道。

4、进入void gotoNextChannel(void)函数
进入通道扫描函数后,配置好EmberAfPluginScanDispatchScanData结构体参数,则执行status = emberAfPluginScanDispatchScheduleScan(&scanData);该函数其实底层就是一个扫描事件

                                   
然后执行d处回调函数scanResultsHandler:
                                     
通道扫描完成,然后执行a处scanCompleteCallback(results->channel, results->status)
                                      
在执行a处,尝试去加入网络:
                                      
判断扫到的网络PANID是否有效,无效则执行下个通道扫描gotoNextChannel();有效则开始加入这个网络;
5、假设网络PANID无效
如果无效则会回到步骤4:
                                      
注意: 假设如果在emAfPluginNetworkSteeringState=EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_CENTRALIZED状态的优先信道掩码7个通道都没有扫描到可用的网络【判断可不可用是判断网络的PANID是否有效】,则会触发上图a处执行,执行emAfPluginNetworkSteeringState=EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_SECONDARY_CENTRALIZED状态,依次类推,状态++直到状态机的值大于所设定的上限【emAfPluginNetworkSteeringState > LAST_JOINING_STATE】还是没尝试加入成功,则停止入网;
                                      
6)    假设网络PANID有效
   如果网络PANID有效,则配置网络结构体参数,然后开始在此信道,加入网络,执行status = emberJoinNetwork(nodeType, &networkParams),加入失败则停止加入网络;

                                       


附录
                                       
上图EmberAfPluginScanDispatchScanData结构体说明:
b扫描策略:

enum
{
  /** An energy scan scans each channel for its RSSI value. */
  EMBER_ENERGY_SCAN,
  /** An active scan scans each channel for available networks. */
  EMBER_ACTIVE_SCAN,
  /** A fake scan that is used to turn off the radio. */
  EMBER_START_RADIO_OFF_SCAN,
  /** A green power channel delivery scan. */
  EMBER_STACK_GP_CHANNEL_DELIVERY_SCAN,
  EMBER_LAST_SCAN_TYPE = EMBER_STACK_GP_CHANNEL_DELIVERY_SCAN
};

C持续时间:

 * @param channelMask  Bits set as 1 indicate that this particular channel
 * should be scanned. Bits set to 0 indicate that this particular channel
 * should not be scanned. For example, a channelMask value of 0x00000001
 * indicates that only channel 0 should be scanned. Valid channels range
 * from 11 to 26 inclusive. This translates to a channel mask value of 0x07
 * FF F8 00. As a convenience, a channelMask of 0 is reinterpreted as the
 * mask for the current channel.

 * @param duration     Sets the exponent of the number of scan periods,
 * where a scan period is 960 symbols, and a symbol is 16 microseconds.
 * The scan will occur for ((2^duration) + 1) scan periods.  The value
 * of duration must be less than 15.  The time corresponding to the first
 * few values is as follows: 0 = 31 msec, 1 = 46 msec, 2 = 77 msec,
 * 3 = 138 msec, 4 = 261 msec, 5 = 507 msec, 6 = 998 msec.

在下图处Plugins处配置:
                                        

猜你喜欢

转载自blog.csdn.net/up5201314/article/details/85322771