void tryToJoinNetwork(void) { EmberNetworkParameters networkParams; EmberStatus status; EmberNodeType nodeType; MEMSET(&networkParams, 0, sizeof(EmberNetworkParameters)); networkParams.panId = getNextCandidate(); if (networkParams.panId == EMBER_AF_INVALID_PAN_ID) { debugPrintln("No networks to join on channel %d", emAfPluginNetworkSteeringCurrentChannel); gotoNextChannel(); return; } emberAfCorePrintln("%p joining 0x%2x", PLUGIN_NAME, networkParams.panId); networkParams.radioChannel = emAfPluginNetworkSteeringCurrentChannel; networkParams.radioTxPower = emberAfPluginNetworkSteeringGetPowerForRadioChannelCallback(emAfPluginNetworkSteeringCurrentChannel); nodeType = emberAfPluginNetworkSteeringGetNodeTypeCallback(emAfPluginNetworkSteeringState); status = emberJoinNetwork(nodeType, &networkParams); emAfPluginNetworkSteeringJoinAttempts++; if (EMBER_SUCCESS != status) { emberAfCorePrintln("Error: %p could not attempt join: 0x%X", PLUGIN_NAME, status); cleanupAndStop(status); return; } }
TDBVector* tdbCursorGetNext(TDBCursor* cursor) { TDBInt32 i; TDBVector* next; TDBInt32 l; TDBInt32 l1; TDBInt32 l2; TDBInt32 numlayers; if (cursor == NULL) { tdb_ASSERT(0); return NULL; } if (cursor->wcursor) { while (1) { if (cursor->vector) tdbVectorFree(cursor->vector); cursor->vector = tdbWindexGetCursorValue(cursor->wcursor); if (!cursor->vector) return NULL; if (tdbVectorLayerMatches(cursor->vector, cursor->tdb)) { cursor->hits++; return cursor->vector; } cursor->misses++; } } if (cursor->alldone) return NULL; while (1) { next = getNextCandidate(cursor); if (next == NULL) { cursor->alldone = TDB_TRUE; if (cursor->vector) tdbVectorFree(cursor->vector); cursor->vector = cursor->candidate; cursor->candidate = NULL; if (cursor->vector) cursor->hits++; return cursor->vector; } if (!tdbVectorLayerMatches(next, cursor->tdb)) { cursor->misses++; continue; } if (cursor->candidate == NULL) { cursor->candidate = next; continue; } if (!tdbVectorEqual(cursor->candidate, next)) { if (cursor->vector) tdbVectorFree(cursor->vector); cursor->vector = cursor->candidate; cursor->candidate = next; cursor->hits++; return cursor->vector; } cursor->misses++; l1 = tdbVectorGetLayer(cursor->candidate); l2 = tdbVectorGetLayer(next); if (l1 != l2) { numlayers = tdbGetNumLayers(cursor->tdb); for (i=0 ; i<numlayers ; i++) { l = tdbGetLayer(cursor->tdb, i); if (l == l1) { break; /* Our existing candidate wins. */ } if (l == l2) { tdbVectorFree(cursor->candidate); cursor->candidate = next; next = NULL; } } } } }