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

Last change on this file since 5480 was 5480, checked in by mervart, 11 years ago
File size: 6.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 // 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().trimmed();
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 if (_port.isEmpty()) {
122 _actConfig->setEnabled(true);
123 _actStartThrift->setEnabled(false);
124 _actStopThrift->setEnabled(false);
125 }
126 else if (_thriftClient) {
127 _actConfig->setEnabled(false);
128 _actStartThrift->setEnabled(false);
129 _actStopThrift->setEnabled(true);
130 }
131 else {
132 _actConfig->setEnabled(true);
133 _actStartThrift->setEnabled(true);
134 _actStopThrift->setEnabled(false);
135 }
136}
137
138//
139/////////////////////////////////////////////////////////////////////////////
140void t_monitor::slotConfig() {
141 t_dlgConf dlg(this);
142 dlg.exec();
143 readSettings();
144 setTitle();
145 enableActions();
146}
147
148//
149/////////////////////////////////////////////////////////////////////////////
150void t_monitor::slotMessage(QByteArray msg) {
151
152}
153
154//
155/////////////////////////////////////////////////////////////////////////////
156void t_monitor::slotStartThrift() {
157 if (!_thriftClient) {
158 _thriftClient = new t_thriftClient(this, _host, _port.toInt());
159 connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
160 connect(_thriftClient, SIGNAL(message(QByteArray)), this, SLOT(slotMessage(QByteArray)));
161 _thriftClient->start();
162 slotPlotResults();
163 }
164 enableActions();
165}
166
167//
168/////////////////////////////////////////////////////////////////////////////
169void t_monitor::slotStopThrift() {
170 if (_thriftClient) {
171 _thriftClient->stop();
172 _thriftClient = 0;
173 }
174 enableActions();
175}
176
177//
178/////////////////////////////////////////////////////////////////////////////
179void t_monitor::slotThriftFinished() {
180 sender()->deleteLater();
181 _thriftClient = 0;
182 enableActions();
183}
184
185//
186/////////////////////////////////////////////////////////////////////////////
187void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
188 QMutexLocker locker(&_mutex);
189 if (_results) {
190 while (!_results->empty()) {
191 delete _results->back();
192 _results->pop_back();
193 }
194 delete _results;
195 }
196 _results = results;
197}
198
199//
200/////////////////////////////////////////////////////////////////////////////
201void t_monitor::slotPlotResults() {
202 QMutexLocker locker(&_mutex);
203
204 if (_results) {
205 QList<t_worldPlot::t_point*> points;
206 for (unsigned ii = 0; ii < _results->size(); ii++) {
207 const t_thriftResult* result = _results->at(ii);
208
209 double xyz[3];
210 xyz[0] = result->_x;
211 xyz[1] = result->_y;
212 xyz[2] = result->_z;
213
214 double ell[3];
215
216 if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
217 double latDeg = ell[0] * 180.0 / M_PI;
218 double lonDeg = ell[1] * 180.0 / M_PI;
219 QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
220 t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
221 points.append(point);
222 }
223 }
224 _plot->slotNewPoints(points);
225
226 QListIterator<t_worldPlot::t_point*> it(points);
227 while (it.hasNext()) {
228 delete it.next();
229 }
230 }
231
232 if (_thriftClient) {
233 QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
234 }
235}
Note: See TracBrowser for help on using the repository browser.