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 
49 void BabyMEGInfo::MGH_LM_Send_CMDPackage(QByteArray DATA)
50 {
51 // qDebug()<<"[BabyMEGInfo]CMD Size:"<<DATA.size();
52  emit SendCMDPackage(DATA);
53 }
54 //*************************************************************************************************************
55 
56 void BabyMEGInfo::MGH_LM_Send_DataPackage(QByteArray DATA)
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 
122 void BabyMEGInfo::MGH_LM_Get_Channel_Info(QByteArray cmdstr)
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  lm_ch_scales.clear();
132  lm_ch_pos1.clear();
133  lm_ch_pos2.clear();
134  lm_ch_pos3.clear();
135  lm_ch_pos4.clear();
136  lm_ch_pos5.clear();
137  lm_ch_pos6.clear();
138  lm_ch_pos7.clear();
139  lm_ch_pos8.clear();
140  lm_ch_pos9.clear();
141  lm_ch_pos10.clear();
142  lm_ch_pos11.clear();
143  lm_ch_pos12.clear();
144  lm_ch_coiltype.clear();
145  lm_ch_calicoef.clear();
146  lm_ch_gain.clear();
147 
148 
149  // parse the information for each channel
150  for(qint32 k =0; k<sList.size(); k++)
151  {
152  QString t = sList.at(k);
153  for (qint32 z=0;z<t.size();z++)
154  {
155  if (t[z]=='|')
156  {
157  lm_ch_names.append(t.left(z));
158  //qDebug()<<t.left(z);
159  //extract the substring contained channel information: scale and coil positions
160  QString tt = t.mid(z);
161  //qDebug()<<tt;
162  //extract value array from tt by separated char ","
163  QStringList schp = tt.split(",");
164  //qDebug()<<schp;
165  // scale
166  lm_ch_scales.append(schp.at(0));
167  // positions : x,y,z and units of x,y,z
168  lm_ch_pos1.append(schp.at(1));
169  lm_ch_pos2.append(schp.at(2));
170  lm_ch_pos3.append(schp.at(3));
171  lm_ch_pos4.append(schp.at(4));
172  lm_ch_pos5.append(schp.at(5));
173  lm_ch_pos6.append(schp.at(6));
174  lm_ch_pos7.append(schp.at(7));
175  lm_ch_pos8.append(schp.at(8));
176  lm_ch_pos9.append(schp.at(9));
177  lm_ch_pos10.append(schp.at(10));
178  lm_ch_pos11.append(schp.at(11));
179  lm_ch_pos12.append(schp.at(12));
180  //coil type
181  lm_ch_coiltype.append(schp.at(13));
182  //calibration coefficient
183  lm_ch_calicoef.append(schp.at(14));
184  //gain
185  lm_ch_gain.append(schp.at(15));
186 
187 // qDebug()<<lm_ch_scales;
188 // qDebug()<<lm_ch_pos2;
189 // qDebug()<<"coiltype"<<lm_ch_coiltype<<"calicoef"<<lm_ch_calicoef;
190  }
191  }
192  }
193  return;
194 }
195 
196 //*************************************************************************************************************
197 
198 void BabyMEGInfo::MGH_LM_Parse_Para(QByteArray cmdstr)
199 {
200 
201  QByteArray CMD = cmdstr.left(4);
202  if (CMD == "INFO")
203  {
204  //remove INFO
205  cmdstr.remove(0,4);
206  //ACQ the number of channels
207  QByteArray T = MGH_LM_Get_Field(cmdstr);
208  cmdstr.remove(0,T.size());
209  T.remove(0,1);
210  chnNum = T.toInt();
211  //ACQ the length of data package
212  T = MGH_LM_Get_Field(cmdstr);
213  cmdstr.remove(0,T.size());
214  T.remove(0,1);
215  dataLength = T.toInt();
216  // ACQ sampling rate
217  T = MGH_LM_Get_Field(cmdstr);
218  cmdstr.remove(0,T.size());
219  T.remove(0,1);
220  sfreq = T.toDouble();
221  qDebug()<<"[babyMEGinfo] chnNum:" << chnNum << "Data Length" <<dataLength<<"sampling rate"<<sfreq;
222  //qDebug()<<"cmdstr"<<cmdstr;
223  // Start to acquire the channel's name and channel's scale
224  MGH_LM_Get_Channel_Info(cmdstr);
225 
226  }
227  else
228  {
229  chnNum = 464;
230  dataLength = 5000;
231  sfreq = 10000;
232  }
233 
234  // Parameters
235  m_FiffInfo.file_id.version = 0; //ToDo
236 
237  m_FiffInfo.meas_date[0] = 0;
238  m_FiffInfo.meas_date[1] = 0;
239  m_FiffInfo.sfreq = sfreq;
240  m_FiffInfo.highpass = 0;
241  m_FiffInfo.lowpass = m_FiffInfo.sfreq/2;
242  m_FiffInfo.acq_pars = QString("BabyMEG");
243  m_FiffInfo.acq_stim = QString("");
244  m_FiffInfo.filename = QString("");
245  m_FiffInfo.meas_id.version = 1;
246  m_FiffInfo.nchan = chnNum; //464;
247 
248  //MEG
249  for(qint32 i = 0; i < chnNum; i++)
250  {
251  FiffChInfo t_ch;
252 
253  t_ch.ch_name = lm_ch_names.at(i); //QString("MEG%1").arg(i);
254  //qDebug()<<t_ch.ch_name;
255  t_ch.scanno = i;
256  t_ch.logno = i+1;
257  t_ch.cal = lm_ch_calicoef.at(i).toDouble();
258  t_ch.unit_mul = 1.0;//lm_ch_scales.at(i).toFloat();
259  t_ch.range =1.0f/lm_ch_gain.at(i).toFloat();//1; // set gain
260 
261  //qDebug()<<i<<":="<<t_ch.ch_name<<","<<t_ch.range<<","<<t_ch.cal;
262 
263  t_ch.loc.setZero(12,1);
264 
265  //set loc
266  t_ch.loc(0,0) = lm_ch_pos1.at(i).toDouble();
267  t_ch.loc(1,0) = lm_ch_pos2.at(i).toDouble();
268  t_ch.loc(2,0) = lm_ch_pos3.at(i).toDouble();
269  t_ch.loc(3,0) = lm_ch_pos4.at(i).toDouble();
270  t_ch.loc(4,0) = lm_ch_pos5.at(i).toDouble();
271  t_ch.loc(5,0) = lm_ch_pos6.at(i).toDouble();
272  t_ch.loc(6,0) = lm_ch_pos7.at(i).toDouble();
273  t_ch.loc(7,0) = lm_ch_pos8.at(i).toDouble();
274  t_ch.loc(8,0) = lm_ch_pos9.at(i).toDouble();
275  t_ch.loc(9,0) = lm_ch_pos10.at(i).toDouble();
276  t_ch.loc(10,0) = lm_ch_pos11.at(i).toDouble();
277  t_ch.loc(11,0) = lm_ch_pos12.at(i).toDouble();
278 
279  //qDebug()<<t_ch.loc(0,0)<<t_ch.loc(1,0)<<t_ch.loc(2,0);
280 
281  int type = lm_ch_coiltype.at(i).toInt();
282  int ntype = 0;
283 
284  if (type == FIFFV_COIL_BABY_MAG) //inner layer MEG
285  ntype = 1;
286  else if (type == FIFFV_COIL_BABY_REF_MAG)
287  ntype = 2;
288  else if (type == FIFFV_COIL_BABY_REF_MAG2)
289  ntype = 3;
290  else if (type == FIFFV_STIM_CH)
291  ntype = 4;
292  else if (type == FIFFV_EEG_CH)
293  ntype = 5;
294 
295  switch (ntype)
296  {
297  case 1: // inner layer meg sensors
298  t_ch.kind = FIFFV_MEG_CH;
299  t_ch.unit = FIFF_UNIT_T;
300  t_ch.unit_mul = FIFF_UNITM_NONE;
302 
303  break;
304  case 2: // outer layer meg sensors
305  t_ch.kind = FIFFV_MEG_CH;
306  t_ch.unit = FIFF_UNIT_T;
307  t_ch.unit_mul = FIFF_UNITM_NONE;
309 
310  break;
311  case 3: // reference meg sensors
312  t_ch.kind = FIFFV_REF_MEG_CH;
313  t_ch.unit = FIFF_UNIT_T;
314  t_ch.unit_mul = FIFF_UNITM_NONE;
316 
317  break;
318  case 4: // trigger lines
319  t_ch.kind = FIFFV_STIM_CH;
320  t_ch.unit = FIFF_UNIT_V;
321  t_ch.unit_mul = FIFF_UNITM_NONE;
322  t_ch.coil_type = FIFFV_STIM_CH;
323  break;
324  case 5: // EEG channels
325  t_ch.kind = FIFFV_EEG_CH;
326  t_ch.unit = FIFF_UNIT_V;
327  t_ch.unit_mul = FIFF_UNITM_NONE;
328  t_ch.coil_type = FIFFV_COIL_EEG;
329 
330  break;
331  default: // other unknown type sensors
332  t_ch.kind = FIFFV_MEG_CH;
333  t_ch.unit = FIFF_UNIT_T;
334  t_ch.unit_mul = FIFF_UNITM_NONE;
335  t_ch.coil_type = FIFFV_COIL_NONE;
336 
337  break;
338  }
339  m_FiffInfo.chs.append(t_ch);
340  m_FiffInfo.ch_names.append(t_ch.ch_name);
341 
342  }
343 
344  emit fiffInfoAvailable(m_FiffInfo);
345 
346  return;
347 }
348 
349 //*************************************************************************************************************
350 
352 {
353  //operation about lm_ch_names
354  if (cmdstr[0]==':')
355  cmdstr.remove(0,1);
356 
357  QStringList sList = MGH_LM_Exact_Single_Channel_Info(cmdstr);
358 
359  lm_ch_names.clear();
360  lm_ch_gain.clear();
361 
362 
363  // parse the information for each channel
364  for(qint32 k =0; k<sList.size(); k++)
365  {
366  QString t = sList.at(k);
367  for (qint32 z=0;z<t.size();z++)
368  {
369  if (t[z]=='|')
370  {
371  lm_ch_names.append(t.left(z));
372  //qDebug()<<t.left(z);
373  //extract the substring contained channel information: scale and coil positions
374  QString tt = t.mid(z+1);
375  qDebug()<<tt;
376  //gain
377  lm_ch_gain.append(tt);
378  qDebug()<<t.left(z)<<"----"<<tt;
379 
380  }
381  }
382  }
383  return;
384 }
385 
386 //*************************************************************************************************************
387 
388 void BabyMEGInfo::MGH_LM_Parse_Para_Infg(QByteArray cmdstr)
389 {
390 
391  QByteArray CMD = cmdstr.left(4);
392  if (CMD == "INFG")
393  {
394  //remove INFG
395  cmdstr.remove(0,4);
396  //ACQ the number of channels
397  QByteArray T = MGH_LM_Get_Field(cmdstr);
398  cmdstr.remove(0,T.size());
399  T.remove(0,1);
400  chnNum = T.toInt();
401  //ACQ the length of data package
402  T = MGH_LM_Get_Field(cmdstr);
403  cmdstr.remove(0,T.size());
404  T.remove(0,1);
405  dataLength = T.toInt();
406  // ACQ sampling rate
407  T = MGH_LM_Get_Field(cmdstr);
408  cmdstr.remove(0,T.size());
409  T.remove(0,1);
410  sfreq = T.toDouble();
411  qDebug()<<"[babyMEG_INFG] chnNum:" << chnNum << "Data Length" <<dataLength<<"sampling rate"<<sfreq;
412  //qDebug()<<"cmdstr"<<cmdstr;
413  // Start to acquire the channel's name and channel's scale
414  MGH_LM_Get_Channel_Infg(cmdstr);
415 
416 
417  //emit gain info
418  emit GainInfoUpdate(lm_ch_gain);
419 
420  }
421 
422  return;
423 }
424 
void MGH_LM_Parse_Para(QByteArray cmdstr)
void MGH_LM_Parse_Para_Infg(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
void MGH_LM_Get_Channel_Infg(QByteArray cmdstr)
fiff_float_t range
Definition: fiff_ch_info.h:125
fiff_float_t cal
Definition: fiff_ch_info.h:126
#define FIFFV_COIL_BABY_REF_MAG2
#define FIFFV_COIL_EEG
void MGH_LM_Get_Channel_Info(QByteArray cmdstr)
#define FIFFV_COIL_BABY_MAG
QByteArray MGH_LM_Get_Field(QByteArray cmdstr)
Definition: babymeginfo.cpp:64
Channel info descriptor.
Definition: fiff_ch_info.h:87
QList< FiffChInfo > chs
void MGH_LM_Send_DataPackage(QByteArray DATA)
Definition: babymeginfo.cpp:56
#define FIFFV_COIL_BABY_REF_MAG
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
#define FIFFV_COIL_NONE
QStringList MGH_LM_Exact_Single_Channel_Info(QByteArray cmdstr)
Definition: babymeginfo.cpp:98