Wiselib
|
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 __ALGORITHMS_LOCALIZATION_DISTANCE_BASED_LOCALIZATION_ITER_LATERATION_MESSAGES_H 00020 #define __ALGORITHMS_LOCALIZATION_DISTANCE_BASED_LOCALIZATION_ITER_LATERATION_MESSAGES_H 00021 00022 #include "util/serialization/simple_types.h" 00023 #include "util/serialization/math_vec.h" 00024 #include "algorithms/localization/distance_based/util/localization_defutils.h" 00025 00026 namespace wiselib 00027 { 00028 00029 template<typename OsModel_P, 00030 typename Radio_P> 00031 class LocalizationIterLaterationMessage 00032 { 00033 public: 00034 typedef OsModel_P OsModel; 00035 typedef Radio_P Radio; 00036 typedef typename Radio::node_id_t node_id_t; 00037 typedef typename Radio::block_data_t block_data_t; 00038 typedef typename Radio::size_t size_t; 00039 typedef typename Radio::message_id_t message_id_t; 00040 // -------------------------------------------------------------------- 00041 inline LocalizationIterLaterationMessage(); 00042 // -------------------------------------------------------------------- 00043 inline message_id_t msg_id() 00044 { return read<OsModel, block_data_t, message_id_t>( buffer ); }; 00045 // -------------------------------------------------------------------- 00046 inline void set_msg_id( message_id_t id ) 00047 { write<OsModel, block_data_t, message_id_t>( buffer, id ); } 00048 // -------------------------------------------------------------------- 00049 inline double confidence() 00050 { return read<OsModel, block_data_t, double>(buffer + CONFIDENCE_POS); } 00051 // -------------------------------------------------------------------- 00052 inline void set_confidence( double confidence ) 00053 { write<OsModel, block_data_t, double>(buffer + CONFIDENCE_POS, confidence); } 00054 // -------------------------------------------------------------------- 00055 inline Vec position() 00056 { return read<OsModel, block_data_t, Vec>(buffer + POSITION_POS); } 00057 // -------------------------------------------------------------------- 00058 inline void set_position( Vec pos ) 00059 { write<OsModel, block_data_t, Vec>(buffer + POSITION_POS, pos); } 00060 // -------------------------------------------------------------------- 00061 inline size_t buffer_size() 00062 { return MSGEND_POS; } 00063 00064 private: 00065 enum data_positions 00066 { 00067 CONFIDENCE_POS = sizeof(message_id_t), 00068 POSITION_POS = CONFIDENCE_POS + sizeof(double), 00069 MSGEND_POS = POSITION_POS + 3 * sizeof(double) 00070 }; 00071 00072 block_data_t buffer[MSGEND_POS]; 00073 }; 00074 // ----------------------------------------------------------------------- 00075 template<typename OsModel_P, 00076 typename Radio_P> 00077 LocalizationIterLaterationMessage<OsModel_P, Radio_P>:: 00078 LocalizationIterLaterationMessage() 00079 { 00080 set_msg_id( 0 ); 00081 set_confidence( 0.0 ); 00082 set_position( UNKNOWN_POSITION ); 00083 } 00084 // ----------------------------------------------------------------------- 00085 // ----------------------------------------------------------------------- 00086 // ----------------------------------------------------------------------- 00087 template<typename OsModel_P, 00088 typename Radio_P> 00089 class LocalizationIterLaterationSoundMessage 00090 { 00091 public: 00092 typedef OsModel_P OsModel; 00093 typedef Radio_P Radio; 00094 typedef typename Radio::node_id_t node_id_t; 00095 typedef typename Radio::block_data_t block_data_t; 00096 typedef typename Radio::size_t size_t; 00097 typedef typename Radio::message_id_t message_id_t; 00098 // -------------------------------------------------------------------- 00099 inline LocalizationIterLaterationSoundMessage() 00100 {} 00101 // -------------------------------------------------------------------- 00102 inline message_id_t msg_id() 00103 { return read<OsModel, block_data_t, message_id_t>( buffer ); }; 00104 // -------------------------------------------------------------------- 00105 inline void set_msg_id( message_id_t id ) 00106 { write<OsModel, block_data_t, message_id_t>( buffer, id ); } 00107 // -------------------------------------------------------------------- 00108 inline size_t buffer_size() 00109 { return MSGEND_POS; } 00110 00111 private: 00112 enum data_positions 00113 { 00114 MSGEND_POS = sizeof(message_id_t) 00115 }; 00116 00117 block_data_t buffer[MSGEND_POS]; 00118 }; 00119 00120 }// namespace wiselib 00121 #endif