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.
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
Diff: Libs/Xbee/Xbee.cpp
- Revision:
- 30:91af74a299e1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Libs/Xbee/Xbee.cpp Thu Nov 13 10:53:10 2014 +0000
@@ -0,0 +1,57 @@
+#include "Xbee.h"
+
+Xbee::Xbee(PinName tx, PinName rx, int baudrate, int bufferSize, char _delim) : xbee(tx, rx, bufferSize) {
+ xbee.baud(baudrate);
+ charCounter = 0;
+ numMessagesIn = 0;
+ numMessagesOut = 0;
+ delim = _delim;
+
+ // Attach callback when a new message delimiter character arrives
+ xbee.autoDetectChar(delim);
+ xbee.attach(this, &Xbee::newMsg, MODSERIAL::RxAutoDetect);
+}
+bool Xbee::send(CANMessage& msg) {
+ if (!xbee.writeable()) return false; // Exit, txBuffer full
+
+ // Format as string
+ char str[100];
+
+ // Will it fit?
+ if (xbee.txBufferGetSize(0) - xbee.txBufferGetCount() > strlen(str)){
+ xbee.printf("%s\n", str);
+ numMessagesOut++;
+ return true;
+
+ // Don't send
+ } else {
+ return false;
+ }
+}
+bool Xbee::receive(CANMessage& msg) {
+ char str[100];
+ unsigned int i = 0;
+
+ if (charCounter == 0) return false; // No messages yet
+ else {
+ while (xbee.readable()) { // Build string until buffer is empty or delimiter char is found
+ char c = xbee.getc();
+ str[i] = c;
+ i++;
+ if (c == delim) {
+ charCounter--;
+ str[i-1] = '\0'; // Null terminator in place of delimiter char
+ break;
+ }
+ }
+ }
+
+ // Process string into CAN Message
+ int len = strlen(str);
+
+ numMessagesIn++;
+ return true;
+}
+void Xbee::newMsg(MODSERIAL_IRQ_INFO *q) {
+ charCounter++;
+}
\ No newline at end of file
