mirror of
https://github.com/espressif/openthread.git
synced 2026-07-11 14:50:18 +00:00
Update JamDetector to invoke handler every second when jam is detected (#972)
This commit is contained in:
committed by
Jonathan Hui
parent
a7668d6475
commit
dd61e9cce6
@@ -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
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user