Wiselib
wiselib.testing/util/wisebed_node_api/sensors/sensor_value.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 
00020 #ifndef _SENSOR_VALUE_H
00021 #define  _SENSOR_VALUE_H
00022 #include "util/serialization/simple_types.h"
00023 namespace wiselib
00024 {
00025 template<typename OsModel_P,
00026          typename Encoding_P,
00027          typename Radio_P = typename OsModel_P::Radio>
00028    class SensorValue
00029    {
00030    public:
00031       typedef OsModel_P OsModel;
00032       typedef Encoding_P Encoding;
00033       typedef Radio_P Radio;
00034       typedef typename Radio::block_data_t block_data_t;
00035       typedef typename Radio::size_t size_t;
00036       // --------------------------------------------------------------------
00037       inline uint8_t encoding()
00038       { return read<OsModel, block_data_t, uint8_t >( buffer ); }
00039       // --------------------------------------------------------------------
00040       inline void set_encoding( uint8_t encoding )
00041       { write<OsModel, block_data_t, uint8_t >( buffer, encoding ); }
00042       // --------------------------------------------------------------------
00043       inline void set_value(Encoding value )
00044       {
00045          set_length( sizeof( Encoding) );
00046          write<OsModel, block_data_t, Encoding >( buffer + VALUE_POS, value  );
00047       }
00048       // --------------------------------------------------------------------
00049       inline size_t buffer_size()
00050       { return VALUE_POS + value_length(); }
00051       // --------------------------------------------------------------------
00052       inline uint8_t value_length()
00053       {
00054         return read<OsModel,block_data_t,uint8_t >(buffer + VALUE_LEN_POS);
00055       }
00056    private:
00057 
00058       inline void set_length( uint8_t len )
00059       { write<OsModel, block_data_t, uint8_t >( buffer + VALUE_LEN_POS, len ); }
00060       // --------------------------------------------------------------------
00061       enum data_in_positions
00062       {
00063          ENCODING      = 0,
00064          VALUE_LEN_POS = 1,
00065          VALUE_POS     = 2
00066       };
00067       // --------------------------------------------------------------------
00068       block_data_t buffer[3];
00069    };
00070 }
00071 #endif   /* _SENSOR_VALUE_H */
00072 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines