XBee and XBee-PRO ZigBee RF modules provide cost-effective wireless connectivity to electronic devices. They are interoperable with other ZigBee PRO feature set devices, including devices from other vendors.

Dependencies:   BufferedArray

Dependents:   MBEDminiproject

Revision:
0:837e6c48e90d
Child:
1:3dc0ec2f9fd6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Core/CoreAPI.h	Thu Oct 22 12:28:26 2015 +0000
@@ -0,0 +1,169 @@
+#ifndef UK_AC_HERTS_SMARTLAB_XBEE_CoreAPI
+#define UK_AC_HERTS_SMARTLAB_XBEE_CoreAPI
+
+#include "APIFrame.h"
+#include "ISerial.h"
+
+#include "ATCommandRequest.h"
+#include "CreateSourceRouteRequest.h"
+#include "IOCDetectionConfigRequest.h"
+#include "PinConfigurationRequest.h"
+#include "RemoteATCommandRequest.h"
+#include "RemoteIODetectionConfigRequest.h"
+#include "RemotePinConfigurationRequest.h"
+#include "XBeeTx16Request.h"
+#include "XBeeTx64Request.h"
+#include "ZigBeeExplicitTxRequest.h"
+#include "ZigBeeTxRequest.h"
+
+
+#include "XBeeRx64Indicator.h"
+#include "XBeeRx16Indicator.h"
+#include "XBeeRx64IOSampleIndicator.h"
+#include "XBeeRx16IOSampleIndicator.h"
+#include "XBeeTxStatusIndicator.h"
+#include "ATCommandIndicator.h"
+#include "ModemStatusIndicator.h"
+#include "ZigBeeTxStatusIndicator.h"
+#include "ZigBeeRxIndicator.h"
+#include "ZigBeeExplicitRxIndicator.h"
+#include "ZigBeeIOSampleIndicator.h"
+#include "SensorReadIndicator.h"
+#include "NodeIdentificationIndicator.h"
+#include "RemoteCommandIndicator.h"
+#include "RouteRecordIndicator.h"
+#include "ManyToOneRouteIndicator.h"
+
+class CoreAPI
+{
+private:
+    static const char KEY = 0x7E;
+    static const char ESCAPED = 0x7D;
+    static const char XON = 0x11;
+    static const char XOFF = 0x13;
+    static const int INITIAL_FRAME_LENGTH = 100;
+
+    ISerial * serial;
+    bool isEscapeMode;
+    bool isRunning;
+    bool isChecksum;
+
+    APIFrame * msg;
+    XBeeRx64Indicator xBeeRx64Indicator;
+    XBeeRx16Indicator xBeeRx16Indicator;
+    XBeeRx64IOSampleIndicator xBeeRx64IOSampleIndicator;
+    XBeeRx16IOSampleIndicator xBeeRx16IOSampleIndicator;
+    XBeeTxStatusIndicator xBeeTxStatusIndicator;
+    ATCommandIndicator aTCommandIndicator;
+    ModemStatusIndicator modemStatusIndicator;
+    ZigBeeTxStatusIndicator zigBeeTxStatusIndicator;
+    ZigBeeRxIndicator zigBeeRxIndicator;
+    ZigBeeExplicitRxIndicator zigBeeExplicitRxIndicator;
+    ZigBeeIOSampleIndicator zigBeeIOSampleIndicator;
+    SensorReadIndicator sensorReadIndicator;
+    NodeIdentificationIndicator nodeIdentificationIndicator;
+    RemoteCommandIndicator remoteCommandIndicator;
+    RouteRecordIndicator routeRecordIndicator;
+    ManyToOneRouteIndicator manyToOneRouteIndicator;
+
+protected:
+
+    /// <summary>
+    /// read one byte payload, which allready handle the escape char, if less than 0 means error occured
+    /// </summary>
+    /// <returns></returns>
+    int readByte();
+
+    /// <summary>
+    /// write one byte to the payload, which allready handle the escape char
+    /// </summary>
+    /// <param name="data"></param>
+    void writeByte(char data);
+
+    void packetProcess();
+
+    int getLength();
+
+    void readPayLoad(int length);
+
+public:
+    CoreAPI(ISerial * serial, bool escape);
+
+    ~CoreAPI();
+
+    /// <summary>
+    /// get or set whether to verify receive packet's checksum
+    /// </summary>
+    void setVerifyChecksum(bool isCheck);
+
+    /// <summary>
+    /// to start send and process response, must be called before any function
+    /// </summary>
+    void start();
+
+    /// <summary>
+    /// stop so the serial port can be used for other purpose
+    /// </summary>
+    void stop();
+
+    /// <summary>
+    /// a general function to send frame out, do not process response
+    /// </summary>
+    /// <param name="request"></param>
+    void send(APIFrame * request);
+
+    APIFrame * getResponse();
+
+    XBeeRx64Indicator * getXBeeRx64();
+
+    XBeeRx16Indicator * getXBeeRx16();
+
+    XBeeRx64IOSampleIndicator * getXBeeRx64IOSample();
+
+    XBeeRx16IOSampleIndicator * getXBeeRx16IOSample();
+
+    XBeeTxStatusIndicator * getXBeeTxStatus();
+
+    ATCommandIndicator * getATCommand();
+    
+    ModemStatusIndicator * getModemStatus();
+    
+    ZigBeeTxStatusIndicator * getZigBeeTxStatus();
+    
+    ZigBeeRxIndicator * getZigBeeRx();
+    
+    ZigBeeExplicitRxIndicator * getZigBeeExplicitRx();
+    
+    ZigBeeIOSampleIndicator * getZigBeeIOSample();
+    
+    SensorReadIndicator * getSensorRead();
+    
+    NodeIdentificationIndicator * getNodeIdentification();
+    
+    RemoteCommandIndicator * getRemoteCommand();
+    
+    RouteRecordIndicator * getRouteRecord();
+    
+    ManyToOneRouteIndicator * getManyToOneRoute();
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#endif
\ No newline at end of file