Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: source/AsyncSerial.cpp
- Revision:
- 13:dbb23efed611
- Parent:
- 12:b45908320b9c
- Child:
- 15:4d7d96cacc18
--- a/source/AsyncSerial.cpp Fri Apr 10 17:02:09 2015 +0100
+++ b/source/AsyncSerial.cpp Fri Apr 10 16:28:15 2015 +0000
@@ -17,7 +17,7 @@
receiveIndex(0),
receiveStatus(AsyncSerial::RECEIVE_TIMEOUT),
receiveResult(),
- timeout()
+ timeout(),
insideCondition(false),
conditionStartBuffer(NULL),
@@ -28,7 +28,7 @@
sendHandler(),
receiveHandler(),
- waitHandler(),
+ waitHandler()
{
// register ISR for receiving and sending
SerialBase::attach<AsyncSerial>(this, &AsyncSerial::getReady, SerialBase::RxIrq);
@@ -213,30 +213,17 @@
/* Receiving block of data. Function pointer interface.
*/
-void AsyncSerial::receive(receive_done_t handler,
- uint8_t* buffer, uint16_t maxLength,
- const char* conditionStartBuffer, uint16_t conditionStartLength,
- const char* conditionEndBuffer, uint16_t conditionEndLength,
- uint32_t timeoutMilli)
-{
- receiveHandler.attach(handler);
-
- receive(buffer, maxLength,
- conditionStartBuffer, conditionStartLength,
- conditionEndBuffer, conditionEndLength,
- timeoutMilli);
-}
-
-/* Common receive function.
-*/
-void AsyncSerial::receive(uint8_t* buffer, uint16_t maxLength,
+void AsyncSerial::receive(receive_done_t _handler,
+ uint8_t* _receiveBuffer, uint16_t _maxLength,
const char* _conditionStartBuffer, uint16_t _conditionStartLength,
const char* _conditionEndBuffer, uint16_t _conditionEndLength,
- uint32_t timeoutMilli)
+ uint32_t _timeoutMilli)
{
+ receiveHandler.attach(_handler);
+
/* Signal callback function immediately if buffer and maxLength are invalid.
*/
- if ((buffer == NULL) || (maxLength == 0))
+ if ((_receiveBuffer == NULL) || (_maxLength == 0))
{
receiveResult.buffer = NULL;
receiveResult.length = 0;
@@ -244,45 +231,56 @@
receiveHandler.call(&receiveResult);
}
- /* Otherwise, setup book keeping variables for reception.
- */
else
{
- // Book keeping variables for reception
- receiveBuffer = buffer;
- receiveMaxLength = maxLength;
- receiveIndex = 0;
- receiveStatus = AsyncSerial::RECEIVE_TIMEOUT;
-
- // Book keeping variables for conditions
- conditionStartBuffer = _conditionStartBuffer;
- conditionStartLength = _conditionStartLength;
- conditionEndBuffer = _conditionEndBuffer;
- conditionEndLength = _conditionEndLength;
- conditionIndex = 0;
+ receive(_receiveBuffer, _maxLength,
+ _conditionStartBuffer, _conditionStartLength,
+ _conditionEndBuffer, _conditionEndLength,
+ _timeoutMilli);
+ }
+}
- // Check if optional start condition is set
- if ((_conditionStartBuffer != NULL) && (_conditionStartLength != 0))
- {
- insideCondition = false;
- }
- else
- {
- insideCondition = true;
- }
+/* Common receive function.
+*/
+void AsyncSerial::receive(uint8_t* _receiveBuffer, uint16_t _maxLength,
+ const char* _conditionStartBuffer, uint16_t _conditionStartLength,
+ const char* _conditionEndBuffer, uint16_t _conditionEndLength,
+ uint32_t _timeoutMilli)
+{
+ // Book keeping variables for reception
+ receiveBuffer = _receiveBuffer;
+ receiveMaxLength = _maxLength;
+ receiveIndex = 0;
+ receiveStatus = AsyncSerial::RECEIVE_TIMEOUT;
- // Clear buffer. This re-arms the rx interrupts.
- while (SerialBase::readable())
- {
- SerialBase::_base_getc();
- }
+ // Book keeping variables for conditions
+ conditionStartBuffer = _conditionStartBuffer;
+ conditionStartLength = _conditionStartLength;
+ conditionEndBuffer = _conditionEndBuffer;
+ conditionEndLength = _conditionEndLength;
+ conditionIndex = 0;
- // Arm timer and start receiving.
- timeout.attach_us<AsyncSerial>(this, &AsyncSerial::receiveTimeout, timeoutMilli * 1000);
- isReceiving = true;
+ // Check if optional start condition is set
+ if ((_conditionStartBuffer != NULL) && (_conditionStartLength != 0))
+ {
+ insideCondition = false;
+ }
+ else
+ {
+ insideCondition = true;
}
- DEBUG("receive: %p\r\n", buffer);
+ // Clear buffer. This re-arms the rx interrupts.
+ while (SerialBase::readable())
+ {
+ SerialBase::_base_getc();
+ }
+
+ // Arm timer and start receiving.
+ timeout.attach_us<AsyncSerial>(this, &AsyncSerial::receiveTimeout, _timeoutMilli * 1000);
+ isReceiving = true;
+
+ DEBUG("receive: %p\r\n", _receiveBuffer);
}
/* Wait until timeout or sequence is detected.

