source: ntrip/trunk/BNC/bnctabledlg.cpp@ 464

Last change on this file since 464 was 464, checked in by weber, 17 years ago

* empty log message *

File size: 13.6 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
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: bncTableDlg
30 *
31 * Purpose: Displays the source table, allows mountpoints selection
32 *
33 * Author: L. Mervart
34 *
35 * Created: 24-Dec-2005
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include "bnctabledlg.h"
42#include "bncgetthread.h"
43
44// Constructor
45////////////////////////////////////////////////////////////////////////////
46bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
47
48 setMinimumSize(600,400);
49 setWindowTitle(tr("Add Mountpoints"));
50
51 QVBoxLayout* mainLayout = new QVBoxLayout(this);
52
53 QSettings settings;
54 _casterHostLineEdit = new QLineEdit(settings.value("casterHost").toString());
55 int ww = QFontMetrics(_casterHostLineEdit->font()).width('w');
56 _casterHostLineEdit->setMaximumWidth(18*ww);
57 _casterHostLineEdit->setWhatsThis(tr("Enter the NTRIP broadcaster host IP name or number and port number. <u>http://www.rtcm-ntrip.org/home</u> provides information about known NTRIP broadcaster installations. Note that EUREF and IGS operate NTRIP broadcasters at <u>http://www.euref-ip.net/home</u> and <u>http://www.igs-ip.net/home</u>."));
58 _casterPortLineEdit = new QLineEdit(settings.value("casterPort").toString());
59 _casterPortLineEdit->setMaximumWidth(9*ww);
60 _casterPortLineEdit->setWhatsThis(tr("Enter the NTRIP broadcaster host IP name or number and port number. <u>http://www.rtcm-ntrip.org/home</u> provides information about known NTRIP broadcaster installations. Note that EUREF and IGS operate NTRIP broadcasters at <u>http://www.euref-ip.net/home</u> and <u>http://www.igs-ip.net/home</u>."));
61 _casterUserLineEdit = new QLineEdit(settings.value("casterUser").toString());
62 _casterUserLineEdit->setMaximumWidth(9*ww);
63 _casterUserLineEdit->setWhatsThis(tr("<p>Streams on NTRIP broadcasters may be protected. Enter a valid 'User' ID and 'Password' for access to protected NTRIP broadcaster streams. Accounts are usually provided per NTRIP broadcaster through a registration procedure. Register through <u>http://igs.bkg.bund.de/index_ntrip_reg.htm</u> for access to protected streams on <u>www.euref-ip.net</u> and <u>www.igs-ip.net</u>.</p><p>Default values for 'User' and 'Password' are empty option fields allowing access to unprotected streams only.</p>"));
64 _casterPasswordLineEdit = new QLineEdit(settings.value("casterPassword").toString());
65 _casterPasswordLineEdit->setMaximumWidth(9*ww);
66 _casterPasswordLineEdit->setEchoMode(QLineEdit::Password);
67 _casterPasswordLineEdit->setWhatsThis(tr("<p>Streams on NTRIP broadcasters may be protected. Enter a valid 'User' ID and 'Password' for access to protected NTRIP broadcaster streams. Accounts are usually provided per NTRIP broadcaster through a registration procedure. Register through <u>http://igs.bkg.bund.de/index_ntrip_reg.htm</u> for access to protected streams on <u>www.euref-ip.net</u> and <u>www.igs-ip.net</u>.</p><p>Default values for 'User' and 'Password' are empty option fields allowing access to unprotected streams only.</p>"));
68
69 QGridLayout* editLayout = new QGridLayout;
70 editLayout->addWidget(new QLabel(tr("Caster host")), 0, 0);
71 editLayout->addWidget(_casterHostLineEdit, 0, 1);
72 editLayout->addWidget(new QLabel(tr("Caster port")), 0, 2);
73 editLayout->addWidget(_casterPortLineEdit, 0, 3);
74 editLayout->addWidget(new QLabel(tr("User")), 1, 0);
75 editLayout->addWidget(_casterUserLineEdit, 1, 1);
76 editLayout->addWidget(new QLabel(tr("Password")), 1, 2);
77 editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
78
79 mainLayout->addLayout(editLayout);
80
81 _table = new QTableWidget(this);
82 _table->setWhatsThis(tr("<p>Hit button 'Get Table' to download the source-table from the NTRIP broadcaster. Select streams line by line, use +Shift and +Ctrl when necessary. Hit 'OK' to return to the main window.</p><p>Pay attention to data fields 'format' and 'format-details'. Keep in mind that BNC can only decode and convert streams that come in RTCM 2.x, RTCM 3, or RTIGS formats. RTCM 2.x streams must contain message types 18 and 19 while RTCM 3 streams must contain GPS message types 1002 or 1004 and may contain GLONASS message types 1010 or 1012, see data field 'format-details' for available message types and their repetition rates in brackets.</p><p>The contents of data field 'nmea' tells you whether or not a stream retrieval needs to be initiated by BNC through sending an NMEA-GGA string carrying the latitude and longitude parameters.</p>"));
83 connect(_table, SIGNAL(itemSelectionChanged()),
84 this, SLOT(slotSelectionChanged()));
85 mainLayout->addWidget(_table);
86
87 _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
88 connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
89
90 _buttonGet = new QPushButton(tr("Get table"), this);
91 _buttonGet->setDefault(true);
92 connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
93
94 _buttonCancel = new QPushButton(tr("Cancel"), this);
95 connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
96
97 _buttonOK = new QPushButton(tr("OK"), this);
98 connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
99
100 QHBoxLayout* buttonLayout = new QHBoxLayout;
101 buttonLayout->addWidget(_buttonWhatsThis);
102 buttonLayout->addStretch(1);
103 buttonLayout->addWidget(_buttonGet);
104 buttonLayout->addWidget(_buttonCancel);
105 buttonLayout->addWidget(_buttonOK);
106
107 mainLayout->addLayout(buttonLayout);
108}
109
110// Destructor
111////////////////////////////////////////////////////////////////////////////
112bncTableDlg::~bncTableDlg() {
113 if (_table) {
114 for (int ir = 0; ir < _table->rowCount(); ir++) {
115 for (int ic = 0; ic < _table->columnCount(); ic++) {
116 delete _table->item(ir,ic);
117 }
118 }
119 }
120}
121
122// Read Table the caster (static)
123////////////////////////////////////////////////////////////////////////////
124t_irc bncTableDlg::getFullTable(const QString& casterHost,
125 int casterPort, QStringList& allLines,
126 bool alwaysRead) {
127
128 static QMutex mutex;
129 static QMap<QString, QStringList> allTables;
130
131 QMutexLocker locker(&mutex);
132
133 if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
134 allLines = allTables.find(casterHost).value();
135 return success;
136 }
137
138 allLines.clear();
139
140 QUrl url;
141 url.setHost(casterHost);
142 url.setPort(casterPort);
143
144 // Send the Request
145 // ----------------
146 const int timeOut = 10*1000;
147 QString msg;
148 QByteArray _latitude;
149 QByteArray _longitude;
150 QByteArray _nmea;
151 QTcpSocket* socket = bncGetThread::request(url, _latitude, _longitude, _nmea, timeOut, msg);
152
153 if (!socket) {
154 return failure;
155 }
156
157 // Read Caster Response
158 // --------------------
159 bool first = true;
160 while (true) {
161 if (socket->canReadLine()) {
162 QString line = socket->readLine();
163 allLines.push_back(line);
164 if (first) {
165 first = false;
166 if (line.indexOf("SOURCETABLE 200 OK") != 0) {
167 break;
168 }
169 }
170 else {
171 if (line.indexOf("ENDSOURCETABLE") == 0) {
172 break;
173 }
174 }
175 }
176 else {
177 socket->waitForReadyRead(timeOut);
178 if (socket->bytesAvailable() > 0) {
179 continue;
180 }
181 else {
182 break;
183 }
184 }
185 }
186 delete socket;
187
188 allTables.insert(casterHost, allLines);
189 return success;
190}
191
192// Read Table from Caster
193////////////////////////////////////////////////////////////////////////////
194void bncTableDlg::slotGetTable() {
195
196 _allLines.clear();
197
198 if ( getFullTable(_casterHostLineEdit->text(),
199 _casterPortLineEdit->text().toInt(),
200 _allLines) != success ) {
201 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
202 return;
203 }
204
205 QStringList lines;
206 QStringListIterator it(_allLines);
207 while (it.hasNext()) {
208 QString line = it.next();
209 if (line.indexOf("STR") == 0) {
210 lines.push_back(line);
211 }
212 }
213
214 static const QStringList labels = QString("mountpoint,identifier,format,"
215 "format-details,carrier,system,network,country,latitude,longitude,"
216 "nmea,solution,generator,compress.,authentic.,fee,bitrate,"
217 "misc").split(",");
218
219 if (lines.size() > 0) {
220 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
221 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
222
223 QStringList hlp = lines[0].split(";");
224 _table->setColumnCount(hlp.size()-1);
225 _table->setRowCount(lines.size());
226
227 QListIterator<QString> it(lines);
228 int nRow = -1;
229 while (it.hasNext()) {
230 QStringList columns = it.next().split(";");
231 ++nRow;
232 for (int ic = 0; ic < columns.size()-1; ic++) {
233
234 if (ic+1 == 11) { if (columns[ic+1] == "0") { columns[ic+1] = "no"; } else { columns[ic+1] = "yes"; }}
235
236 QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
237 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
238 _table->setItem(nRow, ic, it);
239 }
240 }
241 _table->sortItems(0);
242 _table->setHorizontalHeaderLabels(labels);
243 _table->setSortingEnabled(true);
244
245 int ww = QFontMetrics(this->font()).width('w');
246 _table->horizontalHeader()->resizeSection(0,10*ww);
247 _table->horizontalHeader()->resizeSection(2,8*ww);
248 _table->horizontalHeader()->resizeSection(3,15*ww);
249 _table->horizontalHeader()->resizeSection(4,8*ww);
250 _table->horizontalHeader()->resizeSection(5,8*ww);
251 _table->horizontalHeader()->resizeSection(6,8*ww);
252 _table->horizontalHeader()->resizeSection(7,8*ww);
253 _table->horizontalHeader()->resizeSection(8,8*ww);
254 _table->horizontalHeader()->resizeSection(9,8*ww);
255 _table->horizontalHeader()->resizeSection(10,8*ww);
256 _table->horizontalHeader()->resizeSection(11,8*ww);
257 _table->horizontalHeader()->resizeSection(12,15*ww);
258 _table->horizontalHeader()->resizeSection(13,8*ww);
259 _table->horizontalHeader()->resizeSection(14,8*ww);
260 _table->horizontalHeader()->resizeSection(15,8*ww);
261 _table->horizontalHeader()->resizeSection(16,8*ww);
262 _table->horizontalHeader()->resizeSection(17,15*ww);
263 }
264}
265
266// Accept slot
267////////////////////////////////////////////////////////////////////////////
268void bncTableDlg::accept() {
269
270 QSettings settings;
271 settings.setValue("casterHost", _casterHostLineEdit->text());
272 settings.setValue("casterPort", _casterPortLineEdit->text());
273 settings.setValue("casterUser", _casterUserLineEdit->text());
274 settings.setValue("casterPassword", _casterPasswordLineEdit->text());
275
276 QStringList* mountPoints = new QStringList;
277
278 if (_table) {
279 for (int ir = 0; ir < _table->rowCount(); ir++) {
280 QTableWidgetItem* item = _table->item(ir,0);
281 QString format = _table->item(ir,2)->text();
282 QString latitude = _table->item(ir,8)->text();
283 QString longitude = _table->item(ir,9)->text();
284 QString nmea = _table->item(ir,10)->text();
285 format.replace(" ", "_");
286 if (_table->isItemSelected(item)) {
287 QUrl url;
288 url.setUserName(QUrl::toPercentEncoding(_casterUserLineEdit->text()));
289 url.setPassword(QUrl::toPercentEncoding(_casterPasswordLineEdit->text()));
290 url.setHost(_casterHostLineEdit->text());
291 url.setPort(_casterPortLineEdit->text().toInt());
292 url.setPath(item->text());
293
294 mountPoints->push_back(url.toString() + " " + format + " " + latitude + " " + longitude + " " + nmea);
295 }
296 }
297 }
298 emit newMountPoints(mountPoints);
299
300 QDialog::accept();
301}
302
303// User changed the selection of mountPoints
304////////////////////////////////////////////////////////////////////////////
305void bncTableDlg::slotSelectionChanged() {
306 if (_table->selectedItems().isEmpty()) {
307 }
308}
309
310// Create RINEX skeleton header
311////////////////////////////////////////////////////////////////////////////
312void bncTableDlg::slotSkl() {
313
314 int nRows = _table->rowCount();
315 for (int iRow = 0; iRow < nRows; iRow++) {
316 if (_table->isItemSelected(_table->item(iRow,1))) {
317 QString staID = _table->item(iRow,0)->text();
318 QString net = _table->item(iRow,6)->text();
319
320 QString ftpDir;
321 QStringListIterator it(_allLines);
322 while (it.hasNext()) {
323 QString line = it.next();
324 if (line.indexOf("NET") == 0) {
325 QStringList tags = line.split(';');
326 if (tags.at(1) == net) {
327 ftpDir = tags.at(6);
328 break;
329 }
330 }
331 }
332
333 if (!ftpDir.isEmpty()) {
334 QUrl url(ftpDir);
335 QMessageBox::warning(0, "Warning", url.host() + "\n" + url.path() +
336 "\nnot yet implemented");
337 }
338 }
339 }
340}
341
342// Whats This Help
343void bncTableDlg::slotWhatsThis() {
344QWhatsThis::enterWhatsThisMode();
345}
346
347
Note: See TracBrowser for help on using the repository browser.