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

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

* empty log message *

File size: 13.3 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("Streams on NTRIP broadcasters might be protected by password. 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>."));
65 _casterPasswordLineEdit = new QLineEdit(settings.value("casterPassword").toString());
66 _casterPasswordLineEdit->setMaximumWidth(9*ww);
67 _casterPasswordLineEdit->setEchoMode(QLineEdit::Password);
68 _casterPasswordLineEdit->setWhatsThis(tr("Streams on NTRIP broadcasters might be protected by password. 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>."));
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 your 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 'type' tells you whether a stream comes from a physical Reference Station (RS) or a Virtual Reference Station (VRS).</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 _buttonGet = new QPushButton(tr("Get table"), this);
93 connect(_buttonGet, SIGNAL(clicked()), this, SLOT(slotGetTable()));
94
95 _buttonCancel = new QPushButton(tr("Cancel"), this);
96 connect(_buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
97
98 _buttonOK = new QPushButton(tr("OK"), this);
99 connect(_buttonOK, SIGNAL(clicked()), this, SLOT(accept()));
100
101 QHBoxLayout* buttonLayout = new QHBoxLayout;
102 // buttonLayout->addWidget(_buttonSkl);
103 buttonLayout->addStretch(1);
104 buttonLayout->addWidget(_buttonGet);
105 buttonLayout->addWidget(_buttonCancel);
106 buttonLayout->addWidget(_buttonOK);
107
108 mainLayout->addLayout(buttonLayout);
109}
110
111// Destructor
112////////////////////////////////////////////////////////////////////////////
113bncTableDlg::~bncTableDlg() {
114 if (_table) {
115 for (int ir = 0; ir < _table->rowCount(); ir++) {
116 for (int ic = 0; ic < _table->columnCount(); ic++) {
117 delete _table->item(ir,ic);
118 }
119 }
120 }
121}
122
123// Read Table the caster (static)
124////////////////////////////////////////////////////////////////////////////
125t_irc bncTableDlg::getFullTable(const QString& casterHost,
126 int casterPort, QStringList& allLines,
127 bool alwaysRead) {
128
129 static QMutex mutex;
130 static QMap<QString, QStringList> allTables;
131
132 QMutexLocker locker(&mutex);
133
134 if (!alwaysRead && allTables.find(casterHost) != allTables.end()) {
135 allLines = allTables.find(casterHost).value();
136 return success;
137 }
138
139 allLines.clear();
140
141 QUrl url;
142 url.setHost(casterHost);
143 url.setPort(casterPort);
144
145 // Send the Request
146 // ----------------
147 const int timeOut = 10*1000;
148 QString msg;
149 QByteArray _latitude;
150 QByteArray _longitude;
151 QByteArray _nmea;
152 QTcpSocket* socket = bncGetThread::request(url, _latitude, _longitude, _nmea, timeOut, msg);
153
154 if (!socket) {
155 return failure;
156 }
157
158 // Read Caster Response
159 // --------------------
160 bool first = true;
161 while (true) {
162 if (socket->canReadLine()) {
163 QString line = socket->readLine();
164 allLines.push_back(line);
165 if (first) {
166 first = false;
167 if (line.indexOf("SOURCETABLE 200 OK") != 0) {
168 break;
169 }
170 }
171 else {
172 if (line.indexOf("ENDSOURCETABLE") == 0) {
173 break;
174 }
175 }
176 }
177 else {
178 socket->waitForReadyRead(timeOut);
179 if (socket->bytesAvailable() > 0) {
180 continue;
181 }
182 else {
183 break;
184 }
185 }
186 }
187 delete socket;
188
189 allTables.insert(casterHost, allLines);
190 return success;
191}
192
193// Read Table from Caster
194////////////////////////////////////////////////////////////////////////////
195void bncTableDlg::slotGetTable() {
196
197 _allLines.clear();
198
199 if ( getFullTable(_casterHostLineEdit->text(),
200 _casterPortLineEdit->text().toInt(),
201 _allLines) != success ) {
202 QMessageBox::warning(0, "BNC", "Cannot retrieve table of data");
203 return;
204 }
205
206 QStringList lines;
207 QStringListIterator it(_allLines);
208 while (it.hasNext()) {
209 QString line = it.next();
210 if (line.indexOf("STR") == 0) {
211 lines.push_back(line);
212 }
213 }
214
215 static const QStringList labels = QString("mountpoint,identifier,format,"
216 "format-details,carrier,system,network,country,latitude,longitude,"
217 "type,solution,generator,compress.,authentic.,fee,bitrate,"
218 "misc").split(",");
219
220 if (lines.size() > 0) {
221 _table->setSelectionMode(QAbstractItemView::ExtendedSelection);
222 _table->setSelectionBehavior(QAbstractItemView::SelectRows);
223
224 QStringList hlp = lines[0].split(";");
225 _table->setColumnCount(hlp.size()-1);
226 _table->setRowCount(lines.size());
227
228 QListIterator<QString> it(lines);
229 int nRow = -1;
230 while (it.hasNext()) {
231 QStringList columns = it.next().split(";");
232 ++nRow;
233 for (int ic = 0; ic < columns.size()-1; ic++) {
234
235 if (ic+1 == 11) { if (columns[ic+1] == "0") { columns[ic+1] = "RS"; } else { columns[ic+1] = "VRS"; }}
236
237 QTableWidgetItem* it = new QTableWidgetItem(columns[ic+1]);
238 it->setFlags(it->flags() & ~Qt::ItemIsEditable);
239 _table->setItem(nRow, ic, it);
240 }
241 }
242 _table->sortItems(0);
243 _table->setHorizontalHeaderLabels(labels);
244 _table->setSortingEnabled(true);
245
246 int ww = QFontMetrics(this->font()).width('w');
247 _table->horizontalHeader()->resizeSection(0,10*ww);
248 _table->horizontalHeader()->resizeSection(2,8*ww);
249 _table->horizontalHeader()->resizeSection(3,15*ww);
250 _table->horizontalHeader()->resizeSection(4,8*ww);
251 _table->horizontalHeader()->resizeSection(5,8*ww);
252 _table->horizontalHeader()->resizeSection(6,8*ww);
253 _table->horizontalHeader()->resizeSection(7,8*ww);
254 _table->horizontalHeader()->resizeSection(8,8*ww);
255 _table->horizontalHeader()->resizeSection(9,8*ww);
256 _table->horizontalHeader()->resizeSection(10,8*ww);
257 _table->horizontalHeader()->resizeSection(11,8*ww);
258 _table->horizontalHeader()->resizeSection(12,15*ww);
259 _table->horizontalHeader()->resizeSection(13,8*ww);
260 _table->horizontalHeader()->resizeSection(14,8*ww);
261 _table->horizontalHeader()->resizeSection(15,8*ww);
262 _table->horizontalHeader()->resizeSection(16,8*ww);
263 _table->horizontalHeader()->resizeSection(17,15*ww);
264 }
265}
266
267// Accept slot
268////////////////////////////////////////////////////////////////////////////
269void bncTableDlg::accept() {
270
271 QSettings settings;
272 settings.setValue("casterHost", _casterHostLineEdit->text());
273 settings.setValue("casterPort", _casterPortLineEdit->text());
274 settings.setValue("casterUser", _casterUserLineEdit->text());
275 settings.setValue("casterPassword", _casterPasswordLineEdit->text());
276
277 QStringList* mountPoints = new QStringList;
278
279 if (_table) {
280 for (int ir = 0; ir < _table->rowCount(); ir++) {
281 QTableWidgetItem* item = _table->item(ir,0);
282 QString format = _table->item(ir,2)->text();
283 QString latitude = _table->item(ir,8)->text();
284 QString longitude = _table->item(ir,9)->text();
285 QString nmea = _table->item(ir,10)->text();
286 format.replace(" ", "_");
287 if (_table->isItemSelected(item)) {
288 QUrl url;
289 url.setUserName(_casterUserLineEdit->text());
290 url.setPassword(_casterPasswordLineEdit->text());
291 url.setHost(_casterHostLineEdit->text());
292 url.setPort(_casterPortLineEdit->text().toInt());
293 url.setPath(item->text());
294
295 mountPoints->push_back(url.toString() + " " + format + " " + latitude + " " + longitude + " " + nmea);
296 }
297 }
298 }
299 emit newMountPoints(mountPoints);
300
301 QDialog::accept();
302}
303
304// User changed the selection of mountPoints
305////////////////////////////////////////////////////////////////////////////
306void bncTableDlg::slotSelectionChanged() {
307 if (_table->selectedItems().isEmpty()) {
308 // _buttonSkl->setEnabled(false);
309 }
310 else {
311 // _buttonSkl->setEnabled(true);
312 }
313}
314
315// Create RINEX skeleton header
316////////////////////////////////////////////////////////////////////////////
317void bncTableDlg::slotSkl() {
318
319 int nRows = _table->rowCount();
320 for (int iRow = 0; iRow < nRows; iRow++) {
321 if (_table->isItemSelected(_table->item(iRow,1))) {
322 QString staID = _table->item(iRow,0)->text();
323 QString net = _table->item(iRow,6)->text();
324
325 QString ftpDir;
326 QStringListIterator it(_allLines);
327 while (it.hasNext()) {
328 QString line = it.next();
329 if (line.indexOf("NET") == 0) {
330 QStringList tags = line.split(';');
331 if (tags.at(1) == net) {
332 ftpDir = tags.at(6);
333 break;
334 }
335 }
336 }
337
338 if (!ftpDir.isEmpty()) {
339 QUrl url(ftpDir);
340 QMessageBox::warning(0, "Warning", url.host() + "\n" + url.path() +
341 "\nnot yet implemented");
342 }
343 }
344 }
345}
346
Note: See TracBrowser for help on using the repository browser.