XBee API operation library for mbed

Files at this revision

API Documentation at this revision

Comitter:
yangcq88517
Date:
Thu Oct 22 20:02:33 2015 +0000
Parent:
1:b999cb9e310e
Child:
3:408c43b387a5
Commit message:
bug fix

Changed in this revision

SerialData.cpp Show annotated file Show diff for this revision Revisions of this file
SerialData.h Show annotated file Show diff for this revision Revisions of this file
SmartLabXBeeCore.lib Show annotated file Show diff for this revision Revisions of this file
XBeeAPI.cpp Show annotated file Show diff for this revision Revisions of this file
XBeeAPI.h Show annotated file Show diff for this revision Revisions of this file
--- a/SerialData.cpp	Thu Oct 22 12:39:24 2015 +0000
+++ b/SerialData.cpp	Thu Oct 22 20:02:33 2015 +0000
@@ -20,9 +20,7 @@
 
 int SerialData::readByte()
 {
-    if (serialPort->readable())
-        return serialPort->getc();
-    else return -1;
+    return serialPort->getc();
 }
 
 void SerialData::writeByte(char data)
@@ -30,13 +28,18 @@
     serialPort->putc(data);
 }
 
-bool SerialData::isOpen()
+bool SerialData::peek()
 {
     if (serialPort->readable())
         return true;
     else return false;
 }
 
+bool SerialData::isOpen()
+{
+    return true;
+}
+
 void SerialData::open()
 {}
 
--- a/SerialData.h	Thu Oct 22 12:39:24 2015 +0000
+++ b/SerialData.h	Thu Oct 22 20:02:33 2015 +0000
@@ -4,27 +4,64 @@
 #include "mbed.h"
 #include "ISerial.h"
 
+/// The detailed implementation of ISerial, which is responsible for sending and receiving seial data.
 class SerialData: public ISerial
 {
 private:
+    /// mbed serial port interface.
     Serial * serialPort;
 
 public:
+    /** Create a SerialData instance which using pin tx and rx. 
+    *
+    * @param tx data transmission line
+    * @param rx data receiving line
+    *
+    */
     SerialData(PinName tx, PinName rx);
-    
+     /** Create a SerialData instance which using pin tx and rx. 
+    *
+    * @param tx data transmission line
+    * @param rx data receiving line
+    * @param baudRate baud rate
+    *
+    */
     SerialData(PinName tx, PinName rx, int baudRate);
     
     ~SerialData();
 
+    /**
+    * Read the next avaliable data.
+    *
+    * @returns [0x00-0xFF], -1 means data not avaliable.
+    *
+    */
     virtual int readByte();
 
+    /**
+    * Write one byte of data.
+    *
+    * @param data [0x00-0xFF]
+    *
+    */
     virtual void writeByte(char data);
     
+    /** Check if the serial port is open, not implemented and has no affect,
+    * @returns always true
+    */
     virtual bool isOpen();
 
+    /// Open the serial port, not implemented and has no affect.
     virtual void open();
-
+    
+    /// Close the serial port, not implemented and has no affect.
     virtual void close();
+    
+    /** Check if data is ready to read.
+    * @returns true data avaliable.
+    *          false data not avaliable.
+    */
+    virtual bool peek();
 };
 
 #endif
\ No newline at end of file
--- a/SmartLabXBeeCore.lib	Thu Oct 22 12:39:24 2015 +0000
+++ b/SmartLabXBeeCore.lib	Thu Oct 22 20:02:33 2015 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/yangcq88517/code/SmartLabXBeeCore/#837e6c48e90d
+https://developer.mbed.org/users/yangcq88517/code/SmartLabXBeeCore/#3dc0ec2f9fd6
--- a/XBeeAPI.cpp	Thu Oct 22 12:39:24 2015 +0000
+++ b/XBeeAPI.cpp	Thu Oct 22 20:02:33 2015 +0000
@@ -1,29 +1,17 @@
 #include "XBeeAPI.h"
 
 XBeeAPI::XBeeAPI(PinName tx, PinName rx)
-    :CoreAPI(serialData, false)
-{
-    serialData = new SerialData(tx, rx);
-}
+    :CoreAPI(new SerialData(tx, rx), false)
+{}
 
 XBeeAPI::XBeeAPI(PinName tx, PinName rx, bool isEscape)
-    :CoreAPI(serialData, isEscape)
-{
-    serialData = new SerialData(tx, rx);
-}
+    :CoreAPI(new SerialData(tx, rx), isEscape)
+{}
 
 XBeeAPI::XBeeAPI(PinName tx, PinName rx, int baudRate, bool isEscape)
-    :CoreAPI(serialData, isEscape)
-{
-    serialData = new SerialData(tx, rx, baudRate);
-}
+    :CoreAPI(new SerialData(tx, rx, baudRate), isEscape)
+{}
 
 XBeeAPI::XBeeAPI(ISerial * serial, bool isEscape)
     :CoreAPI(serial, isEscape)
-{}
-
-XBeeAPI::~XBeeAPI()
-{
-    if (serialData != NULL)
-        delete serialData;
-}
\ No newline at end of file
+{}
\ No newline at end of file
--- a/XBeeAPI.h	Thu Oct 22 12:39:24 2015 +0000
+++ b/XBeeAPI.h	Thu Oct 22 20:02:33 2015 +0000
@@ -5,21 +5,141 @@
 #include "SerialData.h"
 #include "CoreAPI.h"
 
