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

Last change on this file since 5452 was 5452, checked in by mervart, 11 years ago
File size: 4.5 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;
69 settings.beginGroup(pluginName);
70 settings.setValue("host", "rtnet.rtcm-ntrip.org");
71 settings.setValue("port", 7777);
72 settings.endGroup();
73 settings.sync();
74
75 // Thrift Client;
76 // --------------
77 _thriftClient = 0;
78 _results = 0;
79}
80
81// Destructor
82/////////////////////////////////////////////////////////////////////////////
83t_monitor::~t_monitor() {
84 slotStopThrift();
85 if (_results) {
86 while (!_results->empty()) {
87 delete _results->back();
88 _results->pop_back();
89 }
90 delete _results;
91 }
92}
93
94//
95/////////////////////////////////////////////////////////////////////////////
96void t_monitor::slotStartThrift() {
97 if (!_thriftClient) {
98 t_settings settings;
99 settings.beginGroup(pluginName);
100 QString host = settings.value("host").toString();
101 int port = settings.value("port").toInt();
102 settings.endGroup();
103 _thriftClient = new t_thriftClient(this, host, port);
104 connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
105 _thriftClient->start();
106 slotPlotResults();
107 }
108}
109
110//
111/////////////////////////////////////////////////////////////////////////////
112void t_monitor::slotStopThrift() {
113 if (_thriftClient) {
114 _thriftClient->stop();
115 _thriftClient = 0;
116 }
117}
118
119//
120/////////////////////////////////////////////////////////////////////////////
121void t_monitor::slotThriftFinished() {
122 sender()->deleteLater();
123 _thriftClient = 0;
124}
125
126//
127/////////////////////////////////////////////////////////////////////////////
128void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
129 QMutexLocker locker(&_mutex);
130 if (_results) {
131 while (!_results->empty()) {
132 delete _results->back();
133 _results->pop_back();
134 }
135 delete _results;
136 }
137 _results = results;
138}
139
140//
141/////////////////////////////////////////////////////////////////////////////
142void t_monitor::slotPlotResults() {
143 QMutexLocker locker(&_mutex);
144
145 if (_results) {
146 QList<t_worldPlot::t_point*> points;
147 for (unsigned ii = 0; ii < _results->size(); ii++) {
148 const t_thriftResult* result = _results->at(ii);
149
150 double xyz[3];
151 xyz[0] = result->_x;
152 xyz[1] = result->_y;
153 xyz[2] = result->_z;
154
155 double ell[3];
156
157 if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
158 double latDeg = ell[0] * 180.0 / M_PI;
159 double lonDeg = ell[1] * 180.0 / M_PI;
160 QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
161 t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
162 points.append(point);
163 }
164 }
165 _plot->slotNewPoints(points);
166
167 QListIterator<t_worldPlot::t_point*> it(points);
168 while (it.hasNext()) {
169 delete it.next();
170 }
171 }
172
173 if (_thriftClient) {
174 QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
175 }
176}
Note: See TracBrowser for help on using the repository browser.