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

Last change on this file since 5469 was 5469, checked in by mervart, 11 years ago
File size: 5.0 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 Plot
50 // ----------
51 _plot = new t_worldPlot();
52 _tabWidget->addTab(_plot, "Stations");
53
54 // Tool Bar
55 // --------
56 QToolBar* toolBar = new QToolBar("t_monitor_ToolBar");
57 addToolBar(Qt::BottomToolBarArea, toolBar);
58
59 _actConfig = new QAction("Config", 0);
60 toolBar->addAction(_actConfig);
61 connect(_actConfig, SIGNAL(triggered()), this, SLOT(slotConfig()));
62
63 _actStartThrift = new QAction("Start", 0);
64 toolBar->addAction(_actStartThrift);
65 connect(_actStartThrift, SIGNAL(triggered()), this, SLOT(slotStartThrift()));
66
67 _actStopThrift = new QAction("Stop", 0);
68 toolBar->addAction(_actStopThrift);
69 connect(_actStopThrift, SIGNAL(triggered()), this, SLOT(slotStopThrift()));
70
71 // Window title
72 // ------------
73 setTitle();
74
75 // Thrift Client;
76 // --------------
77 _thriftClient = 0;
78 _results = 0;
79}
80
81// Destructor
82/////////////////////////////////////////////////////////////////////////////
83t_monitor::~t_monitor() {
84 slotStopThrift();
85 if (_results) {
86 while (!_results->empty()) {
87 delete _results->back();
88 _results->pop_back();
89 }
90 delete _results;
91 }
92}
93
94// Set title
95/////////////////////////////////////////////////////////////////////////////
96void t_monitor::setTitle() {
97 t_settings settings(pluginName);
98 QString host = settings.value("host").toString();
99 if (host.isEmpty()) {
100 host = "localhost";
101 }
102 QString port = settings.value("port").toString();
103 setWindowTitle(QString(pluginName) + " " + host + ':' + port);
104}
105
106//
107/////////////////////////////////////////////////////////////////////////////
108void t_monitor::slotConfig() {
109 t_dlgConf dlg(this);
110 dlg.exec();
111 setTitle();
112}
113
114//
115/////////////////////////////////////////////////////////////////////////////
116void t_monitor::slotStartThrift() {
117 if (!_thriftClient) {
118 t_settings settings(pluginName);
119 QString host = settings.value("host").toString();
120 if (host.isEmpty()) {
121 host = "localhost";
122 }
123 int port = settings.value("port").toInt();
124 _thriftClient = new t_thriftClient(this, host, port);
125 connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
126 _thriftClient->start();
127 slotPlotResults();
128 }
129}
130
131//
132/////////////////////////////////////////////////////////////////////////////
133void t_monitor::slotStopThrift() {
134 if (_thriftClient) {
135 _thriftClient->stop();
136 _thriftClient = 0;
137 }
138}
139
140//
141/////////////////////////////////////////////////////////////////////////////
142void t_monitor::slotThriftFinished() {
143 sender()->deleteLater();
144 _thriftClient = 0;
145}
146
147//
148/////////////////////////////////////////////////////////////////////////////
149void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
150 QMutexLocker locker(&_mutex);
151 if (_results) {
152 while (!_results->empty()) {
153 delete _results->back();
154 _results->pop_back();
155 }
156 delete _results;
157 }
158 _results = results;
159}
160
161//
162/////////////////////////////////////////////////////////////////////////////
163void t_monitor::slotPlotResults() {
164 QMutexLocker locker(&_mutex);
165
166 if (_results) {
167 QList<t_worldPlot::t_point*> points;
168 for (unsigned ii = 0; ii < _results->size(); ii++) {
169 const t_thriftResult* result = _results->at(ii);
170
171 double xyz[3];
172 xyz[0] = result->_x;
173 xyz[1] = result->_y;
174 xyz[2] = result->_z;
175
176 double ell[3];
177
178 if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
179 double latDeg = ell[0] * 180.0 / M_PI;
180 double lonDeg = ell[1] * 180.0 / M_PI;
181 QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
182 t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
183 points.append(point);
184 }
185 }
186 _plot->slotNewPoints(points);
187
188 QListIterator<t_worldPlot::t_point*> it(points);
189 while (it.hasNext()) {
190 delete it.next();
191 }
192 }
193
194 if (_thriftClient) {
195 QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
196 }
197}
Note: See TracBrowser for help on using the repository browser.