XBee modules

Dependencies:   DigiLogger

Fork of XBeeLib by Digi International Inc.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ApiFrame.h Source File

ApiFrame.h

00001 /**
00002  * Copyright (c) 2015 Digi International Inc.,
00003  * All rights not expressly granted are reserved.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
00007  * You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
00010  * =======================================================================
00011  */
00012 
00013 #if !defined(__API_FRAME_H_)
00014 #define __API_FRAME_H_
00015 
00016 #include "XBee/Addresses.h"
00017 
00018 /** Class for XBee API frames */
00019 class ApiFrame
00020 {
00021     /** Static variable that contains the last frame ID value assigned */
00022     static uint8_t      last_frame_id;
00023 
00024         public:
00025         /** List of API frames. Note that not all frames are supported by all radios */
00026         enum ApiFrameType {
00027 
00028             TxReq64Bit      = 0x00,     /**< TxReq64Bit: Only for 802.15.4 modules */
00029             TxReq16Bit      = 0x01,     /**< TxReq16Bit: Only for 802.15.4 modules */
00030             AtCmd           = 0x08,     /**< AtCmd */
00031             AtCmdQueuePV    = 0x09,     /**< AtCmdQueuePV */
00032             TxReqZBDM       = 0x10,     /**< TxReqZBDM: Only for ZigBee and DigiMesh modules */
00033             ExpAddrCmd      = 0x11,     /**< ExpAddrCmd: Only for ZigBee modules and DigiMesh */
00034             RemoteCmdReq    = 0x17,     /**< RemoteCmdReq */
00035             CreateSrcRoute  = 0x21,     /**< CreateSrcRoute */
00036             RxPacket64Bit   = 0x80,     /**< RxPacket64Bit: Only for 802.15.4 modules */
00037             RxPacket16Bit   = 0x81,     /**< RxPacket16Bit: Only for 802.15.4 modules */
00038             Io64Bit         = 0x82,     /**< Io64Bit: Only for 802.15.4 modules */
00039             Io16Bit         = 0x83,     /**< Io16Bit */
00040             AtCmdResp       = 0x88,     /**< AtCmdResp */
00041             TxStatus        = 0x89,     /**< TxStatus */
00042             AtModemStatus   = 0x8A,     /**< AtModemStatus */
00043             TxStatusZBDM    = 0x8B,     /**< TxStatusZBDM: Only for ZigBee and DigiMesh modules */
00044             RouteInfo       = 0x8D,     /**< RouteInfo: Only for DigiMesh modules */
00045             AggregateAddr   = 0x8E,     /**< AggregateAddr: Only for DigiMesh modules */
00046             RxPacketAO0     = 0x90,     /**< RxPacketAO0: Only for ZigBee and DigiMesh modules */
00047             RxPacketAO1     = 0x91,     /**< RxPacketAO1: Only for ZigBee and DigiMesh modules */
00048             IoSampleRxZBDM  = 0x92,     /**< IoSampleRxZBDM: Only for ZigBee and DigiMesh modules */
00049             SensorRxIndAO0  = 0x94,     /**< SensorRxIndAO0: Only for ZigBee modules */
00050             NodeIdentIndAO0 = 0x95,     /**< NodeIdentIndAO0: Only for ZigBee and DigiMesh modules */
00051             RemoteCmdResp   = 0x97,     /**< RemoteCmdResp */
00052             OtaFwUpStatus   = 0xA0,     /**< OtaFwUpStatus */
00053             RouteRecInd     = 0xA1,     /**< RouteRecInd */
00054             Many2OneRRInd   = 0xA3,     /**< Many2OneRRInd */
00055             Invalid         = ~0,       /**< Invalid */
00056         };
00057 
00058         /** Default constructor */
00059         ApiFrame();
00060 
00061         /** Constructor
00062          *
00063          * @param len length of the API frame (will allocate len bytes).
00064          */
00065         ApiFrame(uint16_t len);
00066 
00067         /** Constructor
00068          *
00069          * @param type frame type of this api frame.
00070          * @param data pointer to frame data payload.
00071          * @param len length of the payload.
00072          */
00073         ApiFrame(ApiFrameType type, const uint8_t *data, uint16_t len);
00074 
00075         /** Destructor */
00076         ~ApiFrame();
00077 
00078         ApiFrame(const ApiFrame& other); /* Intentionally not implemented */
00079 
00080         /** get_frame_type gets the type of the frame
00081          *
00082          * @returns the type of this frame.
00083          */
00084         ApiFrameType get_frame_type() const;
00085 
00086         /** dump dumps the information of this frame */
00087         void dump() const;
00088 
00089         /** dump_if dumps the information of the frame if the frame type matches
00090          *          with the parameter.
00091          *
00092          * @param type dump the frame info/data if the frame type matches with type.
00093          */
00094         void dump_if(ApiFrameType type);
00095 
00096 
00097         /** set_frame_type sets the type of the frame to type.
00098          *
00099          * @param type the type we want to set on the frame.
00100          */
00101         void set_frame_type(ApiFrameType type);
00102 
00103         /** get_data_len gets the length of the frame data payload.
00104          *
00105          * @returns the length of the data payload.
00106          */
00107         uint16_t get_data_len() const;
00108 
00109         /** set_data_len sets the length of the frame data payload.
00110          *
00111          * @param len the length of the data payload will be set on this frame.
00112          */
00113         void set_data_len(uint16_t len);
00114 
00115         /** get_data returns a pointer to the frame data payload.
00116          *
00117          * @returns a pointer to the frame data payload.
00118          */
00119         const uint8_t *get_data() const;
00120 
00121         /** get_data_at returns the byte at index offset.
00122          *
00123          * @param index offset of the byte we want to get.
00124          * @returns the byte at index offset.
00125          */
00126         uint8_t get_data_at(uint16_t index) const;
00127 
00128         /** set_data sets data byte at the specified index or offset.
00129          *
00130          * @param data byte that will be set at index position.
00131          * @param index offset of the byte we want to set.
00132          */
00133         void set_data(uint8_t data, uint16_t index);
00134 
00135         /** get_frame_id returns the frame id of this frame.
00136          *
00137          * @returns the frame id of this frame.
00138          */
00139         uint8_t get_frame_id() const;
00140 
00141         static uint8_t get_current_frame_id()
00142         {
00143             return last_frame_id;
00144         }
00145 
00146     protected:
00147         /** Type of this frame */
00148         ApiFrameType        _type;
00149 
00150         /** length of the payload, excluding the frame type */
00151         uint16_t            _data_frame_len;
00152 
00153         /** pointer to the frame data */
00154         uint8_t             *_data;
00155 
00156         /** True if the constructor allocates the data. Needed to delete it on the destructor */
00157         bool                _alloc_data;
00158 
00159         /** Frame ID of this frame */
00160         uint8_t             _frame_id;
00161 
00162         /** get_next_frame_id - returns the next frame ID secuentially, skipping the value 0
00163          *
00164          *  @returns the next frame ID that should be assigned to a frame
00165          */
00166         uint8_t get_next_frame_id();
00167 
00168         /** set_api_frame sets several members
00169          *
00170          * @param type frame type of this api frame.
00171          * @param data pointer to frame data payload.
00172          * @param len length of the payload.
00173          */
00174         void set_api_frame(ApiFrameType type, const uint8_t *data, uint16_t len);
00175 };
00176 
00177 #endif /* __API_FRAME_H_ */