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

Last change on this file since 1373 was 1373, checked in by mervart, 15 years ago

* empty log message *

File size: 15.9 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 <iostream>
42
43#include "bnctabledlg.h"
44#include "bncgetthread.h"
45#include "bncnetquery.h"
46#include "bncsocket.h"
47
48using namespace std;
49
50// Constructor
51////////////////////////////////////////////////////////////////////////////
52bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
53
54 setMinimumSize(600,400);
55 setWindowTitle(tr("Add Mountpoints"));
56
57 QVBoxLayout* mainLayout = new QVBoxLayout(this);
58
59 QSettings settings;
60 _casterHostLineEdit = new QComboBox();
61 _casterHostLineEdit->setDuplicatesEnabled(false);
62 _casterHostLineEdit->setEditable(true);
63 int ww = QFontMetrics(_casterHostLineEdit->font()).width('w');
64 _casterHostLineEdit->setMaximumWidth(20*ww);
65 QStringList casterHostList = settings.value("casterHostList").toStringList();
66 _casterHostLineEdit->addItem(settings.value("casterHost").toString());
67 for (int ii = 0; ii < casterHostList.count(); ii++) {
68 QString item = casterHostList[ii];
69 if (_casterHostLineEdit->findText(item, Qt::MatchFixedString) < 0) {
70 _casterHostLineEdit->addItem(item);
71 }
72 }
73 _casterPortLineEdit = new QLineEdit(settings.value("casterPort").toString());
74 _casterPortLineEdit->setMaximumWidth(9*ww);
75 _casterUserLineEdit = new QLineEdit(settings.value("casterUser").toString());
76 _casterUserLineEdit->setMaximumWidth(9*ww);
77 _casterPasswordLineEdit = new QLineEdit(settings.value("casterPassword").toString());
78 _casterPasswordLineEdit->setMaximumWidth(9*ww);
79 _casterPasswordLineEdit->setEchoMode(QLineEdit::Password);
80
81 _ntripVersionComboBox = new QComboBox();
82 _ntripVersionComboBox->addItems(QString("1,2,AUTO").split(","));
83 int kk = _ntripVersionComboBox->findText(settings.value("ntripVersion").toString());
84 if (kk != -1) {
85 _ntripVersionComboBox->setCurrentIndex(kk);
86 }
87
88 // WhatsThis
89 // ---------
90 _casterUserLineEdit->setWhatsThis(tr("Access to some streams on NTRIP broadcasters may be restricted. You'll need to enter a valid 'User ID' and 'Password' for access to these protected streams. Accounts are usually provided per NTRIP broadcaster through a registration process. 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>."));
91 _casterPortLineEdit->setWhatsThis(tr("Enter the NTRIP broadcaster hostname or IP 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>."));
92 _casterHostLineEdit->setWhatsThis(tr("Enter the NTRIP broadcaster hostname or IP 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>."));
93 _casterPasswordLineEdit->setWhatsThis(tr("Access to some streams on NTRIP broadcasters may be restricted. You'll need to enter a valid 'User ID' and 'Password' for access to these protected 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>."));
94
95 QGridLayout* editLayout = new QGridLayout;
96 editLayout->addWidget(new QLabel(tr("Caster host")), 0, 0);
97 editLayout->addWidget(_casterHostLineEdit, 0, 1);
98 editLayout->addWidget(new QLabel(tr("Caster port")), 0, 2);
99 editLayout->addWidget(_casterPortLineEdit, 0, 3);
100 editLayout->addWidget(new QLabel(tr("NTRIP Version")), 0, 4);
101 editLayout->addWidget(_ntripVersionComboBox, 0, 5);
102 editLayout->addWidget(new QLabel(tr("User")), 1, 0);
103 editLayout->addWidget(_casterUserLineEdit, 1, 1);
104 editLayout->addWidget(new QLabel(tr("Password")), 1, 2);
105 editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
106
107 mainLayout->addLayout(editLayout);
108
109 _table = new QTableWidget(this);
110 _table->setWhatsThis(tr("<p>Use the 'Get Table' button to download the sourcetable from the NTRIP broadcaster. Select the desired streams line by line, using +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 Version 2.x, RTCM Version 3.x, or RTIGS format. RTCM Version 2.x streams must contain message Type 18 and 19 or 20 and 21 while RTCM Version 3.x streams must contain GPS or SBAS message Type 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>Note that in order to produce RINEX Navigation files, RTCM Version 3.x streams containing message Type 1019 (GPS) and 1020 (GLONASS) or RTIGS streams are required.</p><p>Search for RTCM Version 3.x streams containing (premature) message Types 4056 and 4057 if you need corrections to Broadcast Ephemeris.</p><p>The content of data field 'nmea' tells you whether a stream retrieval needs to be initiated by BNC by sending an NMEA-GGA message containing the user (or virtual reference station)'s coordinate.</p>"));
111 connect(_table, SIGNAL(itemSelectionChanged()),
112 this, SLOT(slotSelectionChanged()));
113 mainLayout->addWidget(_table);
114
115 _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
116 connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
117
118 _buttonGet = new QPushButton(tr("Get table"), this);
119 _buttonGet->setDefault(true);
120 connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
121
122 _buttonCancel = new QPushButton(tr("Cancel"), this);
123 connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
124
125 _buttonOK = new QPushButton(tr("OK"), this);
126 connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
127
128 QHBoxLayout* buttonLayout = new QHBoxLayout;
129 buttonLayout->addWidget(_buttonWhatsThis);
130 buttonLayout->addStretch(1);
131 buttonLayout->addWidget(_buttonGet);
132 buttonLayout->addWidget(_buttonCancel);
133 buttonLayout->addWidget(_buttonOK);
134
135 mainLayout->addLayout(buttonLayout);
136}
137
138// Destructor
139////////////////////////////////////////////////////////////////////////////
140bncTableDlg::~bncTableDlg() {
141 if (_table) {
142 for (int ir = 0; ir < _table->rowCount(); ir++) {
143 for (int ic = 0; ic < _table->columnCount(); ic++) {
144 delete _table->item(ir,ic);
145 }
146 }
147 }
148}
149
150// Read Table the caster (static)
151////////////////////////////////////////////////////////////////////////////
152t_irc bncTableDlg::getFullTable(const QString& casterHost,
153 int casterPort, const QByteArray& ntripVersion,
154 QStringList& allLines, bool alwaysRead) {
155
156 static QMutex mutex;
157 static QMap<QString, QStringList> allTables;
158
159 QMutexLocker locker(&mutex);
160
161 if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
162 allLines = allTables.find(casterHost).value();
163 return success;
164 }
165
166 allLines.clear();
167
168 QUrl url;
169 url.setHost(casterHost);
170 url.setPort(casterPort);
171
172 // Send the Request
173 // ----------------
174 const int timeOut = 10*1000;
175 QString msg;
176 bncSocket* socket = new bncSocket();
177
178 //// beg test
179 bncNetQuery* query = new bncNetQuery();
180 QByteArray outData;
181 cout << "before request" << endl;
182 t_irc irc = query->waitForRequestResult(url, outData);
183 cout << "after request " << irc << endl;
184 cout << outData.data();
185 return failure;
186 //// end test
187
188 if (socket->request(url, "", "", "", ntripVersion, timeOut, msg) != success) {
189 delete socket;
190 return failure;
191 }
192
193 // Read Caster Response
194 // --------------------
195 bool proxyRespond = false;
196 bool first = true;
197 while (true) {
198 if (socket->canReadLine()) {
199 QString line = socket->readLine();
200
201 // Skip messages from proxy server
202 // -------------------------------
203 if (line.indexOf("SOURCETABLE 200 OK") == -1 &&
204 line.indexOf("200 OK") != -1 ) {
205 proxyRespond = true;
206 }
207 if (proxyRespond) {
208 if (line.trimmed().isEmpty()) {
209 proxyRespond = false;
210 }
211 continue;
212 }
213
214 allLines.push_back(line);
215 if (first) {
216 first = false;
217 if (line.indexOf("SOURCETABLE 200 OK") != 0) {
218 if (ntripVersion == "1") {
219 break;
220 }
221 }
222 }
223 else {
224 if (line.indexOf("ENDSOURCETABLE") == 0) {
225 break;
226 }
227 }
228 }
229 else {
230 socket->waitForReadyRead(timeOut);
231 if (socket->bytesAvailable() > 0) {
232 continue;
233 }
234 else {
235 break;
236 }
237 }
238 }
239 /// delete socket;
240
241 allTables.insert(casterHost, allLines);
242 return success;
243}
244
245// Read Table from Caster
246////////////////////////////////////////////////////////////////////////////
247void bncTableDlg::slotGetTable() {
248
249 _buttonGet->setEnabled(false);
250
251 _allLines.clear();
252
253 if ( getFullTable(_casterHostLineEdit->currentText(),
254 _casterPortLineEdit->text().toInt(),
255 _ntripVersionComboBox->currentText().toAscii(),
256 _allLines) != success ) {
257 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
258 _buttonGet->setEnabled(true);
259 return;
260 }
261
262 QStringList lines;
263 QStringListIterator it(_allLines);
264 while (it.hasNext()) {
265 QString line = it.next();
266 if (line.indexOf("STR") == 0) {
267 lines.push_back(line);
268 }
269 }
270
271 static const QStringList labels = QString("mountpoint,identifier,format,"
272 "format-details,carrier,system,network,country,latitude,longitude,"
273 "nmea,solution,generator,compress.,authentic.,fee,bitrate,"
274 "misc").split(",");
275
276 if (lines.size() > 0) {
277 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
278 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
279
280 QStringList hlp = lines[0].split(";");
281 _table->setColumnCount(hlp.size()-1);
282 _table->setRowCount(lines.size());
283
284 QListIterator<QString> it(lines);
285 int nRow = -1;
286 while (it.hasNext()) {
287 QStringList columns = it.next().split(";");
288 ++nRow;
289 for (int ic = 0; ic < columns.size()-1; ic++) {
290
291 if (ic+1 == 11) { if (columns[ic+1] == "0") { columns[ic+1] = "no"; } else { columns[ic+1] = "yes"; }}
292
293 QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
294 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
295 _table->setItem(nRow, ic, it);
296 }
297 }
298 _table->sortItems(0);
299 _table->setHorizontalHeaderLabels(labels);
300 _table->setSortingEnabled(true);
301
302 int ww = QFontMetrics(this->font()).width('w');
303 _table->horizontalHeader()->resizeSection(0,10*ww);
304 _table->horizontalHeader()->resizeSection(2,8*ww);
305 _table->horizontalHeader()->resizeSection(3,15*ww);
306 _table->horizontalHeader()->resizeSection(4,8*ww);
307 _table->horizontalHeader()->resizeSection(5,8*ww);
308 _table->horizontalHeader()->resizeSection(6,8*ww);
309 _table->horizontalHeader()->resizeSection(7,8*ww);
310 _table->horizontalHeader()->resizeSection(8,8*ww);
311 _table->horizontalHeader()->resizeSection(9,8*ww);
312 _table->horizontalHeader()->resizeSection(10,8*ww);
313 _table->horizontalHeader()->resizeSection(11,8*ww);
314 _table->horizontalHeader()->resizeSection(12,15*ww);
315 _table->horizontalHeader()->resizeSection(13,8*ww);
316 _table->horizontalHeader()->resizeSection(14,8*ww);
317 _table->horizontalHeader()->resizeSection(15,8*ww);
318 _table->horizontalHeader()->resizeSection(16,8*ww);
319 _table->horizontalHeader()->resizeSection(17,15*ww);
320 }
321}
322
323// Accept slot
324////////////////////////////////////////////////////////////////////////////
325void bncTableDlg::accept() {
326
327 QSettings settings;
328 settings.setValue("casterHost", _casterHostLineEdit->currentText());
329 QStringList casterHostList;
330 for (int ii = 0; ii < _casterHostLineEdit->count(); ii++) {
331 casterHostList.push_back(_casterHostLineEdit->itemText(ii));
332 }
333 settings.setValue("casterHostList", casterHostList);
334 settings.setValue("casterPort", _casterPortLineEdit->text());
335 settings.setValue("ntripVersion", _ntripVersionComboBox->currentText());
336 settings.setValue("casterUser", _casterUserLineEdit->text());
337 settings.setValue("casterPassword", _casterPasswordLineEdit->text());
338
339 QStringList* mountPoints = new QStringList;
340
341 if (_table) {
342 for (int ir = 0; ir < _table->rowCount(); ir++) {
343 QTableWidgetItem* item = _table->item(ir,0);
344 QString format = _table->item(ir,2)->text();
345 QString latitude = _table->item(ir,8)->text();
346 QString longitude = _table->item(ir,9)->text();
347 QString nmea = _table->item(ir,10)->text();
348 QString ntripVersion = _ntripVersionComboBox->currentText();
349 format.replace(" ", "_");
350 if (_table->isItemSelected(item)) {
351 QUrl url;
352 url.setUserName(QUrl::toPercentEncoding(_casterUserLineEdit->text()));
353 url.setPassword(QUrl::toPercentEncoding(_casterPasswordLineEdit->text()));
354 url.setHost(_casterHostLineEdit->currentText());
355 url.setPort(_casterPortLineEdit->text().toInt());
356 url.setPath(item->text());
357
358 mountPoints->push_back(url.toString() + " " + format + " " + latitude
359 + " " + longitude + " " + nmea + " " + ntripVersion);
360 }
361 }
362 }
363 emit newMountPoints(mountPoints);
364
365 QDialog::accept();
366}
367
368// User changed the selection of mountPoints
369////////////////////////////////////////////////////////////////////////////
370void bncTableDlg::slotSelectionChanged() {
371 if (_table->selectedItems().isEmpty()) {
372 }
373}
374
375// Create RINEX skeleton header
376////////////////////////////////////////////////////////////////////////////
377void bncTableDlg::slotSkl() {
378
379 int nRows = _table->rowCount();
380 for (int iRow = 0; iRow < nRows; iRow++) {
381 if (_table->isItemSelected(_table->item(iRow,1))) {
382 QString staID = _table->item(iRow,0)->text();
383 QString net = _table->item(iRow,6)->text();
384
385 QString ftpDir;
386 QStringListIterator it(_allLines);
387 while (it.hasNext()) {
388 QString line = it.next();
389 if (line.indexOf("NET") == 0) {
390 QStringList tags = line.split(';');
391 if (tags.at(1) == net) {
392 ftpDir = tags.at(6);
393 break;
394 }
395 }
396 }
397
398 if (!ftpDir.isEmpty()) {
399 QUrl url(ftpDir);
400 QMessageBox::warning(0, "Warning", url.host() + "\n" + url.path() +
401 "\nnot yet implemented");
402 }
403 }
404 }
405}
406
407// Whats This Help
408void bncTableDlg::slotWhatsThis() {
409QWhatsThis::enterWhatsThisMode();
410}
411
412
Note: See TracBrowser for help on using the repository browser.