From 34168f496c23f1dbeb1ab8aec9c1b68265d481ce Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Fri, 8 Aug 2025 17:18:15 +0100 Subject: [PATCH] Rotator Controller: Add line ending setting for GS-232 protocol. For #2486 --- .../gs232controller/gs232controllergui.cpp | 11 ++++++ .../gs232controller/gs232controllergui.h | 1 + .../gs232controller/gs232controllergui.ui | 39 ++++++++++++++++--- .../gs232controllersettings.cpp | 9 +++++ .../gs232controller/gs232controllersettings.h | 1 + .../feature/gs232controller/gs232protocol.cpp | 19 +++++++-- .../feature/gs232controller/gs232protocol.h | 1 + plugins/feature/gs232controller/readme.md | 22 +++++++---- 8 files changed, 87 insertions(+), 16 deletions(-) diff --git a/plugins/feature/gs232controller/gs232controllergui.cpp b/plugins/feature/gs232controller/gs232controllergui.cpp index 460a8279b..f375bd27c 100644 --- a/plugins/feature/gs232controller/gs232controllergui.cpp +++ b/plugins/feature/gs232controller/gs232controllergui.cpp @@ -491,6 +491,7 @@ void GS232ControllerGUI::displaySettings() ui->highSensitivity->setChecked(m_settings.m_highSensitivity); ui->enableTargetControl->setChecked(m_settings.m_targetControlEnabled); ui->enableOffsetControl->setChecked(m_settings.m_offsetControlEnabled); + ui->lineEnding->setCurrentIndex((int) m_settings.m_lineEnding); ui->dfmTrack->setChecked(m_settings.m_dfmTrackOn); ui->dfmLubePumps->setChecked(m_settings.m_dfmLubePumpsOn); ui->dfmBrakes->setChecked(m_settings.m_dfmBrakesOn); @@ -643,17 +644,20 @@ void GS232ControllerGUI::setProtocol(GS232ControllerSettings::Protocol protocol) ui->precision->setValue(0); ui->precision->setEnabled(false); ui->precisionLabel->setEnabled(false); + ui->lineEnding->setEnabled(true); } else if (protocol == GS232ControllerSettings::SPID) { ui->precision->setValue(1); ui->precision->setEnabled(false); ui->precisionLabel->setEnabled(false); + ui->lineEnding->setEnabled(false); } else { ui->precision->setEnabled(true); ui->precisionLabel->setEnabled(true); + ui->lineEnding->setEnabled(false); } bool dfm = protocol == GS232ControllerSettings::DFM; ui->dfmLine->setVisible(dfm); @@ -869,6 +873,12 @@ void GS232ControllerGUI::on_sources_currentTextChanged(const QString& text) applySetting("source"); } +void GS232ControllerGUI::on_lineEnding_currentIndexChanged(int index) +{ + m_settings.m_lineEnding = (GS232ControllerSettings::LineEnding)index; + applySetting("lineEnding"); +} + void GS232ControllerGUI::on_dfmTrack_clicked(bool checked) { m_settings.m_dfmTrackOn = checked; @@ -1004,6 +1014,7 @@ void GS232ControllerGUI::makeUIConnections() QObject::connect(ui->highSensitivity, &QToolButton::clicked, this, &GS232ControllerGUI::on_highSensitivity_clicked); QObject::connect(ui->enableTargetControl, &QToolButton::clicked, this, &GS232ControllerGUI::on_enableTargetControl_clicked); QObject::connect(ui->enableOffsetControl, &QToolButton::clicked, this, &GS232ControllerGUI::on_enableOffsetControl_clicked); + QObject::connect(ui->lineEnding, qOverload(&QComboBox::currentIndexChanged), this, &GS232ControllerGUI::on_lineEnding_currentIndexChanged); QObject::connect(ui->dfmTrack, &QToolButton::toggled, this, &GS232ControllerGUI::on_dfmTrack_clicked); QObject::connect(ui->dfmLubePumps, &QToolButton::toggled, this, &GS232ControllerGUI::on_dfmLubePumps_clicked); QObject::connect(ui->dfmBrakes, &QToolButton::toggled, this, &GS232ControllerGUI::on_dfmBrakes_clicked); diff --git a/plugins/feature/gs232controller/gs232controllergui.h b/plugins/feature/gs232controller/gs232controllergui.h index 4a7a36347..0d96019ce 100644 --- a/plugins/feature/gs232controller/gs232controllergui.h +++ b/plugins/feature/gs232controller/gs232controllergui.h @@ -125,6 +125,7 @@ private slots: void on_tolerance_valueChanged(double value); void on_precision_valueChanged(int value); void on_coordinates_currentIndexChanged(int index); + void on_lineEnding_currentIndexChanged(int index); void on_dfmTrack_clicked(bool checked=false); void on_dfmLubePumps_clicked(bool checked=false); void on_dfmBrakes_clicked(bool checked=false); diff --git a/plugins/feature/gs232controller/gs232controllergui.ui b/plugins/feature/gs232controller/gs232controllergui.ui index 2cf086935..97373c8ec 100644 --- a/plugins/feature/gs232controller/gs232controllergui.ui +++ b/plugins/feature/gs232controller/gs232controllergui.ui @@ -85,7 +85,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -107,7 +107,7 @@ Azimuth - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter @@ -146,7 +146,7 @@ - Qt::Vertical + Qt::Orientation::Vertical @@ -162,7 +162,7 @@ Elevation - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter @@ -240,7 +240,7 @@ - Qt::Horizontal + Qt::Orientation::Horizontal @@ -765,6 +765,35 @@ + + + + Character sequence to transmit at end of line + + + + CR/LF + + + + + CR + + + + + LF + + + + + + + + Line ending + + + diff --git a/plugins/feature/gs232controller/gs232controllersettings.cpp b/plugins/feature/gs232controller/gs232controllersettings.cpp index cfd169815..5c77c4d20 100644 --- a/plugins/feature/gs232controller/gs232controllersettings.cpp +++ b/plugins/feature/gs232controller/gs232controllersettings.cpp @@ -70,6 +70,7 @@ void GS232ControllerSettings::resetToDefaults() for (int i = 0; i < INPUTCONTROLLER_MAX_AXES; i++) { m_inputControllerSettings.m_deadzone[i] = 10.0f; } + m_lineEnding = CRLF; m_dfmTrackOn = false; m_dfmLubePumpsOn = false; m_dfmBrakesOn = false; @@ -129,6 +130,7 @@ QByteArray GS232ControllerSettings::serialize() const s.writeBool(37, m_targetControlEnabled); s.writeBool(38, m_offsetControlEnabled); s.writeBool(39, m_highSensitivity); + s.writeS32(40, m_lineEnding); s.writeFloat(50, m_inputControllerSettings.m_lowSensitivity); s.writeFloat(51, m_inputControllerSettings.m_highSensitivity); @@ -207,6 +209,7 @@ bool GS232ControllerSettings::deserialize(const QByteArray& data) d.readBool(37, &m_targetControlEnabled, true); d.readBool(38, &m_offsetControlEnabled, true); d.readBool(39, &m_highSensitivity, true); + d.readS32(40, (int *) &m_lineEnding, (int) CRLF); d.readFloat(50, &m_inputControllerSettings.m_lowSensitivity, 5.0f); d.readFloat(51, &m_inputControllerSettings.m_highSensitivity, 50.0f); @@ -312,6 +315,9 @@ void GS232ControllerSettings::applySettings(const QStringList& settingsKeys, con if (settingsKeys.contains("highSensitivity")) { m_highSensitivity = settings.m_highSensitivity; } + if (settingsKeys.contains("lineEnding")) { + m_lineEnding = settings.m_lineEnding; + } if (settingsKeys.contains("dfmTrackOn")) { m_dfmTrackOn = settings.m_dfmTrackOn; } @@ -430,6 +436,9 @@ QString GS232ControllerSettings::getDebugString(const QStringList& settingsKeys, if (settingsKeys.contains("highSensitivity") || force) { ostr << " m_highSensitivity: " << m_highSensitivity; } + if (settingsKeys.contains("lineEnding") || force) { + ostr << " m_lineEnding: " << m_lineEnding; + } if (settingsKeys.contains("title") || force) { ostr << " m_title: " << m_title.toStdString(); } diff --git a/plugins/feature/gs232controller/gs232controllersettings.h b/plugins/feature/gs232controller/gs232controllersettings.h index 438b3d2d2..8dd420fed 100644 --- a/plugins/feature/gs232controller/gs232controllersettings.h +++ b/plugins/feature/gs232controller/gs232controllersettings.h @@ -54,6 +54,7 @@ struct GS232ControllerSettings bool m_targetControlEnabled; bool m_offsetControlEnabled; bool m_highSensitivity; + enum LineEnding { CRLF, CR, LF } m_lineEnding; // GS232 only bool m_dfmTrackOn; bool m_dfmLubePumpsOn; diff --git a/plugins/feature/gs232controller/gs232protocol.cpp b/plugins/feature/gs232controller/gs232protocol.cpp index 97851e97e..9b99595a9 100644 --- a/plugins/feature/gs232controller/gs232protocol.cpp +++ b/plugins/feature/gs232controller/gs232protocol.cpp @@ -28,7 +28,7 @@ GS232Protocol::GS232Protocol() void GS232Protocol::setAzimuth(float azimuth) { - QString cmd = QString("M%1\r\n").arg((int)std::round(azimuth), 3, 10, QLatin1Char('0')); + QString cmd = QString("M%1%2").arg((int)std::round(azimuth), 3, 10, QLatin1Char('0')).arg(lineEnding()); QByteArray data = cmd.toLatin1(); m_device->write(data); m_lastAzimuth = azimuth; @@ -36,7 +36,7 @@ void GS232Protocol::setAzimuth(float azimuth) void GS232Protocol::setAzimuthElevation(float azimuth, float elevation) { - QString cmd = QString("W%1 %2\r\n").arg((int)std::round(azimuth), 3, 10, QLatin1Char('0')).arg((int)std::round(elevation), 3, 10, QLatin1Char('0')); + QString cmd = QString("W%1 %2%3").arg((int)std::round(azimuth), 3, 10, QLatin1Char('0')).arg((int)std::round(elevation), 3, 10, QLatin1Char('0')).arg(lineEnding()); QByteArray data = cmd.toLatin1(); m_device->write(data); ControllerProtocol::setAzimuthElevation(azimuth, elevation); @@ -94,7 +94,18 @@ void GS232Protocol::readData() // Request current Az/El from controller void GS232Protocol::update() { - QByteArray cmd("C2\r\n"); - m_device->write(cmd); + QString cmd = QString("C2%1").arg(lineEnding()); + QByteArray data = cmd.toLatin1(); + m_device->write(data); } +QString GS232Protocol::lineEnding() const +{ + if (m_settings.m_lineEnding == GS232ControllerSettings::CRLF) { + return "\r\n"; + } else if (m_settings.m_lineEnding == GS232ControllerSettings::CR) { + return "\r"; + } else { + return "\n"; + } +} diff --git a/plugins/feature/gs232controller/gs232protocol.h b/plugins/feature/gs232controller/gs232protocol.h index a97203b9b..83e03978a 100644 --- a/plugins/feature/gs232controller/gs232protocol.h +++ b/plugins/feature/gs232controller/gs232protocol.h @@ -31,6 +31,7 @@ public: void setAzimuthElevation(float azimuth, float elevation) override; void readData() override; void update() override; + QString lineEnding() const; }; #endif // INCLUDE_FEATURE_GS232PROTOCOL_H_ diff --git a/plugins/feature/gs232controller/readme.md b/plugins/feature/gs232controller/readme.md index 339c4f86f..a26d5e25e 100644 --- a/plugins/feature/gs232controller/readme.md +++ b/plugins/feature/gs232controller/readme.md @@ -107,7 +107,15 @@ Specifies the coordinate system used by the GUI for entry and display of the pos Equations for translating between these coordinate systems can be found [here](https://ntrs.nasa.gov/citations/19670030005). -

