| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2020 Jon Beniston, M7RCE                                        //
 | 
					
						
							|  |  |  | // Copyright (C) 2020 Edouard Griffiths, F4EXB                                   //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							|  |  |  | // (at your option) any later version.                                           //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-27 17:03:54 +00:00
										 |  |  | #include <cmath>
 | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | #include <QMessageBox>
 | 
					
						
							|  |  |  | #include <QSerialPortInfo>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  | #include "SWGTargetAzimuthElevation.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | #include "feature/featureuiset.h"
 | 
					
						
							|  |  |  | #include "gui/basicfeaturesettingsdialog.h"
 | 
					
						
							|  |  |  | #include "mainwindow.h"
 | 
					
						
							|  |  |  | #include "device/deviceuiset.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ui_gs232controllergui.h"
 | 
					
						
							|  |  |  | #include "gs232controller.h"
 | 
					
						
							|  |  |  | #include "gs232controllergui.h"
 | 
					
						
							|  |  |  | #include "gs232controllerreport.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GS232ControllerGUI* GS232ControllerGUI::create(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     GS232ControllerGUI* gui = new GS232ControllerGUI(pluginAPI, featureUISet, feature); | 
					
						
							|  |  |  |     return gui; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::destroy() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     delete this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::resetToDefaults() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.resetToDefaults(); | 
					
						
							|  |  |  |     displaySettings(); | 
					
						
							|  |  |  |     applySettings(true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QByteArray GS232ControllerGUI::serialize() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_settings.serialize(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool GS232ControllerGUI::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_settings.deserialize(data)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         displaySettings(); | 
					
						
							|  |  |  |         applySettings(true); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         resetToDefaults(); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool GS232ControllerGUI::handleMessage(const Message& message) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (GS232Controller::MsgConfigureGS232Controller::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         qDebug("GS232ControllerGUI::handleMessage: GS232Controller::MsgConfigureGS232Controller"); | 
					
						
							|  |  |  |         const GS232Controller::MsgConfigureGS232Controller& cfg = (GS232Controller::MsgConfigureGS232Controller&) message; | 
					
						
							|  |  |  |         m_settings = cfg.getSettings(); | 
					
						
							|  |  |  |         blockApplySettings(true); | 
					
						
							|  |  |  |         displaySettings(); | 
					
						
							|  |  |  |         blockApplySettings(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |     else if (PipeEndPoint::MsgReportPipes::match(message)) | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |         PipeEndPoint::MsgReportPipes& report = (PipeEndPoint::MsgReportPipes&) message; | 
					
						
							|  |  |  |         m_availablePipes = report.getAvailablePipes(); | 
					
						
							|  |  |  |         updatePipeList(); | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     else if (GS232ControllerReport::MsgReportAzAl::match(message)) | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         GS232ControllerReport::MsgReportAzAl& azAl = (GS232ControllerReport::MsgReportAzAl&) message; | 
					
						
							| 
									
										
										
										
											2021-05-30 12:38:07 +01:00
										 |  |  |         ui->azimuthCurrentText->setText(QString("%1").arg(azAl.getAzimuth())); | 
					
						
							|  |  |  |         ui->elevationCurrentText->setText(QString("%1").arg(azAl.getElevation())); | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (MainCore::MsgTargetAzimuthElevation::match(message)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MainCore::MsgTargetAzimuthElevation& msg = (MainCore::MsgTargetAzimuthElevation&) message; | 
					
						
							|  |  |  |         SWGSDRangel::SWGTargetAzimuthElevation *swgTarget = msg.getSWGTargetAzimuthElevation(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ui->azimuth->setValue(round(swgTarget->getAzimuth())); | 
					
						
							|  |  |  |         ui->elevation->setValue(round(swgTarget->getElevation())); | 
					
						
							|  |  |  |         ui->targetName->setText(*swgTarget->getName()); | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::handleInputMessages() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Message* message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     while ((message = getInputMessageQueue()->pop())) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (handleMessage(*message)) { | 
					
						
							|  |  |  |             delete message; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::onWidgetRolled(QWidget* widget, bool rollDown) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     (void) widget; | 
					
						
							|  |  |  |     (void) rollDown; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GS232ControllerGUI::GS232ControllerGUI(PluginAPI* pluginAPI, FeatureUISet *featureUISet, Feature *feature, QWidget* parent) : | 
					
						
							|  |  |  |     FeatureGUI(parent), | 
					
						
							|  |  |  |     ui(new Ui::GS232ControllerGUI), | 
					
						
							|  |  |  |     m_pluginAPI(pluginAPI), | 
					
						
							|  |  |  |     m_featureUISet(featureUISet), | 
					
						
							|  |  |  |     m_doApplySettings(true), | 
					
						
							| 
									
										
										
										
											2021-10-05 14:03:31 +01:00
										 |  |  |     m_lastFeatureState(0), | 
					
						
							|  |  |  |     m_lastOnTarget(false) | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     ui->setupUi(this); | 
					
						
							|  |  |  |     setAttribute(Qt::WA_DeleteOnClose, true); | 
					
						
							|  |  |  |     setChannelWidget(false); | 
					
						
							|  |  |  |     connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); | 
					
						
							|  |  |  |     m_gs232Controller = reinterpret_cast<GS232Controller*>(feature); | 
					
						
							|  |  |  |     m_gs232Controller->setMessageQueueToGUI(&m_inputMessageQueue); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_featureUISet->addRollupWidget(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &))); | 
					
						
							|  |  |  |     connect(getInputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     connect(&m_statusTimer, SIGNAL(timeout()), this, SLOT(updateStatus())); | 
					
						
							| 
									
										
										
										
											2021-10-05 14:03:31 +01:00
										 |  |  |     m_statusTimer.start(250); | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-30 12:38:07 +01:00
										 |  |  |     ui->azimuthCurrentText->setText("-"); | 
					
						
							|  |  |  |     ui->elevationCurrentText->setText("-"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     updateSerialPortList(); | 
					
						
							|  |  |  |     displaySettings(); | 
					
						
							|  |  |  |     applySettings(true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GS232ControllerGUI::~GS232ControllerGUI() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     delete ui; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::blockApplySettings(bool block) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_doApplySettings = !block; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::displaySettings() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     setTitleColor(m_settings.m_rgbColor); | 
					
						
							|  |  |  |     setWindowTitle(m_settings.m_title); | 
					
						
							|  |  |  |     blockApplySettings(true); | 
					
						
							|  |  |  |     ui->azimuth->setValue(m_settings.m_azimuth); | 
					
						
							|  |  |  |     ui->elevation->setValue(m_settings.m_elevation); | 
					
						
							| 
									
										
										
										
											2021-05-30 12:38:07 +01:00
										 |  |  |     ui->protocol->setCurrentIndex((int)m_settings.m_protocol); | 
					
						
							|  |  |  |     updateDecimals(m_settings.m_protocol); | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     if (m_settings.m_serialPort.length() > 0) | 
					
						
							|  |  |  |         ui->serialPort->lineEdit()->setText(m_settings.m_serialPort); | 
					
						
							|  |  |  |     ui->baudRate->setCurrentText(QString("%1").arg(m_settings.m_baudRate)); | 
					
						
							|  |  |  |     ui->track->setChecked(m_settings.m_track); | 
					
						
							| 
									
										
										
										
											2021-10-03 23:15:15 +02:00
										 |  |  |     ui->sources->setCurrentIndex(ui->sources->findText(m_settings.m_source)); | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |     ui->azimuthOffset->setValue(m_settings.m_azimuthOffset); | 
					
						
							|  |  |  |     ui->elevationOffset->setValue(m_settings.m_elevationOffset); | 
					
						
							| 
									
										
										
										
											2021-02-26 20:27:35 +00:00
										 |  |  |     ui->azimuthMin->setValue(m_settings.m_azimuthMin); | 
					
						
							|  |  |  |     ui->azimuthMax->setValue(m_settings.m_azimuthMax); | 
					
						
							|  |  |  |     ui->elevationMin->setValue(m_settings.m_elevationMin); | 
					
						
							|  |  |  |     ui->elevationMax->setValue(m_settings.m_elevationMax); | 
					
						
							| 
									
										
										
										
											2021-10-05 14:03:31 +01:00
										 |  |  |     ui->tolerance->setValue(m_settings.m_tolerance); | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     blockApplySettings(false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::updateSerialPortList() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ui->serialPort->clear(); | 
					
						
							|  |  |  |     QList<QSerialPortInfo> serialPorts = QSerialPortInfo::availablePorts(); | 
					
						
							|  |  |  |     QListIterator<QSerialPortInfo> i(serialPorts); | 
					
						
							|  |  |  |     while (i.hasNext()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QSerialPortInfo info = i.next(); | 
					
						
							|  |  |  |         ui->serialPort->addItem(info.portName()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  | void GS232ControllerGUI::updatePipeList() | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-10-03 23:15:15 +02:00
										 |  |  |     QString currentText = ui->sources->currentText(); | 
					
						
							|  |  |  |     ui->sources->blockSignals(true); | 
					
						
							|  |  |  |     ui->sources->clear(); | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |     QList<PipeEndPoint::AvailablePipeSource>::const_iterator it = m_availablePipes.begin(); | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |     for (int i = 0; it != m_availablePipes.end(); ++it, i++) | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-10-03 23:15:15 +02:00
										 |  |  |         ui->sources->addItem(it->getName()); | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |     if (currentText.isEmpty()) | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-10-12 12:10:12 +01:00
										 |  |  |         // Source feature may be loaded after this, so may not have existed when
 | 
					
						
							|  |  |  |         // displaySettings was called
 | 
					
						
							|  |  |  |         if (m_availablePipes.size() > 0) { | 
					
						
							|  |  |  |             ui->sources->setCurrentIndex(ui->sources->findText(m_settings.m_source)); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2021-10-03 23:15:15 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         ui->sources->setCurrentIndex(ui->sources->findText(currentText)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ui->sources->blockSignals(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString newText = ui->sources->currentText(); | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |     if (currentText != newText) | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-10-03 23:15:15 +02:00
										 |  |  |        m_settings.m_source = newText; | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |        ui->targetName->setText(""); | 
					
						
							|  |  |  |        applySettings(); | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::leaveEvent(QEvent*) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::enterEvent(QEvent*) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::onMenuDialogCalled(const QPoint &p) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_contextMenuType == ContextMenuChannelSettings) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         BasicFeatureSettingsDialog dialog(this); | 
					
						
							|  |  |  |         dialog.setTitle(m_settings.m_title); | 
					
						
							|  |  |  |         dialog.setColor(m_settings.m_rgbColor); | 
					
						
							|  |  |  |         dialog.setUseReverseAPI(m_settings.m_useReverseAPI); | 
					
						
							|  |  |  |         dialog.setReverseAPIAddress(m_settings.m_reverseAPIAddress); | 
					
						
							|  |  |  |         dialog.setReverseAPIPort(m_settings.m_reverseAPIPort); | 
					
						
							|  |  |  |         dialog.setReverseAPIFeatureSetIndex(m_settings.m_reverseAPIFeatureSetIndex); | 
					
						
							|  |  |  |         dialog.setReverseAPIFeatureIndex(m_settings.m_reverseAPIFeatureIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dialog.move(p); | 
					
						
							|  |  |  |         dialog.exec(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_settings.m_rgbColor = dialog.getColor().rgb(); | 
					
						
							|  |  |  |         m_settings.m_title = dialog.getTitle(); | 
					
						
							|  |  |  |         m_settings.m_useReverseAPI = dialog.useReverseAPI(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIPort = dialog.getReverseAPIPort(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIFeatureSetIndex = dialog.getReverseAPIFeatureSetIndex(); | 
					
						
							|  |  |  |         m_settings.m_reverseAPIFeatureIndex = dialog.getReverseAPIFeatureIndex(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         setWindowTitle(m_settings.m_title); | 
					
						
							|  |  |  |         setTitleColor(m_settings.m_rgbColor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         applySettings(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     resetContextMenuType(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::on_startStop_toggled(bool checked) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_doApplySettings) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         GS232Controller::MsgStartStop *message = GS232Controller::MsgStartStop::create(checked); | 
					
						
							|  |  |  |         m_gs232Controller->getInputMessageQueue()->push(message); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-30 12:38:07 +01:00
										 |  |  | void GS232ControllerGUI::updateDecimals(GS232ControllerSettings::Protocol protocol) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (protocol == GS232ControllerSettings::GS232) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ui->azimuth->setDecimals(0); | 
					
						
							|  |  |  |         ui->elevation->setDecimals(0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ui->azimuth->setDecimals(1); | 
					
						
							|  |  |  |         ui->elevation->setDecimals(1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::on_protocol_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.m_protocol = (GS232ControllerSettings::Protocol)index; | 
					
						
							|  |  |  |     updateDecimals(m_settings.m_protocol); | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | void GS232ControllerGUI::on_serialPort_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-14 11:13:32 +01:00
										 |  |  |     (void) index; | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     m_settings.m_serialPort = ui->serialPort->currentText(); | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::on_baudRate_currentIndexChanged(int index) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-14 11:13:32 +01:00
										 |  |  |     (void) index; | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     m_settings.m_baudRate = ui->baudRate->currentText().toInt(); | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-30 12:38:07 +01:00
										 |  |  | void GS232ControllerGUI::on_azimuth_valueChanged(double value) | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-30 12:38:07 +01:00
										 |  |  |     m_settings.m_azimuth = (float)value; | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |     ui->targetName->setText(""); | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-30 12:38:07 +01:00
										 |  |  | void GS232ControllerGUI::on_elevation_valueChanged(double value) | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-05-30 12:38:07 +01:00
										 |  |  |     m_settings.m_elevation = (float)value; | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |     ui->targetName->setText(""); | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::on_azimuthOffset_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.m_azimuthOffset = value; | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::on_elevationOffset_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.m_elevationOffset = value; | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-26 20:27:35 +00:00
										 |  |  | void GS232ControllerGUI::on_azimuthMin_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.m_azimuthMin = value; | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::on_azimuthMax_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.m_azimuthMax = value; | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::on_elevationMin_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.m_elevationMin = value; | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::on_elevationMax_valueChanged(int value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.m_elevationMax = value; | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 14:03:31 +01:00
										 |  |  | void GS232ControllerGUI::on_tolerance_valueChanged(double value) | 
					
						
							| 
									
										
										
										
											2021-05-30 12:38:07 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     m_settings.m_tolerance = value; | 
					
						
							|  |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | void GS232ControllerGUI::on_track_stateChanged(int state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     m_settings.m_track = state == Qt::Checked; | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |     ui->targetsLabel->setEnabled(m_settings.m_track); | 
					
						
							| 
									
										
										
										
											2021-10-03 23:15:15 +02:00
										 |  |  |     ui->sources->setEnabled(m_settings.m_track); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!m_settings.m_track) { | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |         ui->targetName->setText(""); | 
					
						
							| 
									
										
										
										
											2021-10-03 23:15:15 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-03 23:15:15 +02:00
										 |  |  | void GS232ControllerGUI::on_sources_currentTextChanged(const QString& text) | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-10-03 23:15:15 +02:00
										 |  |  |     qDebug("GS232ControllerGUI::on_sources_currentTextChanged: %s", qPrintable(text)); | 
					
						
							|  |  |  |     m_settings.m_source = text; | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |     ui->targetName->setText(""); | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |     applySettings(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::updateStatus() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int state = m_gs232Controller->getState(); | 
					
						
							| 
									
										
										
										
											2021-10-05 14:03:31 +01:00
										 |  |  |     bool onTarget = m_gs232Controller->getOnTarget(); | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_lastFeatureState != state) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |         // We set checked state of start/stop button, in case it was changed via API
 | 
					
						
							|  |  |  |         bool oldState; | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |         switch (state) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             case Feature::StNotStarted: | 
					
						
							|  |  |  |                 ui->startStop->setStyleSheet("QToolButton { background:rgb(79,79,79); }"); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case Feature::StIdle: | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |                 oldState = ui->startStop->blockSignals(true); | 
					
						
							|  |  |  |                 ui->startStop->setChecked(false); | 
					
						
							|  |  |  |                 ui->startStop->blockSignals(oldState); | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |                 ui->startStop->setStyleSheet("QToolButton { background-color : blue; }"); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             case Feature::StRunning: | 
					
						
							| 
									
										
										
										
											2021-01-13 19:44:53 +00:00
										 |  |  |                 oldState = ui->startStop->blockSignals(true); | 
					
						
							|  |  |  |                 ui->startStop->setChecked(true); | 
					
						
							|  |  |  |                 ui->startStop->blockSignals(oldState); | 
					
						
							| 
									
										
										
										
											2021-10-05 14:03:31 +01:00
										 |  |  |                 if (onTarget) { | 
					
						
							|  |  |  |                     ui->startStop->setStyleSheet("QToolButton { background-color : green; }"); | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     ui->startStop->setStyleSheet("QToolButton { background-color : yellow; }"); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 m_lastOnTarget = onTarget; | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  |                 break; | 
					
						
							|  |  |  |             case Feature::StError: | 
					
						
							|  |  |  |                 ui->startStop->setStyleSheet("QToolButton { background-color : red; }"); | 
					
						
							|  |  |  |                 QMessageBox::information(this, tr("Message"), m_gs232Controller->getErrorMessage()); | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             default: | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_lastFeatureState = state; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-05 14:03:31 +01:00
										 |  |  |     else if (state == Feature::StRunning) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (onTarget != m_lastOnTarget) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (onTarget) { | 
					
						
							|  |  |  |                 ui->startStop->setStyleSheet("QToolButton { background-color : green; }"); | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 ui->startStop->setStyleSheet("QToolButton { background-color : yellow; }"); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         m_lastOnTarget = onTarget; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-10-27 16:22:10 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GS232ControllerGUI::applySettings(bool force) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_doApplySettings) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         GS232Controller::MsgConfigureGS232Controller* message = GS232Controller::MsgConfigureGS232Controller::create(m_settings, force); | 
					
						
							|  |  |  |         m_gs232Controller->getInputMessageQueue()->push(message); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |