From 16522a6887bf76d3fedf552d3f6b2ffd596f93a0 Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Tue, 25 Oct 2016 17:35:26 +0100 Subject: [PATCH] microbit: Update Radio RSSI value to be -dbm Normalisation of RSSI value from the inverted dbm value return by the nrf51822 hardware into a true, signed RSSI value measured in -dbm. --- inc/drivers/MicroBitRadio.h | 6 +++--- inc/types/PacketBuffer.h | 2 +- source/drivers/MicroBitRadio.cpp | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/inc/drivers/MicroBitRadio.h b/inc/drivers/MicroBitRadio.h index 9ed0fe7..522bb22 100644 --- a/inc/drivers/MicroBitRadio.h +++ b/inc/drivers/MicroBitRadio.h @@ -87,7 +87,7 @@ struct FrameBuffer uint8_t payload[MICROBIT_RADIO_MAX_PACKET_SIZE]; // User / higher layer protocol data FrameBuffer *next; // Linkage, to allow this and other protocols to queue packets pending processing. - uint8_t rssi; // Received signal strength of this frame. + int rssi; // Received signal strength of this frame. }; @@ -95,7 +95,7 @@ class MicroBitRadio : MicroBitComponent { uint8_t group; // The radio group to which this micro:bit belongs. uint8_t queueDepth; // The number of packets in the receiver queue. - uint8_t rssi; + int rssi; FrameBuffer *rxQueue; // A linear list of incoming packets, queued awaiting processing. FrameBuffer *rxBuf; // A pointer to the buffer being actively used by the RADIO hardware. @@ -156,7 +156,7 @@ class MicroBitRadio : MicroBitComponent * * @note should only be called from RADIO_IRQHandler... */ - int setRSSI(uint8_t rssi); + int setRSSI(int rssi); /** * Retrieves the current RSSI for the most recent packet. diff --git a/inc/types/PacketBuffer.h b/inc/types/PacketBuffer.h index 30e9d7b..04a1eb6 100644 --- a/inc/types/PacketBuffer.h +++ b/inc/types/PacketBuffer.h @@ -32,7 +32,7 @@ DEALINGS IN THE SOFTWARE. struct PacketData : RefCounted { - uint16_t rssi; // The radio signal strength this packet was received. + int rssi; // The radio signal strength this packet was received. uint8_t length; // The length of the payload in bytes uint8_t payload[0]; // User / higher layer protocol data }; diff --git a/source/drivers/MicroBitRadio.cpp b/source/drivers/MicroBitRadio.cpp index c69bcd8..fe3fc70 100644 --- a/source/drivers/MicroBitRadio.cpp +++ b/source/drivers/MicroBitRadio.cpp @@ -72,11 +72,11 @@ extern "C" void RADIO_IRQHandler(void) NRF_RADIO->EVENTS_END = 0; if(NRF_RADIO->CRCSTATUS == 1) { - uint8_t sample = NRF_RADIO->RSSISAMPLE; + int sample = (int)NRF_RADIO->RSSISAMPLE; // Associate this packet's rssi value with the data just // transferred by DMA receive - MicroBitRadio::instance->setRSSI(sample); + MicroBitRadio::instance->setRSSI(-sample); // Now move on to the next buffer, if possible. // The queued packet will get the rssi value set above. @@ -220,7 +220,7 @@ int MicroBitRadio::queueRxBuf() * * @note should only be called from RADIO_IRQHandler... */ -int MicroBitRadio::setRSSI(uint8_t rssi) +int MicroBitRadio::setRSSI(int rssi) { if (!(status & MICROBIT_RADIO_STATUS_INITIALISED)) return MICROBIT_NOT_SUPPORTED;