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 "utils.h"
|
---|
32 | #include "worldplot.h"
|
---|
33 | #include "thriftclient.h"
|
---|
34 |
|
---|
35 | using namespace std;
|
---|
36 | using namespace GnssCenter;
|
---|
37 |
|
---|
38 | Q_EXPORT_PLUGIN2(gnsscenter_monitor, t_monitorFactory)
|
---|
39 |
|
---|
40 | // Constructor
|
---|
41 | /////////////////////////////////////////////////////////////////////////////
|
---|
42 | t_monitor::t_monitor() : QMainWindow() {
|
---|
43 |
|
---|
44 | _tabWidget = new QTabWidget();
|
---|
45 | setCentralWidget(_tabWidget);
|
---|
46 |
|
---|
47 | // World Plot
|
---|
48 | // ----------
|
---|
49 | _plot = new t_worldPlot();
|
---|
50 | _tabWidget->addTab(_plot, "Stations");
|
---|
51 |
|
---|
52 | // Tool Bar
|
---|
53 | // --------
|
---|
54 | QToolBar* toolBar = new QToolBar("t_monitor_ToolBar");
|
---|
55 | addToolBar(Qt::BottomToolBarArea, toolBar);
|
---|
56 |
|
---|
57 | QAction* actStartThrift = new QAction("Start Thrift", 0);
|
---|
58 | toolBar->addAction(actStartThrift);
|
---|
59 | connect(actStartThrift, SIGNAL(triggered()), this, SLOT(slotStartThrift()));
|
---|
60 |
|
---|
61 | QAction* actStopThrift = new QAction("Stop Thrift", 0);
|
---|
62 | toolBar->addAction(actStopThrift);
|
---|
63 | connect(actStopThrift, SIGNAL(triggered()), this, SLOT(slotStopThrift()));
|
---|
64 |
|
---|
65 | // Thrift Client;
|
---|
66 | // --------------
|
---|
67 | _thriftClient = 0;
|
---|
68 | _results = 0;
|
---|
69 | }
|
---|
70 |
|
---|
71 | // Destructor
|
---|
72 | /////////////////////////////////////////////////////////////////////////////
|
---|
73 | t_monitor::~t_monitor() {
|
---|
74 | slotStopThrift();
|
---|
75 | if (_results) {
|
---|
76 | while (!_results->empty()) {
|
---|
77 | delete _results->back();
|
---|
78 | _results->pop_back();
|
---|
79 | }
|
---|
80 | delete _results;
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | //
|
---|
85 | /////////////////////////////////////////////////////////////////////////////
|
---|
86 | void t_monitor::slotStartThrift() {
|
---|
87 | if (!_thriftClient) {
|
---|
88 | _thriftClient = new t_thriftClient(this);
|
---|
89 | connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
|
---|
90 | _thriftClient->start();
|
---|
91 | slotPlotResults();
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | //
|
---|
96 | /////////////////////////////////////////////////////////////////////////////
|
---|
97 | void t_monitor::slotStopThrift() {
|
---|
98 | if (_thriftClient) {
|
---|
99 | _thriftClient->stop();
|
---|
100 | _thriftClient = 0;
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | //
|
---|
105 | /////////////////////////////////////////////////////////////////////////////
|
---|
106 | void t_monitor::slotThriftFinished() {
|
---|
107 | sender()->deleteLater();
|
---|
108 | _thriftClient = 0;
|
---|
109 | }
|
---|
110 |
|
---|
111 | //
|
---|
112 | /////////////////////////////////////////////////////////////////////////////
|
---|
113 | void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
|
---|
114 | QMutexLocker locker(&_mutex);
|
---|
115 | if (_results) {
|
---|
116 | while (!_results->empty()) {
|
---|
117 | delete _results->back();
|
---|
118 | _results->pop_back();
|
---|
119 | }
|
---|
120 | delete _results;
|
---|
121 | }
|
---|
122 | _results = results;
|
---|
123 | }
|
---|
124 |
|
---|
125 | //
|
---|
126 | /////////////////////////////////////////////////////////////////////////////
|
---|
127 | void t_monitor::slotPlotResults() {
|
---|
128 | QMutexLocker locker(&_mutex);
|
---|
129 |
|
---|
130 | if (_results) {
|
---|
131 | QList<t_worldPlot::t_point*> points;
|
---|
132 | for (unsigned ii = 0; ii < _results->size(); ii++) {
|
---|
133 | const t_thriftResult* result = _results->at(ii);
|
---|
134 |
|
---|
135 | double xyz[3];
|
---|
136 | xyz[0] = result->_x;
|
---|
137 | xyz[1] = result->_y;
|
---|
138 | xyz[2] = result->_z;
|
---|
139 |
|
---|
140 | double ell[3];
|
---|
141 |
|
---|
142 | if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
|
---|
143 | double latDeg = ell[0] * 180.0 / M_PI;
|
---|
144 | double lonDeg = ell[1] * 180.0 / M_PI;
|
---|
145 | QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
|
---|
146 | t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
|
---|
147 | points.append(point);
|
---|
148 | }
|
---|
149 | }
|
---|
150 | _plot->slotNewPoints(points);
|
---|
151 |
|
---|
152 | QListIterator<t_worldPlot::t_point*> it(points);
|
---|
153 | while (it.hasNext()) {
|
---|
154 | delete it.next();
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | if (_thriftClient) {
|
---|
159 | QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
|
---|
160 | }
|
---|
161 | }
|
---|