예제 #1
0
otError JamDetector::SetRssiThreshold(int8_t aThreshold)
{
    mRssiThreshold = aThreshold;
    otLogInfoUtil(GetInstance(), "JamDetector - RSSI threshold set to %d", mRssiThreshold);

    return OT_ERROR_NONE;
}
예제 #2
0
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();
    }
}
예제 #3
0
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;
}
예제 #4
0
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;
}
예제 #5
0
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");
    }
}
예제 #6
0
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;
}
예제 #7
0
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);
    }
}
예제 #8
0
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;
}
예제 #9
0
void JamDetector::SetRssiThreshold(int8_t aThreshold)
{
    mRssiThreshold = aThreshold;
    otLogInfoUtil("JamDetector - RSSI threshold set to %d", mRssiThreshold);
}