diff --git a/include/openthread-jam-detection.h b/include/openthread-jam-detection.h index ecdef9fde..b1e95f069 100644 --- a/include/openthread-jam-detection.h +++ b/include/openthread-jam-detection.h @@ -130,7 +130,7 @@ uint8_t otGetJamDetectionBusyPeriod(otInstance *aInstance); * Start the jamming detection. * * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aCallback A pointer to a function called when jamming state changes. + * @param[in] aCallback A pointer to a function called to notify of jamming state change. * @param[in] aContext A pointer to application-specific context. * * @retval kThreadErrorNone Successfully started the jamming detection. @@ -159,7 +159,6 @@ ThreadError otStopJamDetection(otInstance *aInstance); */ bool otIsJamDetectionEnabled(otInstance *aInstance); - /** * Get the Jam Detection State * diff --git a/src/core/utils/jam_detector.cpp b/src/core/utils/jam_detector.cpp index 8f3954b25..d41be5e28 100644 --- a/src/core/utils/jam_detector.cpp +++ b/src/core/utils/jam_detector.cpp @@ -183,6 +183,8 @@ exit: void JamDetector::UpdateHistory(bool aDidExceedThreshold) { + uint32_t now = Timer::GetNow(); + // If the RSSI is ever below the threshold, update mAlwaysAboveThreshold // for current second interval. if (!aDidExceedThreshold) @@ -191,7 +193,7 @@ void JamDetector::UpdateHistory(bool aDidExceedThreshold) } // If we reached end of current one second interval, update the history bitmap - if (Timer::GetNow() - mCurSecondStartTime >= kOneSecondInterval) + if (now - mCurSecondStartTime >= kOneSecondInterval) { mHistoryBitmap <<= 1; @@ -201,7 +203,11 @@ void JamDetector::UpdateHistory(bool aDidExceedThreshold) } mAlwaysAboveThreshold = true; - mCurSecondStartTime += kOneSecondInterval; + + while (now - mCurSecondStartTime >= kOneSecondInterval) + { + mCurSecondStartTime += kOneSecondInterval; + } UpdateJamState(); } @@ -227,7 +233,7 @@ void JamDetector::UpdateJamState(void) mJamState = (numJammedSeconds >= mBusyPeriod); // If there is a change, invoke the handler. - if (mJamState != oldJamState) + if ((mJamState != oldJamState) || (mJamState == true)) { mHandler(mJamState, mContext); }