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

Last change on this file since 5473 was 5473, checked in by mervart, 11 years ago
File size: 5.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 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 if (port.isEmpty()) {
104 setWindowTitle(QString(pluginName));
105 _actStartThrift->setEnabled(false);
106 _actStopThrift->setEnabled(false);
107 }
108 else {
109 _actStartThrift->setEnabled(true);
110 _actStopThrift->setEnabled(false);
111 setWindowTitle(QString(pluginName) + " " + host + ':' + port);
112 }
113}
114
115//
116/////////////////////////////////////////////////////////////////////////////
117void t_monitor::slotConfig() {
118 t_dlgConf dlg(this);
119 dlg.exec();
120 setTitle();
121}
122
123//
124/////////////////////////////////////////////////////////////////////////////
125void t_monitor::slotStartThrift() {
126 _actConfig->setEnabled(false);
127 _actStartThrift->setEnabled(false);
128 _actStopThrift->setEnabled(true);
129 if (!_thriftClient) {
130 t_settings settings(pluginName);
131 QString host = settings.value("host").toString();
132 if (host.isEmpty()) {
133 host = "localhost";
134 }
135 int port = settings.value("port").toInt();
136 _thriftClient = new t_thriftClient(this, host, port);
137 connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
138 _thriftClient->start();
139 slotPlotResults();
140 }
141}
142
143//
144/////////////////////////////////////////////////////////////////////////////
145void t_monitor::slotStopThrift() {
146 _actStopThrift->setEnabled(false);
147 if (_thriftClient) {
148 _thriftClient->stop();
149 _thriftClient = 0;
150 }
151}
152
153//
154/////////////////////////////////////////////////////////////////////////////
155void t_monitor::slotThriftFinished() {
156 _actConfig->setEnabled(true);
157 _actStartThrift->setEnabled(true);
158 _actStopThrift->setEnabled(false);
159 sender()->deleteLater();
160 _thriftClient = 0;
161}
162
163//
164/////////////////////////////////////////////////////////////////////////////
165void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
166 QMutexLocker locker(&_mutex);
167 if (_results) {
168 while (!_results->empty()) {
169 delete _results->back();
170 _results->pop_back();
171 }
172 delete _results;
173 }
174 _results = results;
175}
176
177//
178/////////////////////////////////////////////////////////////////////////////
179void t_monitor::slotPlotResults() {
180 QMutexLocker locker(&_mutex);
181
182 if (_results) {
183 QList<t_worldPlot::t_point*> points;
184 for (unsigned ii = 0; ii < _results->size(); ii++) {
185 const t_thriftResult* result = _results->at(ii);
186
187 double xyz[3];
188 xyz[0] = result->_x;
189 xyz[1] = result->_y;
190 xyz[2] = result->_z;
191
192 double ell[3];
193
194 if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
195 double latDeg = ell[0] * 180.0 / M_PI;
196 double lonDeg = ell[1] * 180.0 / M_PI;
197 QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
198 t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
199 points.append(point);
200 }
201 }
202 _plot->slotNewPoints(points);
203
204 QListIterator<t_worldPlot::t_point*> it(points);
205 while (it.hasNext()) {
206 delete it.next();
207 }
208 }
209
210 if (_thriftClient) {
211 QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
212 }
213}
Note: See TracBrowser for help on using the repository browser.