22: Input Control

+

22: Line Ending

+ +For the GS-232 protocol only, sets the control characters that are transmitted after each command: + +* CRLF - "\r\n" +* CR - "\r" +* LF - "\n" + +

23: Input Control

Specifies a controller/gamepad that can be used to specify target coordinates or azimuth and elevation offset. @@ -130,21 +138,21 @@ On Linux, using Qt Gamepad with the evdev backend, all joysticks & gamepads appe If using a joystick which only has 2 axes, whether it corresponds to the left or right stick can be configured by pressing the 'Config...' button. On Linux, the [xone driver](https://github.com/medusalix/xone) has support for the Xbox Wireless Controller, that isn't supported by the older xpad driver that is included with Ubuntu. -

23: High or Low Sensitivity

+

24: High or Low Sensitivity

Specifies High (H) or Low (L) Sensitivity mode. This is how fast coordinates will change for a given control stick movement. High Sensitivity is used for coarse target/offset adjustment, whereas Low sensitivity is used for fine target/offset adjustment. -The sensitivity in each mode can be set in the Input Configuration Dialog (22). +The sensitivity in each mode can be set in the Input Configuration Dialog (23). -

24: (T) Enable Target Control

+

25: (T) Enable Target Control

When checked, the target coordinates can be set with the input controller. When unchecked, the axes controlling the target will be ignored. -

25: (O) Enable Offset Control

+

26: (O) Enable Offset Control

When checked, the offset coordinates can be set with the input controller. When unchecked, the axes controlling the offset will be ignored. -

26: Input Control Configuration

+

27: Input Control Configuration

Pressing the Config... button will display the Input Configuration Dialog: @@ -160,7 +168,7 @@ when a stick is centered, but is reporting a non-zero position on the axis.

3: Sensitivity

-Specifies the sensitivity of the input in Low and High Sensitivity mode (23). The higher the value, the faster coordinates will change for a given control stick movement. +Specifies the sensitivity of the input in Low and High Sensitivity mode (24). The higher the value, the faster coordinates will change for a given control stick movement.

Protocol Implementations