TOBI SignalServer  0.1
/home/breidi/Dropbox/signalserver/include/hardware/dataq.h
Go to the documentation of this file.
00001 /*
00002     This file is part of the TOBI SignalServer.
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 General Public License Usage
00014     Alternatively, this file may be used under the terms of the GNU
00015     General Public License version 3.0 as published by the Free Software
00016     Foundation and appearing in the file gpl.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/gpl.html.
00020 
00021     In case of GNU General Public License Usage ,the TOBI SignalServer
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 General Public License
00028     along with the TOBI SignalServer. If not, see <http://www.gnu.org/licenses/>.
00029 
00030     Copyright 2010 Graz University of Technology
00031     Contact: SignalServer@tobi-project.org
00032 */
00033 
00034 #ifndef DATAQ_H
00035 #define DATAQ_H
00036 
00042 #include <vector>
00043 #include <string>
00044 
00045 #include "misc/databuffer.h"
00046 #include "hardware/hw_thread.h"
00047 #include "hardware/hw_thread_builder.h"
00048 #include "hardware/dataq_wrapper.h"
00049 
00050 #include <boost/date_time/posix_time/posix_time.hpp>
00051 #include <boost/asio/deadline_timer.hpp>
00052 
00053 namespace tobiss
00054 {
00055 //-----------------------------------------------------------------------------
00056 
00061 class DataQ : public HWThread
00062 {
00063   public:
00067     DataQ(ticpp::Iterator<ticpp::Element> hw);
00071     virtual ~DataQ();
00072 
00073     virtual SampleBlock<double> getSyncData();
00074     virtual SampleBlock<double> getAsyncData();
00075 
00079     virtual void run();
00083     virtual void stop();
00084 
00085   private:
00089     virtual void setDeviceSettings(ticpp::Iterator<ticpp::Element>const &father);
00093     virtual void setChannelSettings(ticpp::Iterator<ticpp::Element>const &father);
00097     void setHardware(ticpp::Iterator<ticpp::Element>const &hw);
00098 
00099     void setDeviceRange(ticpp::Iterator<ticpp::Element>const &father);
00100     void setDeviceBipolar(ticpp::Iterator<ticpp::Element>const &father);
00101 
00102     void setChannelBipolar(ticpp::Iterator<ticpp::Element>const &father);
00103     void setChannelRange(ticpp::Iterator<ticpp::Element>const &father);
00104 
00105 
00106     int checkErrorCode(int error_code, bool throw_on_error);
00107     void printDataQInfo();
00108     int openDev(bool throw_on_error);
00109     int closeDev(bool throw_on_error);
00110     int startAcqu(bool throw_on_error);
00111     int stopAcqu(bool throw_on_error);
00112     void setInList();
00113     void setDaqMode();
00114     double getVoltageValue(short val, boost::uint16_t ch_nr);
00115     void acquireData();
00116     void checkBiploarConfig();
00117     void checkChannels();
00118 
00119   private:
00120     boost::thread*      acq_thread_;
00121     DataQWrapper*       dataq_dev_ptr_;
00122     unsigned int        dev_nr_;
00123     short*              dev_buffer_;
00124 
00125     bool                device_opened_;
00126     bool                acqu_running_;
00127 
00128     double              burst_rate_count_;
00129     unsigned int        last_pos_;
00130 
00131     di_inlist_struct*   inlist_ptr_;
00132     di_info_struct      info_;
00133     di_mode_struct      mode_;
00134 
00135     std::vector<bool>               bipolar_list_;
00136     std::vector<unsigned int>       gain_index_;
00137     std::vector<double>             v_max_;
00138     std::vector<double>             v_min_;
00139     DataBuffer<short>               buffer_;
00140 
00141     boost::asio::io_service         io_service_;
00142     boost::asio::deadline_timer     sleep_timer_;
00143     boost::posix_time::microseconds sleep_time_;
00144     boost::system::error_code       error_;
00145 
00146     static const HWThreadBuilderTemplateRegistratorWithoutIOService<DataQ> factory_registrator_;
00147 
00148     //--------------------------------------
00149     // Constants:
00150 
00151     static const unsigned int           DMA_IN_SIZ;
00152     static const unsigned int           RING_BUFFER_SIZE;
00153 
00154     static const std::string            hw_dataq_range_;
00155     static const std::string            hw_dataq_bipolar_;
00156     static const std::string            hw_dataq_value_;
00157 
00158     int sample_count_;
00159 
00160 };
00161 
00162 //-----------------------------------------------------------------------------
00163 
00164 }  // Namespace tobiss
00165 
00166 
00167 #endif // DATAQ_H
 All Data Structures Files Functions Variables