source: ntrip/trunk/BNC/src/bncserialport.cpp@ 10766

Last change on this file since 10766 was 10766, checked in by stuerze, 12 months ago

external class QextSerialPort was replaced by Qt5 internal class QSerialPort, serial port is now introduced as case sensitive

File size: 10.1 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2009
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: bncSerialPort
30 *
31 * Purpose: Select serial port for stream retrieval
32 *
33 * Author: G. Weber
34 *
35 * Created: 18-Feb-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42
43#include <QComboBox>
44#include <QHBoxLayout>
45#include <QLabel>
46#include <QLineEdit>
47#include <QMessageBox>
48#include <QPushButton>
49
50#include "bncserialport.h"
51
52using namespace std;
53
54// Constructor
55////////////////////////////////////////////////////////////////////////////
56bncSerialPort::bncSerialPort(QWidget* parent) : QDialog(parent) {
57
58 setMinimumSize(400,150);
59 QVBoxLayout* mainLayout = new QVBoxLayout(this);
60 QGridLayout* editLayout = new QGridLayout;
61
62 setWindowTitle(tr("Add Stream from Serial Port"));
63
64 _serialMountpointLineEdit = new QLineEdit();
65 _serialPortLineEdit = new QLineEdit();
66 _serialFormatLineEdit = new QLineEdit();
67 _serialBaudRateComboBox = new QComboBox();
68 _serialFlowControlComboBox = new QComboBox();
69 _serialDataBitsComboBox = new QComboBox();
70 _serialParityComboBox = new QComboBox();
71 _serialStopBitsComboBox = new QComboBox();
72 _serialLatLineEdit = new QLineEdit();
73 _serialLonLineEdit = new QLineEdit();
74 _serialCountryLineEdit = new QLineEdit();
75
76 _serialBaudRateComboBox->addItems(QString("1200,2400,4800,9600,19200,38400,57600,115200").split(","));
77 _serialFlowControlComboBox->addItems(QString("OFF,XONXOFF,HARDWARE").split(","));
78 _serialDataBitsComboBox->addItems(QString("5,6,7,8").split(","));
79 _serialParityComboBox->addItems(QString("NONE,ODD,EVEN,SPACE,MARK").split(","));
80 _serialStopBitsComboBox->addItems(QString("1,1.5,2").split(","));
81
82 _serialBaudRateComboBox->setCurrentIndex(7);
83 _serialDataBitsComboBox->setCurrentIndex(3);
84
85 int ww = QFontMetrics(font()).horizontalAdvance('w');
86 _serialMountpointLineEdit->setMaximumWidth(11*ww);
87 _serialPortLineEdit->setMaximumWidth(11*ww);
88 _serialBaudRateComboBox->setMaximumWidth(9*ww);
89 _serialFlowControlComboBox->setMaximumWidth(11*ww);
90 _serialDataBitsComboBox->setMaximumWidth(5*ww);
91 _serialParityComboBox->setMaximumWidth(9*ww);
92 _serialStopBitsComboBox->setMaximumWidth(5*ww);
93 _serialLatLineEdit->setMaximumWidth(11*ww);
94 _serialLonLineEdit->setMaximumWidth(9*ww);
95 _serialFormatLineEdit->setMaximumWidth(9*ww);
96 _serialCountryLineEdit->setMaximumWidth(11*ww);
97
98 // WhatsThis, Add Stream from Serial Port
99 // --------------------------------------
100 _serialMountpointLineEdit->setWhatsThis(tr("<p>BNC allows to retrieve streams via serial port without using the Ntrip transport protocol.</p><p>Specify a mountpoint. Recommended is a 9-character station ID.<br>Example: FFMJ01DEU</p>"));
101 _serialFormatLineEdit->setWhatsThis(tr("<p>Specify the stream format.</p><p>Available options are 'RTCM_2', 'RTCM_3', 'RTNET', 'ZERO' and 'ZERO2FILE'.</p>"));
102 _serialLatLineEdit->setWhatsThis(tr("<p>Enter the approximate latitude of the stream providing receiver in degrees.<p></p>Example: 45.32</p>"));
103 _serialLonLineEdit->setWhatsThis(tr("<p>Enter the approximate latitude of the stream providing receiver in degrees.<p></p>Example: 45.32</p>"));
104 _serialCountryLineEdit->setWhatsThis(tr("<p>Specify the country code.</p><p>Follow the ISO 3166-1 alpha-3a code.<br>Example, Germany: DEU</p>"));
105 _serialPortLineEdit->setWhatsThis(tr("<p>Enter the serial 'Port name' selected for communication with your serial connected device. Valid port names are e.g. </p><pre>Windows: COM1, COM2<br>Linux: /dev/ttyS0, /dev/ttyS1<br>FreeBSD: /dev/ttyd0, /dev/ttyd1<br>Digital Unix: /dev/tty01, /dev/tty02<br>HP-UX: /dev/tty1p0, /dev/tty2p0<br>SGI/IRIX: /dev/ttyf1, /dev/ttyf2<br>SunOS/Solaris: /dev/ttya, /dev/ttyb</pre><p>You must plug a serial cable in the port defined here before you start BNC.</p>"));
106 _serialBaudRateComboBox->setWhatsThis(tr("<p>Select a 'Baud rate' for the serial input link.</p><p>Your selection must equal the baud rate configured to the serial connected device. Note that using a high baud rate is recommended.</p>"));
107 _serialDataBitsComboBox->setWhatsThis(tr("<p>Select the number of 'Data bits' for the serial input link.</p><p>Your selection must equal the number of data bits configured to the serial connected device. Note that often 8 data bits are used.</p>"));
108 _serialParityComboBox->setWhatsThis(tr("<p>Select the 'Parity' for the serial input link.</p><p>Your selection must equal the parity selection configured to the serial connected device. Note that parity is often set to 'NONE'.</p>"));
109 _serialStopBitsComboBox->setWhatsThis(tr("<p>Select the number of 'Stop bits' for the serial input link.</p><p>Your selection must equal the number of stop bits configured to the serial connected device. Note that often 1 stop bit is used.</p>"));
110 _serialFlowControlComboBox->setWhatsThis(tr("<p>Select a 'Flow control' for the serial input link.</p><p>Your selection must equal the flow control configured to the serial connected device. Select 'OFF' if you don't know better.</p>"));
111
112 editLayout->addWidget(new QLabel(tr("Mountpoint")), 0, 0, Qt::AlignRight);
113 editLayout->addWidget(_serialMountpointLineEdit, 0, 1);
114 editLayout->addWidget(new QLabel(tr("Format")), 0, 2, Qt::AlignRight);
115 editLayout->addWidget(_serialFormatLineEdit, 0, 3);
116 editLayout->addWidget(new QLabel(tr("Latitude")), 1, 0, Qt::AlignRight);
117 editLayout->addWidget(_serialLatLineEdit, 1, 1);
118 editLayout->addWidget(new QLabel(tr("Longitude")), 1, 2, Qt::AlignRight);
119 editLayout->addWidget(_serialLonLineEdit, 1, 3);
120 editLayout->addWidget(new QLabel(tr("Country")), 2, 0, Qt::AlignRight);
121 editLayout->addWidget(_serialCountryLineEdit, 2, 1);
122 editLayout->addWidget(new QLabel(tr("Port name")), 3, 0, Qt::AlignRight);
123 editLayout->addWidget(_serialPortLineEdit, 3, 1);
124 editLayout->addWidget(new QLabel(tr("Baud rate")), 3, 2, Qt::AlignRight);
125 editLayout->addWidget(_serialBaudRateComboBox, 3, 3);
126 editLayout->addWidget(new QLabel(tr("Data bits")), 4, 0, Qt::AlignRight);
127 editLayout->addWidget(_serialDataBitsComboBox, 4, 1);
128 editLayout->addWidget(new QLabel(tr("Parity")), 4, 2, Qt::AlignRight);
129 editLayout->addWidget(_serialParityComboBox, 4, 3);
130 editLayout->addWidget(new QLabel(tr("Stop bits")), 5, 0, Qt::AlignRight);
131 editLayout->addWidget(_serialStopBitsComboBox, 5, 1);
132 editLayout->addWidget(new QLabel(tr("Flow control")),5, 2, Qt::AlignRight);
133 editLayout->addWidget(_serialFlowControlComboBox, 5, 3);
134
135 mainLayout->addLayout(editLayout);
136
137 _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
138 connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
139
140 _buttonCancel = new QPushButton(tr("Cancel"), this);
141 connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
142
143 _buttonOK = new QPushButton(tr("OK"), this);
144 connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
145
146 _buttonOK->setDefault(true);
147
148 QHBoxLayout* buttonLayout = new QHBoxLayout;
149
150 buttonLayout->addWidget(_buttonWhatsThis);
151 buttonLayout->addStretch(1);
152 buttonLayout->addWidget(_buttonCancel);
153 buttonLayout->addWidget(_buttonOK);
154
155 mainLayout->addLayout(buttonLayout);
156}
157
158// Destructor
159////////////////////////////////////////////////////////////////////////////
160bncSerialPort::~bncSerialPort() {
161 delete _buttonCancel;
162 delete _buttonOK;
163 delete _buttonWhatsThis;
164}
165
166// Accept slot
167////////////////////////////////////////////////////////////////////////////
168void bncSerialPort::accept() {
169
170 QStringList* mountPoints = new QStringList;
171
172 QString _serialBaudRate = _serialBaudRateComboBox->currentText();
173 QString _serialFlowControl = _serialFlowControlComboBox->currentText();
174 QString _serialDataBits = _serialDataBitsComboBox->currentText();
175 QString _serialParity = _serialParityComboBox->currentText();
176 QString _serialStopBits = _serialStopBitsComboBox->currentText();
177
178 if ( !_serialMountpointLineEdit->text().isEmpty() &&
179 !_serialPortLineEdit->text().isEmpty() &&
180 !_serialFormatLineEdit->text().isEmpty() &&
181 !_serialCountryLineEdit->text().isEmpty() &&
182 !_serialLatLineEdit->text().isEmpty() &&
183 !_serialLonLineEdit->text().isEmpty() ) {
184 mountPoints->push_back("//"
185 + _serialPortLineEdit->text().replace("/","-").replace(QRegExp("^[-]"), "") + "@"
186 + _serialDataBits + "-"
187 + _serialParity + "-"
188 + _serialStopBits + "-"
189 + _serialFlowControl + "-"
190 + _serialBaudRate + "/"
191 + _serialMountpointLineEdit->text() + " "
192 + _serialFormatLineEdit->text() + " "
193 + _serialCountryLineEdit->text() + " "
194 + _serialLatLineEdit->text() + " "
195 + _serialLonLineEdit->text() + " "
196 + "no S");
197 } else {
198 QMessageBox::warning(this, tr("Warning"),
199 tr("Incomplete settings"),
200 QMessageBox::Ok);
201 }
202
203 emit newMountPoints(mountPoints);
204
205 QDialog::accept();
206}
207
208// Whats This Help
209void bncSerialPort::slotWhatsThis() {
210QWhatsThis::enterWhatsThisMode();
211}
212
Note: See TracBrowser for help on using the repository browser.