Wiselib
wiselib.testing/util/wisebed_node_api/virtual_link_in_message.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  ** This file is part of the generic algorithm library Wiselib.           **
00003  ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project.      **
00004  **                                                                       **
00005  ** The Wiselib is free software: you can redistribute it and/or modify   **
00006  ** it under the terms of the GNU Lesser General Public License as        **
00007  ** published by the Free Software Foundation, either version 3 of the    **
00008  ** License, or (at your option) any later version.                       **
00009  **                                                                       **
00010  ** The Wiselib is distributed in the hope that it will be useful,        **
00011  ** but WITHOUT ANY WARRANTY; without even the implied warranty of        **
00012  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         **
00013  ** GNU Lesser General Public License for more details.                   **
00014  **                                                                       **
00015  ** You should have received a copy of the GNU Lesser General Public      **
00016  ** License along with the Wiselib.                                       **
00017  ** If not, see <http://www.gnu.org/licenses/>.                           **
00018  ***************************************************************************/
00019 #ifndef CONNECTOR_ISENSE_VIRTUAL_LINK_IN_MESSAGE_H
00020 #define CONNECTOR_ISENSE_VIRTUAL_LINK_IN_MESSAGE_H
00021 
00022 #include "util/serialization/simple_types.h"
00023 
00024 namespace wiselib
00025 {
00026 
00027    template<typename OsModel_P,
00028             typename Radio_P = typename OsModel_P::Radio>
00029    class VirtualLinkInMessage
00030    {
00031    public:
00032       typedef OsModel_P OsModel;
00033       typedef Radio_P Radio;
00034       typedef typename Radio::block_data_t block_data_t;
00035       // --------------------------------------------------------------------
00036       inline uint8_t command_type()
00037       { return read<OsModel, block_data_t, uint8_t>( buffer ); }
00038       // --------------------------------------------------------------------
00039       inline void set_command_type( uint8_t type )
00040       { write<OsModel, block_data_t, uint8_t>( buffer, type ); }
00041       // --------------------------------------------------------------------
00042       inline uint8_t request_id()
00043       { return read<OsModel, block_data_t, uint8_t>( buffer + REQUESTID_POS); }
00044       // --------------------------------------------------------------------
00045       inline void set_request_id( uint8_t request_id )
00046       { write<OsModel, block_data_t, uint8_t>( buffer + REQUESTID_POS, request_id ); }
00047       // --------------------------------------------------------------------
00048       inline uint8_t rssi()
00049       { return read<OsModel, block_data_t, uint8_t>( buffer + RSSI_POS ); }
00050       // --------------------------------------------------------------------
00051       inline void set_rssi( uint8_t rssi )
00052       { write<OsModel, block_data_t, uint8_t>( buffer + RSSI_POS, rssi ); }
00053       // --------------------------------------------------------------------
00054       inline uint8_t lqi()
00055       { return read<OsModel, block_data_t, uint8_t>( buffer + LQI_POS ); }
00056       // --------------------------------------------------------------------
00057       inline void set_lqi( uint8_t lqi )
00058       { write<OsModel, block_data_t, uint8_t>( buffer + LQI_POS, lqi ); }
00059       // --------------------------------------------------------------------
00060       inline uint8_t payload_length()
00061       { return read<OsModel, block_data_t, uint8_t>( buffer + PAYLOAD_SIZE_POS ); }
00062       // --------------------------------------------------------------------
00063       inline uint64_t destination()
00064       { return read<OsModel, block_data_t, uint64_t>( buffer + DESTINATION_POS ); }
00065       // --------------------------------------------------------------------
00066       inline void set_destination( uint64_t dst )
00067       { write<OsModel, block_data_t, uint64_t>( buffer + DESTINATION_POS, dst ); }
00068       // --------------------------------------------------------------------
00069       inline uint64_t source()
00070       { return read<OsModel, block_data_t, uint64_t>( buffer + SOURCE_POS ); }
00071       // --------------------------------------------------------------------
00072       inline void set_source( uint64_t src )
00073       { write<OsModel, block_data_t, uint64_t>( buffer + SOURCE_POS, src ); }
00074       // --------------------------------------------------------------------
00075       inline uint8_t* payload()
00076       { return buffer + PAYLOAD_POS; }
00077       // --------------------------------------------------------------------
00078       inline void set_payload( uint8_t len, uint8_t *buf )
00079       {
00080          set_payload_length( len );
00081          memcpy( buffer + PAYLOAD_POS, buf, len);
00082       }
00083       // --------------------------------------------------------------------
00084       inline size_t buffer_size()
00085       { return 21 + payload_length(); }
00086 
00087 
00088    private:
00089 
00090       inline void set_payload_length( uint8_t len )
00091       { write<OsModel, block_data_t, uint8_t>( buffer + PAYLOAD_SIZE_POS, len ); }
00092       // --------------------------------------------------------------------
00093       enum data_in_positions
00094       {
00095          COMMAND_TYPE     = 0,
00096          REQUESTID_POS    = 1,
00097          RSSI_POS         = 2,
00098          LQI_POS          = 3,
00099          PAYLOAD_SIZE_POS = 4,
00100          DESTINATION_POS  = 5,
00101          SOURCE_POS       = 13,
00102          PAYLOAD_POS      = 21
00103       };
00104       // --------------------------------------------------------------------
00105       uint8_t buffer[Radio_P::MAX_MESSAGE_LENGTH];
00106    };
00107 
00108 }
00109 
00110 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines