MNE-CPP  beta 1.0
babymeginfo.cpp
1 //=============================================================================================================
37 #include "babymeginfo.h"
38 
39 
40 
41 //*************************************************************************************************************
42 
44 : g_maxlen(500)
45 {
46 }
47 //*************************************************************************************************************
48 
50 {
51 // qDebug()<<"[BabyMEGInfo]CMD Size:"<<DATA.size();
52  emit SendCMDPackage(DATA);
53 }
54 //*************************************************************************************************************
55 
57 {
58 // qDebug()<<"[BabyMEGInfo]Data Size:"<<DATA.size();
59  emit SendDataPackage(DATA);
60 }
61 
62 //*************************************************************************************************************
63 
64 QByteArray BabyMEGInfo::MGH_LM_Get_Field(QByteArray cmdstr)
65 {
66  bool Start = false;
67  qint32 bPos = 0;
68  qint32 ePos = 0;
69  qint32 cn = 0;
70  for(qint32 i=0;i<cmdstr.size();i++)
71  {
72  if (cmdstr[i] == ':')
73  { // get channel number
74  Start = !Start;
75  if (Start)
76  {
77  bPos = i;
78  }
79  else
80  {
81  ePos = i;
82  }
83  cn ++;
84  }
85  if (cn == 2)
86  { // find the first ":" and the next ":"
87  break;
88  }
89 
90  }
91 
92  return cmdstr.mid(bPos,ePos-bPos);
93 
94 }
95 
96 //*************************************************************************************************************
97 
98 QStringList BabyMEGInfo::MGH_LM_Exact_Single_Channel_Info(QByteArray cmdstr)
99 {
100  QStringList sList;
101  qint32 sp =0;
102  qint32 ep =0;
103  //extract single channel information by char ';'
104  for (qint32 i=0;i<cmdstr.size();i++)
105  {
106  if (cmdstr[i]==';')
107  {
108  ep = i;
109  QString t = cmdstr.mid(sp,ep-sp);
110  //qDebug()<<"[BabyMEGInfo] chan-name"<<t;
111  sList.append(t);
112  sp = i+1;
113  }
114  }
115 
116  return sList;
117 
118 }
119 
120 //*************************************************************************************************************
121 
123 {
124  //operation about lm_ch_names
125  if (cmdstr[0]==':')
126  cmdstr.remove(0,1);
127 
128  QStringList sList = MGH_LM_Exact_Single_Channel_Info(cmdstr);
129 
130  lm_ch_names.clear();
131  // parse the information for each channel
132  for(qint32 k =0; k<sList.size(); k++)
133  {
134  QString t = sList.at(k);
135  for (qint32 z=0;z<t.size();z++)
136  {
137  if (t[z]=='|')
138  {
139  lm_ch_names.append(t.left(z));
140  //qDebug()<<t.left(z);
141  }
142  }
143  }
144  return;
145 }
146 
147 //*************************************************************************************************************
148 
149 void BabyMEGInfo::MGH_LM_Parse_Para(QByteArray cmdstr)
150 {
151 
152  QByteArray CMD = cmdstr.left(4);
153  if (CMD == "INFO")
154  {
155  //remove INFO
156  cmdstr.remove(0,4);
157  //ACQ the number of channels
158  QByteArray T = MGH_LM_Get_Field(cmdstr);
159  cmdstr.remove(0,T.size());
160  T.remove(0,1);
161  chnNum = T.toInt();
162  //ACQ the length of data package
163  T = MGH_LM_Get_Field(cmdstr);
164  cmdstr.remove(0,T.size());
165  T.remove(0,1);
166  dataLength = T.toInt();
167  // ACQ sampling rate
168  T = MGH_LM_Get_Field(cmdstr);
169  cmdstr.remove(0,T.size());
170  T.remove(0,1);
171  sfreq = T.toDouble();
172  qDebug()<<"[babyMEGinfo] chnNum:" << chnNum << "Data Length" <<dataLength<<"sampling rate"<<sfreq;
173  //qDebug()<<"cmdstr"<<cmdstr;
174  // Start to acquire the channel's name and channel's scale
175  MGH_LM_Get_Channel_Info(cmdstr);
176 
177  }
178  else
179  {
180  chnNum = 464;
181  dataLength = 5000;
182  sfreq = 10000;
183  }
184 
185  // Parameters
186  m_FiffInfo.file_id.version = 0; //ToDo
187 
188  m_FiffInfo.meas_date[0] = 0;
189  m_FiffInfo.meas_date[1] = 0;
190  m_FiffInfo.sfreq = sfreq;
191  m_FiffInfo.highpass = 0;
192  m_FiffInfo.lowpass = m_FiffInfo.sfreq/2;
193  m_FiffInfo.acq_pars = QString("BabyMEG");
194  m_FiffInfo.acq_stim = QString("");
195  m_FiffInfo.filename = QString("");
196  m_FiffInfo.meas_id.version = 1;
197  m_FiffInfo.nchan = chnNum; //464;
198 
199  //MEG
200  for(qint32 i = 0; i < chnNum; i++)
201  {
202  FiffChInfo t_ch;
203 
204  t_ch.ch_name = lm_ch_names.at(i); //QString("MEG%1").arg(i);
205  //qDebug()<<t_ch.ch_name;
206  t_ch.scanno = i;
207  t_ch.logno = i+1;
208  t_ch.cal = 1;
209  t_ch.range = 1;
210  t_ch.loc.setZero(12,1);
211 
212  QString type = t_ch.ch_name.left(3);
213  int ntype = 0;
214  if (type == "MEG")
215  ntype = 1;
216  else if (type == "EEG")
217  ntype = 2;
218  switch (ntype)
219  {
220  case 1:
221  t_ch.kind = FIFFV_MEG_CH;
222  t_ch.unit = FIFF_UNIT_T;
223  t_ch.unit_mul = FIFF_UNITM_NONE;
224  t_ch.coil_type = FIFFV_COIL_BABY_MAG;// ToDo FIFFV_COIL_BABY_REF_MAG
225  break;
226  case 2:
227  t_ch.kind = FIFFV_EEG_CH;
228  t_ch.unit = FIFF_UNIT_V;
229  t_ch.unit_mul = FIFF_UNITM_NONE;
230  t_ch.coil_type = FIFFV_COIL_EEG;
231  break;
232  default:
233  t_ch.kind = FIFFV_MEG_CH;
234  t_ch.unit = FIFF_UNIT_T;
235  t_ch.unit_mul = FIFF_UNITM_NONE;
236  t_ch.coil_type = FIFFV_COIL_BABY_MAG;// ToDo FIFFV_COIL_BABY_REF_MAG
237 
238  break;
239  }
240  m_FiffInfo.chs.append(t_ch);
241  m_FiffInfo.ch_names.append(t_ch.ch_name);
242  }
243 
244  emit fiffInfoAvailable(m_FiffInfo);
245 
246  return;
247 }
248 
249 //*************************************************************************************************************
250 
251 void BabyMEGInfo::EnQueue(QByteArray DataIn)
252 {
253  g_mutex.lock();
254  if (g_queue.size() == g_maxlen) {
255  qDebug() << "g_queue is full, waiting!";
256  g_queueNotFull.wait(&g_mutex);
257  }
258  g_queue.enqueue(DataIn);
259  g_queueNotEmpty.wakeAll();
260  g_mutex.unlock();
261  qDebug() << "Data In...[size="<<g_queue.size()<<"]";
262 }
263 //*************************************************************************************************************
264 
266 {
267  QMutexLocker locker(&g_mutex);
268  if (g_queue.isEmpty()) {
269  qDebug() << "g_queue empty, waiting!";
270  g_queueNotEmpty.wait(&g_mutex);
271  }
272  QByteArray val = g_queue.dequeue();
273  g_queueNotFull.wakeAll();
274  qDebug() << "Data Out...[size="<<g_queue.size()<<"]";
275  return val;
276 }
void MGH_LM_Parse_Para(QByteArray cmdstr)
fiff_int_t meas_date[2]
Definition: fiff_info.h:259
QString acq_stim
Definition: fiff_info.h:269
fiff_int_t version
Definition: fiff_id.h:127
fiff_float_t range
Definition: fiff_ch_info.h:125
fiff_float_t cal
Definition: fiff_ch_info.h:126
#define FIFFV_COIL_EEG
void MGH_LM_Get_Channel_Info(QByteArray cmdstr)
#define FIFFV_COIL_BABY_MAG
QByteArray DeQueue()
QByteArray MGH_LM_Get_Field(QByteArray cmdstr)
Definition: babymeginfo.cpp:64
Channel info descriptor.
Definition: fiff_ch_info.h:87
QList< FiffChInfo > chs
void EnQueue(QByteArray DataIn)
void MGH_LM_Send_DataPackage(QByteArray DATA)
Definition: babymeginfo.cpp:56
fiff_int_t coil_type
Definition: fiff_ch_info.h:128
QString acq_pars
Definition: fiff_info.h:268
void MGH_LM_Send_CMDPackage(QByteArray DATA)
Definition: babymeginfo.cpp:49
Matrix< double, 12, 1, DontAlign > loc
Definition: fiff_ch_info.h:130
QStringList MGH_LM_Exact_Single_Channel_Info(QByteArray cmdstr)
Definition: babymeginfo.cpp:98