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

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