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
Libs/Xbee/Xbee.cpp
- Committer:
- pspatel321
- Date:
- 2014-11-13
- Revision:
- 30:91af74a299e1
File content as of revision 30:91af74a299e1:
#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++;
}
