source: ntrip/trunk/GnssCenter/monitor/monitor.cpp@ 8486

Last change on this file since 8486 was 5499, checked in by mervart, 11 years ago
File size: 8.5 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * RTNet Monitor
4 * -------------------------------------------------------------------------
5 *
6 * Class: t_monitor
7 *
8 * Purpose: Real-Time Monitoring of RTNet
9 *
10 * Author: L. Mervart
11 *
12 * Created: 05-Jan-2013
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include <iostream>
19#include <QtSvg>
20
21#include <qwt_symbol.h>
22#include <qwt_plot.h>
23#include <qwt_plot_svgitem.h>
24#include <qwt_plot_curve.h>
25#include <qwt_plot_marker.h>
26#include <qwt_plot_canvas.h>
27#include <qwt_plot_zoomer.h>
28#include <qwt_plot_renderer.h>
29
30#include "monitor.h"
31#include "dlgconf.h"
32#include "utils.h"
33#include "worldplot.h"
34#include "thriftclient.h"
35#include "settings.h"
36
37using namespace std;
38using namespace GnssCenter;
39
40Q_EXPORT_PLUGIN2(gnsscenter_monitor, t_monitorFactory)
41
42// Constructor
43/////////////////////////////////////////////////////////////////////////////
44t_monitor::t_monitor() : QMainWindow() {
45
46 _tabWidget = new QTabWidget();
47 setCentralWidget(_tabWidget);
48
49 // World Plots
50 // -----------
51 _plotStations = new t_worldPlot();
52 _tabWidget->addTab(_plotStations, "Stations");
53
54 _plotSatellites = new t_worldPlot();
55 _tabWidget->addTab(_plotSatellites, "Satellites");
56
57 // Tool Bar
58 // --------
59 QToolBar* toolBar = new QToolBar("t_monitor_ToolBar");
60 addToolBar(Qt::BottomToolBarArea, toolBar);
61
62 _actConfig = new QAction("Config", 0);
63 toolBar->addAction(_actConfig);
64 connect(_actConfig, SIGNAL(triggered()), this, SLOT(slotConfig()));
65
66 _actStartThrift = new QAction("Start", 0);
67 toolBar->addAction(_actStartThrift);
68 connect(_actStartThrift, SIGNAL(triggered()), this, SLOT(slotStartThrift()));
69
70 _actStopThrift = new QAction("Stop", 0);
71 toolBar->addAction(_actStopThrift);
72 connect(_actStopThrift, SIGNAL(triggered()), this, SLOT(slotStopThrift()));
73
74 // Thrift Client;
75 // --------------
76 _thriftClient = 0;
77 _results = 0;
78 _satellites = 0;
79
80 // Read Settings, Set Title, Enable/Disable Actions
81 // ------------------------------------------------
82 readSettings();
83 setTitle();
84 enableActions();
85}
86
87// Destructor
88/////////////////////////////////////////////////////////////////////////////
89t_monitor::~t_monitor() {
90 slotStopThrift();
91 if (_results) {
92 while (!_results->empty()) {
93 delete _results->back();
94 _results->pop_back();
95 }
96 delete _results;
97 }
98 if (_satellites) {
99 while (!_satellites->empty()) {
100 delete _satellites->back();
101 _satellites->pop_back();
102 }
103 delete _satellites;
104 }
105}
106
107// Read Settings
108/////////////////////////////////////////////////////////////////////////////
109void t_monitor::readSettings() {
110 t_settings settings(pluginName);
111 _host = settings.value("host").toString().trimmed();
112 if (_host.isEmpty()) {
113 _host = "localhost";
114 }
115 _port = settings.value("port").toString();
116}
117
118// Set title
119/////////////////////////////////////////////////////////////////////////////
120void t_monitor::setTitle() {
121 if (_port.isEmpty()) {
122 setWindowTitle(QString(pluginName));
123 }
124 else {
125 setWindowTitle(QString(pluginName) + " " + _host + ':' + _port);
126 }
127}
128
129// Enable/Disable Actions
130/////////////////////////////////////////////////////////////////////////////
131void t_monitor::enableActions() {
132 if (_port.isEmpty()) {
133 _actConfig->setEnabled(true);
134 _actStartThrift->setEnabled(false);
135 _actStopThrift->setEnabled(false);
136 }
137 else if (_thriftClient) {
138 _actConfig->setEnabled(false);
139 _actStartThrift->setEnabled(false);
140 _actStopThrift->setEnabled(true);
141 }
142 else {
143 _actConfig->setEnabled(true);
144 _actStartThrift->setEnabled(true);
145 _actStopThrift->setEnabled(false);
146 }
147}
148
149//
150/////////////////////////////////////////////////////////////////////////////
151void t_monitor::slotConfig() {
152 t_dlgConf dlg(this);
153 dlg.exec();
154 readSettings();
155 setTitle();
156 enableActions();
157}
158
159//
160/////////////////////////////////////////////////////////////////////////////
161void t_monitor::slotMessage(QByteArray msg) {
162 QMessageBox::information(this, "Message", msg);
163}
164
165//
166/////////////////////////////////////////////////////////////////////////////
167void t_monitor::slotStartThrift() {
168 if (!_thriftClient) {
169 _thriftClient = new t_thriftClient(this, _host, _port.toInt());
170 connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
171 connect(_thriftClient, SIGNAL(message(QByteArray)), this, SLOT(slotMessage(QByteArray)));
172 _thriftClient->start();
173 slotPlot();
174 }
175 enableActions();
176}
177
178//
179/////////////////////////////////////////////////////////////////////////////
180void t_monitor::slotStopThrift() {
181 if (_thriftClient) {
182 _thriftClient->stop();
183 _thriftClient = 0;
184 }
185 enableActions();
186}
187
188//
189/////////////////////////////////////////////////////////////////////////////
190void t_monitor::slotThriftFinished() {
191 sender()->deleteLater();
192 _thriftClient = 0;
193 enableActions();
194}
195
196//
197/////////////////////////////////////////////////////////////////////////////
198void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
199 QMutexLocker locker(&_mutex);
200 if (_results) {
201 while (!_results->empty()) {
202 delete _results->back();
203 _results->pop_back();
204 }
205 delete _results;
206 }
207 _results = results;
208}
209
210//
211/////////////////////////////////////////////////////////////////////////////
212void t_monitor::putThriftSatellites(std::vector<t_thriftSatellite*>* satellites) {
213 QMutexLocker locker(&_mutex);
214 if (_satellites) {
215 while (!_satellites->empty()) {
216 delete _satellites->back();
217 _satellites->pop_back();
218 }
219 delete _satellites;
220 }
221 _satellites = satellites;
222}
223
224//
225/////////////////////////////////////////////////////////////////////////////
226void t_monitor::slotPlot() {
227 QMutexLocker locker(&_mutex);
228 plotResults();
229 plotSatellites();
230 if (_thriftClient) {
231 QTimer::singleShot(1000, this, SLOT(slotPlot()));
232 }
233}
234
235//
236/////////////////////////////////////////////////////////////////////////////
237void t_monitor::plotResults() {
238 if (_results) {
239 QList<t_worldPlot::t_point*> points;
240 for (unsigned ii = 0; ii < _results->size(); ii++) {
241 const t_thriftResult* result = _results->at(ii);
242
243 double xyz[3];
244 xyz[0] = result->_x;
245 xyz[1] = result->_y;
246 xyz[2] = result->_z;
247
248 double ell[3];
249
250 if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
251 double latDeg = ell[0] * 180.0 / M_PI;
252 double lonDeg = ell[1] * 180.0 / M_PI;
253 QString str = QString(result->_name.c_str()) +
254 QString().sprintf("\n%d/%d", result->_nGPS, result->_nGLO);
255 QColor color = result->_nGPS >= 4 ? Qt::black : Qt::red;
256 t_worldPlot::t_point* point = new t_worldPlot::t_point(color, str, latDeg, lonDeg);
257 points.append(point);
258 }
259 }
260 _plotStations->slotNewPoints(points);
261
262 QListIterator<t_worldPlot::t_point*> it(points);
263 while (it.hasNext()) {
264 delete it.next();
265 }
266 }
267}
268
269//
270/////////////////////////////////////////////////////////////////////////////
271void t_monitor::plotSatellites() {
272 if (_satellites) {
273 QList<t_worldPlot::t_point*> points;
274 for (unsigned ii = 0; ii < _satellites->size(); ii++) {
275 const t_thriftSatellite* sat = _satellites->at(ii);
276
277 double xyz[3];
278 xyz[0] = sat->_x;
279 xyz[1] = sat->_y;
280 xyz[2] = sat->_z;
281
282 double ell[3];
283
284 if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
285 double latDeg = ell[0] * 180.0 / M_PI;
286 double lonDeg = ell[1] * 180.0 / M_PI;
287
288 QString str = sat->_prn.c_str();
289
290 QColor color;
291 if (str[0] == 'G') {
292 color = Qt::darkBlue;
293 }
294 else if (str[0] == 'R') {
295 color = Qt::darkGreen;
296 }
297 else {
298 color = Qt::black;
299 }
300
301 if (_results) {
302 int numSta = 0;
303 for (unsigned jj = 0; jj < _results->size(); jj++) {
304 const t_thriftResult* result = _results->at(jj);
305 if (result->_prns.find(sat->_prn) != result->_prns.end()) {
306 numSta += 1;
307 }
308 }
309 str += QString().sprintf("\n%d", numSta);
310 if (numSta < 4) {
311 color = Qt::red;
312 }
313 }
314
315 t_worldPlot::t_point* point = new t_worldPlot::t_point(color, str, latDeg, lonDeg);
316 points.append(point);
317 }
318 }
319 _plotSatellites->slotNewPoints(points);
320
321 QListIterator<t_worldPlot::t_point*> it(points);
322 while (it.hasNext()) {
323 delete it.next();
324 }
325 }
326}
Note: See TracBrowser for help on using the repository browser.