John Bailey / XBeeApi

Dependencies:   CircularBuffer FixedLengthList

Dependents:   XBeeApiTest XBeeApiSimpleATCmdsExample XBeeApiBroadcastExample XBeeApiBroadcastExampleRTOS ... more

Utility/XBeeApiCmdAt.hpp

Committer:
johnb
Date:
2014-02-05
Revision:
25:db6874b7ac4b
Parent:
24:2cd1094c4fd7
Child:
26:f5df80e990f4

File content as of revision 25:db6874b7ac4b:

/**
   @file
   @brief Class to abstract AT commands send to the XBee API
   
   AT commands have the payload:
   
     Byte 1     : Frame ID
     Byte 2 & 3 : AT command
     Byte 4-n   : Parameter Value 
   
   @author John Bailey 

   @copyright Copyright 2014 John Bailey

   @section LICENSE
   
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

#if !defined XBEEAPICMDAT_HPP
#define      XBEEAPICMDAT_HPP

#include "XBeeApiFrame.hpp"
#include "XBeeDevice.hpp"

#include <stdint.h>

class XBeeApiCmdAt : public XBeeApiFrameDecoder
{
    public:
       typedef uint16_t panId_t;
       typedef uint8_t  channel_t;
    
    protected:
        bool m_haveHwVer;
        bool m_haveFwVer;
        bool m_haveChan;
        bool m_havePANId;
        bool m_haveEDA;
        bool m_haveCE;
        
        uint16_t m_hwVer;
        uint16_t m_fwVer;
        channel_t m_chan;
        channel_t m_chanPend;
        panId_t m_PANId;
        panId_t m_PANIdPend;
        bool m_EDA;
        bool m_EDAPend;
        bool m_CE;
        bool m_CEPend;

        template< typename T >
        class XBeeApiCmdAtSet : public XBeeApiFrame {
            uint8_t m_buffer[ 3 + sizeof( T ) ];
            public:
                XBeeApiCmdAtSet( const uint8_t* const p_data,
                                 const T p_val );
            virtual ~XBeeApiCmdAtSet();
        };

    public:

       XBeeApiCmdAt( );
       virtual ~XBeeApiCmdAt( void ) {};
       
       bool requestHardwareVersion( void );
       bool requestFirmwareVersion( void );
       bool requestChannel( void );
       bool requestCoordinatorEnabled( void );
       bool requestEndDeviceAssociationEnabled( void );
       bool requestPanId( void );

       virtual bool getHardwareVersion( uint16_t* const p_ver );
       virtual bool getFirmwareVersion( uint16_t* const p_ver );
       
       virtual bool getChannel( uint8_t* const p_chan );
       virtual bool setChannel( uint8_t const p_chan );
       
       virtual bool getCoordinatorEnabled( bool* constp_en );
       virtual bool setCoordinatorEnabled( const bool p_en );
       
       virtual bool getEndDeviceAssociationEnabled( bool* const p_en ); 
       virtual bool setEndDeviceAssociationEnabled( const bool p_en  );
       
       virtual bool getPanId( panId_t* const p_id );       
       virtual bool setPanId( const panId_t p_id );       
       
       /* Implement XBeeApiCmdDecoder interface */
       virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len );

};

class XBeeApiCmdAtBlocking : public XBeeApiCmdAt
{
    protected:
        uint16_t m_timeout;
        uint16_t m_slice;

    public:
       XBeeApiCmdAtBlocking( const uint16_t p_timeout = 1000, const uint16_t p_slice = 100);
       
       virtual ~XBeeApiCmdAtBlocking( void ) {};
       /* Implement XBeeApiCmdAt's virtual methods */
       virtual bool getHardwareVersion( uint16_t* const p_ver );
       virtual bool getFirmwareVersion( uint16_t* const p_ver );

       virtual bool getChannel( uint8_t* const p_chan );
       virtual bool setChannel( uint8_t const p_chan );
        
       virtual bool getCoordinatorEnabled( bool* constp_en );
       virtual bool setCoordinatorEnabled( const bool p_en );
       
       virtual bool getEndDeviceAssociationEnabled( bool* const p_en ); 
       virtual bool setEndDeviceAssociationEnabled( const bool p_en  );
       
       virtual bool getPanId( panId_t* const p_id );       
       virtual bool setPanId( const panId_t p_id );       

};

#endif