Skip to content

Commit

Permalink
add unnamed namespaces and implement filename chunk parser from ftbuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
juangpc committed Sep 29, 2021
1 parent f17a9bf commit aba68a9
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 57 deletions.
47 changes: 45 additions & 2 deletions applications/mne_scan/plugins/ftbuffer/ftconnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,14 @@ BufferInfo FtConnector::getBufferInfo()

//=============================================================================================================

FIFFLIB::FiffInfo FtConnector::infoFromSimpleHeader()
FIFFLIB::FiffInfo FtConnector::infoFromSimpleHeader() const
{
FIFFLIB::FiffInfo defaultInfo;

defaultInfo.sfreq = m_fSampleFreq;
defaultInfo.meas_date[0] = static_cast<int32_t>(QDateTime::currentDateTime().toSecsSinceEpoch());
defaultInfo.meas_date[1] = 0;

defaultInfo.sfreq = m_fSamplingFreq;
defaultInfo.nchan = m_iNumChannels;

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

return defaultInfo;
}

//=============================================================================================================

void FtConnector::checkForMissingMetadataFields(MetaData& data) const
{
if (!data.bFiffInfo){
data.setFiffinfo(infoFromSimpleHeader());
} else {
if ( data.info.meas_date[0] == -1 )
{
data.info.meas_date[0] = static_cast<int32_t>(QDateTime::currentDateTime().toSecsSinceEpoch());
data.info.meas_date[1] = 0;
}

if ( data.info.sfreq <= 0 )
{
data.info.sfreq = m_fSamplingFreq;
}
if ( data.info.nchan == -1 )
{
data.info.nchan = m_iNumChannels;
data.info.chs.clear();
for (int chani = 0; chani< m_iNumChannels; chani++)
{
FIFFLIB::FiffChInfo channel;

channel.ch_name = "Ch. " + QString::number(chani);
channel.kind = FIFFV_MEG_CH;
channel.unit = FIFF_UNIT_T;
channel.unit_mul = FIFF_UNITM_NONE;
channel.chpos.coil_type = FIFFV_COIL_NONE;

data.info.chs.append(channel);

data.info.ch_names.append("Ch. " + QString::number(chani));

}
}
}
}
17 changes: 13 additions & 4 deletions applications/mne_scan/plugins/ftbuffer/ftconnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ class FtConnector : public QObject
* @param[out] buffer QBuffer to which daa will be written.
* @param[in] numBytes How many bytes to read from socket.
*/
void copyAllChunks(QBuffer &buffer,
int numBytes);
void copyResponse(QBuffer &buffer,
int numBytes);

//=========================================================================================================
/**
Expand All @@ -310,7 +310,16 @@ class FtConnector : public QObject
*
* @return FiffInfo object based on filedtrip header
*/
FIFFLIB::FiffInfo infoFromSimpleHeader();
FIFFLIB::FiffInfo infoFromSimpleHeader() const;

//=========================================================================================================
/**
* Checks for empty or invalid important fields in the parsed metadata and attempts to fill them.
*
* @param[in] data FiffInfo structure with information parsed from the FTBuffer headers.
*
*/
void checkForMissingMetadataFields(MetaData& data) const;

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

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

float m_fSampleFreq; /**< Sampling frequency of data in the buffer. */
float m_fSamplingFreq; /**< Sampling frequency of data in the buffer. */

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

Expand Down
53 changes: 19 additions & 34 deletions applications/mne_scan/plugins/ftbuffer/ftheaderparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
//=============================================================================================================

#include "ftheaderparser.h"
#include "fiff/fiff_ch_info.h"
#include "fiff/fiff_constants.h"

//=============================================================================================================
// QT INCLUDES
Expand Down Expand Up @@ -85,40 +87,23 @@ void parseChannelNamesHeader( MetaData& data, QBuffer& channelNamesBuffer)

// qInfo() << channelNames;
FIFFLIB::FiffInfo info;
info.clear();
info.file_id =
info.meas_id =
info.meas_date[0] =
info.meas_date[1] =

info.nchan =
info.chs =
info.ch_names =

info.sfreq =
info.linefreq =

info.highpass =
info.lowpass =

info.dig = dig;
if (!dig_trans.isEmpty())
info.dig_trans = dig_trans;

