TOBI SignalServer
0.1
|
00001 /* 00002 This file is part of the TOBI signal server. 00003 00004 The TOBI signal server is free software: you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation, either version 3 of the License, or 00007 (at your option) any later version. 00008 00009 The TOBI signal server is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with Foobar. If not, see <http://www.gnu.org/licenses/>. 00016 00017 Copyright 2010 Christian Breitwieser 00018 Contact: c.breitwieser@tugraz.at 00019 */ 00020 00036 #ifndef SINEGENERATOR_H 00037 #define SINEGENERATOR_H 00038 00039 #include <vector> 00040 #include <map> 00041 00042 #include <boost/asio.hpp> 00043 #include <boost/thread/condition.hpp> // for mutex and cond. variables 00044 #include <boost/thread/shared_mutex.hpp> 00045 #include <boost/date_time/posix_time/posix_time.hpp> 00046 #include <boost/cstdint.hpp> 00047 00048 #include "hw_thread.h" 00049 #include "hardware/hw_thread_builder.h" 00050 00051 namespace tobiss 00052 { 00053 //----------------------------------------------------------------------------- 00065 class SineGenerator : public HWThread 00066 { 00067 public: 00076 SineGenerator(boost::asio::io_service& io, const int sampling_rate, const int nr_ch, const int blocks) 00077 : HWThread(sampling_rate, nr_ch, blocks), step_(1/static_cast<float>(fs_)), \ 00078 cycle_dur_(1/static_cast<float>(fs_)), current_block_(0), td_(1000000/fs_), samples_(1,0) 00079 { 00080 t_ = new boost::asio::deadline_timer(io, td_); 00081 genSine(); 00082 } 00089 SineGenerator(boost::asio::io_service& io, ticpp::Iterator<ticpp::Element> hw); 00090 00094 virtual ~SineGenerator() { delete t_; } 00095 00103 virtual SampleBlock<double> getSyncData(); 00116 virtual SampleBlock<double> getAsyncData(); 00120 virtual void run(); 00124 virtual void stop(); 00125 00126 //----------------------------------------------- 00127 private: 00133 void setHardware(ticpp::Iterator<ticpp::Element>const &hw); 00146 void genSine(); 00152 virtual void setDeviceSettings(ticpp::Iterator<ticpp::Element>const &father); 00158 virtual void setChannelSettings(ticpp::Iterator<ticpp::Element>const &father); 00159 00160 //----------------------------------------------- 00161 00162 private: 00163 bool acquiring_; 00164 boost::asio::deadline_timer* t_; 00165 double step_; 00166 double cycle_dur_; 00167 boost::uint16_t current_block_; 00168 boost::posix_time::microseconds td_; 00169 00170 boost::mutex sync_mut_; 00171 boost::condition_variable_any cond_; 00172 00173 std::vector<double> samples_; 00174 00182 SampleBlock<double> buffer_; 00183 00184 static const HWThreadBuilderTemplateRegistrator<SineGenerator> factory_registrator_; 00185 }; 00186 00187 } // Namespace tobiss 00188 00189 #endif // SINEGENERATOR_H 00190 00191 //-----------------------------------------------------------------------------