microbit: minor updates to consistently use the MICROBIT_RADIO_HEADER_SIZE constant

This commit is contained in:
Joe Finney 2016-02-01 18:05:02 +00:00
parent 12c9ed246a
commit d7aa95e867
3 changed files with 6 additions and 6 deletions

View file

@ -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.

View file

@ -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;

View file

@ -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;