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

Last change on this file since 8450 was 8252, checked in by stoecker, 7 years ago

see #105 - reenable Qt4 build options, drop generic version dependend includes, replace by direct requirements, remaining QtCore lines should also be replaced

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("110,300,600,"
77 "1200,2400,4800,9600,19200,38400,57600,115200").split(","));
78 _serialFlowControlComboBox->addItems(QString("OFF,XONXOFF,HARDWARE").split(","));
79 _serialDataBitsComboBox->addItems(QString("5,6,7,8").split(","));
80 _serialParityComboBox->addItems(QString("NONE,ODD,EVEN,SPACE").split(","));
81 _serialStopBitsComboBox->addItems(QString("1,2").split(","));
82
83 _serialBaudRateComboBox->setCurrentIndex(7);
84 _serialDataBitsComboBox->setCurrentIndex(3);
85
86 int ww = QFontMetrics(font()).width('w');
87 _serialMountpointLineEdit->setMaximumWidth(11*ww);
88 _serialPortLineEdit->setMaximumWidth(11*ww);
89 _serialBaudRateComboBox->setMaximumWidth(9*ww);
90 _serialFlowControlComboBox->setMaximumWidth(11*ww);
91 _serialDataBitsComboBox->setMaximumWidth(5*ww);
92 _serialParityComboBox->setMaximumWidth(9*ww);
93 _serialStopBitsComboBox->setMaximumWidth(5*ww);
94 _serialLatLineEdit->setMaximumWidth(11*ww);
95 _serialLonLineEdit->setMaximumWidth(9*ww);
96 _serialFormatLineEdit->setMaximumWidth(9*ww);
97 _serialCountryLineEdit->setMaximumWidth(11*ww);
98
99 // WhatsThis, Add Stream from Serial Port
100 // --------------------------------------
101 _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 4-character station ID.<br>Example: FFMJ</p>"));
102 _serialFormatLineEdit->setWhatsThis(tr("<p>Specify the stream format.</p><p>Available options are 'RTCM_2', 'RTCM_3', 'RTNET', and 'ZERO'.</p>"));
103 _serialLatLineEdit->setWhatsThis(tr("<p>Enter the approximate latitude of the stream providing receiver in degrees.<p></p>Example: 45.32</p>"));
104 _serialLonLineEdit->setWhatsThis(tr("<p>Enter the approximate latitude of the stream providing receiver in degrees.<p></p>Example: 45.32</p>"));
105 _serialCountryLineEdit->setWhatsThis(tr("<p>Specify the country code.</p><p>Follow the ISO 3166-1 alpha-3a code.<br>Example, Germany: DEU</p>"));
106 _serialPortLineEdit->setWhatsThis(tr("<p>Enter the serial 'Port name' selected for communication with your serial connected device. Valid port names are</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>"));
107 _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>"));
108 _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>"));
109 _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>"));
110 _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>"));
111 _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>"));
112
113 editLayout->addWidget(new QLabel(tr("Mountpoint")), 0, 0, Qt::AlignRight);
114 editLayout->addWidget(_serialMountpointLineEdit, 0, 1);
115 editLayout->addWidget(new QLabel(tr("Format")), 0, 2, Qt::AlignRight);
116 editLayout->addWidget(_serialFormatLineEdit, 0, 3);
117 editLayout->addWidget(new QLabel(tr("Latitude")), 1, 0, Qt::AlignRight);
118 editLayout->addWidget(_serialLatLineEdit, 1, 1);
119 editLayout->addWidget(new QLabel(tr("Longitude")), 1, 2, Qt::AlignRight);
120 editLayout->addWidget(_serialLonLineEdit, 1, 3);
121 editLayout->addWidget(new QLabel(tr("Country")), 2, 0, Qt::AlignRight);
122 editLayout->addWidget(_serialCountryLineEdit, 2, 1);
123 editLayout->addWidget(new QLabel(tr("Port name")), 3, 0, Qt::AlignRight);
124 editLayout->addWidget(_serialPortLineEdit, 3, 1);
125 editLayout->addWidget(new QLabel(tr("Baud rate")), 3, 2, Qt::AlignRight);
126 editLayout->addWidget(_serialBaudRateComboBox, 3, 3);
127 editLayout->addWidget(new QLabel(tr("Data bits")), 4, 0, Qt::AlignRight);
128 editLayout->addWidget(_serialDataBitsComboBox, 4, 1);
129 editLayout->addWidget(new QLabel(tr("Parity")), 4, 2, Qt::AlignRight);
130 editLayout->addWidget(_serialParityComboBox, 4, 3);
131 editLayout->addWidget(new QLabel(tr("Stop bits")), 5, 0, Qt::AlignRight);
132 editLayout->addWidget(_serialStopBitsComboBox, 5, 1);
133 editLayout->addWidget(new QLabel(tr("Flow control")),5, 2, Qt::AlignRight);
134 editLayout->addWidget(_serialFlowControlComboBox, 5, 3);
135
136 mainLayout->addLayout(editLayout);
137
138 _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
139 connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
140
141 _buttonCancel = new QPushButton(tr("Cancel"), this);
142 connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
143
144 _buttonOK = new QPushButton(tr("OK"), this);
145 connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
146
147 _buttonOK->setDefault(true);
148
149 QHBoxLayout* buttonLayout = new QHBoxLayout;
150
151 buttonLayout->addWidget(_buttonWhatsThis);
152 buttonLayout->addStretch(1);
153 buttonLayout->addWidget(_buttonCancel);
154 buttonLayout->addWidget(_buttonOK);
155
156 mainLayout->addLayout(buttonLayout);
157}
158
159// Destructor
160////////////////////////////////////////////////////////////////////////////
161bncSerialPort::~bncSerialPort() {
162 delete _buttonCancel;
163 delete _buttonOK;
164 delete _buttonWhatsThis;
165}
166
167// Accept slot
168////////////////////////////////////////////////////////////////////////////
169void bncSerialPort::accept() {
170
171 QStringList* mountPoints = new QStringList;
172
173 QString _serialBaudRate = _serialBaudRateComboBox->currentText();
174 QString _serialFlowControl = _serialFlowControlComboBox->currentText();
175 QString _serialDataBits = _serialDataBitsComboBox->currentText();
176 QString _serialParity = _serialParityComboBox->currentText();
177 QString _serialStopBits = _serialStopBitsComboBox->currentText();
178
179 if ( !_serialMountpointLineEdit->text().isEmpty() &&
180 !_serialPortLineEdit->text().isEmpty() &&
181 !_serialFormatLineEdit->text().isEmpty() &&
182 !_serialCountryLineEdit->text().isEmpty() &&
183 !_serialLatLineEdit->text().isEmpty() &&
184 !_serialLonLineEdit->text().isEmpty() ) {
185 mountPoints->push_back("//"
186 + _serialPortLineEdit->text().replace("/","-").replace(QRegExp("^[-]"), "") + "-"
187 + _serialDataBits + "-"
188 + _serialParity + "-"
189 + _serialStopBits + "-"
190 + _serialFlowControl + "-"
191 + _serialBaudRate + "/"
192 + _serialMountpointLineEdit->text() + " "
193 + _serialFormatLineEdit->text() + " "
194 + _serialCountryLineEdit->text() + " "
195 + _serialLatLineEdit->text() + " "
196 + _serialLonLineEdit->text() + " "
197 + "no S");
198 } else {
199 QMessageBox::warning(this, tr("Warning"),
200 tr("Incomplete settings"),
201 QMessageBox::Ok);
202 }
203
204 emit newMountPoints(mountPoints);
205
206 QDialog::accept();
207}
208
209// Whats This Help
210void bncSerialPort::slotWhatsThis() {
211QWhatsThis::enterWhatsThisMode();
212}
213
Note: See TracBrowser for help on using the repository browser.