• Main Page
  • Packages
  • Classes
  • Files
  • File List
  • File Members

unlock/bci/acquire-c++/unlock_signal.hpp

Go to the documentation of this file.
00001 // Copyright (c) James Percent and Unlock contributors.
00002 // All rights reserved.
00003 // Redistribution and use in source and binary forms, with or without modification,
00004 // are permitted provided that the following conditions are met:
00005 //
00006 //    1. Redistributions of source code must retain the above copyright notice,
00007 //       this list of conditions and the following disclaimer.
00008 //    
00009 //    2. Redistributions in binary form must reproduce the above copyright
00010 //       notice, this list of conditions and the following disclaimer in the
00011 //       documentation and/or other materials provided with the distribution.
00012 //
00013 //    3. Neither the name of Unlock nor the names of its contributors may be used
00014 //       to endorse or promote products derived from this software without
00015 //       specific prior written permission.
00016 
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00018 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
00021 // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00024 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 #ifndef UNLOCK_SIGNAL_HPP
00028 #define UNLOCK_SIGNAL_HPP
00029 
00030 #include "ISignal.hpp"
00031 #include "NonblockingSignal.hpp"
00032 #include "Portability.hpp"
00033 #include "PythonSignal.hpp"
00034 #include "ITimer.hpp"
00035 #include "WinTimer.hpp"
00036 
00037 #include <boost/python.hpp>
00038 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
00039 #include <vector>
00040 #include <stdint.h>
00041 
00042 using namespace boost::python;
00043 
00044 class DllExport SignalPythonWrap : public ISignal, public wrapper<ISignal>
00045 {
00046  public:
00047   SignalPythonWrap(ISignal* pSignal) : mpSignal(pSignal) {
00048         
00049   }
00050     
00051   virtual ~SignalPythonWrap() {
00052     delete mpSignal;
00053   }
00054     
00055   bool open(uint8_t mac[]) {
00056     return this->get_override("open")(mac);
00057   }
00058     
00059   bool init(size_t channels) {
00060     return this->get_override("init")(channels);
00061   }
00062     
00063   size_t channels() {
00064     return this->get_override("channels")();
00065   }
00066     
00067   bool start() {
00068     return this->get_override("start")();        
00069   }
00070     
00071   size_t acquire() {
00072     return this->get_override("acquire")();                
00073     return 0;
00074   }
00075     
00076   void getdata(uint32_t* data, size_t n) {
00077     this->get_override("getdata")(data, n);        
00078   }
00079     
00080   uint64_t timestamp() {
00081     return this->get_override("timestamp")();                
00082     return 0;    
00083   }
00084     
00085   bool stop() {
00086     return this->get_override("stop")();                
00087   }
00088     
00089   bool close() {
00090     return this->get_override("close")();                
00091   }
00092  private:
00093   ISignal* mpSignal;    
00094 };
00095 
00096 class DllExport TimerPythonWrap : public ITimer, public wrapper<ITimer>
00097 {
00098  public:
00099   TimerPythonWrap(ITimer* pTimer) : mpTimer(pTimer) {
00100   }
00101 
00102   virtual ~TimerPythonWrap() {
00103     delete mpTimer;
00104   }
00105 
00106   void start() {
00107     this->get_override("start")();
00108   }
00109 
00110   uint32_t elapsedCycles() {
00111     return this->get_override("elapsedCycles")();
00112   }
00113 
00114   uint32_t elapsedMilliSecs() {
00115     return this->get_override("elapsedMilliSecs")();
00116   }
00117 
00118   uint32_t elapsedMicroSecs() {
00119     return this->get_override("elapsedMicroSecs")();
00120   }
00121 
00122   int64_t getFrequency() {
00123     return this->get_override("getFrequency")();
00124   }
00125 
00126   int64_t getStartValue() {
00127     return this->get_override("getStartValue")();
00128   }
00129 
00130  private:
00131   ITimer* mpTimer;
00132 };
00133 
00134 BOOST_PYTHON_MODULE(neuralsignal)
00135 {
00136   class_<std::vector<int32_t> >("int32_vector")
00137         .def(vector_indexing_suite<std::vector<int32_t> >() );
00138         
00139 //  def("create_timer", create_timer, return_value_policy<manage_new_object>());
00140 
00141   class_<SignalPythonWrap, boost::noncopyable>("ISignal", no_init)
00142     .def("open", pure_virtual(&ISignal::open))
00143     .def("init", pure_virtual(&ISignal::init))
00144     .def("channels", pure_virtual(&ISignal::channels))      
00145     .def("start", pure_virtual(&ISignal::start))
00146     .def("acquire", pure_virtual(&ISignal::acquire))
00147     .def("getdata", pure_virtual(&ISignal::getdata))
00148     .def("timestamp", pure_virtual(&ISignal::timestamp))
00149     .def("stop", pure_virtual(&ISignal::stop))
00150     .def("close", pure_virtual(&ISignal::close))             
00151     ;
00152 
00153   class_<NonblockingSignal, bases<ISignal> >("NonblockingSignal", init<ISignal*>())
00154     .def("open", &NonblockingSignal::open)
00155     .def("init", &NonblockingSignal::init)
00156     .def("channels", &NonblockingSignal::channels)        
00157     .def("start", &NonblockingSignal::start)    
00158     .def("acquire", &NonblockingSignal::acquire)
00159     .def("getdata", &NonblockingSignal::getdata)    
00160     .def("timestamp", &NonblockingSignal::timestamp)
00161     .def("stop", &NonblockingSignal::stop)    
00162     .def("close", &NonblockingSignal::close)             
00163     ;
00164     
00165   class_<PythonSignal>("PythonSignal", init<ISignal*, ITimer*>())
00166     .def("open", &PythonSignal::open)
00167     .def("init", &PythonSignal::init)
00168     .def("channels", &PythonSignal::channels)        
00169     .def("start", &PythonSignal::start)    
00170     .def("acquire", &PythonSignal::acquire)
00171     .def("getdata", &PythonSignal::getdata)
00172     .def("elapsedMicroSecs", &PythonSignal::elapsedMicroSecs)
00173     .def("timestamp", &PythonSignal::timestamp)
00174     .def("stop", &PythonSignal::stop)    
00175     .def("close", &PythonSignal::close)             
00176     ;
00177 }
00178 
00179 #endif

Generated on Mon Nov 10 2014 11:09:08 for The Unlock Project by  doxygen 1.7.1