Wiselib
wiselib.testing/algorithms/tracking/PLTT_node_target.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 __PLTT_NODE_TARGET_H__
00020 #define __PLTT_NODE_TARGET_H__
00021 namespace wiselib
00022 {
00023    template<   typename Os_P,
00024             typename Radio_P,
00025             typename NodeID_P,
00026             typename IntensityNumber_P,
00027             typename Debug_P>
00028    class PLTT_NodeTargetType
00029    {
00030    public:
00031       typedef Os_P Os;
00032       typedef Radio_P Radio;
00033       typedef  NodeID_P NodeID;
00034       typedef IntensityNumber_P IntensityNumber;
00035       typedef Debug_P Debug;
00036       typedef typename Radio::block_data_t block_data_t;
00037       typedef typename Radio::size_t size_t;
00038       typedef PLTT_NodeTargetType<Os, Radio, NodeID, IntensityNumber, Debug> self_type;
00039       PLTT_NodeTargetType()
00040       {}
00041       PLTT_NodeTargetType( const self_type& _nt )
00042       {
00043          *this = _nt;
00044       }
00045       PLTT_NodeTargetType( block_data_t* buff, size_t offset = 0 )
00046       {
00047          get_from_buffer( buff, offset );
00048       }
00049       PLTT_NodeTargetType( const NodeID& _id, const IntensityNumber& _in )
00050       {
00051          set_all( _id, _in );
00052       }
00053       inline block_data_t* set_buffer_from( block_data_t* buff, size_t offset = 0 )
00054       {
00055          uint8_t TARGET_ID_POS = 0;
00056          uint8_t INTENSITY_POS = TARGET_ID_POS + sizeof(NodeID);
00057          write<Os, block_data_t, NodeID>( buff + TARGET_ID_POS + offset, target_id );
00058          write<Os, block_data_t, IntensityNumber>( buff + INTENSITY_POS + offset, intensity );
00059          return buff;
00060       }
00061       inline void get_from_buffer(block_data_t* buff, size_t offset = 0 )
00062       {
00063          uint8_t TARGET_ID_POS = 0;
00064          uint8_t INTENSITY_POS = TARGET_ID_POS + sizeof( NodeID );
00065          target_id = read<Os, block_data_t, NodeID> ( buff + TARGET_ID_POS + offset );
00066          intensity = read<Os, block_data_t, IntensityNumber>( buff + INTENSITY_POS + offset );
00067       }
00068       inline size_t get_buffer_size()
00069       {
00070          uint8_t TARGET_ID_POS = 0;
00071          uint8_t INTENSITY_POS = TARGET_ID_POS + sizeof( NodeID );
00072          return INTENSITY_POS + sizeof( IntensityNumber );
00073       }
00074       inline self_type& operator=( const self_type& _nt )
00075       {
00076          target_id = _nt.target_id;
00077          intensity = _nt.intensity;
00078          return *this;
00079       }
00080       inline void set_target_id( const NodeID& _tid )
00081       {
00082          target_id = _tid;
00083       }
00084       inline void set_intensity( const IntensityNumber& _i )
00085       {
00086          intensity = _i;
00087       }
00088       inline void set_all( const NodeID& _tid, const IntensityNumber& _i )
00089       {
00090          target_id = _tid;
00091          intensity = _i;
00092       }
00093       inline NodeID get_target_id()
00094       {
00095          return target_id;
00096       }
00097       inline IntensityNumber get_intensity()
00098       {
00099          return intensity;
00100       }
00101       inline void print( Debug& debug )
00102       {
00103          debug.debug( "NodeTarget (size %i) : ", get_buffer_size() );
00104          debug.debug( "target_id (size %i) : %x", sizeof( NodeID ), target_id );
00105          debug.debug( "intensity (size %i) : %i", sizeof( IntensityNumber ), intensity );
00106       }
00107    private:
00108       NodeID target_id;
00109       IntensityNumber intensity;
00110    };
00111 }
00112 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines