[diag] add radio state command (#4394)

This commit is contained in:
Łukasz Duda
2019-12-13 08:53:46 -08:00
committed by Jonathan Hui
parent 7f61a9ee15
commit 295ce1125e
5 changed files with 58 additions and 0 deletions
+1
View File
@@ -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;
/**
+9
View File
@@ -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.
+29
View File
@@ -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);
+12
View File
@@ -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.
*
+7
View File
@@ -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;
}