info.experimenter = experimenter;
info.description = description;
info.proj_id = proj_id;
info.proj_name = proj_name;
info.xplotter_layout = xplotter_layout;
info.gantry_angle = gantry_angle;
info.utc_offset = utc_offset;

info.bads = bads;
info.projs = projs;
info.comps = comps;
info.acq_pars = acq_pars;
info.acq_stim = acq_stim;

info.nchan = static_cast<FIFFLIB::fiff_int_t>(channelNames.size());

QList<FIFFLIB::FiffChInfo> chanList;
for ( auto& name : channelNames)
{
FIFFLIB::FiffChInfo chanInfo;
chanInfo.ch_name = name;
chanInfo.kind = FIFFV_MEG_CH;
chanInfo.unit = FIFF_UNIT_T;
chanInfo.unit_mul = FIFF_UNITM_NONE;
chanList.append(chanInfo);
}
info.chs = chanList;
info.ch_names = channelNames;

data.setFiffinfo(info);
}

//=============================================================================================================
Expand Down Expand Up @@ -185,7 +170,7 @@ FtHeaderParser::FtHeaderParser()

//=============================================================================================================

MetaData FtHeaderParser::parseHeader(QBuffer &buffer)
MetaData FtHeaderParser::parseExtendedHeader(QBuffer &buffer)
{
MetaData data;
while(!buffer.atEnd()){
Expand Down
14 changes: 1 addition & 13 deletions applications/mne_scan/plugins/ftbuffer/ftheaderparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,6 @@ struct FTBUFFER_EXPORT MetaData{
bFiffDigitizerData = true;};
};

//namespace {

//void parseChannelNamesHeader(MetaData& data, const QBuffer& neuromagBuffer);

//void parseNeuromagHeader(MetaData& data, QBuffer& neuromagBuffer);

//void parseIsotrakHeader(MetaData& data, QBuffer& isotrakBuffer);

//QStringList extractChannelNamesFromBuffer(QBuffer& buffer);

//} //namespace details

//=============================================================================================================
/**
* This class parses the extended header chunks of a fieldtrip buffer and returns measurement metadata.
Expand All @@ -125,7 +113,7 @@ class FTBUFFER_EXPORT FtHeaderParser{
*
* @return Returns MetaData object containing buffer/measurement metadata.
*/
MetaData parseHeader(QBuffer& buffer);
MetaData parseExtendedHeader(QBuffer& buffer);

private:
class Chunk
Expand Down
8 changes: 4 additions & 4 deletions libraries/fiff/fiff_ch_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ FiffChInfo::FiffChInfo()
, kind(0)
, range(1.0f)
, cal(1.0f)
, coord_frame(FIFFV_COORD_UNKNOWN)
, unit(0)
, unit_mul(0)
, ch_name(QString(""))
, coord_frame(FIFFV_COORD_UNKNOWN)
{
coil_trans.setIdentity();
}
Expand All @@ -73,12 +73,12 @@ FiffChInfo::FiffChInfo(const FiffChInfo &p_FiffChInfo)
, range(p_FiffChInfo.range)
, cal(p_FiffChInfo.cal)
, chpos(p_FiffChInfo.chpos)
, coil_trans(p_FiffChInfo.coil_trans)
, eeg_loc(p_FiffChInfo.eeg_loc)
, coord_frame(p_FiffChInfo.coord_frame)
, unit(p_FiffChInfo.unit)
, unit_mul(p_FiffChInfo.unit_mul)
, ch_name(p_FiffChInfo.ch_name)
, coil_trans(p_FiffChInfo.coil_trans)
, eeg_loc(p_FiffChInfo.eeg_loc)
, coord_frame(p_FiffChInfo.coord_frame)
{
}

Expand Down
1 change: 1 addition & 0 deletions libraries/fiff/fiff_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ namespace FIFFLIB
#define FIFFV_COIL_KRISS_GRAD 9001 /**< KRISS gradiometer. */
#define FIFFV_COIL_COMPUMEDICS_ADULT_GRAD 9101 /**< Compumedics adult gradiometer. */
#define FIFFV_COIL_COMPUMEDICS_PEDIATRIC_GRAD 9102 /**< Compumedics pediatric gradiometer. */
#define FIFFV_COIL_FIELDLINE_OPM 10001 /**< Fieldliine OPM magnetometer. */

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

Expand Down

0 comments on commit aba68a9

Please sign in to comment.