v2.0.0
Loading...
Searching...
No Matches
polhemus_connection.h
Go to the documentation of this file.
1//=============================================================================================================
29
30#ifndef UTILS_POLHEMUS_CONNECTION_H
31#define UTILS_POLHEMUS_CONNECTION_H
32
33//=============================================================================================================
34// INCLUDES
35//=============================================================================================================
36
37#include "../utils_global.h"
38#include "fastrak_parser.h"
39
40//=============================================================================================================
41// QT INCLUDES
42//=============================================================================================================
43
44#include <QObject>
45#include <QQuaternion>
46#include <QSerialPort>
47#include <QSerialPortInfo>
48#include <QString>
49#include <QStringList>
50#include <QTimer>
51#include <QVector3D>
52
53//=============================================================================================================
54// DEFINE NAMESPACE UTILSLIB
55//=============================================================================================================
56
57namespace UTILSLIB
58{
59
60//=============================================================================================================
67{
68 int baudRate = 115200;
75 QVector3D hemisphere = QVector3D(0, 0, 0);
79 QByteArray streamCommand = QByteArrayLiteral("C\r");
80};
81
82//=============================================================================================================
89{
90 Q_OBJECT
91
92public:
93 explicit PolhemusConnection(QObject* parent = nullptr);
94 ~PolhemusConnection() override;
95
105 bool open(const QString& portName,
107
109 void close();
110
111 bool isConnected() const;
112 QString backendName() const;
113
114 //=========================================================================================================
125 static QStringList availablePorts();
126
127 //=========================================================================================================
139 static QString autoDetectPortName();
140
141signals:
147 void pointReceived(int station, const QVector3D& position, const QQuaternion& orientation);
148
151
153 void errorOccurred(const QString& message);
154
163 void penButtonPressed(int station, const QVector3D& position, const QQuaternion& orientation);
164
165private slots:
166 void onMockTick();
167 void onSerialReadyRead();
168 void onSerialError(QSerialPort::SerialPortError err);
169 void onStreamPauseTimeout();
170
171private:
172 bool openMock();
173 void closeMock();
174
175 bool openSerial(const QString& portName, const PolhemusSerialConfig& cfg);
176 void closeSerial();
177 void drainParser();
178
179 bool m_isConnected = false;
180 QString m_backendName;
181
182 // Mock backend ------------------------------------------------------------
183 QTimer m_mockTimer;
184 int m_mockSampleIdx = 0;
185
186 // Serial backend ----------------------------------------------------------
187 QSerialPort* m_pSerial = nullptr;
188 FastrakParser m_parser;
189
190 // Pen-button detection (stream-pause timeout) -----------------------------
191 QTimer m_streamPauseTimer;
192 struct StationSample
193 {
194 QVector3D position;
195 QQuaternion orientation;
196 };
197 QMap<int, StationSample> m_lastSamples;
198};
199
200} // namespace UTILSLIB
201
202#endif // UTILS_POLHEMUS_CONNECTION_H
Polhemus Fastrak / FastSCAN ASCII record parser.
Public umbrella header for UTILSLIB exposing the UTILSSHARED_EXPORT macro and build-info accessors.
#define UTILSSHARED_EXPORT
Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms).
Streaming parser for Fastrak / FastSCAN ASCII records.
@ Inches
Fastrak factory default.
Settings used to open a real Polhemus serial connection.
void connectedChanged(bool isConnected)
void penButtonPressed(int station, const QVector3D &position, const QQuaternion &orientation)
void pointReceived(int station, const QVector3D &position, const QQuaternion &orientation)
PolhemusConnection(QObject *parent=nullptr)
void errorOccurred(const QString &message)
bool open(const QString &portName, const PolhemusSerialConfig &cfg=PolhemusSerialConfig{})
static QString autoDetectPortName()
Best-effort auto-detection of an attached Fastrak/FastSCAN.
static QStringList availablePorts()
Enumerate every serial port currently visible to the OS.