Wiselib
|
00001 /* 00002 * File: sensor_value.h 00003 * Author: maxpagel 00004 * 00005 * Created on 5. Januar 2011, 11:46 00006 */ 00007 00008 #ifndef _SENSOR_VALUE_H 00009 #define _SENSOR_VALUE_H 00010 #include "util/serialization/simple_types.h" 00011 namespace wiselib 00012 { 00013 template<typename OsModel_P,typename Encoding_P, 00014 typename Radio_P = typename OsModel_P::Radio> 00015 class SensorValue 00016 { 00017 public: 00018 typedef OsModel_P OsModel; 00019 typedef Encoding_P Encoding; 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 encoding() 00025 { return read<OsModel, block_data_t, uint8_t >( buffer ); } 00026 // -------------------------------------------------------------------- 00027 inline void set_encoding( uint8_t encoding ) 00028 { write<OsModel, block_data_t, uint8_t >( buffer, encoding ); } 00029 // -------------------------------------------------------------------- 00030 inline void set_value(Encoding value ) 00031 { 00032 set_length( sizeof( Encoding) ); 00033 write<OsModel, block_data_t, Encoding >( buffer + VALUE_POS, value ); 00034 } 00035 // -------------------------------------------------------------------- 00036 inline size_t buffer_size() 00037 { return VALUE_POS + value_length(); } 00038 00039 inline uint8_t value_length() 00040 { 00041 return read<OsModel,block_data_t,uint8_t >(buffer + VALUE_LEN_POS); 00042 } 00043 private: 00044 00045 inline void set_length( uint8_t len ) 00046 { write<OsModel, block_data_t, uint8_t >( buffer + VALUE_LEN_POS, len ); } 00047 // -------------------------------------------------------------------- 00048 enum data_in_positions 00049 { 00050 ENCODING = 0, 00051 VALUE_LEN_POS = 1, 00052 VALUE_POS = 2 00053 }; 00054 // -------------------------------------------------------------------- 00055 block_data_t buffer[3]; 00056 }; 00057 } 00058 #endif /* _SENSOR_VALUE_H */ 00059