Wiselib
wiselib.testing/util/wisebed_node_api/virtual_link_out_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_MESSAGE_H
00020 #define CONNECTOR_ISENSE_VIRTUAL_LINK_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 VirtualLinkOutMessage
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 rssi()
00043       { return read<OsModel, block_data_t, uint8_t>( buffer + RSSI_POS ); }
00044       // --------------------------------------------------------------------
00045       inline void set_rssi( uint8_t rssi )
00046       { write<OsModel, block_data_t, uint8_t>( buffer + RSSI_POS, rssi ); }
00047       // --------------------------------------------------------------------
00048       inline uint8_t lqi()
00049       { return read<OsModel, block_data_t, uint8_t>( buffer + LQI_POS ); }
00050       // --------------------------------------------------------------------
00051       inline void set_lqi( uint8_t lqi )
00052       { write<OsModel, block_data_t, uint8_t>( buffer + LQI_POS, lqi ); }
00053       // --------------------------------------------------------------------
00054       inline uint8_t payload_length()
00055       { return read<OsModel, block_data_t, uint8_t>( buffer + PAYLOAD_SIZE_POS ); }
00056       // --------------------------------------------------------------------
00057       inline uint64_t destination()
00058       { return read<OsModel, block_data_t, uint64_t>( buffer + DESTINATION_POS ); }
00059       // --------------------------------------------------------------------
00060       inline void set_destination( uint64_t dst )
00061       { write<OsModel, block_data_t, uint64_t>( buffer + DESTINATION_POS, dst ); }
00062       // --------------------------------------------------------------------
00063       inline uint64_t source()
00064       { return read<OsModel, block_data_t, uint64_t>( buffer + SOURCE_POS ); }
00065       // --------------------------------------------------------------------
00066       inline void set_source( uint64_t src )
00067       { write<OsModel, block_data_t, uint64_t>( buffer + SOURCE_POS, src ); }
00068       // --------------------------------------------------------------------
00069       inline uint8_t* payload()
00070       { return buffer + PAYLOAD_POS; }
00071       // --------------------------------------------------------------------
00072       inline void set_payload( uint8_t len, uint8_t *buf )
00073       {
00074          set_payload_length( len );
00075          memcpy( buffer + PAYLOAD_POS, buf, len);
00076       }
00077       // --------------------------------------------------------------------
00078       inline size_t buffer_size()
00079       { return 20 + payload_length(); }
00080 
00081 
00082    private:
00083 
00084       inline void set_payload_length( uint8_t len )
00085       { write<OsModel, block_data_t, uint8_t>( buffer + PAYLOAD_SIZE_POS, len ); }
00086       // --------------------------------------------------------------------
00087       enum data_out_positions
00088       {
00089          COMMAND_TYPE     = 0,
00090          RSSI_POS         = 1,
00091          LQI_POS          = 2,
00092          PAYLOAD_SIZE_POS = 3,
00093          DESTINATION_POS  = 4,
00094          SOURCE_POS       = 12,
00095          PAYLOAD_POS      = 20
00096       };
00097       // --------------------------------------------------------------------
00098       uint8_t buffer[Radio_P::MAX_MESSAGE_LENGTH];
00099    };
00100 
00101 }
00102 
00103 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines