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_DVHOP_MESSAGES_H 00020 #define __ALGORITHMS_LOCALIZATION_DISTANCE_BASED_LOCALIZATION_DVHOP_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 template<typename OsModel_P, 00029 typename Radio_P, 00030 typename Arithmatic_P > 00031 class LocalizationDvHopMessage 00032 { 00033 public: 00034 typedef OsModel_P OsModel; 00035 typedef Radio_P Radio; 00036 typedef Arithmatic_P Arithmatic; 00037 typedef typename Radio::node_id_t node_id_t; 00038 typedef typename Radio::block_data_t block_data_t; 00039 typedef typename Radio::size_t size_t; 00040 typedef typename Radio::message_id_t message_id_t; 00041 // -------------------------------------------------------------------- 00042 inline LocalizationDvHopMessage(); 00043 // -------------------------------------------------------------------- 00044 inline message_id_t msg_id() 00045 { return read<OsModel, block_data_t, message_id_t>( buffer ); }; 00046 // -------------------------------------------------------------------- 00047 inline void set_msg_id( message_id_t id ) 00048 { write<OsModel, block_data_t, message_id_t>( buffer, id ); } 00049 // -------------------------------------------------------------------- 00050 inline node_id_t anchor() 00051 { return read<OsModel, block_data_t, node_id_t>(buffer + ANCHOR_POS); } 00052 // -------------------------------------------------------------------- 00053 inline void set_anchor( node_id_t anchor ) 00054 { write<OsModel, block_data_t, node_id_t>(buffer + ANCHOR_POS, anchor); } 00055 // -------------------------------------------------------------------- 00056 inline uint16_t hop_count() 00057 { return read<OsModel, block_data_t, uint16_t>(buffer + HOP_COUNT_POS); } 00058 // -------------------------------------------------------------------- 00059 inline void set_hop_count( uint16_t hops ) 00060 { write<OsModel, block_data_t, uint16_t>(buffer + HOP_COUNT_POS, hops); } 00061 // -------------------------------------------------------------------- 00062 inline Vec<Arithmatic> anchor_position() 00063 { return read<OsModel, block_data_t, Vec<Arithmatic> >(buffer + ANCHOR_POSITION_POS); } 00064 // -------------------------------------------------------------------- 00065 inline void set_anchor_position( Vec<Arithmatic> pos ) 00066 { write<OsModel, block_data_t, Vec<Arithmatic> >(buffer + ANCHOR_POSITION_POS, pos); } 00067 // -------------------------------------------------------------------- 00068 inline size_t buffer_size() 00069 { return MSGEND_POS; } 00070 00071 private: 00072 enum data_positions 00073 { 00074 ANCHOR_POS = sizeof(message_id_t), 00075 HOP_COUNT_POS = ANCHOR_POS + sizeof(node_id_t), 00076 ANCHOR_POSITION_POS = HOP_COUNT_POS + sizeof(uint16_t), 00077 MSGEND_POS = ANCHOR_POSITION_POS + 3 * sizeof(Arithmatic) 00078 }; 00079 00080 block_data_t buffer[MSGEND_POS]; 00081 }; 00082 // ----------------------------------------------------------------------- 00083 template<typename OsModel_P, 00084 typename Radio_P, 00085 typename Arithmatic_P> 00086 LocalizationDvHopMessage<OsModel_P, Radio_P, Arithmatic_P>:: 00087 LocalizationDvHopMessage() 00088 { 00089 set_msg_id( 0 ); 00090 set_anchor( 0 ); 00091 set_hop_count( 0 ); 00092 set_anchor_position( UNKNOWN_POSITION ); 00093 } 00094 // ----------------------------------------------------------------------- 00095 // ----------------------------------------------------------------------- 00096 // ----------------------------------------------------------------------- 00097 template<typename OsModel_P, 00098 typename Radio_P, 00099 typename Arithmatic_P = double> 00100 class LocalizationDvCalMessage 00101 { 00102 public: 00103 typedef OsModel_P OsModel; 00104 typedef Radio_P Radio; 00105 typedef Arithmatic_P Arithmatic; 00106 typedef typename Radio::node_id_t node_id_t; 00107 typedef typename Radio::block_data_t block_data_t; 00108 typedef typename Radio::size_t size_t; 00109 typedef typename Radio::message_id_t message_id_t; 00110 // -------------------------------------------------------------------- 00111 inline LocalizationDvCalMessage(); 00112 // -------------------------------------------------------------------- 00113 inline message_id_t msg_id() 00114 { return read<OsModel, block_data_t, message_id_t>( buffer ); }; 00115 // -------------------------------------------------------------------- 00116 inline void set_msg_id( message_id_t id ) 00117 { write<OsModel, block_data_t, message_id_t>( buffer, id ); } 00118 // -------------------------------------------------------------------- 00119 inline Arithmatic avg_hop_dist() 00120 { return read<OsModel, block_data_t, Arithmatic>(buffer + AVG_HOP_COUNT_POS); } 00121 // -------------------------------------------------------------------- 00122 inline void set_avg_hop_dist( Arithmatic avg_hop_dist ) 00123 { write<OsModel, block_data_t, Arithmatic>(buffer + AVG_HOP_COUNT_POS, avg_hop_dist); } 00124 // -------------------------------------------------------------------- 00125 inline size_t buffer_size() 00126 { return MSGEND_POS; } 00127 00128 private: 00129 enum data_positions 00130 { 00131 AVG_HOP_COUNT_POS = sizeof(message_id_t), 00132 MSGEND_POS = AVG_HOP_COUNT_POS + sizeof(Arithmatic) 00133 }; 00134 00135 block_data_t buffer[MSGEND_POS]; 00136 }; 00137 // ----------------------------------------------------------------------- 00138 template<typename OsModel_P, 00139 typename Radio_P, 00140 typename Arithmatic_P> 00141 LocalizationDvCalMessage<OsModel_P, Radio_P, Arithmatic_P>:: 00142 LocalizationDvCalMessage() 00143 { 00144 set_msg_id( 0 ); 00145 set_avg_hop_dist( 0 ); 00146 } 00147 00148 }// namespace wiselib 00149 #endif