XBee API operation library for mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers CoreAPI.h Source File

CoreAPI.h

00001 #ifndef UK_AC_HERTS_SMARTLAB_XBEE_CoreAPI
00002 #define UK_AC_HERTS_SMARTLAB_XBEE_CoreAPI
00003 
00004 #include "APIFrame.h"
00005 #include "ISerial.h"
00006 
00007 #include "ATCommandRequest.h"
00008 #include "CreateSourceRouteRequest.h"
00009 #include "IOCDetectionConfigRequest.h"
00010 #include "PinConfigurationRequest.h"
00011 #include "RemoteATCommandRequest.h"
00012 #include "RemoteIODetectionConfigRequest.h"
00013 #include "RemotePinConfigurationRequest.h"
00014 #include "XBeeTx16Request.h"
00015 #include "XBeeTx64Request.h"
00016 #include "ZigBeeExplicitTxRequest.h"
00017 #include "ZigBeeTxRequest.h"
00018 
00019 #include "XBeeRx64Indicator.h"
00020 #include "XBeeRx16Indicator.h"
00021 #include "XBeeRx64IOSampleIndicator.h"
00022 #include "XBeeRx16IOSampleIndicator.h"
00023 #include "XBeeTxStatusIndicator.h"
00024 #include "ATCommandIndicator.h"
00025 #include "ModemStatusIndicator.h"
00026 #include "ZigBeeTxStatusIndicator.h"
00027 #include "ZigBeeRxIndicator.h"
00028 #include "ZigBeeExplicitRxIndicator.h"
00029 #include "ZigBeeIOSampleIndicator.h"
00030 #include "SensorReadIndicator.h"
00031 #include "NodeIdentificationIndicator.h"
00032 #include "RemoteCommandIndicator.h"
00033 #include "RouteRecordIndicator.h"
00034 #include "ManyToOneRouteIndicator.h"
00035 
00036 /**
00037 * The core API class which responseable for processing frame data, but not the serial operation.
00038 */
00039 class CoreAPI
00040 {
00041 private:
00042     static const unsigned char KEY = 0x7E;
00043     static const unsigned char ESCAPED = 0x7D;
00044     static const unsigned char XON = 0x11;
00045     static const unsigned char XOFF = 0x13;
00046     static const unsigned int INITIAL_FRAME_LENGTH = 10;
00047 
00048     ISerial * serial;
00049     bool isEscapeMode;
00050     bool isChecksum;
00051     Timer timer;
00052 
00053     unsigned char waitFrameID;
00054 
00055     APIFrame * msg;
00056     XBeeRx64Indicator xBeeRx64Indicator;
00057     XBeeRx16Indicator xBeeRx16Indicator;
00058     XBeeRx64IOSampleIndicator xBeeRx64IOSampleIndicator;
00059     XBeeRx16IOSampleIndicator xBeeRx16IOSampleIndicator;
00060     XBeeTxStatusIndicator xBeeTxStatusIndicator;
00061     ATCommandIndicator aTCommandIndicator;
00062     ModemStatusIndicator modemStatusIndicator;
00063     ZigBeeTxStatusIndicator zigBeeTxStatusIndicator;
00064     ZigBeeRxIndicator zigBeeRxIndicator;
00065     ZigBeeExplicitRxIndicator zigBeeExplicitRxIndicator;
00066     ZigBeeIOSampleIndicator zigBeeIOSampleIndicator;
00067     SensorReadIndicator sensorReadIndicator;
00068     NodeIdentificationIndicator nodeIdentificationIndicator;
00069     RemoteCommandIndicator remoteCommandIndicator;
00070     RouteRecordIndicator routeRecordIndicator;
00071     ManyToOneRouteIndicator manyToOneRouteIndicator;
00072 
00073 protected:
00074 
00075     /** Read one byte payload, which allready handle the escape char, if less than 0 means error occured
00076     * @returns if less than 0 means error occured.
00077     */
00078     int readByte();
00079 
00080     /** Write one byte to the payload, which allready handle the escape char.
00081     * @param data one byte [0x00-0xFF]
00082     */
00083     void writeByte(unsigned  char data);
00084 
00085     /// Processing API frame.
00086     void packetProcess();
00087 
00088     /// Get the next avaliable API frame length.
00089     int getLength();
00090 
00091     /// Read the next avaliable API frame data.
00092     void readPayLoad(int length);
00093 
00094 public:
00095     CoreAPI(ISerial * serial, bool escape);
00096 
00097     ~CoreAPI();
00098 
00099     /** Set whether to verify checksum during receiving, default is not verify.
00100     *
00101     * @param isCheck true only to process API frame when checksum matches.
00102     *                false ignore the checksum.
00103     */
00104     void setVerifyChecksum(bool isCheck);
00105 
00106     /** A general function to send frame out
00107     *
00108     * @param request any API frame
00109     */
00110     void send(APIFrame * request);
00111 
00112     /** Read the next avaliable API frame, and the type of fram can be retrieved from getFrameType().
00113     *
00114     * @returns a API frame, NULL means data not avaliable.
00115     */
00116     APIFrame * getResponse();
00117 
00118     /** Read the next avaliable API frame.
00119     *
00120     * @returns a API frame, NULL means data not avaliable.
00121     */
00122     XBeeRx64Indicator * getXBeeRx64();
00123 
00124     /** Read the next avaliable API frame.
00125     *
00126     * @returns a API frame, NULL means data not avaliable.
00127     */
00128     XBeeRx16Indicator * getXBeeRx16();
00129 
00130     /** Read the next avaliable API frame.
00131     *
00132     * @returns a API frame, NULL means data not avaliable.
00133     */
00134     XBeeRx64IOSampleIndicator * getXBeeRx64IOSample();
00135 
00136     /** Read the next avaliable API frame.
00137     *
00138     * @returns a API frame, NULL means data not avaliable.
00139     */
00140     XBeeRx16IOSampleIndicator * getXBeeRx16IOSample();
00141 
00142     /** Read the next avaliable API frame.
00143     *
00144     * @returns a API frame, NULL means data not avaliable.
00145     */
00146     XBeeTxStatusIndicator * getXBeeTxStatus();
00147 
00148     /** Read the next avaliable API frame.
00149     *
00150     * @returns a API frame, NULL means data not avaliable.
00151     */
00152     ATCommandIndicator * getATCommand();
00153 
00154     /** Read the next avaliable API frame.
00155     *
00156     * @returns a API frame, NULL means data not avaliable.
00157     */
00158     ModemStatusIndicator * getModemStatus();
00159 
00160     /** Read the next avaliable API frame.
00161     *
00162     * @returns a API frame, NULL means data not avaliable.
00163     */
00164     ZigBeeTxStatusIndicator * getZigBeeTxStatus();
00165 
00166     /** Read the next avaliable API frame.
00167     *
00168     * @returns a API frame, NULL means data not avaliable.
00169     */
00170     ZigBeeRxIndicator * getZigBeeRx();
00171 
00172     /** Read the next avaliable API frame.
00173     *
00174     * @returns a API frame, NULL means data not avaliable.
00175     */
00176     ZigBeeExplicitRxIndicator * getZigBeeExplicitRx();
00177 
00178     /** Read the next avaliable API frame.
00179     *
00180     * @returns a API frame, NULL means data not avaliable.
00181     */
00182     ZigBeeIOSampleIndicator * getZigBeeIOSample();
00183 
00184     /** Read the next avaliable API frame.
00185     *
00186     * @returns a API frame, NULL means data not avaliable.
00187     */
00188     SensorReadIndicator * getSensorRead();
00189 
00190     /** Read the next avaliable API frame.
00191     *
00192     * @returns a API frame, NULL means data not avaliable.
00193     */
00194     NodeIdentificationIndicator * getNodeIdentification();
00195 
00196     /** Read the next avaliable API frame.
00197     *
00198     * @returns a API frame, NULL means data not avaliable.
00199     */
00200     RemoteCommandIndicator * getRemoteCommand();
00201 
00202     /** Read the next avaliable API frame.
00203     *
00204     * @returns a API frame, NULL means data not avaliable.
00205     */
00206     RouteRecordIndicator * getRouteRecord();
00207 
00208     /** Read the next avaliable API frame.
00209     *
00210     * @returns a API frame, NULL means data not avaliable.
00211     */
00212     ManyToOneRouteIndicator * getManyToOneRoute();
00213     
00214     XBeeTxStatusIndicator * sendXBeeTx16(Address * remoteAddress, OptionsBase * option, const unsigned char * payload, int offset, int length);
00215 
00216     XBeeTxStatusIndicator * sendXBeeTx64(Address * remoteAddress, OptionsBase * option, const unsigned char * payload, int offset, int length);
00217 
00218     ATCommandIndicator * sendATCommand(const char * command, bool applyChange, const unsigned  char * parameter = NULL, int offset = 0, int length = 0);
00219 
00220     RemoteCommandIndicator * sendRemoteATCommand(Address * remoteAddress, const char * command, OptionsBase * transmitOptions, const unsigned  char * parameter = NULL, int parameterOffset = 0, int parameterLength = 0);
00221 
00222     ZigBeeTxStatusIndicator * sendZigBeeTx(Address * remoteAddress, OptionsBase * option, const unsigned  char * payload, int offset, int length);
00223 
00224     ZigBeeTxStatusIndicator * sendZigBeeExplicitTx(ExplicitAddress * remoteAddress, OptionsBase * option, const unsigned  char * payload, int offset, int length);
00225 
00226     /**
00227     * @param function
00228     * DISABLED = 0x00,
00229     * RESERVED_FOR_PIN_SPECIFIC_ALTERNATE_FUNCTIONALITIES = 0x01,
00230     * ANALOG_INPUT_SINGLE_ENDED = 0x02,
00231     * DIGITAL_INPUT_MONITORED = 0x03,
00232     * DIGITAL_OUTPUT_DEFAULT_LOW = 0x04,
00233     * DIGITAL_OUTPUT_DEFAULT_HIGH = 0x05,
00234     * ALTERNATE_FUNCTIONALITIES_WHERE_APPLICABLE = 0x06//0x06~0x09
00235     */
00236     ATCommandIndicator * setPinFunction (Pin * pin, unsigned  char function);
00237 
00238     ATCommandIndicator * setIODetection(Pin ** pins, int size);
00239 
00240     /**
00241     * @param function
00242     * DISABLED = 0x00,
00243     * RESERVED_FOR_PIN_SPECIFIC_ALTERNATE_FUNCTIONALITIES = 0x01,
00244     * ANALOG_INPUT_SINGLE_ENDED = 0x02,
00245     * DIGITAL_INPUT_MONITORED = 0x03,
00246     * DIGITAL_OUTPUT_DEFAULT_LOW = 0x04,
00247     * DIGITAL_OUTPUT_DEFAULT_HIGH = 0x05,
00248     * ALTERNATE_FUNCTIONALITIES_WHERE_APPLICABLE = 0x06//0x06~0x09
00249     */
00250     RemoteCommandIndicator * setRemotePinFunction (Address * remoteAddress, Pin * pin, unsigned char function);
00251 
00252     RemoteCommandIndicator * setRemoteIODetection(Address * remoteAddress, Pin ** pins, int size);
00253 
00254     /// <summary>
00255     /// The command will immediately return an "OK" response. The data will follow in the normal API format for DIO data event.
00256     /// </summary>
00257     /// <returns>true if the command is "OK", false if no IO is enabled.</returns>
00258     bool forceXBeeLocalIOSample();
00259 
00260     /// <summary>
00261     /// Return 1 IO sample from the local module.
00262     /// </summary>
00263     /// <returns></returns>
00264     IOSamples * forceZigBeeLocalIOSample();
00265 
00266     /// <summary>
00267     /// Return 1 IO sample only, Samples before TX (IT) does not affect.
00268     /// </summary>
00269     /// <param name="remote"Remote address of the device></param>
00270     /// <returns></returns>
00271     IOSamples * forceXBeeRemoteIOSample(Address * remote);
00272 
00273     /// <summary>
00274     /// Return 1 IO sample only.
00275     /// </summary>
00276     /// <param name="remote">Remote address of the device</param>
00277     /// <returns></returns>
00278     IOSamples * forceZigBeeRemoteIOSample(Address * remote);
00279 };
00280 
00281 #endif