+/** XBee API library entry poiont.
+*Example:
+* @code
+*#include "mbed.h"
+*#include "XBeeAPI.h"
+*
+*XBeeAPI xbee(p9, p10, true);
+*Address add(0x00,0x00,0x1022);
+*XBeeTx16Request tx16(0x00, &add, &OptionsBase::DEFAULT, "Hello From XBEE API", 0, 19);
+*XBeeRx16Indicator rx16(NULL);
+*
+*int main()
+*{
+*    xbee.setVerifyChecksum(false);
+*    xbee.start();
+*
+*    // option 1
+*    while(1) {
+*        XBeeRx16Indicator * response = xbee.getXBeeRx16();
+*        if (response != NULL) {
+*            tx16.setPayload(response->getReceivedData(), 0, response->getReceivedDataLength());
+*            xbee.send(&tx16);
+*        }
+*    }
+*
+*    // option 2
+*    while(1) {
+*
+*        APIFrame * frame = xbee.getResponse();
+*        while(frame != NULL) {
+*            switch (frame->getFrameType()) {
+*                case APIFrame::Tx64_Request :
+*                    break;
+*                case APIFrame::Tx16_Request :
+*                    break;
+*                case APIFrame::AT_Command:
+*                    break;
+*                case APIFrame::AT_Command_Queue_Parameter_Value:
+*                    break;
+*                case APIFrame::ZigBee_Transmit_Request:
+*                    break;
+*                case APIFrame::Explicit_Addressing_ZigBee_Command_Frame:
+*                    break;
+*                case APIFrame::Remote_Command_Request :
+*                    break;
+*                case APIFrame::Create_Source_Route :
+*                    break;
+*                case APIFrame::Register_Joining_Device:
+*                    break;
+*                case APIFrame::Rx64_Receive_Packet :
+*                    break;
+*                case APIFrame::Rx16_Receive_Packet:
+*                    rx16.convert(frame);
+*                    tx16.setPayload(rx16.getReceivedData(), 0, rx16.getReceivedDataLength());
+*                    xbee.send(&tx16);
+*                    break;
+*                case APIFrame::Rx64_IO_Data_Sample_Rx_Indicator:
+*                    break;
+*                case APIFrame::Rx16_IO_Data_Sample_Rx_Indicator :
+*                    xbee.send(&tx16);
+*                    break;
+*                case APIFrame::AT_Command_Response:
+*                    break;
+*                case APIFrame::XBee_Transmit_Status :
+*                    break;
+*                case APIFrame::Modem_Status:
+*                    break;
+*                case APIFrame::ZigBee_Transmit_Status :
+*                    break;
+*                case APIFrame::ZigBee_Receive_Packet:
+*                    break;
+*                case APIFrame::ZigBee_Explicit_Rx_Indicator :
+*                    break;
+*                case APIFrame::ZigBee_IO_Data_Sample_Rx_Indicator :
+*                    break;
+*                case APIFrame::XBee_Sensor_Read_Indicato :
+*                    break;
+*                case APIFrame::Node_Identification_Indicator:
+*                    break;
+*                case APIFrame::Remote_Command_Response:
+*                    break;
+*                case APIFrame::Over_the_Air_Firmware_Update_Status :
+*                    break;
+*                case APIFrame::Route_Record_Indicator :
+*                    break;
+*                case APIFrame::Device_Authenticated_Indicator:
+*                    break;
+*                case APIFrame::Many_to_One_Route_Request_Indicator:
+*                    break;
+*            }
+*
+*            frame = xbee.getResponse();
+*        }
+*    }
+*}
+*@endcode
+*/
 class XBeeAPI: public CoreAPI
 {
-private:
-    SerialData * serialData;
+public:
 
-public:
+    /** Create a XBeeAPI instance. 
+    *
+    * @param tx data transmission line
+    * @param rx data receiving line
+    *
+    */
     XBeeAPI(PinName tx, PinName rx);
 
+    /** Create a XBeeAPI instance. 
+    *
+    * @param tx data transmission line
+    * @param rx data receiving line
+    * @param isEscape API escaped operating mode (AP = 2) works similarly to API mode. The only difference is that when working in API escaped mode, some bytes of the API frame specific data must be escaped.
+    *
+    */
     XBeeAPI(PinName tx, PinName rx, bool isEscape);
 
+    /** Create a XBeeAPI instance. 
+    *
+    * @param tx data transmission line
+    * @param rx data receiving line
+    * @param baudRate baud rate
+    * @param isEscape API escaped operating mode (AP = 2) works similarly to API mode. The only difference is that when working in API escaped mode, some bytes of the API frame specific data must be escaped.
+    *
+    */
     XBeeAPI(PinName tx, PinName rx, int baudRate, bool isEscape);
 
+    /** Create a SerialData instance with other serial interface.
+    *
+    * @param serial class that implementes ISerial interface.
+    * @param isEscape API escaped operating mode (AP = 2) works similarly to API mode. The only difference is that when working in API escaped mode, some bytes of the API frame specific data must be escaped.
+    *
+    */
     XBeeAPI(ISerial * serial, bool isEscape);
-    
-    ~XBeeAPI();
 };
 
 #endif
\ No newline at end of file