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

Last change on this file since 5470 was 5470, checked in by mervart, 11 years ago
File size: 5.4 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(true);
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 if (!_thriftClient) {
127 _actConfig->setEnabled(false);
128 _actStartThrift->setEnabled(false);
129 _actStopThrift->setEnabled(true);
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 if (_thriftClient) {
147 _actConfig->setEnabled(true);
148 _actStartThrift->setEnabled(true);
149 _actStopThrift->setEnabled(false);
150 _thriftClient->stop();
151 _thriftClient = 0;
152 }
153}
154
155//
156/////////////////////////////////////////////////////////////////////////////
157void t_monitor::slotThriftFinished() {
158 sender()->deleteLater();
159 _thriftClient = 0;
160}
161
162//
163/////////////////////////////////////////////////////////////////////////////
164void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
165 QMutexLocker locker(&_mutex);
166 if (_results) {
167 while (!_results->empty()) {
168 delete _results->back();
169 _results->pop_back();
170 }
171 delete _results;
172 }
173 _results = results;
174}
175
176//
177/////////////////////////////////////////////////////////////////////////////
178void t_monitor::slotPlotResults() {
179 QMutexLocker locker(&_mutex);
180
181 if (_results) {
182 QList<t_worldPlot::t_point*> points;
183 for (unsigned ii = 0; ii < _results->size(); ii++) {
184 const t_thriftResult* result = _results->at(ii);
185
186 double xyz[3];
187 xyz[0] = result->_x;
188 xyz[1] = result->_y;
189 xyz[2] = result->_z;
190
191 double ell[3];
192
193 if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
194 double latDeg = ell[0] * 180.0 / M_PI;
195 double lonDeg = ell[1] * 180.0 / M_PI;
196 QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
197 t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
198 points.append(point);
199 }
200 }
201 _plot->slotNewPoints(points);
202
203 QListIterator<t_worldPlot::t_point*> it(points);
204 while (it.hasNext()) {
205 delete it.next();
206 }
207 }
208
209 if (_thriftClient) {
210 QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
211 }
212}
Note: See TracBrowser for help on using the repository browser.