otError JamDetector::SetRssiThreshold(int8_t aThreshold) { mRssiThreshold = aThreshold; otLogInfoUtil(GetInstance(), "JamDetector - RSSI threshold set to %d", mRssiThreshold); return OT_ERROR_NONE; }
void ChildSupervisor::SendMessage(Child &aChild) { Message *message = NULL; uint8_t childIndex; VerifyOrExit(aChild.GetIndirectMessageCount() == 0); message = Get<MessagePool>().New(Message::kTypeSupervision, sizeof(uint8_t)); VerifyOrExit(message != NULL); // Supervision message is an empty payload 15.4 data frame. // The child index is stored here in the message content to allow // the destination of the message to be later retrieved using // `ChildSupervisor::GetDestination(message)`. childIndex = Get<ChildTable>().GetChildIndex(aChild); SuccessOrExit(message->Append(&childIndex, sizeof(childIndex))); SuccessOrExit(Get<ThreadNetif>().SendMessage(*message)); message = NULL; otLogInfoUtil("Sending supervision message to child 0x%04x", aChild.GetRloc16()); exit: if (message != NULL) { message->Free(); } }
otError JamDetector::SetBusyPeriod(uint8_t aBusyPeriod) { otError error = OT_ERROR_NONE; VerifyOrExit(aBusyPeriod != 0, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aBusyPeriod <= mWindow, error = OT_ERROR_INVALID_ARGS); mBusyPeriod = aBusyPeriod; otLogInfoUtil(GetInstance(), "JamDetector - busy period set to %d", mBusyPeriod); exit: return error; }
otError JamDetector::SetWindow(uint8_t aWindow) { otError error = OT_ERROR_NONE; VerifyOrExit(aWindow != 0, error = OT_ERROR_INVALID_ARGS); VerifyOrExit(aWindow <= kMaxWindow, error = OT_ERROR_INVALID_ARGS); mWindow = aWindow; otLogInfoUtil(GetInstance(), "JamDetector - window set to %d", mWindow); exit: return error; }
void ChildSupervisor::CheckState(void) { bool shouldRun = false; // Child Supervision should run if `mSupervisionInterval` is not // zero, Thread MLE operation is enabled, and there is at least one // "valid" child in the child table. shouldRun = ((mSupervisionInterval != 0) && (Get<Mle::MleRouter>().GetRole() != OT_DEVICE_ROLE_DISABLED) && Get<ChildTable>().HasChildren(ChildTable::kInStateValid)); if (shouldRun && !mTimer.IsRunning()) { mTimer.Start(kOneSecond); otLogInfoUtil("Starting Child Supervision"); } if (!shouldRun && mTimer.IsRunning()) { mTimer.Stop(); otLogInfoUtil("Stopping Child Supervision"); } }
otError JamDetector::Stop(void) { otError error = OT_ERROR_NONE; VerifyOrExit(mEnabled, error = OT_ERROR_ALREADY); mEnabled = false; mJamState = false; mTimer.Stop(); otLogInfoUtil(GetInstance(), "JamDetector - Stopped"); exit: return error; }
void JamDetector::SetJamState(bool aNewState) { bool shouldInvokeHandler = aNewState; if (aNewState != mJamState) { mJamState = aNewState; shouldInvokeHandler = true; otLogInfoUtil(GetInstance(), "JamDetector - jamming %s", mJamState ? "detected" : "cleared"); } if (shouldInvokeHandler) { mHandler(mJamState, mContext); } }
otError JamDetector::Start(Handler aHandler, void *aContext) { otError error = OT_ERROR_NONE; VerifyOrExit(!mEnabled, error = OT_ERROR_ALREADY); VerifyOrExit(aHandler != NULL, error = OT_ERROR_INVALID_ARGS); mHandler = aHandler; mContext = aContext; mEnabled = true; otLogInfoUtil(GetInstance(), "JamDetector - Started"); CheckState(); exit: return error; }
void JamDetector::SetRssiThreshold(int8_t aThreshold) { mRssiThreshold = aThreshold; otLogInfoUtil("JamDetector - RSSI threshold set to %d", mRssiThreshold); }