MNE-CPP  beta 1.0
tmsiproducer.cpp
Go to the documentation of this file.
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include "tmsiproducer.h"
43 #include "tmsi.h"
44 #include "tmsidriver.h"
45 
46 #include <QDebug>
47 
48 
49 //*************************************************************************************************************
50 //=============================================================================================================
51 // USED NAMESPACES
52 //=============================================================================================================
53 
54 using namespace TMSIPlugin;
55 
56 
57 //*************************************************************************************************************
58 //=============================================================================================================
59 // DEFINE MEMBER METHODS
60 //=============================================================================================================
61 
63 : m_pTMSI(pTMSI)
64 , m_pTMSIDriver(new TMSIDriver(this))
65 , m_bIsRunning(true)
66 {
67 }
68 
69 
70 //*************************************************************************************************************
71 
73 {
74  //cout << "TMSIProducer::~TMSIProducer()" << endl;
75 }
76 
77 
78 //*************************************************************************************************************
79 
80 void TMSIProducer::start(int iNumberOfChannels,
81  int iSamplingFrequency,
82  int iSamplesPerBlock,
83  bool bUseChExponent,
84  bool bUseUnitGain,
85  bool bUseUnitOffset,
86  bool bWriteDriverDebugToFile,
87  QString sOutputFilePath,
88  bool bUseCommonAverage,
89  bool bMeasureImpedance)
90 {
91  //Initialise device
92  if(m_pTMSIDriver->initDevice(iNumberOfChannels,
93  iSamplingFrequency,
94  iSamplesPerBlock,
95  bUseChExponent,
96  bUseUnitGain,
97  bUseUnitOffset,
98  bWriteDriverDebugToFile,
99  sOutputFilePath,
100  bUseCommonAverage,
101  bMeasureImpedance))
102  {
103  m_bIsRunning = true;
104  QThread::start();
105  }
106  else
107  m_bIsRunning = false;
108 }
109 
110 
111 //*************************************************************************************************************
112 
114 {
115  //Wait until this thread (TMSIProducer) is stopped
116  m_bIsRunning = false;
117 
118  //In case the semaphore blocks the thread -> Release the QSemaphore and let it exit from the push function (acquire statement)
119  m_pTMSI->m_pRawMatrixBuffer_In->releaseFromPush();
120 
121  while(this->isRunning())
122  m_bIsRunning = false;
123 
124  //Unitialise device only after the thread stopped
125  m_pTMSIDriver->uninitDevice();
126 }
127 
128 
129 //*************************************************************************************************************
130 
132 {
133  MatrixXf matRawBuffer(m_pTMSI->m_iNumberOfChannels, m_pTMSI->m_iSamplesPerBlock);
134 
135  while(m_bIsRunning)
136  {
137  //std::cout<<"TMSIProducer::run()"<<std::endl;
138  //Get the TMSi EEG data out of the device buffer and write received data to circular buffer
139  if(m_pTMSIDriver->getSampleMatrixValue(matRawBuffer))
140  m_pTMSI->m_pRawMatrixBuffer_In->push(&matRawBuffer);
141  }
142 
143  //std::cout<<"EXITING - TMSIProducer::run()"<<std::endl;
144 }
145 
146 
virtual void start(int iNumberOfChannels, int iSamplingFrequency, int iSamplesPerBlock, bool bUseChExponent, bool bUseUnitGain, bool bUseUnitOffset, bool bWriteDriverDebugToFile, QString sOutputFilePath, bool bUseCommonAverage, bool bMeasureImpedance)
Contains the declaration of the tmsidriver class. This class implements the basic communication betwe...
Contains the declaration of the TMSI class.
The TMSI class provides a EEG connector. In order for this plugin to work properly the driver dll "RT...
Definition: tmsi.h:122
The TMSIDriver class provides real time data acquisition of EEG data with a TMSi Refa device...
Definition: tmsidriver.h:272
Contains the declaration of the TMSIProducer class.