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

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