From d7aa95e8675760efa4659d1136ed20af53229c3c Mon Sep 17 00:00:00 2001 From: Joe Finney Date: Mon, 1 Feb 2016 18:05:02 +0000 Subject: [PATCH] microbit: minor updates to consistently use the MICROBIT_RADIO_HEADER_SIZE constant --- source/ble-services/MicroBitRadio.cpp | 2 +- source/ble-services/MicroBitRadioDatagram.cpp | 8 ++++---- source/ble-services/MicroBitRadioEvent.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source/ble-services/MicroBitRadio.cpp b/source/ble-services/MicroBitRadio.cpp index 89609a0..8f31b31 100644 --- a/source/ble-services/MicroBitRadio.cpp +++ b/source/ble-services/MicroBitRadio.cpp @@ -364,7 +364,7 @@ int MicroBitRadio::send(PacketBuffer *buffer) if (buffer == NULL) return MICROBIT_INVALID_PARAMETER; - if (buffer->length > MICROBIT_RADIO_MAX_PACKET_SIZE + 3) + if (buffer->length > MICROBIT_RADIO_MAX_PACKET_SIZE + MICROBIT_RADIO_HEADER_SIZE - 1) return MICROBIT_INVALID_PARAMETER; // Firstly, disable the Radio interrupt. We want to wait until the trasmission completes. diff --git a/source/ble-services/MicroBitRadioDatagram.cpp b/source/ble-services/MicroBitRadioDatagram.cpp index 4d1f9e6..29091aa 100644 --- a/source/ble-services/MicroBitRadioDatagram.cpp +++ b/source/ble-services/MicroBitRadioDatagram.cpp @@ -39,7 +39,7 @@ int MicroBitRadioDatagram::recv(uint8_t *buf, int len) PacketBuffer *p = rxQueue; rxQueue = rxQueue->next; - int l = min(len, p->length - 3); + int l = min(len, p->length - MICROBIT_RADIO_HEADER_SIZE - 1); // Fill in the buffer provided, if possible. memcpy(buf, p->payload, l); @@ -60,7 +60,7 @@ ManagedString MicroBitRadioDatagram::recv() PacketBuffer *p = rxQueue; rxQueue = rxQueue->next; - ManagedString s((const char *)p->payload, p->length - 3); + ManagedString s((const char *)p->payload, p->length - MICROBIT_RADIO_HEADER_SIZE - 1); delete p; return s; @@ -76,12 +76,12 @@ ManagedString MicroBitRadioDatagram::recv() */ int MicroBitRadioDatagram::send(uint8_t *buffer, int len) { - if (buffer == NULL || len < 0 || len > MICROBIT_RADIO_MAX_PACKET_SIZE + 3) + if (buffer == NULL || len < 0 || len > MICROBIT_RADIO_MAX_PACKET_SIZE + MICROBIT_RADIO_HEADER_SIZE - 1) return MICROBIT_INVALID_PARAMETER; PacketBuffer buf; - buf.length = len+3; + buf.length = len + MICROBIT_RADIO_HEADER_SIZE - 1; buf.version = 1; buf.group = 0; buf.protocol = MICROBIT_RADIO_PROTOCOL_DATAGRAM; diff --git a/source/ble-services/MicroBitRadioEvent.cpp b/source/ble-services/MicroBitRadioEvent.cpp index 6beb91c..e3a1bec 100644 --- a/source/ble-services/MicroBitRadioEvent.cpp +++ b/source/ble-services/MicroBitRadioEvent.cpp @@ -77,7 +77,7 @@ void MicroBitRadioEvent::eventReceived(MicroBitEvent e) PacketBuffer buf; - buf.length = sizeof(MicroBitEvent)+3; + buf.length = sizeof(MicroBitEvent) + MICROBIT_RADIO_HEADER_SIZE - 1; buf.version = 1; buf.group = 0; buf.protocol = MICROBIT_RADIO_PROTOCOL_EVENTBUS;