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.
Dependents: DISCO-F746NG_rtos_test MbedTableControl
Revision 21:cce827364df1, committed 2016-08-08
- Comitter:
- Weimen Li
- Date:
- Mon Aug 08 19:48:19 2016 -0400
- Parent:
- 20:13283edd1aba
- Commit message:
- Converted std::queue to RTOS's Queue to pass information from receivedByteISR to receivedByteThread, as std::queue is not ISR-safe.
Changed in this revision
| HC06Bluetooth.cpp | Show annotated file Show diff for this revision Revisions of this file |
| HC06Bluetooth.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/HC06Bluetooth.cpp Mon Aug 08 15:03:13 2016 -0400
+++ b/HC06Bluetooth.cpp Mon Aug 08 19:48:19 2016 -0400
@@ -124,53 +124,46 @@
while(btSerialObj.readable())
{
- dataReceivedBuffer.push(btSerialObj.getc());
+ dataReceivedBuffer.put((char*) btSerialObj.getc());
}
- receiveByteThreadObj.signal_set(SIG_BT_BYTE);
}
void HC06Bluetooth::receiveByteThread()
{
// Now that all characters have been read, process them.
+ char receivedChar;
while(true)
{
- if (!dataReceivedBuffer.empty())
+ receivedChar = (uint32_t) dataReceivedBuffer.get().value.p;
+ // Call the character callback function if it is not null.
+ if (charCallbackFunc != NULL) charCallbackFunc(receivedChar);
+
+ if (lineCallbackFunc != NULL)
{
- char receivedChar = dataReceivedBuffer.front();
- dataReceivedBuffer.pop();
- // Call the character callback function if it is not null.
- if (charCallbackFunc != NULL) charCallbackFunc(receivedChar);
-
- if (lineCallbackFunc != NULL)
+ // If the character is a newline or carriage return, then call the line callback function.
+ if ((receivedChar == '\n') || (receivedChar == '\r'))
{
- // If the character is a newline or carriage return, then call the line callback function.
- if ((receivedChar == '\n') || (receivedChar == '\r'))
+ // Clear whatever was in the toClient buffer before.
+ dataReceivedToClient.clear();
+ // Copy everything from the queue to the client buffer.
+ while(!dataReceivedBufferCopy.empty())
{
- // Clear whatever was in the toClient buffer before.
- dataReceivedToClient.clear();
- // Copy everything from the queue to the client buffer.
- while(!dataReceivedBufferCopy.empty())
- {
- dataReceivedToClient.push_back(dataReceivedBufferCopy.front());
- dataReceivedBufferCopy.pop();
- }
- // Null-terminate the string.
- dataReceivedToClient.push_back('\0');
+ dataReceivedToClient.push_back(dataReceivedBufferCopy.front());
+ dataReceivedBufferCopy.pop();
+ }
+ // Null-terminate the string.
+ dataReceivedToClient.push_back('\0');
- // Call the callback function with the toClient buffer.
- lineCallbackFunc(&dataReceivedToClient[0], dataReceivedToClient.size());
- }
+ // Call the callback function with the toClient buffer.
+ lineCallbackFunc(&dataReceivedToClient[0], dataReceivedToClient.size());
+ }
- // Otherwise, enqueue it in the copy.
- else
- {
- dataReceivedBufferCopy.push(receivedChar);
- }
+ // Otherwise, enqueue it in the copy.
+ else
+ {
+ dataReceivedBufferCopy.push(receivedChar);
}
}
- else {
- receiveByteThreadObj.signal_wait(SIG_BT_BYTE);
- }
}
}
--- a/HC06Bluetooth.h Mon Aug 08 15:03:13 2016 -0400
+++ b/HC06Bluetooth.h Mon Aug 08 19:48:19 2016 -0400
@@ -76,7 +76,7 @@
void (*lineCallbackFunc) (const char*, size_t strlen);
/// Pointer to a callback function the client provides when a character is received.
void (*charCallbackFunc) (char);
- std::queue<char> dataReceivedBuffer;
+ Queue<char, 64> dataReceivedBuffer;
std::queue<char> dataReceivedBufferCopy;
std::vector<char> dataReceivedToClient;
};