TOBI SignalServer  0.1
/home/breidi/Dropbox/signalserver/include/hardware/gtec_usbamp_wrapper.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 
00038 #ifndef GTEC_USBAMP_WRAPPER_H
00039 #define GTEC_USBAMP_WRAPPER_H
00040 
00041 #include <exception>
00042 
00043 namespace tobiss
00044 {
00045 
00046 // FILTER
00047 #define F_CHEBYSHEV  0
00048 #define F_BUTTERWORTH 1
00049 #define F_BESSEL  2
00050 
00051 // MODES
00052 #define M_NORMAL  0
00053 #define M_IMPEDANCE  1
00054 #define M_CALIBRATE  2
00055 #define M_COUNTER  3
00056 
00057 //WAVESHAPES
00058 #define WS_SQUARE  0x01
00059 #define WS_SAWTOOTH  0x02
00060 #define WS_SINE   0x03
00061 #define WS_DRL   0x04
00062 #define WS_NOISE  0x05
00063 
00064 
00065 #define HEADER_SIZE  38
00066 
00067   //_____________________________________________________________________________
00068 //
00069 //       DATA STRUCTURES
00070 //_____________________________________________________________________________
00071 
00072 
00073 typedef struct _DigitalIO
00074 {
00075    BOOL  DIN1; // True if set (high voltage level)
00076    BOOL  DIN2;
00077    BOOL  DOUT1;
00078    BOOL  DOUT2;
00079 } DigitalIO, *PDigitalIO;
00080 
00081 typedef struct _DigitalOUT
00082 {
00083  BOOL SET_0; // True if digital OUT0 should be set to VALUE_0 ...
00084  BOOL VALUE_0;
00085  BOOL SET_1;
00086  BOOL VALUE_1;
00087  BOOL SET_2;
00088  BOOL VALUE_2;
00089  BOOL SET_3;
00090  BOOL VALUE_3;
00091 }DigitalOUT, *PDigitalOUT;
00092 
00093 typedef struct _GND
00094 {
00095  BOOL GND1;
00096  BOOL GND2;
00097  BOOL GND3;
00098  BOOL GND4;
00099 } GND, *PGND;
00100 
00101 typedef struct _REF
00102 {
00103  BOOL ref1;
00104  BOOL ref2;
00105  BOOL ref3;
00106  BOOL ref4;
00107 } REF, *PREF;
00108 
00109 typedef struct _DAC
00110 {
00111  BYTE WaveShape;
00112  WORD Amplitude;
00113  WORD Frequency;
00114  WORD Offset;
00115 } DAC, *PDAC;
00116 
00117 typedef struct _CHANNEL
00118 {
00119  UCHAR Channel1;
00120  UCHAR Channel2;
00121  UCHAR Channel3;
00122  UCHAR Channel4;
00123  UCHAR Channel5;
00124  UCHAR Channel6;
00125  UCHAR Channel7;
00126  UCHAR Channel8;
00127  UCHAR Channel9;
00128  UCHAR Channel10;
00129  UCHAR Channel11;
00130  UCHAR Channel12;
00131  UCHAR Channel13;
00132  UCHAR Channel14;
00133  UCHAR Channel15;
00134  UCHAR Channel16;
00135 } CHANNEL, *PCHANNEL;
00136 
00137 typedef struct _SCALE
00138 {
00139  float factor[16];
00140  float offset[16];
00141 } SCALE, *PSCALE;
00142 
00143 
00144 typedef struct _GT_DEVICEINFO
00145 {
00146  char deviceInfo[256];
00147 } GT_DEVICEINFO, *PGT_DEVICEINFO;
00148 
00149 typedef struct _FILT
00150 {
00151  float fu;
00152  float fo;
00153  float fs;
00154  float type;
00155  float order;
00156 
00157 } FILT, *PFILT;
00158 
00159 typedef FLOAT (CALLBACK* GT_GetDriverVersionType)(void);
00160 typedef BOOL (CALLBACK* GT_GetDataType)(HANDLE, BYTE*, DWORD, OVERLAPPED*);
00161 typedef FLOAT (CALLBACK* GT_GetHWVersionType)(HANDLE);
00162 typedef HANDLE (CALLBACK* GT_OpenDeviceType) (int);
00163 typedef HANDLE (CALLBACK* GT_OpenDeviceExType) (LPSTR);
00164 typedef BOOL (CALLBACK* GT_CloseDeviceType) (HANDLE*);
00165 typedef BOOL (CALLBACK* GT_SetBufferSizeType) (HANDLE, WORD);
00166 typedef BOOL (CALLBACK* GT_SetSampleRateType) (HANDLE, WORD);
00167 typedef BOOL (CALLBACK* GT_StartType) (HANDLE);
00168 typedef BOOL (CALLBACK* GT_StopType) (HANDLE);
00169 typedef BOOL (CALLBACK* GT_SetChannelsType) (HANDLE, UCHAR*, UCHAR);
00170 typedef BOOL (CALLBACK* GT_SetDigitalOutType) (HANDLE, UCHAR, UCHAR);
00171 typedef BOOL (CALLBACK* GT_SetDigitalOutExType) (HANDLE, DigitalOUT);
00172 typedef BOOL (CALLBACK* GT_GetDigitalIOType) (HANDLE , PDigitalIO );
00173 typedef BOOL (CALLBACK* GT_GetDigitalOutType) (HANDLE , PDigitalOUT );
00174 typedef BOOL (CALLBACK* GT_GetLastErrorType) (WORD * , char *);
00175 typedef BOOL (CALLBACK* GT_ResetTransferType) (HANDLE );
00176 typedef BOOL (CALLBACK* GT_GetSerialType) (HANDLE , LPSTR ,UINT );
00177 typedef BOOL (CALLBACK* GT_VRType) (int , void **,int , void **);
00178 typedef BOOL (CALLBACK* GT_EnableTriggerLineType) (HANDLE , BOOL );
00179 typedef BOOL (CALLBACK* GT_GetImpedanceType) (HANDLE , UCHAR , double* );
00180 typedef BOOL (CALLBACK* GT_CalibrateType) (HANDLE ,PSCALE );
00181 typedef BOOL (CALLBACK* GT_SetScaleType) (HANDLE , PSCALE );
00182 typedef BOOL (CALLBACK* GT_GetScaleType) (HANDLE , PSCALE );
00183 typedef BOOL (CALLBACK* GT_GetFilterSpecType) (FILT *);
00184 typedef BOOL (CALLBACK* GT_GetNumberOfFilterType) (int* );
00185 typedef BOOL (CALLBACK* GT_SetBandPassType) (HANDLE , UCHAR , int );
00186 typedef BOOL (CALLBACK* GT_GetNotchSpecType) (FILT *);
00187 typedef BOOL (CALLBACK* GT_GetNumberOfNotchType) (int* );
00188 typedef BOOL (CALLBACK* GT_SetNotchType) (HANDLE , UCHAR , int );
00189 typedef BOOL (CALLBACK* GT_SetModeType) (HANDLE , UCHAR );
00190 typedef BOOL (CALLBACK* GT_GetModeType) (HANDLE , UCHAR* );
00191 typedef BOOL (CALLBACK* GT_SetGroundType) (HANDLE , GND );
00192 typedef BOOL (CALLBACK* GT_GetGroundType) (HANDLE , GND* );
00193 typedef BOOL (CALLBACK* GT_SetReferenceType) (HANDLE , REF );
00194 typedef BOOL (CALLBACK* GT_GetReferenceType) (HANDLE , REF* );
00195 typedef BOOL (CALLBACK* GT_SetBipolarType) (HANDLE , CHANNEL );
00196 typedef BOOL (CALLBACK* GT_SetDRLChannelType) (HANDLE , CHANNEL );
00197 typedef BOOL (CALLBACK* GT_EnableSCType) (HANDLE , BOOL );
00198 typedef BOOL (CALLBACK* GT_SetSlaveType) (HANDLE , BOOL );
00199 
00200 //---------------------------------
00202 class GTECUSBampWrapper
00203 {
00204 public:
00205  GTECUSBampWrapper () : dll_handle_ (NULL)
00206  {
00207   dll_handle_ = LoadLibrary("gUSBamp.dll");
00208   if (dll_handle_ == NULL)
00209    throw std::runtime_error ("Can't load gUSBamp.dll");
00210 
00211   setupDLLFunction (get_driver_verstion_ptr_, "GT_GetDriverVersion");
00212   setupDLLFunction (get_data_ptr_, "GT_GetData");
00213   setupDLLFunction (get_hw_version_ptr_, "GT_GetHWVersion");
00214   setupDLLFunction (open_device_ptr_, "GT_OpenDevice");
00215   setupDLLFunction (open_device_ex_ptr_, "GT_OpenDeviceEx");
00216   setupDLLFunction (close_device_ptr_, "GT_CloseDevice");
00217 
00218   setupDLLFunction (set_buffer_size_ptr_, "GT_SetBufferSize");
00219   setupDLLFunction (set_sample_rate_ptr_, "GT_SetSampleRate");
00220   setupDLLFunction (start_ptr_, "GT_Start");
00221   setupDLLFunction (stop_ptr_, "GT_Stop");
00222   setupDLLFunction (set_channels_ptr_, "GT_SetChannels");
00223   setupDLLFunction (set_digital_out_ptr_, "GT_SetDigitalOut");
00224   setupDLLFunction (set_digital_out_ex_ptr_, "GT_SetDigitalOutEx");
00225   setupDLLFunction (get_digital_io_ptr_, "GT_GetDigitalIO");
00226   setupDLLFunction (get_digital_out_ptr_, "GT_GetDigitalOut");
00227   setupDLLFunction (get_last_error_ptr_, "GT_GetLastError");
00228   setupDLLFunction (reset_transfer_ptr_, "GT_ResetTransfer");
00229   setupDLLFunction (get_serial_ptr_, "GT_GetSerial");
00230 
00231   setupDLLFunction (vr_ptr_, "GT_VR");
00232   setupDLLFunction (enable_trigger_line_ptr_, "GT_EnableTriggerLine");
00233   setupDLLFunction (get_impedance_ptr_, "GT_GetImpedance");
00234   setupDLLFunction (calibrate_ptr_, "GT_Calibrate");
00235   setupDLLFunction (set_scale_ptr_, "GT_SetScale");
00236   setupDLLFunction (get_scale_ptr_, "GT_GetScale");
00237   setupDLLFunction (get_filter_spec_ptr_, "GT_GetFilterSpec");
00238   setupDLLFunction (get_number_of_filter_ptr_, "GT_GetNumberOfFilter");
00239   setupDLLFunction (set_band_pass_ptr_, "GT_SetBandPass");
00240   setupDLLFunction (get_notch_spec_ptr_, "GT_GetNotchSpec");
00241 
00242   setupDLLFunction (get_number_of_notch_ptr_, "GT_GetNumberOfNotch");
00243   setupDLLFunction (set_notch_ptr_, "GT_SetNotch");
00244   setupDLLFunction (set_mode_ptr_, "GT_SetMode");
00245   setupDLLFunction (get_mode_ptr_, "GT_GetMode");
00246   setupDLLFunction (set_ground_ptr_, "GT_SetGround");
00247   setupDLLFunction (get_ground_ptr_, "GT_GetGround");
00248   setupDLLFunction (set_reference_ptr_, "GT_SetReference");
00249   setupDLLFunction (get_reference_ptr_, "GT_GetReference");
00250   setupDLLFunction (set_bipolar_ptr_, "GT_SetBipolar");
00251   setupDLLFunction (set_drl_channel_ptr_, "GT_SetDRLChannel");
00252   setupDLLFunction (enable_sc_ptr_, "GT_EnableSC");
00253   setupDLLFunction (set_slave_ptr_, "GT_SetSlave");
00254  }
00255 
00256  ~GTECUSBampWrapper ()
00257  {
00258   FreeLibrary (dll_handle_);
00259  }
00260 
00261  FLOAT getDriverVersion ()
00262  {
00263   return get_driver_verstion_ptr_ ();
00264  }
00265 
00266  BOOL getData (HANDLE hDevice, BYTE *pData, DWORD dwSzBuffer, OVERLAPPED *ov)
00267  {
00268   return get_data_ptr_ (hDevice, pData, dwSzBuffer, ov);
00269  }
00270 
00271  BOOL start (HANDLE hDevice)
00272  {
00273   return start_ptr_ (hDevice);
00274  }
00275 
00276  BOOL stop (HANDLE hDevice)
00277  {
00278   return stop_ptr_ (hDevice);
00279  }
00280 
00281  BOOL closeDevice (HANDLE* hDevice)
00282  {
00283   return close_device_ptr_ (hDevice);
00284  }
00285 
00286  BOOL setChannels(HANDLE hDevice, UCHAR *ucChannels, UCHAR ucSizeChannels)
00287  {
00288   return set_channels_ptr_ (hDevice, ucChannels, ucSizeChannels);
00289  }
00290 
00291  BOOL resetTransfer (HANDLE hDevice)
00292  {
00293   return reset_transfer_ptr_ (hDevice);
00294  }
00295 
00296  BOOL getLastError (WORD * wErrorCode, char *pLastError)
00297  {
00298   return get_last_error_ptr_ (wErrorCode, pLastError);
00299  }
00300 
00301  HANDLE openDevice (int portNr)
00302  {
00303   return open_device_ptr_ (portNr);
00304  }
00305 
00306  HANDLE openDeviceEx (LPSTR lpSerial)
00307  {
00308   return open_device_ex_ptr_ (lpSerial);
00309  }
00310 
00311  FLOAT getHWVersion (HANDLE hDevise)
00312  {
00313   return get_hw_version_ptr_ (hDevise);
00314  }
00315 
00316  BOOL setBufferSize(HANDLE hDevice, WORD wBufferSize)
00317  {
00318   return set_buffer_size_ptr_ (hDevice, wBufferSize);
00319  }
00320  BOOL setSampleRate(HANDLE hDevice, WORD wSampleRate)
00321  {
00322   return set_sample_rate_ptr_ (hDevice, wSampleRate);
00323  }
00324  BOOL setDigitalOut(HANDLE hDevice, UCHAR ucNumber, UCHAR ucValue)
00325  {
00326   return set_digital_out_ptr_ (hDevice, ucNumber, ucValue);
00327  }
00328  BOOL setDigitalOutEx(HANDLE hDevice, DigitalOUT dout)
00329  {
00330   return set_digital_out_ex_ptr_ (hDevice, dout);
00331  }
00332  BOOL getDigitalIO(HANDLE hDevice, PDigitalIO pDIO)
00333  {
00334   return get_digital_io_ptr_ (hDevice, pDIO);
00335  }
00336  BOOL getDigitalOut(HANDLE hDevice, PDigitalOUT pDOUT)
00337  {
00338   return get_digital_out_ptr_ (hDevice, pDOUT);
00339  }
00340  BOOL getSerial(HANDLE hDevice, LPSTR lpstrSerial,UINT uiSize)
00341  {
00342   return get_serial_ptr_ (hDevice, lpstrSerial, uiSize);
00343  }
00344  BOOL VR(int nargin, void *varargin[],int nargout, void *varargout[])
00345  {
00346   return vr_ptr_ (nargin, varargin, nargout, varargout);
00347  }
00348  BOOL enableTriggerLine(HANDLE hDevice, BOOL bEnable)
00349  {
00350   return enable_trigger_line_ptr_ (hDevice, bEnable);
00351  }
00352  BOOL getImpedance(HANDLE hDevice, UCHAR Channel, double* Impedance)
00353  {
00354   return get_impedance_ptr_ (hDevice, Channel, Impedance);
00355  }
00356  BOOL calibrate(HANDLE hDevice,PSCALE Scaling)
00357  {
00358   return calibrate_ptr_ (hDevice, Scaling);
00359  }
00360 
00361  //------------
00362  // filters
00363  BOOL setScale (HANDLE hDevice, PSCALE Scaling)
00364  {
00365   return set_scale_ptr_ (hDevice, Scaling);
00366  }
00367  BOOL getScale (HANDLE hDevice, PSCALE Scaling)
00368  {
00369   return get_scale_ptr_ (hDevice, Scaling);
00370  }
00371  BOOL getFilterSpec (FILT *FilterSpec)
00372  {
00373   return get_filter_spec_ptr_ (FilterSpec);
00374  }
00375  BOOL getNumberOfFilter (int* nof)
00376  {
00377   return get_number_of_filter_ptr_ (nof);
00378  }
00379  BOOL setBandPass (HANDLE hDevice, UCHAR ucChannel, int index)
00380  {
00381   return set_band_pass_ptr_ (hDevice, ucChannel, index);
00382  }
00383  BOOL getNotchSpec (FILT *FilterSpec)
00384  {
00385   return get_notch_spec_ptr_ (FilterSpec);
00386  }
00387  BOOL getNumberOfNotch (int *nof)
00388  {
00389   return get_number_of_notch_ptr_ (nof);
00390  }
00391  BOOL setNotch (HANDLE hDevice, UCHAR ucChannel, int index)
00392  {
00393   return set_notch_ptr_ (hDevice, ucChannel, index);
00394  }
00395 
00396  //--------------
00397  // mode
00398  BOOL setMode(HANDLE hDevice, UCHAR ucMode)
00399  {
00400   return set_mode_ptr_ (hDevice, ucMode);
00401  }
00402 
00403  BOOL getMode(HANDLE hDevice, UCHAR* ucMode)
00404  {
00405   return get_mode_ptr_ (hDevice, ucMode);
00406  }
00407  BOOL setGround(HANDLE hDevice, GND CommonGround)
00408  {
00409   return set_ground_ptr_ (hDevice, CommonGround);
00410  }
00411  BOOL getGround(HANDLE hDevice, GND* CommonGround)
00412  {
00413   return get_ground_ptr_ (hDevice, CommonGround);
00414  }
00415  BOOL setReference(HANDLE hDevice, REF CommonReference)
00416  {
00417   return set_reference_ptr_ (hDevice, CommonReference);
00418  }
00419  BOOL getReference(HANDLE hDevice, REF* CommonReference)
00420  {
00421   return get_reference_ptr_ (hDevice, CommonReference);
00422  }
00423  BOOL setBipolar(HANDLE hDevice, CHANNEL bipoChannel)
00424  {
00425   return set_bipolar_ptr_ (hDevice, bipoChannel);
00426  }
00427  BOOL setDRLChannel(HANDLE hDevice, CHANNEL drlChannel)
00428  {
00429   return set_drl_channel_ptr_ (hDevice, drlChannel);
00430  }
00431  BOOL enableSC(HANDLE hDevice, BOOL bEnable)
00432  {
00433   return enable_sc_ptr_ (hDevice, bEnable);
00434  }
00435  BOOL setSlave(HANDLE hDevice, BOOL bSlave)
00436  {
00437   return set_slave_ptr_ (hDevice, bSlave);
00438  }
00439 
00440 private:
00441  template<typename T>
00442  void setupDLLFunction (T& pointer, std::string const& name)
00443  {
00444   pointer = (T)GetProcAddress (dll_handle_, name.c_str());
00445   if (pointer == NULL)
00446    throw std::runtime_error (std::string ("gUSBamp.dll: missing function ").append (name));
00447  }
00448 
00449  HINSTANCE dll_handle_;
00450  GT_GetDriverVersionType get_driver_verstion_ptr_;
00451  GT_GetDataType get_data_ptr_;
00452  GT_GetHWVersionType get_hw_version_ptr_;
00453  GT_OpenDeviceType open_device_ptr_;
00454  GT_OpenDeviceExType open_device_ex_ptr_;
00455  GT_CloseDeviceType close_device_ptr_;
00456  GT_SetBufferSizeType set_buffer_size_ptr_;
00457  GT_SetSampleRateType set_sample_rate_ptr_;
00458  GT_StartType start_ptr_;
00459  GT_StopType stop_ptr_;
00460  GT_SetChannelsType set_channels_ptr_;
00461  GT_SetDigitalOutType set_digital_out_ptr_;
00462  GT_SetDigitalOutExType set_digital_out_ex_ptr_;
00463  GT_GetDigitalIOType get_digital_io_ptr_;
00464  GT_GetDigitalOutType get_digital_out_ptr_;
00465  GT_GetLastErrorType get_last_error_ptr_;
00466  GT_ResetTransferType reset_transfer_ptr_;
00467  GT_GetSerialType get_serial_ptr_;
00468  GT_VRType vr_ptr_;
00469  GT_EnableTriggerLineType enable_trigger_line_ptr_;
00470  GT_GetImpedanceType get_impedance_ptr_;
00471  GT_CalibrateType calibrate_ptr_;
00472  GT_SetScaleType set_scale_ptr_;
00473  GT_GetScaleType get_scale_ptr_;
00474  GT_GetFilterSpecType get_filter_spec_ptr_;
00475  GT_GetNumberOfFilterType get_number_of_filter_ptr_;
00476  GT_SetBandPassType set_band_pass_ptr_;
00477  GT_GetNotchSpecType get_notch_spec_ptr_;
00478  GT_GetNumberOfNotchType get_number_of_notch_ptr_;
00479  GT_SetNotchType set_notch_ptr_;
00480  GT_SetModeType set_mode_ptr_;
00481  GT_GetModeType get_mode_ptr_;
00482  GT_SetGroundType set_ground_ptr_;
00483  GT_GetGroundType get_ground_ptr_;
00484  GT_SetReferenceType set_reference_ptr_;
00485  GT_GetReferenceType get_reference_ptr_;
00486  GT_SetBipolarType set_bipolar_ptr_;
00487  GT_SetDRLChannelType set_drl_channel_ptr_;
00488  GT_EnableSCType enable_sc_ptr_;
00489  GT_SetSlaveType set_slave_ptr_;
00490 };
00491 
00492 } // namespace tobiss
00493 
00494 #endif // GTEC_USBAMP_WRAPPER_H
 All Data Structures Files Functions Variables