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: mtsas mtsas mtsas mtsas
Diff: Utils/MTSSerialRadioInterface.cpp
- Revision:
- 1:f155d94d6f3a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Utils/MTSSerialRadioInterface.cpp Mon May 19 12:34:32 2014 -0500
@@ -0,0 +1,76 @@
+#include "MTSSerialRadioInterface.h"
+#include "MTSLog.h"
+
+using namespace mts;
+
+MTSSerialRadioInterface::MTSSerialRadioInterface(PinName TXD, PinName RXD, PinName RTS, PinName CTS, int txBufSize, int rxBufSize) {
+ if (RTS == NC && CTS == NC) {
+ io = new MTSSerial(TXD, RXD, txBufSize, rxBufSize);
+ } else {
+ io = new MTSSerialFlowControl(TXD, RXD, RTS, CTS, txBufSize, rxBufSize);
+ }
+}
+
+MTSSerialRadioInterface::~MTSSerialRadioInterface() {
+ delete io;
+}
+
+void MTSSerialRadioInterface::baud(unsigned int baud) {
+ io->baud(baud);
+}
+
+void MTSSerialRadioInterface::format(int bits, Parity parity, int stop_bits) {
+ io->format(bits, parity, stop_bits);
+}
+
+bool MTSSerialRadioInterface::putc(char data, unsigned int timeoutMillis) {
+ if (timeoutMillis) {
+ return io->write(data, timeoutMillis) ? true : false;
+ } else {
+ return io->write(data) ? true : false;
+ }
+}
+
+int MTSSerialRadioInterface::write(char* data, int size, unsigned int timeoutMillis) {
+ if (size < 0) {
+ log_err("cannot write fewer than 0 bytes");
+ return -1;
+ }
+
+ if (timeoutMillis) {
+ return io->write(data, size, timeoutMillis);
+ } else {
+ return io->write(data, size);
+ }
+}
+
+bool MTSSerialRadioInterface::writeable() {
+ return io->writeable() ? true : false;
+}
+
+bool MTSSerialRadioInterface::getc(char& data, unsigned int timeoutMillis) {
+ if (timeoutMillis) {
+ return io->read(data, timeoutMillis) ? true : false;
+ } else {
+ return io->read(data) ? true : false;
+ }
+}
+
+int MTSSerialRadioInterface::read(char* data, int size, unsigned int timeoutMillis) {
+ if (size < 0) {
+ log_err("cannot read fewer than 0 bytes");
+ return -1;
+ } else if (size == 0) {
+ return 0;
+ }
+
+ if (timeoutMillis) {
+ return io->read(data, size, timeoutMillis);
+ } else {
+ return io->read(data, size);
+ }
+}
+
+bool MTSSerialRadioInterface::readable() {
+ return io->readable() ? true : false;
+}