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

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