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

Last change on this file since 543 was 473, checked in by mervart, 17 years ago

* empty log message *

File size: 14.0 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 proxyRespond = false;
160 bool first = true;
161 while (true) {
162 if (socket->canReadLine()) {
163 QString line = socket->readLine();
164
165 // Skip messages from proxy server
166 // -------------------------------
167 if (line.indexOf("SOURCETABLE 200 OK") == -1 &&
168 line.indexOf("200 OK") != -1 ) {
169 proxyRespond = true;
170 }
171 if (proxyRespond) {
172 if (line.trimmed().isEmpty()) {
173 proxyRespond = false;
174 }
175 continue;
176 }
177
178 allLines.push_back(line);
179 if (first) {
180 first = false;
181 if (line.indexOf("SOURCETABLE 200 OK") != 0) {
182 break;
183 }
184 }
185 else {
186 if (line.indexOf("ENDSOURCETABLE") == 0) {
187 break;
188 }
189 }
190 }
191 else {
192 socket->waitForReadyRead(timeOut);
193 if (socket->bytesAvailable() > 0) {
194 continue;
195 }
196 else {
197 break;
198 }
199 }
200 }
201 delete socket;
202
203 allTables.insert(casterHost, allLines);
204 return success;
205}
206
207// Read Table from Caster
208////////////////////////////////////////////////////////////////////////////
209void bncTableDlg::slotGetTable() {
210
211 _allLines.clear();
212
213 if ( getFullTable(_casterHostLineEdit->text(),
214 _casterPortLineEdit->text().toInt(),
215 _allLines) != success ) {
216 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
217 return;
218 }
219
220 QStringList lines;
221 QStringListIterator it(_allLines);
222 while (it.hasNext()) {
223 QString line = it.next();
224 if (line.indexOf("STR") == 0) {
225 lines.push_back(line);
226 }
227 }
228
229 static const QStringList labels = QString("mountpoint,identifier,format,"
230 "format-details,carrier,system,network,country,latitude,longitude,"
231 "nmea,solution,generator,compress.,authentic.,fee,bitrate,"
232 "misc").split(",");
233
234 if (lines.size() > 0) {
235 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
236 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
237
238 QStringList hlp = lines[0].split(";");
239 _table->setColumnCount(hlp.size()-1);
240 _table->setRowCount(lines.size());
241
242 QListIterator<QString> it(lines);
243 int nRow = -1;
244 while (it.hasNext()) {
245 QStringList columns = it.next().split(";");
246 ++nRow;
247 for (int ic = 0; ic < columns.size()-1; ic++) {
248
249 if (ic+1 == 11) { if (columns[ic+1] == "0") { columns[ic+1] = "no"; } else { columns[ic+1] = "yes"; }}
250
251 QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
252 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
253 _table->setItem(nRow, ic, it);
254 }
255 }
256 _table->sortItems(0);
257 _table->setHorizontalHeaderLabels(labels);
258 _table->setSortingEnabled(true);
259
260 int ww = QFontMetrics(this->font()).width('w');
261 _table->horizontalHeader()->resizeSection(0,10*ww);
262 _table->horizontalHeader()->resizeSection(2,8*ww);
263 _table->horizontalHeader()->resizeSection(3,15*ww);
264 _table->horizontalHeader()->resizeSection(4,8*ww);
265 _table->horizontalHeader()->resizeSection(5,8*ww);
266 _table->horizontalHeader()->resizeSection(6,8*ww);
267 _table->horizontalHeader()->resizeSection(7,8*ww);
268 _table->horizontalHeader()->resizeSection(8,8*ww);
269 _table->horizontalHeader()->resizeSection(9,8*ww);
270 _table->horizontalHeader()->resizeSection(10,8*ww);
271 _table->horizontalHeader()->resizeSection(11,8*ww);
272 _table->horizontalHeader()->resizeSection(12,15*ww);
273 _table->horizontalHeader()->resizeSection(13,8*ww);
274 _table->horizontalHeader()->resizeSection(14,8*ww);
275 _table->horizontalHeader()->resizeSection(15,8*ww);
276 _table->horizontalHeader()->resizeSection(16,8*ww);
277 _table->horizontalHeader()->resizeSection(17,15*ww);
278 }
279}
280
281// Accept slot
282////////////////////////////////////////////////////////////////////////////
283void bncTableDlg::accept() {
284
285 QSettings settings;
286 settings.setValue("casterHost", _casterHostLineEdit->text());
287 settings.setValue("casterPort", _casterPortLineEdit->text());
288 settings.setValue("casterUser", _casterUserLineEdit->text());
289 settings.setValue("casterPassword", _casterPasswordLineEdit->text());
290
291 QStringList* mountPoints = new QStringList;
292
293 if (_table) {
294 for (int ir = 0; ir < _table->rowCount(); ir++) {
295 QTableWidgetItem* item = _table->item(ir,0);
296 QString format = _table->item(ir,2)->text();
297 QString latitude = _table->item(ir,8)->text();
298 QString longitude = _table->item(ir,9)->text();
299 QString nmea = _table->item(ir,10)->text();
300 format.replace(" ", "_");
301 if (_table->isItemSelected(item)) {
302 QUrl url;
303 url.setUserName(QUrl::toPercentEncoding(_casterUserLineEdit->text()));
304 url.setPassword(QUrl::toPercentEncoding(_casterPasswordLineEdit->text()));
305 url.setHost(_casterHostLineEdit->text());
306 url.setPort(_casterPortLineEdit->text().toInt());
307 url.setPath(item->text());
308
309 mountPoints->push_back(url.toString() + " " + format + " " + latitude + " " + longitude + " " + nmea);
310 }
311 }
312 }
313 emit newMountPoints(mountPoints);
314
315 QDialog::accept();
316}
317
318// User changed the selection of mountPoints
319////////////////////////////////////////////////////////////////////////////
320void bncTableDlg::slotSelectionChanged() {
321 if (_table->selectedItems().isEmpty()) {
322 }
323}
324
325// Create RINEX skeleton header
326////////////////////////////////////////////////////////////////////////////
327void bncTableDlg::slotSkl() {
328
329 int nRows = _table->rowCount();
330 for (int iRow = 0; iRow < nRows; iRow++) {
331 if (_table->isItemSelected(_table->item(iRow,1))) {
332 QString staID = _table->item(iRow,0)->text();
333 QString net = _table->item(iRow,6)->text();
334
335 QString ftpDir;
336 QStringListIterator it(_allLines);
337 while (it.hasNext()) {
338 QString line = it.next();
339 if (line.indexOf("NET") == 0) {
340 QStringList tags = line.split(';');
341 if (tags.at(1) == net) {
342 ftpDir = tags.at(6);
343 break;
344 }
345 }
346 }
347
348 if (!ftpDir.isEmpty()) {
349 QUrl url(ftpDir);
350 QMessageBox::warning(0, "Warning", url.host() + "\n" + url.path() +
351 "\nnot yet implemented");
352 }
353 }
354 }
355}
356
357// Whats This Help
358void bncTableDlg::slotWhatsThis() {
359QWhatsThis::enterWhatsThisMode();
360}
361
362
Note: See TracBrowser for help on using the repository browser.