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

Last change on this file since 426 was 410, checked in by weber, 18 years ago

* empty log message *

File size: 13.9 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters,
3// written by Leos Mervart.
4//
5// Copyright (C) 2006
6// German Federal Agency for Cartography and Geodesy (BKG)
7// http://www.bkg.bund.de
8// Czech Technical University Prague, Department of Advanced Geodesy
9// http://www.fsv.cvut.cz
10//
11// Email: euref-ip@bkg.bund.de
12//
13// This program is free software; you can redistribute it and/or
14// modify it under the terms of the GNU General Public License
15// as published by the Free Software Foundation, version 2.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26/* -------------------------------------------------------------------------
27 * BKG NTRIP Client
28 * -------------------------------------------------------------------------
29 *
30 * Class: bncTableDlg
31 *
32 * Purpose: Displays the source table, allows mountpoints selection
33 *
34 * Author: L. Mervart
35 *
36 * Created: 24-Dec-2005
37 *
38 * Changes:
39 *
40 * -----------------------------------------------------------------------*/
41
42#include "bnctabledlg.h"
43#include "bncgetthread.h"
44
45// Constructor
46////////////////////////////////////////////////////////////////////////////
47bncTableDlg::bncTableDlg(QWidget* parent) : QDialog(parent) {
48
49 setMinimumSize(600,400);
50 setWindowTitle(tr("Add Mountpoints"));
51
52 QVBoxLayout* mainLayout = new QVBoxLayout(this);
53
54 QSettings settings;
55 _casterHostLineEdit = new QLineEdit(settings.value("casterHost").toString());
56 int ww = QFontMetrics(_casterHostLineEdit->font()).width('w');
57 _casterHostLineEdit->setMaximumWidth(18*ww);
58 _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>."));
59 _casterPortLineEdit = new QLineEdit(settings.value("casterPort").toString());
60 _casterPortLineEdit->setMaximumWidth(9*ww);
61 _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>."));
62 _casterUserLineEdit = new QLineEdit(settings.value("casterUser").toString());
63 _casterUserLineEdit->setMaximumWidth(9*ww);
64 _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>"));
65 _casterPasswordLineEdit = new QLineEdit(settings.value("casterPassword").toString());
66 _casterPasswordLineEdit->setMaximumWidth(9*ww);
67 _casterPasswordLineEdit->setEchoMode(QLineEdit::Password);
68 _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>"));
69
70 QGridLayout* editLayout = new QGridLayout;
71 editLayout->addWidget(new QLabel(tr("Caster host")), 0, 0);
72 editLayout->addWidget(_casterHostLineEdit, 0, 1);
73 editLayout->addWidget(new QLabel(tr("Caster port")), 0, 2);
74 editLayout->addWidget(_casterPortLineEdit, 0, 3);
75 editLayout->addWidget(new QLabel(tr("User")), 1, 0);
76 editLayout->addWidget(_casterUserLineEdit, 1, 1);
77 editLayout->addWidget(new QLabel(tr("Password")), 1, 2);
78 editLayout->addWidget(_casterPasswordLineEdit, 1, 3);
79
80 mainLayout->addLayout(editLayout);
81
82 _table = new QTableWidget(this);
83 _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>"));
84 connect(_table, SIGNAL(itemSelectionChanged()),
85 this, SLOT(slotSelectionChanged()));
86 mainLayout->addWidget(_table);
87
88 // _buttonSkl = new QPushButton(tr("Create skeleton headers"), this);
89 // _buttonSkl->setEnabled(false);
90 // connect(_buttonSkl, SIGNAL(clicked()), this, SLOT(slotSkl()));
91
92 _buttonWhatsThis = new QPushButton(tr("Help=Shift+F1"), this);
93 connect(_buttonWhatsThis, SIGNAL(clicked()), this, SLOT(slotWhatsThis()));
94
95 _buttonGet = new QPushButton(tr("Get table"), this);
96 _buttonGet->setDefault(true);
97 connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
98
99 _buttonCancel = new QPushButton(tr("Cancel"), this);
100 connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
101
102 _buttonOK = new QPushButton(tr("OK"), this);
103 connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
104
105 QHBoxLayout* buttonLayout = new QHBoxLayout;
106 // buttonLayout->addWidget(_buttonSkl);
107 buttonLayout->addWidget(_buttonWhatsThis);
108 buttonLayout->addStretch(1);
109 buttonLayout->addWidget(_buttonGet);
110 buttonLayout->addWidget(_buttonCancel);
111 buttonLayout->addWidget(_buttonOK);
112
113 mainLayout->addLayout(buttonLayout);
114}
115
116// Destructor
117////////////////////////////////////////////////////////////////////////////
118bncTableDlg::~bncTableDlg() {
119 if (_table) {
120 for (int ir = 0; ir < _table->rowCount(); ir++) {
121 for (int ic = 0; ic < _table->columnCount(); ic++) {
122 delete _table->item(ir,ic);
123 }
124 }
125 }
126}
127
128// Read Table the caster (static)
129////////////////////////////////////////////////////////////////////////////
130t_irc bncTableDlg::getFullTable(const QString& casterHost,
131 int casterPort, QStringList& allLines,
132 bool alwaysRead) {
133
134 static QMutex mutex;
135 static QMap<QString, QStringList> allTables;
136
137 QMutexLocker locker(&mutex);
138
139 if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
140 allLines = allTables.find(casterHost).value();
141 return success;
142 }
143
144 allLines.clear();
145
146 QUrl url;
147 url.setHost(casterHost);
148 url.setPort(casterPort);
149
150 // Send the Request
151 // ----------------
152 const int timeOut = 10*1000;
153 QString msg;
154 QByteArray _latitude;
155 QByteArray _longitude;
156 QByteArray _nmea;
157 QTcpSocket* socket = bncGetThread::request(url, _latitude, _longitude, _nmea, timeOut, msg);
158
159 if (!socket) {
160 return failure;
161 }
162
163 // Read Caster Response
164 // --------------------
165 bool first = true;
166 while (true) {
167 if (socket->canReadLine()) {
168 QString line = socket->readLine();
169 allLines.push_back(line);
170 if (first) {
171 first = false;
172 if (line.indexOf("SOURCETABLE 200 OK") != 0) {
173 break;
174 }
175 }
176 else {
177 if (line.indexOf("ENDSOURCETABLE") == 0) {
178 break;
179 }
180 }
181 }
182 else {
183 socket->waitForReadyRead(timeOut);
184 if (socket->bytesAvailable() > 0) {
185 continue;
186 }
187 else {
188 break;
189 }
190 }
191 }
192 delete socket;
193
194 allTables.insert(casterHost, allLines);
195 return success;
196}
197
198// Read Table from Caster
199////////////////////////////////////////////////////////////////////////////
200void bncTableDlg::slotGetTable() {
201
202 _allLines.clear();
203
204 if ( getFullTable(_casterHostLineEdit->text(),
205 _casterPortLineEdit->text().toInt(),
206 _allLines) != success ) {
207 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
208 return;
209 }
210
211 QStringList lines;
212 QStringListIterator it(_allLines);
213 while (it.hasNext()) {
214 QString line = it.next();
215 if (line.indexOf("STR") == 0) {
216 lines.push_back(line);
217 }
218 }
219
220 static const QStringList labels = QString("mountpoint,identifier,format,"
221 "format-details,carrier,system,network,country,latitude,longitude,"
222 "nmea,solution,generator,compress.,authentic.,fee,bitrate,"
223 "misc").split(",");
224
225 if (lines.size() > 0) {
226 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
227 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
228
229 QStringList hlp = lines[0].split(";");
230 _table->setColumnCount(hlp.size()-1);
231 _table->setRowCount(lines.size());
232
233 QListIterator<QString> it(lines);
234 int nRow = -1;
235 while (it.hasNext()) {
236 QStringList columns = it.next().split(";");
237 ++nRow;
238 for (int ic = 0; ic < columns.size()-1; ic++) {
239
240 if (ic+1 == 11) { if (columns[ic+1] == "0") { columns[ic+1] = "no"; } else { columns[ic+1] = "yes"; }}
241
242 QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
243 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
244 _table->setItem(nRow, ic, it);
245 }
246 }
247 _table->sortItems(0);
248 _table->setHorizontalHeaderLabels(labels);
249 _table->setSortingEnabled(true);
250
251 int ww = QFontMetrics(this->font()).width('w');
252 _table->horizontalHeader()->resizeSection(0,10*ww);
253 _table->horizontalHeader()->resizeSection(2,8*ww);
254 _table->horizontalHeader()->resizeSection(3,15*ww);
255 _table->horizontalHeader()->resizeSection(4,8*ww);
256 _table->horizontalHeader()->resizeSection(5,8*ww);
257 _table->horizontalHeader()->resizeSection(6,8*ww);
258 _table->horizontalHeader()->resizeSection(7,8*ww);
259 _table->horizontalHeader()->resizeSection(8,8*ww);
260 _table->horizontalHeader()->resizeSection(9,8*ww);
261 _table->horizontalHeader()->resizeSection(10,8*ww);
262 _table->horizontalHeader()->resizeSection(11,8*ww);
263 _table->horizontalHeader()->resizeSection(12,15*ww);
264 _table->horizontalHeader()->resizeSection(13,8*ww);
265 _table->horizontalHeader()->resizeSection(14,8*ww);
266 _table->horizontalHeader()->resizeSection(15,8*ww);
267 _table->horizontalHeader()->resizeSection(16,8*ww);
268 _table->horizontalHeader()->resizeSection(17,15*ww);
269 }
270}
271
272// Accept slot
273////////////////////////////////////////////////////////////////////////////
274void bncTableDlg::accept() {
275
276 QSettings settings;
277 settings.setValue("casterHost", _casterHostLineEdit->text());
278 settings.setValue("casterPort", _casterPortLineEdit->text());
279 settings.setValue("casterUser", _casterUserLineEdit->text());
280 settings.setValue("casterPassword", _casterPasswordLineEdit->text());
281
282 QStringList* mountPoints = new QStringList;
283
284 if (_table) {
285 for (int ir = 0; ir < _table->rowCount(); ir++) {
286 QTableWidgetItem* item = _table->item(ir,0);
287 QString format = _table->item(ir,2)->text();
288 QString latitude = _table->item(ir,8)->text();
289 QString longitude = _table->item(ir,9)->text();
290 QString nmea = _table->item(ir,10)->text();
291 format.replace(" ", "_");
292 if (_table->isItemSelected(item)) {
293 QUrl url;
294 url.setUserName(_casterUserLineEdit->text());
295 url.setPassword(_casterPasswordLineEdit->text());
296 url.setHost(_casterHostLineEdit->text());
297 url.setPort(_casterPortLineEdit->text().toInt());
298 url.setPath(item->text());
299
300 mountPoints->push_back(url.toString() + " " + format + " " + latitude + " " + longitude + " " + nmea);
301 }
302 }
303 }
304 emit newMountPoints(mountPoints);
305
306 QDialog::accept();
307}
308
309// User changed the selection of mountPoints
310////////////////////////////////////////////////////////////////////////////
311void bncTableDlg::slotSelectionChanged() {
312 if (_table->selectedItems().isEmpty()) {
313 // _buttonSkl->setEnabled(false);
314 }
315 else {
316 // _buttonSkl->setEnabled(true);
317 }
318}
319
320// Create RINEX skeleton header
321////////////////////////////////////////////////////////////////////////////
322void bncTableDlg::slotSkl() {
323
324 int nRows = _table->rowCount();
325 for (int iRow = 0; iRow < nRows; iRow++) {
326 if (_table->isItemSelected(_table->item(iRow,1))) {
327 QString staID = _table->item(iRow,0)->text();
328 QString net = _table->item(iRow,6)->text();
329
330 QString ftpDir;
331 QStringListIterator it(_allLines);
332 while (it.hasNext()) {
333 QString line = it.next();
334 if (line.indexOf("NET") == 0) {
335 QStringList tags = line.split(';');
336 if (tags.at(1) == net) {
337 ftpDir = tags.at(6);
338 break;
339 }
340 }
341 }
342
343 if (!ftpDir.isEmpty()) {
344 QUrl url(ftpDir);
345 QMessageBox::warning(0, "Warning", url.host() + "\n" + url.path() +
346 "\nnot yet implemented");
347 }
348 }
349 }
350}
351
352// Whats This Help
353void bncTableDlg::slotWhatsThis() {
354QWhatsThis::enterWhatsThisMode();
355}
356
357
Note: See TracBrowser for help on using the repository browser.