FastrakParser
Namespace: UTILSLIB · Library: Utilities Library
#include <utils/fastrak_parser.h>
class UTILSLIB::FastrakParser
Streaming parser for Fastrak / FastSCAN ASCII records.
Thread-affine: the caller is responsible for serialising calls. No heap allocations on the hot path other than the internal buffer.
FastrakParser parser;
parser.setUnits(FastrakParser::Units::Centimetres);
parser.append("01 12.50 -3.25 8.00\r\n02 1.0"); // the second record is still incomplete
FastrakSample sample;
const bool complete = parser.nextSample(sample);
const bool pending = parser.nextSample(sample);
Public Methods
FastrakParser()
setUnits(units)
Configure the linear unit reported by the device.
Parameters:
- units : Units Unit of incoming positions; samples are converted to metres.
units()
append(chunk)
Append raw bytes received from the serial port.
Parameters:
- chunk : const QByteArray & Raw bytes to append to the internal buffer; may contain partial records.
nextSample(out)
Pop the next fully-decoded sample, if any.
Parameters:
- out : FastrakSample & Receives the decoded sample; malformed lines are skipped.
Returns:
- bool — true when
outwas populated; false when the buffer does not yet contain a complete record.
reset()
Reset accumulated buffer state.
Static Methods
parseRecord(record, units, out)
Parse one record line (without trailing CR/LF) — exposed for unit tests and for callers that pre-frame their data.
Parameters:
-
record : const QByteArray & One ASCII record: station, x, y, z, and optional Euler angles or quaternion.
-
units : Units Unit of the positions in
record. -
out : FastrakSample & Receives the decoded sample with the position in metres.
Returns:
- bool — true on success; false on malformed input.
Example
- Full source:
src/examples/ex_utils/main.cpp - Build target:
ex_utils(runs under CTest)
Used in examples
ex_utils
Utilities library: buffers, observers, logging, file formats, montages, layouts and reports.
FastrakParser parser;
parser.setUnits(FastrakParser::Units::Centimetres);
parser.append("01 12.50 -3.25 8.00\r\n02 1.0"); // the second record is still incomplete
FastrakSample sample;
const bool complete = parser.nextSample(sample);
const bool pending = parser.nextSample(sample);
ok &= expect(complete && !pending && sample.station == 1 && std::fabs(sample.position.x() - 0.125f) < 1e-6f && std::fabs(sample.position.y() + 0.0325f) < 1e-6f,
"FastrakParser converts centimetres to metres and waits for the partial record");
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>