针对Simplicity Studio 4,EmberZNet协议栈Zigbee3.0设备入网流程
Platform:Simplicity Studio 4、EmberZNet SDK 6.4.1.0
【SPP】Content:
Zigbee3.0设备sleep机制(低功耗)
1、zigbee低功耗设备进入睡眠需满足四个条件
- emAfForceEndDeviceToStayAwake=FALSE; 才能进入SLEEP
- 如果emAfStayAwakeWhenNotJoined=1,则只有设备加入网络了才能睡觉
- 串口BUF中要没有数据才能睡觉
- (emberAfGetCurrentSleepControlCallback() != EMBER_AF_STAY_AWAKE)此关系式不成立
bool emAfOkToIdleOrSleep(void)
{
uint8_t i;
if (emAfForceEndDeviceToStayAwake) {
return false;
}
#if defined(EMBER_AF_PLUGIN_BLE)
if (emberAfPluginBleHasEventPending()) {
return false;
}
#endif
if (emAfStayAwakeWhenNotJoined) {
bool awake = false;
for (i = 0; !awake && i < EMBER_SUPPORTED_NETWORKS; i++) {
if (emberAfPushNetworkIndex(i) == EMBER_SUCCESS) {
awake = (emberAfNetworkState() != EMBER_JOINED_NETWORK);
emberAfPopNetworkIndex();
}
}
if (awake) {
return false;
}
}
#ifdef EM_NUM_SERIAL_PORTS
for (i = 0; i < EM_NUM_SERIAL_PORTS; i++) {
if (!emberSerialUnused(i)
&& (emberSerialReadAvailable(i) != 0
|| emberSerialWriteUsed(i) != 0
|| simulatorDoingSerialTx(i))) {
return false;
}
}
#else
if (!emberSerialUnused(APP_SERIAL)
&& (emberSerialReadAvailable(APP_SERIAL) != 0
|| emberSerialWriteUsed(APP_SERIAL) != 0
|| simulatorDoingSerialTx(APP_SERIAL))) {
return false;
}
#endif
return (emberAfGetCurrentSleepControlCallback() != EMBER_AF_STAY_AWAKE);
}
static EmberAfEventSleepControl defaultSleepControl = EMBER_AF_OK_TO_SLEEP;
EmberAfEventSleepControl emberAfGetCurrentSleepControlCallback(void)
{
EmberAfEventSleepControl sleepControl = defaultSleepControl;
#ifdef EMBER_AF_GENERATED_EVENT_CONTEXT
uint8_t i;
for (i = 0; i < emAfAppEventContextLength; i++) {
EmberAfEventContext *context = &emAfAppEventContext[i];
if (emberEventControlGetActive(*context->eventControl)
&& sleepControl < context->sleepControl) {
sleepControl = context->sleepControl;
}
}
#endif
return sleepControl;
}
2、用户可通过以下协议栈API来控制设备是否进入休眠
void emberAfForceEndDeviceToStayAwake(bool stayAwake)
// NO PRINTFS. This may be called in ISR context.
void emberAfForceEndDeviceToStayAwake(bool stayAwake)
{
emAfForceEndDeviceToStayAwake = stayAwake;
}