mirror of
https://github.com/espressif/openthread.git
synced 2026-08-18 08:29:52 +00:00
[diag] add radio state command (#4394)
This commit is contained in:
committed by
Jonathan Hui
parent
7f61a9ee15
commit
295ce1125e
@@ -230,6 +230,7 @@ typedef enum otRadioState
|
||||
OT_RADIO_STATE_SLEEP = 1,
|
||||
OT_RADIO_STATE_RECEIVE = 2,
|
||||
OT_RADIO_STATE_TRANSMIT = 3,
|
||||
OT_RADIO_STATE_INVALID = 255,
|
||||
} otRadioState;
|
||||
|
||||
/**
|
||||
|
||||
@@ -125,6 +125,15 @@ set radio from sleep to receive on channel 11
|
||||
status 0x00
|
||||
```
|
||||
|
||||
### diag radio state
|
||||
|
||||
Return the state of the radio.
|
||||
|
||||
```bash
|
||||
> diag radio state
|
||||
sleep
|
||||
```
|
||||
|
||||
### diag stats
|
||||
|
||||
Print statistics during diagnostics mode.
|
||||
|
||||
@@ -366,6 +366,35 @@ void Diags::ProcessRadio(int aArgCount, char *aArgVector[], char *aOutput, size_
|
||||
snprintf(aOutput, aOutputMaxLen, "set radio from sleep to receive on channel %d\r\nstatus 0x%02x\r\n", mChannel,
|
||||
error);
|
||||
}
|
||||
else if (strcmp(aArgVector[0], "state") == 0)
|
||||
{
|
||||
otRadioState state = Get<Radio>().GetState();
|
||||
|
||||
error = OT_ERROR_NONE;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case OT_RADIO_STATE_DISABLED:
|
||||
snprintf(aOutput, aOutputMaxLen, "disabled\r\n");
|
||||
break;
|
||||
|
||||
case OT_RADIO_STATE_SLEEP:
|
||||
snprintf(aOutput, aOutputMaxLen, "sleep\r\n");
|
||||
break;
|
||||
|
||||
case OT_RADIO_STATE_RECEIVE:
|
||||
snprintf(aOutput, aOutputMaxLen, "receive\r\n");
|
||||
break;
|
||||
|
||||
case OT_RADIO_STATE_TRANSMIT:
|
||||
snprintf(aOutput, aOutputMaxLen, "transmit\r\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
snprintf(aOutput, aOutputMaxLen, "invalid\r\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
exit:
|
||||
AppendErrorResult(error, aOutput, aOutputMaxLen);
|
||||
|
||||
@@ -317,6 +317,18 @@ public:
|
||||
*/
|
||||
void SetPromiscuous(bool aEnable) { otPlatRadioSetPromiscuous(GetInstance(), aEnable); }
|
||||
|
||||
/**
|
||||
* This method returns the current state of the radio.
|
||||
*
|
||||
* This function is not required by OpenThread. It may be used for debugging and/or application-specific purposes.
|
||||
*
|
||||
* @note This function may be not implemented. In this case it always returns OT_RADIO_STATE_INVALID state.
|
||||
*
|
||||
* @return Current state of the radio.
|
||||
*
|
||||
*/
|
||||
otRadioState GetState(void) { return otPlatRadioGetState(GetInstance()); }
|
||||
|
||||
/**
|
||||
* This method enables the radio.
|
||||
*
|
||||
|
||||
@@ -117,3 +117,10 @@ OT_TOOL_WEAK const char *otPlatRadioGetVersionString(otInstance *aInstance)
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
return otGetVersionString();
|
||||
}
|
||||
|
||||
OT_TOOL_WEAK otRadioState otPlatRadioGetState(otInstance *aInstance)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
return OT_RADIO_STATE_INVALID;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user