microbit-dal: added validation to send [#151]

This commit is contained in:
James Devine 2016-05-31 10:53:27 +01:00
parent a962befe74
commit 05c03b06fa
2 changed files with 15 additions and 8 deletions

View File

@ -265,8 +265,9 @@ class MicroBitSerial : public RawSerial
*
* 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 @@ class MicroBitSerial : public RawSerial
*
* 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);

View File

@ -441,8 +441,9 @@ int MicroBitSerial::sendChar(char c, MicroBitSerialMode mode)
*
* 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 @@ int MicroBitSerial::send(ManagedString s, MicroBitSerialMode mode)
*
* 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