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

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