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

Last change on this file since 5474 was 5474, 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 // Thrift Client;
72 // --------------
73 _thriftClient = 0;
74 _results = 0;
75
76 // Read Settings, Set Title, Enable/Disable Actions
77 // ------------------------------------------------
78 readSettings();
79 setTitle();
80 enableActions();
81}
82
83// Destructor
84/////////////////////////////////////////////////////////////////////////////
85t_monitor::~t_monitor() {
86 slotStopThrift();
87 if (_results) {
88 while (!_results->empty()) {
89 delete _results->back();
90 _results->pop_back();
91 }
92 delete _results;
93 }
94}
95
96// Read Settings
97/////////////////////////////////////////////////////////////////////////////
98void t_monitor::readSettings() {
99 t_settings settings(pluginName);
100 _host = settings.value("host").toString();
101 if (_host.isEmpty()) {
102 _host = "localhost";
103 }
104 _port = settings.value("port").toString();
105}
106
107// Set title
108/////////////////////////////////////////////////////////////////////////////
109void t_monitor::setTitle() {
110 if (_port.isEmpty()) {
111 setWindowTitle(QString(pluginName));
112 }
113 else {
114 setWindowTitle(QString(pluginName) + " " + _host + ':' + _port);
115 }
116}
117
118// Enable/Disable Actions
119/////////////////////////////////////////////////////////////////////////////
120void t_monitor::enableActions() {
121 _actConfig->setEnabled(true);
122 _actStartThrift->setEnabled(true);
123 _actStopThrift->setEnabled(true);
124}
125
126//
127/////////////////////////////////////////////////////////////////////////////
128void t_monitor::slotConfig() {
129 t_dlgConf dlg(this);
130 dlg.exec();
131 readSettings();
132 setTitle();
133 enableActions();
134}
135
136//
137/////////////////////////////////////////////////////////////////////////////
138void t_monitor::slotStartThrift() {
139 enableActions();
140 if (!_thriftClient) {
141 _thriftClient = new t_thriftClient(this, _host, _port.toInt());
142 connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
143 _thriftClient->start();
144 slotPlotResults();
145 }
146}
147
148//
149/////////////////////////////////////////////////////////////////////////////
150void t_monitor::slotStopThrift() {
151 enableActions();
152 if (_thriftClient) {
153 _thriftClient->stop();
154 _thriftClient = 0;
155 }
156}
157
158//
159/////////////////////////////////////////////////////////////////////////////
160void t_monitor::slotThriftFinished() {
161 enableActions();
162 sender()->deleteLater();
163 _thriftClient = 0;
164}
165
166//
167/////////////////////////////////////////////////////////////////////////////
168void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
169 QMutexLocker locker(&_mutex);
170 if (_results) {
171 while (!_results->empty()) {
172 delete _results->back();
173 _results->pop_back();
174 }
175 delete _results;
176 }
177 _results = results;
178}
179
180//
181/////////////////////////////////////////////////////////////////////////////
182void t_monitor::slotPlotResults() {
183 QMutexLocker locker(&_mutex);
184
185 if (_results) {
186 QList<t_worldPlot::t_point*> points;
187 for (unsigned ii = 0; ii < _results->size(); ii++) {
188 const t_thriftResult* result = _results->at(ii);
189
190 double xyz[3];
191 xyz[0] = result->_x;
192 xyz[1] = result->_y;
193 xyz[2] = result->_z;
194
195 double ell[3];
196
197 if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
198 double latDeg = ell[0] * 180.0 / M_PI;
199 double lonDeg = ell[1] * 180.0 / M_PI;
200 QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
201 t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
202 points.append(point);
203 }
204 }
205 _plot->slotNewPoints(points);
206
207 QListIterator<t_worldPlot::t_point*> it(points);
208 while (it.hasNext()) {
209 delete it.next();
210 }
211 }
212
213 if (_thriftClient) {
214 QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
215 }
216}
Note: See TracBrowser for help on using the repository browser.