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 |
|
---|
37 | using namespace std;
|
---|
38 | using namespace GnssCenter;
|
---|
39 |
|
---|
40 | Q_EXPORT_PLUGIN2(gnsscenter_monitor, t_monitorFactory)
|
---|
41 |
|
---|
42 | // Constructor
|
---|
43 | /////////////////////////////////////////////////////////////////////////////
|
---|
44 | t_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 | /////////////////////////////////////////////////////////////////////////////
|
---|
85 | t_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 | /////////////////////////////////////////////////////////////////////////////
|
---|
98 | void 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 | /////////////////////////////////////////////////////////////////////////////
|
---|
109 | void 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 | /////////////////////////////////////////////////////////////////////////////
|
---|
120 | void 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 | /////////////////////////////////////////////////////////////////////////////
|
---|
140 | void t_monitor::slotConfig() {
|
---|
141 | t_dlgConf dlg(this);
|
---|
142 | dlg.exec();
|
---|
143 | readSettings();
|
---|
144 | setTitle();
|
---|
145 | enableActions();
|
---|
146 | }
|
---|
147 |
|
---|
148 | //
|
---|
149 | /////////////////////////////////////////////////////////////////////////////
|
---|
150 | void t_monitor::slotStartThrift() {
|
---|
151 | if (!_thriftClient) {
|
---|
152 | _thriftClient = new t_thriftClient(this, _host, _port.toInt());
|
---|
153 | connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
|
---|
154 | _thriftClient->start();
|
---|
155 | slotPlotResults();
|
---|
156 | }
|
---|
157 | enableActions();
|
---|
158 | }
|
---|
159 |
|
---|
160 | //
|
---|
161 | /////////////////////////////////////////////////////////////////////////////
|
---|
162 | void t_monitor::slotStopThrift() {
|
---|
163 | if (_thriftClient) {
|
---|
164 | _thriftClient->stop();
|
---|
165 | _thriftClient = 0;
|
---|
166 | }
|
---|
167 | enableActions();
|
---|
168 | }
|
---|
169 |
|
---|
170 | //
|
---|
171 | /////////////////////////////////////////////////////////////////////////////
|
---|
172 | void t_monitor::slotThriftFinished() {
|
---|
173 | sender()->deleteLater();
|
---|
174 | _thriftClient = 0;
|
---|
175 | enableActions();
|
---|
176 | }
|
---|
177 |
|
---|
178 | //
|
---|
179 | /////////////////////////////////////////////////////////////////////////////
|
---|
180 | void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
|
---|
181 | QMutexLocker locker(&_mutex);
|
---|
182 | if (_results) {
|
---|
183 | while (!_results->empty()) {
|
---|
184 | delete _results->back();
|
---|
185 | _results->pop_back();
|
---|
186 | }
|
---|
187 | delete _results;
|
---|
188 | }
|
---|
189 | _results = results;
|
---|
190 | }
|
---|
191 |
|
---|
192 | //
|
---|
193 | /////////////////////////////////////////////////////////////////////////////
|
---|
194 | void t_monitor::slotPlotResults() {
|
---|
195 | QMutexLocker locker(&_mutex);
|
---|
196 |
|
---|
197 | if (_results) {
|
---|
198 | QList<t_worldPlot::t_point*> points;
|
---|
199 | for (unsigned ii = 0; ii < _results->size(); ii++) {
|
---|
200 | const t_thriftResult* result = _results->at(ii);
|
---|
201 |
|
---|
202 | double xyz[3];
|
---|
203 | xyz[0] = result->_x;
|
---|
204 | xyz[1] = result->_y;
|
---|
205 | xyz[2] = result->_z;
|
---|
206 |
|
---|
207 | double ell[3];
|
---|
208 |
|
---|
209 | if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
|
---|
210 | double latDeg = ell[0] * 180.0 / M_PI;
|
---|
211 | double lonDeg = ell[1] * 180.0 / M_PI;
|
---|
212 | QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
|
---|
213 | t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
|
---|
214 | points.append(point);
|
---|
215 | }
|
---|
216 | }
|
---|
217 | _plot->slotNewPoints(points);
|
---|
218 |
|
---|
219 | QListIterator<t_worldPlot::t_point*> it(points);
|
---|
220 | while (it.hasNext()) {
|
---|
221 | delete it.next();
|
---|
222 | }
|
---|
223 | }
|
---|
224 |
|
---|
225 | if (_thriftClient) {
|
---|
226 | QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
|
---|
227 | }
|
---|
228 | }
|
---|