diff --git a/examples/platforms/simulation/diag.c b/examples/platforms/simulation/diag.c index 5b1065c26..dcd9f1d9f 100644 --- a/examples/platforms/simulation/diag.c +++ b/examples/platforms/simulation/diag.c @@ -168,4 +168,12 @@ otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable) return OT_ERROR_NONE; } + +otError otPlatDiagRadioTransmitStream(otInstance *aInstance, bool aEnable) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aEnable); + + return OT_ERROR_NONE; +} #endif // OPENTHREAD_CONFIG_DIAG_ENABLE diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 257ae4a0e..b6bb24855 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (312) +#define OPENTHREAD_API_VERSION (313) /** * @addtogroup api-instance diff --git a/include/openthread/platform/diag.h b/include/openthread/platform/diag.h index df889d277..6f65f8234 100644 --- a/include/openthread/platform/diag.h +++ b/include/openthread/platform/diag.h @@ -260,6 +260,19 @@ otError otPlatDiagRadioRawPowerSettingEnable(otInstance *aInstance, bool aEnable */ otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool aEnable); +/** + * Start/stop the platform layer to transmit stream of characters. + * + * @param[in] aInstance The OpenThread instance structure. + * @param[in] aEnable TRUE to enable or FALSE to disable the platform layer to transmit stream. + * + * @retval OT_ERROR_NONE Successfully enabled/disabled. + * @retval OT_ERROR_INVALID_STATE The radio was not in the Receive state. + * @retval OT_ERROR_NOT_IMPLEMENTED This function is not implemented. + * + */ +otError otPlatDiagRadioTransmitStream(otInstance *aInstance, bool aEnable); + /** * Get the power settings for the given channel. * diff --git a/src/core/diags/README.md b/src/core/diags/README.md index b137b14c7..2ddb658ac 100644 --- a/src/core/diags/README.md +++ b/src/core/diags/README.md @@ -10,6 +10,7 @@ The diagnostics module supports common diagnostics features that are listed belo - [diag start](#diag-start) - [diag channel](#diag-channel) - [diag cw](#diag-cw-start) +- [diag stream](#diag-stream-start) - [diag power](#diag-power) - [diag powersettings](#diag-powersettings) - [diag send](#diag-send-packets-length) @@ -76,6 +77,24 @@ Stop transmitting continuous carrier wave. Done ``` +### diag stream start + +Start transmitting a stream of characters. + +```bash +> diag stream start +Done +``` + +### diag stream stop + +Stop transmitting a stream of characters. + +```bash +> diag stream stop +Done +``` + ### diag power Get the tx power value(dBm) for diagnostics module. diff --git a/src/core/diags/factory_diags.cpp b/src/core/diags/factory_diags.cpp index 542b493e7..5eed151f3 100644 --- a/src/core/diags/factory_diags.cpp +++ b/src/core/diags/factory_diags.cpp @@ -79,6 +79,7 @@ const struct Diags::Command Diags::sCommands[] = { {"rawpowersetting", &Diags::ProcessRawPowerSetting}, {"start", &Diags::ProcessStart}, {"stop", &Diags::ProcessStop}, + {"stream", &Diags::ProcessStream}, }; Diags::Diags(Instance &aInstance) @@ -196,6 +197,7 @@ const struct Diags::Command Diags::sCommands[] = { {"start", &Diags::ProcessStart}, {"stats", &Diags::ProcessStats}, {"stop", &Diags::ProcessStop}, + {"stream", &Diags::ProcessStream}, }; Diags::Diags(Instance &aInstance) @@ -573,6 +575,27 @@ exit: return error; } +Error Diags::ProcessStream(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen) +{ + Error error = kErrorInvalidArgs; + + VerifyOrExit(otPlatDiagModeGet(), error = kErrorInvalidState); + VerifyOrExit(aArgsLength > 0, error = kErrorInvalidArgs); + + if (strcmp(aArgs[0], "start") == 0) + { + error = otPlatDiagRadioTransmitStream(&GetInstance(), true); + } + else if (strcmp(aArgs[0], "stop") == 0) + { + error = otPlatDiagRadioTransmitStream(&GetInstance(), false); + } + +exit: + AppendErrorResult(error, aOutput, aOutputMaxLen); + return error; +} + Error Diags::GetPowerSettings(uint8_t aChannel, PowerSettings &aPowerSettings) { aPowerSettings.mRawPowerSetting.mLength = RawPowerSetting::kMaxDataSize; @@ -939,6 +962,14 @@ OT_TOOL_WEAK otError otPlatDiagRadioTransmitCarrier(otInstance *aInstance, bool return OT_ERROR_NOT_IMPLEMENTED; } +OT_TOOL_WEAK otError otPlatDiagRadioTransmitStream(otInstance *aInstance, bool aEnable) +{ + OT_UNUSED_VARIABLE(aInstance); + OT_UNUSED_VARIABLE(aEnable); + + return OT_ERROR_NOT_IMPLEMENTED; +} + OT_TOOL_WEAK otError otPlatDiagRadioGetPowerSettings(otInstance *aInstance, uint8_t aChannel, int16_t *aTargetPower, diff --git a/src/core/diags/factory_diags.hpp b/src/core/diags/factory_diags.hpp index 9115e5150..d7ac648f9 100644 --- a/src/core/diags/factory_diags.hpp +++ b/src/core/diags/factory_diags.hpp @@ -193,6 +193,7 @@ private: Error ProcessStart(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen); Error ProcessStats(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen); Error ProcessStop(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen); + Error ProcessStream(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen); #if OPENTHREAD_RADIO && !OPENTHREAD_RADIO_CLI Error ProcessEcho(uint8_t aArgsLength, char *aArgs[], char *aOutput, size_t aOutputMaxLen); #endif diff --git a/src/posix/platform/radio.cpp b/src/posix/platform/radio.cpp index 0134e28d2..98f580a6f 100644 --- a/src/posix/platform/radio.cpp +++ b/src/posix/platform/radio.cpp @@ -735,6 +735,16 @@ exit: return error; } +otError otPlatDiagRadioTransmitStream(otInstance *aInstance, bool aEnable) +{ + OT_UNUSED_VARIABLE(aInstance); + + char cmd[OPENTHREAD_CONFIG_DIAG_CMD_LINE_BUFFER_SIZE]; + + snprintf(cmd, sizeof(cmd), "stream %s", aEnable ? "start" : "stop"); + return sRadioSpinel.PlatDiagProcess(cmd, nullptr, 0); +} + void otPlatDiagRadioReceived(otInstance *aInstance, otRadioFrame *aFrame, otError aError) { OT_UNUSED_VARIABLE(aInstance); diff --git a/tests/scripts/expect/cli-diags.exp b/tests/scripts/expect/cli-diags.exp index ab4986f8b..e5d2fbfab 100755 --- a/tests/scripts/expect/cli-diags.exp +++ b/tests/scripts/expect/cli-diags.exp @@ -181,6 +181,12 @@ expect_line "Done" send "diag cw stop\n" expect_line "Done" +send "diag stream start\n" +expect_line "Done" + +send "diag stream stop\n" +expect_line "Done" + send "diag rawpowersetting 112233\n" expect_line "Done"