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

Core/CoreAPI.h

Committer:
yangcq88517
Date:
2015-10-22
Revision:
1:3dc0ec2f9fd6
Parent:
0:837e6c48e90d
Child:
3:6b205ec8624b

File content as of revision 1:3dc0ec2f9fd6:

#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"

/// The core API class which responseable for processing frame data, but not the serial operation.
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:

    /** Read one byte payload, which allready handle the escape char, if less than 0 means error occured
    * @returns if less than 0 means error occured.
    */
    int readByte();

    /** Write one byte to the payload, which allready handle the escape char.
    * @param data one byte [0x00-0xFF]
    */
    void writeByte(char data);
    
    /// Processing API frame.
    void packetProcess();
    
    /// Get the next avaliable API frame length.
    int getLength();
    
    /// Read the next avaliable API frame data.
    void readPayLoad(int length);

public:
    CoreAPI(ISerial * serial, bool escape);

    ~CoreAPI();

    /** Set whether to verify checksum during receiving, default is not verify.
    *
    * @param isCheck true only to process API frame when checksum matches.
    *                false ignore the checksum.
    */
    void setVerifyChecksum(bool isCheck);

    /// Start send and process response, must call this method before starting processing data.
    void start();

    /// Stop the serial port.
    void stop();

    /** A general function to send frame out
    *
    * @param request any API frame
    */
    void send(APIFrame * request);

    /** Read the next avaliable API frame, and the type of fram can be retrieved from getFrameType().
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    APIFrame * getResponse();

    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    XBeeRx64Indicator * getXBeeRx64();

    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    XBeeRx16Indicator * getXBeeRx16();

    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    XBeeRx64IOSampleIndicator * getXBeeRx64IOSample();

    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    XBeeRx16IOSampleIndicator * getXBeeRx16IOSample();

    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    XBeeTxStatusIndicator * getXBeeTxStatus();

    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    ATCommandIndicator * getATCommand();
    
    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    ModemStatusIndicator * getModemStatus();
    
    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    ZigBeeTxStatusIndicator * getZigBeeTxStatus();
    
    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    ZigBeeRxIndicator * getZigBeeRx();
    
    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    ZigBeeExplicitRxIndicator * getZigBeeExplicitRx();
    
    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    ZigBeeIOSampleIndicator * getZigBeeIOSample();
    
    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    SensorReadIndicator * getSensorRead();
    
    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    NodeIdentificationIndicator * getNodeIdentification();
    
    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    RemoteCommandIndicator * getRemoteCommand();
    
    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    RouteRecordIndicator * getRouteRecord();
    
    /** Read the next avaliable API frame.
    *
    * @returns a API frame, NULL means data not avaliable.
    */
    ManyToOneRouteIndicator * getManyToOneRoute();
};




















#endif