net: openthread: Add modcarrier
command to OT diag module.
Commit add `modcarrier` shell command for Openthread diagnostic mode. Command can transmit modulated carrier out of device for test purposes. Signed-off-by: Przemyslaw Bida <przemyslaw.bida@nordicsemi.no>
This commit is contained in:
parent
ae7613b2c9
commit
63e1bb41b1
5 changed files with 75 additions and 2 deletions
|
@ -102,6 +102,7 @@ config IEEE802154_SELECTIVE_TXCHANNEL
|
|||
|
||||
config IEEE802154_CARRIER_FUNCTIONS
|
||||
bool "Support for carrier functions"
|
||||
default y if OPENTHREAD_DIAG
|
||||
help
|
||||
Enable support for functions such as modulated carrier and continuous carrier.
|
||||
|
||||
|
|
|
@ -144,7 +144,6 @@ config OPENTHREAD_DHCP6_SERVER
|
|||
|
||||
config OPENTHREAD_DIAG
|
||||
bool "Diagnostic functions support"
|
||||
depends on IEEE802154_CARRIER_FUNCTIONS
|
||||
help
|
||||
Enable OpenThread CLI diagnostic commands
|
||||
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
|
||||
#include <openthread/error.h>
|
||||
#include <openthread/platform/diag.h>
|
||||
|
||||
#include "platform-zephyr.h"
|
||||
#include "zephyr/sys/util.h"
|
||||
|
||||
/**
|
||||
* Diagnostics mode variables.
|
||||
|
@ -19,6 +21,8 @@ static bool sDiagMode;
|
|||
static void *sDiagCallbackContext;
|
||||
static otPlatDiagOutputCallback sDiagOutputCallback;
|
||||
|
||||
static otError startModCarrier(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[]);
|
||||
|
||||
static void diag_output(const char *aFormat, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
@ -47,6 +51,12 @@ otError otPlatDiagProcess(otInstance *aInstance, uint8_t aArgsLength, char *aArg
|
|||
ARG_UNUSED(aInstance);
|
||||
ARG_UNUSED(aArgsLength);
|
||||
|
||||
#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
|
||||
if (strcmp(aArgs[0], "modcarrier") == 0) {
|
||||
return startModCarrier(aInstance, aArgsLength - 1, aArgs + 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Add more platform specific diagnostics features here. */
|
||||
diag_output("diag feature '%s' is not supported\r\n", aArgs[0]);
|
||||
|
||||
|
@ -276,3 +286,30 @@ otError otPlatDiagGpioGetMode(uint32_t aGpio, otGpioMode *aMode)
|
|||
#endif /* DT_HAS_COMPAT_STATUS_OKAY(openthread_config) && \
|
||||
* DT_NODE_HAS_PROP(DT_COMPAT_GET_ANY_STATUS_OKAY(openthread_config), diag_gpios)
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
|
||||
|
||||
static otError startModCarrier(otInstance *aInstance, uint8_t aArgsLength, char *aArgs[])
|
||||
{
|
||||
ARG_UNUSED(aInstance);
|
||||
ARG_UNUSED(aArgsLength);
|
||||
|
||||
bool enable = true;
|
||||
uint8_t data[OT_RADIO_FRAME_MAX_SIZE + 1];
|
||||
|
||||
if (aArgsLength <= 0) {
|
||||
return OT_ERROR_INVALID_ARGS;
|
||||
}
|
||||
|
||||
if (strcmp(aArgs[0], "stop") == 0) {
|
||||
enable = false;
|
||||
} else {
|
||||
if (hex2bin(aArgs[0], strlen(aArgs[0]), data, ARRAY_SIZE(data)) == 0) {
|
||||
return OT_ERROR_INVALID_ARGS;
|
||||
}
|
||||
}
|
||||
|
||||
return platformRadioTransmitModulatedCarrier(aInstance, enable, data);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -77,13 +77,20 @@ uint16_t platformRadioChannelGet(otInstance *aInstance);
|
|||
otError platformRadioTransmitCarrier(otInstance *aInstance, bool aEnable);
|
||||
#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */
|
||||
|
||||
#if defined(CONFIG_IEEE802154_CARRIER_FUNCTIONS)
|
||||
/**
|
||||
* Start/stop modulated carrier wave transmission.
|
||||
*/
|
||||
otError platformRadioTransmitModulatedCarrier(otInstance *aInstance, bool aEnable,
|
||||
const uint8_t *aData);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function initializes the random number service used by OpenThread.
|
||||
*
|
||||
*/
|
||||
void platformRandomInit(void);
|
||||
|
||||
|
||||
/**
|
||||
* Initialize platform Shell driver.
|
||||
*/
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <openthread/error.h>
|
||||
#define LOG_MODULE_NAME net_otPlat_radio
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
|
@ -846,6 +847,34 @@ otError platformRadioTransmitCarrier(otInstance *aInstance, bool aEnable)
|
|||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError platformRadioTransmitModulatedCarrier(otInstance *aInstance, bool aEnable,
|
||||
const uint8_t *aData)
|
||||
{
|
||||
if (radio_api->modulated_carrier == NULL) {
|
||||
return OT_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
if (aEnable && sState == OT_RADIO_STATE_RECEIVE) {
|
||||
if (aData == NULL) {
|
||||
return OT_ERROR_INVALID_ARGS;
|
||||
}
|
||||
|
||||
radio_api->set_txpower(radio_dev, get_transmit_power_for_channel(channel));
|
||||
|
||||
if (radio_api->modulated_carrier(radio_dev, aData) != 0) {
|
||||
return OT_ERROR_FAILED;
|
||||
}
|
||||
sState = OT_RADIO_STATE_TRANSMIT;
|
||||
} else if ((!aEnable) && sState == OT_RADIO_STATE_TRANSMIT) {
|
||||
return otPlatRadioReceive(aInstance, channel);
|
||||
} else {
|
||||
return OT_ERROR_INVALID_STATE;
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_IEEE802154_CARRIER_FUNCTIONS */
|
||||
|
||||
otRadioState otPlatRadioGetState(otInstance *aInstance)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue