Skip to content

Commit d205647

Browse files
committed
add unnamed namespaces and implement filename chunk parser from ftbuffer
1 parent 99363c7 commit d205647

File tree

6 files changed

+83
-57
lines changed

6 files changed

+83
-57
lines changed

applications/mne_scan/plugins/ftbuffer/ftconnector.cpp

+45-2
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,14 @@ BufferInfo FtConnector::getBufferInfo()
573573

574574
//=============================================================================================================
575575

576-
FIFFLIB::FiffInfo FtConnector::infoFromSimpleHeader()
576+
FIFFLIB::FiffInfo FtConnector::infoFromSimpleHeader() const
577577
{
578578
FIFFLIB::FiffInfo defaultInfo;
579579

580-
defaultInfo.sfreq = m_fSampleFreq;
580+
defaultInfo.meas_date[0] = static_cast<int32_t>(QDateTime::currentDateTime().toSecsSinceEpoch());
581+
defaultInfo.meas_date[1] = 0;
582+
583+
defaultInfo.sfreq = m_fSamplingFreq;
581584
defaultInfo.nchan = m_iNumChannels;
582585

583586
defaultInfo.chs.clear();
@@ -598,3 +601,43 @@ FIFFLIB::FiffInfo FtConnector::infoFromSimpleHeader()
598601

599602
return defaultInfo;
600603
}
604+
605+
//=============================================================================================================
606+
607+
void FtConnector::checkForMissingMetadataFields(MetaData& data) const
608+
{
609+
if (!data.bFiffInfo){
610+
data.setFiffinfo(infoFromSimpleHeader());
611+
} else {
612+
if ( data.info.meas_date[0] == -1 )
613+
{
614+
data.info.meas_date[0] = static_cast<int32_t>(QDateTime::currentDateTime().toSecsSinceEpoch());
615+
data.info.meas_date[1] = 0;
616+
}
617+
618+
if ( data.info.sfreq <= 0 )
619+
{
620+
data.info.sfreq = m_fSamplingFreq;
621+
}
622+
if ( data.info.nchan == -1 )
623+
{
624+
data.info.nchan = m_iNumChannels;
625+
data.info.chs.clear();
626+
for (int chani = 0; chani< m_iNumChannels; chani++)
627+
{
628+
FIFFLIB::FiffChInfo channel;
629+
630+
channel.ch_name = "Ch. " + QString::number(chani);
631+
channel.kind = FIFFV_MEG_CH;
632+
channel.unit = FIFF_UNIT_T;
633+
channel.unit_mul = FIFF_UNITM_NONE;
634+
channel.chpos.coil_type = FIFFV_COIL_NONE;
635+
636+
data.info.chs.append(channel);
637+
638+
data.info.ch_names.append("Ch. " + QString::number(chani));
639+
640+
}
641+
}
642+
}
643+
}

applications/mne_scan/plugins/ftbuffer/ftconnector.h

+13-4
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ class FtConnector : public QObject
293293
* @param[out] buffer QBuffer to which daa will be written.
294294
* @param[in] numBytes How many bytes to read from socket.
295295
*/
296-
void copyAllChunks(QBuffer &buffer,
297-
int numBytes);
296+
void copyResponse(QBuffer &buffer,
297+
int numBytes);
298298

299299
//=========================================================================================================
300300
/**
@@ -310,7 +310,16 @@ class FtConnector : public QObject
310310
*
311311
* @return FiffInfo object based on filedtrip header
312312
*/
313-
FIFFLIB::FiffInfo infoFromSimpleHeader();
313+
FIFFLIB::FiffInfo infoFromSimpleHeader() const;
314+
315+
//=========================================================================================================
316+
/**
317+
* Checks for empty or invalid important fields in the parsed metadata and attempts to fill them.
318+
*
319+
* @param[in] data FiffInfo structure with information parsed from the FTBuffer headers.
320+
*
321+
*/
322+
void checkForMissingMetadataFields(MetaData& data) const;
314323

315324
int m_iMinSampleRead; /**< Number of samples that need to be added t obuffer before we try to read. */
316325
int m_iNumSamples; /**< Number of samples we've read from the buffer. */
@@ -323,7 +332,7 @@ class FtConnector : public QObject
323332

324333
bool m_bNewData; /**< Indicate whether we've received new data. */
325334

326-
float m_fSampleFreq; /**< Sampling frequency of data in the buffer. */
335+
float m_fSamplingFreq; /**< Sampling frequency of data in the buffer. */
327336

328337
QString m_sAddress; /**< Address where the ft buffer is found. */
329338

applications/mne_scan/plugins/ftbuffer/ftheaderparser.cpp

+19-34
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
//=============================================================================================================
3939

4040
#include "ftheaderparser.h"
41+
#include "fiff/fiff_ch_info.h"
42+
#include "fiff/fiff_constants.h"
4143

4244
//=============================================================================================================
4345
// QT INCLUDES
@@ -85,40 +87,23 @@ void parseChannelNamesHeader( MetaData& data, QBuffer& channelNamesBuffer)
8587

