TOBI Interface A  0.1
/home/breidi/Dropbox/libtia/include/tia-private/datapacket/data_packet_impl.h
Go to the documentation of this file.
00001 /*
00002     This file is part of the TOBI Interface A (TiA) library.
00003 
00004     Commercial Usage
00005     Licensees holding valid Graz University of Technology Commercial
00006     licenses may use this file in accordance with the Graz University
00007     of Technology Commercial License Agreement provided with the
00008     Software or, alternatively, in accordance with the terms contained in
00009     a written agreement between you and Graz University of Technology.
00010 
00011     --------------------------------------------------
00012 
00013     GNU Lesser General Public License Usage
00014     Alternatively, this file may be used under the terms of the GNU Lesser
00015     General Public License version 3.0 as published by the Free Software
00016     Foundation and appearing in the file lgpl.txt included in the
00017     packaging of this file.  Please review the following information to
00018     ensure the GNU General Public License version 3.0 requirements will be
00019     met: http://www.gnu.org/copyleft/lgpl.html.
00020 
00021     In case of GNU Lesser General Public License Usage ,the TiA library
00022     is distributed in the hope that it will be useful,
00023     but WITHOUT ANY WARRANTY; without even the implied warranty of
00024     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025     GNU General Public License for more details.
00026 
00027     You should have received a copy of the GNU Lesser General Public License
00028     along with the TiA library. If not, see <http://www.gnu.org/licenses/>.
00029 
00030     Copyright 2010 Graz University of Technology
00031     Contact: TiA@tobi-project.org
00032 */
00033 
00046 #ifndef DATAPACKET_H
00047 #define DATAPACKET_H
00048 
00049 #include <boost/date_time/posix_time/posix_time.hpp>
00050 #include <boost/cstdint.hpp>
00051 
00052 #include "tia/data_packet_interface.h"
00053 
00054 namespace tia
00055 {
00056 
00057 class RawMem;
00058 
00073 class DataPacketImpl :public DataPacket
00074 {
00080   public:
00084     DataPacketImpl()
00085     : flags_(0), packet_nr_(0),
00086       timestamp_(boost::posix_time::microsec_clock::local_time()), nr_of_signal_types_(0)
00087     {
00088       //std::cout << "DataPacketImpl::Constructor" << std::endl;
00089     }
00090 
00102     void reset(void* mem);
00103 
00111     virtual ~DataPacketImpl();
00112 
00117     DataPacketImpl(const DataPacketImpl &src)
00118     {
00119       #ifdef DEBUG
00120         //std::cout << "DataPacketImpl::CopyConstr" << std::endl;
00121       #endif
00122 
00123       sample_nr_ = src.sample_nr_;
00124       flags_ = src.flags_;
00125       packet_nr_ = src.packet_nr_;
00126       timestamp_ = src.timestamp_;
00127       nr_of_signal_types_ = src.nr_of_signal_types_;
00128 
00129       nr_blocks_ = src.nr_blocks_;
00130       nr_values_ = src.nr_values_;
00131       data_ = src.data_;
00132 
00133       std::map<boost::uint32_t, RawMem*> raw_map_;
00134     }
00135 
00136     virtual DataPacketImpl& operator=(const DataPacketImpl &src)
00137     {
00138       #ifdef DEBUG
00139         //std::cout << "DataPacketImpl::operator=" << std::endl;
00140       #endif
00141 
00142       sample_nr_ = src.sample_nr_;
00143       flags_ = src.flags_;
00144       packet_nr_ = src.packet_nr_;
00145       timestamp_ = src.timestamp_;
00146       nr_of_signal_types_ = src.nr_of_signal_types_;
00147 
00148       nr_blocks_ = src.nr_blocks_;
00149       nr_values_ = src.nr_values_;
00150       data_ = src.data_;
00151 
00152       std::map<boost::uint32_t, RawMem*> raw_map_;
00153 
00154       return *this;
00155     }
00156 
00160     virtual void reset();
00164     void incSampleNr();
00165     virtual void incPacketID() {incSampleNr();}
00166 
00183     virtual void insertDataBlock(std::vector<double> v, boost::uint32_t signal_flag, boost::uint16_t blocks, bool prepend = false);
00184 
00188     void setPacketNr(boost::uint64_t);
00189     virtual void setConnectionPacketNr(boost::uint64_t val) { setPacketNr(val); }
00190 
00194     boost::uint64_t getPacketNr();
00195     virtual boost::uint64_t getConnectionPacketNr(){ return(getPacketNr()); }
00196 
00200     void setBoostPosixTimestamp();
00201 
00205     boost::posix_time::ptime getBoostPosixTimestamp()   { return(timestamp_);  }
00206 
00210     virtual void setTimestamp() {setBoostPosixTimestamp();}
00211 
00215     virtual boost::uint64_t getTimestamp()  { return( *(reinterpret_cast<boost::uint64_t*>(&timestamp_)) ); }
00216 
00221     virtual bool hasFlag(boost::uint32_t f);
00227     virtual boost::uint16_t getNrOfSignalTypes();
00233     virtual boost::uint32_t getFlags();
00238     boost::uint64_t getSampleNr();
00239     virtual boost::uint64_t getPacketID() { return(getSampleNr() ); };
00240     virtual void setPacketID(boost::uint64_t val) { sample_nr_ = val;};
00241 
00246     virtual std::vector<boost::uint16_t> getNrOfBlocks();
00251     std::vector<boost::uint16_t> getNrOfSamples();
00257     const std::vector<double>& getData();
00265     virtual std::vector<double> getSingleDataBlock(boost::uint32_t flag);
00266 
00272     virtual boost::uint16_t getNrOfSamples(boost::uint32_t flag);
00273 
00279     boost::uint16_t getNrOfBlocks(boost::uint32_t flag);
00280 
00281 
00282     virtual std::vector<boost::uint16_t> getNrSamplesPerChannel()
00283     {
00284       return(getNrOfBlocks());
00285     }
00286 
00287     virtual std::vector<boost::uint16_t> getNrOfChannels()
00288     {
00289       std::vector<boost::uint16_t> vec(nr_values_.size());
00290       for(unsigned int n = 0; n < nr_values_.size(); n++)
00291         vec[n] = nr_values_[n]/nr_blocks_[n];
00292       return vec;
00293     }
00294 
00295     virtual boost::uint16_t getNrOfChannels(boost::uint32_t flag)
00296     {
00297       return(nr_values_[getDataPos(flag)]/nr_blocks_[getDataPos(flag)]);
00298     }
00299 
00300     virtual boost::uint16_t getNrSamplesPerChannel(boost::uint32_t flag)
00301     {
00302       return(getNrSamplesPerChannel(flag));
00303     }
00304 
00305 
00314     virtual void* getRaw();
00315 
00321     virtual boost::uint32_t getRawMemorySize();
00322 
00327     virtual boost::uint32_t getRequiredRawMemorySize();
00328 
00339     virtual boost::uint32_t getRequiredRawMemorySize(void* mem, boost::uint32_t bytes_available);
00340 
00341   private:
00346     boost::uint16_t calcNrOfSignalTypes(boost::uint32_t f);
00351     bool flagsOK();
00356     void setFlag(boost::uint32_t flag);
00362     boost::uint32_t getDataPos(boost::uint32_t flag);
00368     boost::uint32_t getOffset(boost::uint32_t pos);
00369 
00379     void appendDataBlock(std::vector<double> &v, boost::uint32_t signal_flag, boost::uint16_t blocks);
00380 
00390     void prependDataBlock(std::vector<double> &v, boost::uint32_t signal_flag, boost::uint16_t blocks);
00391 
00392   private:
00397     static boost::uint64_t  sample_nr_;
00398 
00403     boost::uint32_t  flags_;
00404     boost::uint64_t  packet_nr_;        
00405     boost::posix_time::ptime  timestamp_;   
00406 
00407     boost::uint16_t  nr_of_signal_types_;   
00408 
00409     std::vector<boost::uint16_t>  nr_blocks_;  
00410     std::vector<boost::uint16_t>  nr_values_;  
00411     std::vector<double> data_;  
00412 
00413     std::map<boost::uint32_t, RawMem*> raw_map_; 
00414 };
00415 
00416 } // Namespace tobiss
00417 
00418 #endif // DATAPACKET_H
 All Data Structures Files Functions Variables Typedefs Enumerations