針對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;
}