XBee API operation library for mbed
Revision 0:415f4b1b988e, committed 2015-10-22
- Comitter:
- yangcq88517
- Date:
- Thu Oct 22 12:32:36 2015 +0000
- Child:
- 1:b999cb9e310e
- Commit message:
- initial upload
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SerialData.cpp Thu Oct 22 12:32:36 2015 +0000 @@ -0,0 +1,44 @@ +#include "SerialData.h" + +SerialData::SerialData(PinName tx, PinName rx) +{ + serialPort = new Serial(tx, rx); + serialPort->baud(9600); +} + +SerialData::SerialData(PinName tx, PinName rx, int baudRate) +{ + serialPort = new Serial(tx, rx); + serialPort->baud(baudRate); +} + +SerialData::~SerialData() +{ + if (serialPort != NULL) + delete serialPort; +} + +int SerialData::readByte() +{ + if (serialPort->readable()) + return serialPort->getc(); + else return -1; +} + +void SerialData::writeByte(char data) +{ + serialPort->putc(data); +} + +bool SerialData::isOpen() +{ + if (serialPort->readable()) + return true; + else return false; +} + +void SerialData::open() +{} + +void SerialData::close() +{} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SerialData.h Thu Oct 22 12:32:36 2015 +0000 @@ -0,0 +1,30 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_SerialData +#define UK_AC_HERTS_SMARTLAB_XBEE_SerialData + +#include "mbed.h" +#include "ISerial.h" + +class SerialData: public ISerial +{ +private: + Serial * serialPort; + +public: + SerialData(PinName tx, PinName rx); + + SerialData(PinName tx, PinName rx, int baudRate); + + ~SerialData(); + + virtual int readByte(); + + virtual void writeByte(char data); + + virtual bool isOpen(); + + virtual void open(); + + virtual void close(); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XBeeAPI.cpp Thu Oct 22 12:32:36 2015 +0000 @@ -0,0 +1,29 @@ +#include "XBeeAPI.h" + +XBeeAPI::XBeeAPI(PinName tx, PinName rx) + :CoreAPI(serialData, false) +{ + serialData = new SerialData(tx, rx); +} + +XBeeAPI::XBeeAPI(PinName tx, PinName rx, bool isEscape) + :CoreAPI(serialData, isEscape) +{ + serialData = new SerialData(tx, rx); +} + +XBeeAPI::XBeeAPI(PinName tx, PinName rx, int baudRate, bool isEscape) + :CoreAPI(serialData, isEscape) +{ + serialData = new SerialData(tx, rx, baudRate); +} + +XBeeAPI::XBeeAPI(ISerial * serial, bool isEscape) + :CoreAPI(serial, isEscape) +{} + +XBeeAPI::~XBeeAPI() +{ + if (serialData != NULL) + delete serialData; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XBeeAPI.h Thu Oct 22 12:32:36 2015 +0000 @@ -0,0 +1,25 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_API +#define UK_AC_HERTS_SMARTLAB_XBEE_API + +#include "mbed.h" +#include "SerialData.h" +#include "CoreAPI.h" + +class XBeeAPI: public CoreAPI +{ +private: + SerialData * serialData; + +public: + XBeeAPI(PinName tx, PinName rx); + + XBeeAPI(PinName tx, PinName rx, bool isEscape); + + XBeeAPI(PinName tx, PinName rx, int baudRate, bool isEscape); + + XBeeAPI(ISerial * serial, bool isEscape); + + ~XBeeAPI(); +}; + +#endif \ No newline at end of file