8688
// qInfo() << channelNames;
8789
FIFFLIB::FiffInfo info;
88-
info.clear();
89-
info.file_id =
90-
info.meas_id =
91-
info.meas_date[0] =
92-
info.meas_date[1] =
93-
94-
info.nchan =
95-
info.chs =
96-
info.ch_names =
97-
98-
info.sfreq =
99-
info.linefreq =
100-
101-
info.highpass =
102-
info.lowpass =
103-
104-
info.dig = dig;
105-
if (!dig_trans.isEmpty())
106-
info.dig_trans = dig_trans;
107-
108-
info.experimenter = experimenter;
109-
info.description = description;
110-
info.proj_id = proj_id;
111-
info.proj_name = proj_name;
112-
info.xplotter_layout = xplotter_layout;
113-
info.gantry_angle = gantry_angle;
114-
info.utc_offset = utc_offset;
115-
116-
info.bads = bads;
117-
info.projs = projs;
118-
info.comps = comps;
119-
info.acq_pars = acq_pars;
120-
info.acq_stim = acq_stim;
12190

91+
info.nchan = static_cast<FIFFLIB::fiff_int_t>(channelNames.size());
92+
93+
QList<FIFFLIB::FiffChInfo> chanList;
94+
for ( auto& name : channelNames)
95+
{
96+
FIFFLIB::FiffChInfo chanInfo;
97+
chanInfo.ch_name = name;
98+
chanInfo.kind = FIFFV_MEG_CH;
99+
chanInfo.unit = FIFF_UNIT_T;
100+
chanInfo.unit_mul = FIFF_UNITM_NONE;
101+
chanList.append(chanInfo);
102+
}
103+
info.chs = chanList;
104+
info.ch_names = channelNames;
105+
106+
data.setFiffinfo(info);
122107
}
123108

124109
//=============================================================================================================
@@ -185,7 +170,7 @@ FtHeaderParser::FtHeaderParser()
185170

186171
//=============================================================================================================
187172

188-
MetaData FtHeaderParser::parseHeader(QBuffer &buffer)
173+
MetaData FtHeaderParser::parseExtendedHeader(QBuffer &buffer)
189174
{
190175
MetaData data;
191176
while(!buffer.atEnd()){

applications/mne_scan/plugins/ftbuffer/ftheaderparser.h

+1-13
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,6 @@ struct FTBUFFER_EXPORT MetaData{
8787
bFiffDigitizerData = true;};
8888
};
8989

90-
//namespace {
91-
92-
//void parseChannelNamesHeader(MetaData& data, const QBuffer& neuromagBuffer);
93-
94-
//void parseNeuromagHeader(MetaData& data, QBuffer& neuromagBuffer);
95-
96-
//void parseIsotrakHeader(MetaData& data, QBuffer& isotrakBuffer);
97-
98-
//QStringList extractChannelNamesFromBuffer(QBuffer& buffer);
99-
100-
//} //namespace details
101-
10290
//=============================================================================================================
10391
/**
10492
* This class parses the extended header chunks of a fieldtrip buffer and returns measurement metadata.
@@ -125,7 +113,7 @@ class FTBUFFER_EXPORT FtHeaderParser{
125113
*
126114
* @return Returns MetaData object containing buffer/measurement metadata.
127115
*/
128-
MetaData parseHeader(QBuffer& buffer);
116+
MetaData parseExtendedHeader(QBuffer& buffer);
129117

130118
private:
131119
class Chunk

libraries/fiff/fiff_ch_info.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ FiffChInfo::FiffChInfo()
5656
, kind(0)
5757
, range(1.0f)
5858
, cal(1.0f)
59-
, coord_frame(FIFFV_COORD_UNKNOWN)
6059
, unit(0)
6160
, unit_mul(0)
6261
, ch_name(QString(""))
62+
, coord_frame(FIFFV_COORD_UNKNOWN)
6363
{
6464
coil_trans.setIdentity();
6565
}
@@ -73,12 +73,12 @@ FiffChInfo::FiffChInfo(const FiffChInfo &p_FiffChInfo)
7373
, range(p_FiffChInfo.range)
7474
, cal(p_FiffChInfo.cal)
7575
, chpos(p_FiffChInfo.chpos)
76-
, coil_trans(p_FiffChInfo.coil_trans)
77-
, eeg_loc(p_FiffChInfo.eeg_loc)
78-
, coord_frame(p_FiffChInfo.coord_frame)
7976
, unit(p_FiffChInfo.unit)
8077
, unit_mul(p_FiffChInfo.unit_mul)
8178
, ch_name(p_FiffChInfo.ch_name)
79+
, coil_trans(p_FiffChInfo.coil_trans)
80+
, eeg_loc(p_FiffChInfo.eeg_loc)
81+
, coord_frame(p_FiffChInfo.coord_frame)
8282
{
8383
}
8484

libraries/fiff/fiff_constants.h

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ namespace FIFFLIB
198198
#define FIFFV_COIL_KRISS_GRAD 9001 /**< KRISS gradiometer. */
199199
#define FIFFV_COIL_COMPUMEDICS_ADULT_GRAD 9101 /**< Compumedics adult gradiometer. */
200200
#define FIFFV_COIL_COMPUMEDICS_PEDIATRIC_GRAD 9102 /**< Compumedics pediatric gradiometer. */
201+
#define FIFFV_COIL_FIELDLINE_OPM 10001 /**< Fieldliine OPM magnetometer. */
201202

202203
#define FIFFM_IS_VV_COIL(c) ((c)/1000 == 3)
203204

0 commit comments

Comments
 (0)