From 04caca7cc8820a415d7721bc4c5b430981eeb6cf Mon Sep 17 00:00:00 2001 From: pvanhorn Date: Fri, 3 Mar 2017 11:09:33 -0800 Subject: [PATCH] Implement the use of otPlatRadioDefaultTxPower API. (#1417) * Implement the use of otPlatRadioDefaultTxPower API. * Add implementation of otPlatRadioSetDefaultTxPower for windows. --- examples/drivers/windows/otLwf/radio.c | 20 ++++++++++++++++++++ examples/platforms/cc2538/radio.c | 7 +++++++ examples/platforms/cc2650/radio.c | 7 +++++++ examples/platforms/da15000/radio.c | 7 +++++++ examples/platforms/nrf52840/radio.c | 7 +++++++ examples/platforms/posix/radio.c | 6 ++++++ include/openthread/platform/radio.h | 9 +++++++++ src/core/api/link_api.cpp | 1 + tests/unit/test_platform.cpp | 6 ++++++ 9 files changed, 70 insertions(+) diff --git a/examples/drivers/windows/otLwf/radio.c b/examples/drivers/windows/otLwf/radio.c index 7b5d04329..f89b98783 100644 --- a/examples/drivers/windows/otLwf/radio.c +++ b/examples/drivers/windows/otLwf/radio.c @@ -759,6 +759,26 @@ error: return NT_SUCCESS(status) ? kThreadError_None : kThreadError_Failed; } +void otPlatRadioSetDefaultTxPower(_In_ otInstance *otCtx, int8_t aPower) +{ + NT_ASSERT(otCtx); + PMS_FILTER pFilter = otCtxToFilter(otCtx); + NTSTATUS status; + + // Indicate to the miniport + status = + otLwfCmdSetProp( + pFilter, + SPINEL_PROP_PHY_TX_POWER, + SPINEL_DATATYPE_INT8_S, + aPower + ); + if (!NT_SUCCESS(status)) + { + LogError(DRIVER_DEFAULT, "Set SPINEL_PROP_PHY_TX_POWER failed, %!STATUS!", status); + } +} + inline USHORT getDstShortAddress(const UCHAR *frame) { return (((USHORT)frame[IEEE802154_DSTADDR_OFFSET + 1]) << 8) | frame[IEEE802154_DSTADDR_OFFSET]; diff --git a/examples/platforms/cc2538/radio.c b/examples/platforms/cc2538/radio.c index 723fb5007..23c10018d 100644 --- a/examples/platforms/cc2538/radio.c +++ b/examples/platforms/cc2538/radio.c @@ -785,3 +785,10 @@ ThreadError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, u (void)aScanDuration; return kThreadError_NotImplemented; } + +void otPlatRadioSetDefaultTxPower(otInstance *aInstance, int8_t aPower) +{ + // TODO: Create a proper implementation for this driver. + (void)aInstance; + (void)aPower; +} diff --git a/examples/platforms/cc2650/radio.c b/examples/platforms/cc2650/radio.c index 3c847896c..9bea60b6d 100644 --- a/examples/platforms/cc2650/radio.c +++ b/examples/platforms/cc2650/radio.c @@ -1214,6 +1214,13 @@ exit: return error; } +void otPlatRadioSetDefaultTxPower(otInstance *aInstance, int8_t aPower) +{ + // TODO: Create a proper implementation for this driver. + (void)aInstance; + (void)aPower; +} + /** * Function documented in platform/radio.h */ diff --git a/examples/platforms/da15000/radio.c b/examples/platforms/da15000/radio.c index 61097ddea..5e7e8602b 100644 --- a/examples/platforms/da15000/radio.c +++ b/examples/platforms/da15000/radio.c @@ -410,6 +410,13 @@ ThreadError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, u return kThreadError_NotImplemented; } +void otPlatRadioSetDefaultTxPower(otInstance *aInstance, int8_t aPower) +{ + // TODO: Create a proper implementation for this driver. + (void)aInstance; + (void)aPower; +} + void da15000RadioProcess(otInstance *aInstance) { if (sSendFrameDone) diff --git a/examples/platforms/nrf52840/radio.c b/examples/platforms/nrf52840/radio.c index ca0d52b40..a3c016ddc 100644 --- a/examples/platforms/nrf52840/radio.c +++ b/examples/platforms/nrf52840/radio.c @@ -434,6 +434,13 @@ ThreadError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, u return kThreadError_None; } +void otPlatRadioSetDefaultTxPower(otInstance *aInstance, int8_t aPower) +{ + // TODO: Create a proper implementation for this driver. + (void)aInstance; + (void)aPower; +} + void nrf5RadioProcess(otInstance *aInstance) { for (uint32_t i = 0; i < RADIO_RX_BUFFERS; i++) diff --git a/examples/platforms/posix/radio.c b/examples/platforms/posix/radio.c index 16b3e7c2e..d88191b50 100644 --- a/examples/platforms/posix/radio.c +++ b/examples/platforms/posix/radio.c @@ -738,3 +738,9 @@ ThreadError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, u (void)aScanDuration; return kThreadError_NotImplemented; } + +void otPlatRadioSetDefaultTxPower(otInstance *aInstance, int8_t aPower) +{ + (void)aInstance; + (void)aPower; +} diff --git a/include/openthread/platform/radio.h b/include/openthread/platform/radio.h index 65df7f656..3c45e696a 100644 --- a/include/openthread/platform/radio.h +++ b/include/openthread/platform/radio.h @@ -407,6 +407,15 @@ int8_t otPlatRadioGetRssi(otInstance *aInstance); */ otRadioCaps otPlatRadioGetCaps(otInstance *aInstance); +/** + * Set the radio Tx power used for auto-generated frames. + * + * @param[in] aInstance The OpenThread instance structure. + * @param[in] aPower The Tx power to use in dBm. + * + */ +void otPlatRadioSetDefaultTxPower(otInstance *aInstance, int8_t aPower); + /** * Get the status of promiscuous mode. * diff --git a/src/core/api/link_api.cpp b/src/core/api/link_api.cpp index 4fbeebbd4..6914341c1 100644 --- a/src/core/api/link_api.cpp +++ b/src/core/api/link_api.cpp @@ -91,6 +91,7 @@ int8_t otLinkGetMaxTransmitPower(otInstance *aInstance) void otLinkSetMaxTransmitPower(otInstance *aInstance, int8_t aPower) { aInstance->mThreadNetif.GetMac().SetMaxTransmitPower(aPower); + otPlatRadioSetDefaultTxPower(aInstance, aPower); } otPanId otLinkGetPanId(otInstance *aInstance) diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp index 282efe519..fe3aa1b6c 100644 --- a/tests/unit/test_platform.cpp +++ b/tests/unit/test_platform.cpp @@ -319,6 +319,12 @@ extern "C" { return kThreadError_NotImplemented; } + void otPlatRadioSetDefaultTxPower(otInstance *aInstance, int8_t aPower) + { + (void)aInstance; + (void)aPower; + } + // // Random //