void LinkRaw::HandleEnergyScanTask(void) { // Only process task if we are still energy scanning if (mTimerReason == kTimerReasonEnergyScanComplete) { int8_t rssi = otPlatRadioGetRssi(&mInstance); // Only apply the RSSI if it was a valid value if (rssi != kInvalidRssiValue) { if ((mEnergyScanRssi == kInvalidRssiValue) || (rssi > mEnergyScanRssi)) { mEnergyScanRssi = rssi; } } // Post another instance of tha task, since we are // still doing the energy scan. mEnergyScanTask.Post(); } }
void JamDetector::HandleTimer(void) { int8_t rssi; bool didExceedThreshold = true; VerifyOrExit(mEnabled); rssi = otPlatRadioGetRssi(&GetInstance()); // If the RSSI is valid, check if it exceeds the threshold // and try to update the history bit map if (rssi != OT_RADIO_RSSI_INVALID) { didExceedThreshold = (rssi >= mRssiThreshold); UpdateHistory(didExceedThreshold); } // If the RSSI sample does not exceed the threshold, go back to max sample interval // Otherwise, divide the sample interval by half while ensuring it does not go lower // than minimum sample interval. if (!didExceedThreshold) { mSampleInterval = kMaxSampleInterval; } else { mSampleInterval /= 2; if (mSampleInterval < kMinSampleInterval) { mSampleInterval = kMinSampleInterval; } } mTimer.Start(mSampleInterval + Random::GetUint32InRange(0, kMaxRandomDelay)); exit: return; }