updates

Dependencies:   BLE_API mbed-dev-bin nRF51822

Fork of microbit-dal-eddystone by Martin Woolley

Files at this revision

API Documentation at this revision

Comitter:
LancasterUniversity
Date:
Wed Jul 13 12:18:47 2016 +0100
Parent:
66:2fc7d7c2fffc
Child:
68:9dd4fb5caf0a
Commit message:
Synchronized with git rev 05c03b06
Author: James Devine
microbit-dal: added validation to send [#151]

Changed in this revision

inc/drivers/MicroBitSerial.h Show annotated file Show diff for this revision Revisions of this file
source/drivers/MicroBitSerial.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/inc/drivers/MicroBitSerial.h	Wed Jul 13 12:18:46 2016 +0100
+++ b/inc/drivers/MicroBitSerial.h	Wed Jul 13 12:18:47 2016 +0100
@@ -265,8 +265,9 @@
       *
       *         Defaults to SYNC_SLEEP.
       *
-      * @return the number of bytes written, or MICROBIT_SERIAL_IN_USE if another fiber
-      *         is using the serial instance for transmission.
+      * @return the number of bytes written, MICROBIT_SERIAL_IN_USE if another fiber
+      *         is using the serial instance for transmission, MICROBIT_INVALID_PARAMETER
+      *         if buffer is invalid, or the given bufferLen is <= 0.
       */
     int send(ManagedString s, MicroBitSerialMode mode = MICROBIT_DEFAULT_SERIAL_MODE);
 
@@ -292,8 +293,9 @@
       *
       *         Defaults to SYNC_SLEEP.
       *
-      * @return the number of bytes written, or MICROBIT_SERIAL_IN_USE if another fiber
-      *         is using the serial instance for transmission.
+      * @return the number of bytes written, MICROBIT_SERIAL_IN_USE if another fiber
+      *         is using the serial instance for transmission, MICROBIT_INVALID_PARAMETER
+      *         if buffer is invalid, or the given bufferLen is <= 0.
       */
     int send(uint8_t *buffer, int bufferLen, MicroBitSerialMode mode = MICROBIT_DEFAULT_SERIAL_MODE);
 
--- a/source/drivers/MicroBitSerial.cpp	Wed Jul 13 12:18:46 2016 +0100
+++ b/source/drivers/MicroBitSerial.cpp	Wed Jul 13 12:18:47 2016 +0100
@@ -441,8 +441,9 @@
   *
   *         Defaults to SYNC_SLEEP.
   *
-  * @return the number of bytes written, or MICROBIT_SERIAL_IN_USE if another fiber
-  *         is using the serial instance for transmission.
+  * @return the number of bytes written, MICROBIT_SERIAL_IN_USE if another fiber
+  *         is using the serial instance for transmission, MICROBIT_INVALID_PARAMETER
+  *         if buffer is invalid, or the given bufferLen is <= 0.
   */
 int MicroBitSerial::send(ManagedString s, MicroBitSerialMode mode)
 {
@@ -471,14 +472,18 @@
   *
   *         Defaults to SYNC_SLEEP.
   *
-  * @return the number of bytes written, or MICROBIT_SERIAL_IN_USE if another fiber
-  *         is using the serial instance for transmission.
+  * @return the number of bytes written, MICROBIT_SERIAL_IN_USE if another fiber
+  *         is using the serial instance for transmission, MICROBIT_INVALID_PARAMETER
+  *         if buffer is invalid, or the given bufferLen is <= 0.
   */
 int MicroBitSerial::send(uint8_t *buffer, int bufferLen, MicroBitSerialMode mode)
 {
     if(txInUse())
         return MICROBIT_SERIAL_IN_USE;
 
+    if(bufferLen <= 0 || buffer == NULL)
+        return MICROBIT_INVALID_PARAMETER;
+
     lockTx();
 
     //lazy initialisation of our tx buffer