Wiselib
wiselib.testing/util/glab_rest_connector/swap_response_message.h
Go to the documentation of this file.
00001 /* 
00002  * File:   rest_response.h
00003  * Author: maxpagel
00004  *
00005  * Created on 27. Dezember 2010, 16:03
00006  */
00007 
00008 #ifndef _REST_RESPONSE_H
00009 #define  _REST_RESPONSE_H
00010 
00011 namespace wiselib
00012 {
00013 
00014    template<typename OsModel_P,
00015             typename Radio_P = typename OsModel_P::Radio>
00016    class SwapResponseMessage
00017    {
00018    public:
00019       typedef OsModel_P OsModel;
00020       typedef Radio_P Radio;
00021       typedef typename Radio::block_data_t block_data_t;
00022       typedef typename Radio::size_t size_t;
00023       // --------------------------------------------------------------------
00024       inline uint8_t command_type()
00025       { return read<OsModel, block_data_t, uint8_t>( buffer ); }
00026       // --------------------------------------------------------------------
00027       inline void set_command_type( uint8_t type )
00028       { write<OsModel, block_data_t, uint8_t>( buffer, type ); }
00029       // --------------------------------------------------------------------
00030       inline uint8_t request_id()
00031       { return read<OsModel, block_data_t, uint8_t>( buffer + REQUEST_ID_POS ); }
00032       // --------------------------------------------------------------------
00033       inline void set_request_id( uint8_t type )
00034       { write<OsModel, block_data_t, uint8_t>( buffer + REQUEST_ID_POS, type ); }
00035       // --------------------------------------------------------------------
00036       inline uint8_t payload_length()
00037       { return read<OsModel, block_data_t, uint8_t>( buffer + PAYLOAD_SIZE_POS ); }
00038       // --------------------------------------------------------------------
00039       inline uint8_t resonse_code()
00040       { return read<OsModel, block_data_t, uint8_t>( buffer + RESPONSE_CODE_POS ); }
00041       // --------------------------------------------------------------------
00042       inline void set_response_code( uint8_t dst )
00043       { write<OsModel, block_data_t, uint8_t>( buffer + RESPONSE_CODE_POS, dst ); }
00044       // --------------------------------------------------------------------
00045       inline block_data_t* payload()
00046       { return buffer + PAYLOAD_POS; }
00047       // --------------------------------------------------------------------
00048       inline void set_payload( size_t len, block_data_t *buf )
00049       {
00050          set_payload_length( len );
00051          memcpy( buffer + PAYLOAD_POS, buf, len);
00052       }
00053       // --------------------------------------------------------------------
00054       inline size_t buffer_size()
00055       { return PAYLOAD_POS + payload_length(); }
00056 
00057 
00058    private:
00059 
00060       inline void set_payload_length( uint8_t len )
00061       { write<OsModel, block_data_t, uint8_t>( buffer + PAYLOAD_SIZE_POS, len ); }
00062       // --------------------------------------------------------------------
00063       enum data_in_positions
00064       {
00065          COMMAND_TYPE     = 0,
00066          REQUEST_ID_POS   = 1,
00067          RESPONSE_CODE_POS= 2,
00068          PAYLOAD_SIZE_POS = 3,
00069          PAYLOAD_POS      = 4
00070       };
00071       // --------------------------------------------------------------------
00072       block_data_t buffer[Radio_P::MAX_MESSAGE_LENGTH];
00073    };
00074 
00075 }
00076 
00077 #endif   /* _REST_RESPONSE_H */
00078 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines