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
RevLine 
[4836]1
2/* -------------------------------------------------------------------------
[5445]3 * RTNet Monitor
[4836]4 * -------------------------------------------------------------------------
5 *
[5445]6 * Class: t_monitor
[4836]7 *
[5445]8 * Purpose: Real-Time Monitoring of RTNet
[4836]9 *
10 * Author: L. Mervart
11 *
12 * Created: 05-Jan-2013
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
[5418]18#include <iostream>
[4836]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
[5445]30#include "monitor.h"
[5438]31#include "utils.h"
[5420]32#include "worldplot.h"
[5416]33#include "thriftclient.h"
[5452]34#include "settings.h"
[4836]35
[4858]36using namespace std;
[5001]37using namespace GnssCenter;
[4858]38
[5447]39Q_EXPORT_PLUGIN2(gnsscenter_monitor, t_monitorFactory)
[5018]40
[4836]41// Constructor
42/////////////////////////////////////////////////////////////////////////////
[5445]43t_monitor::t_monitor() : QMainWindow() {
[4836]44
[5449]45 _tabWidget = new QTabWidget();
46 setCentralWidget(_tabWidget);
47
[5420]48 // World Plot
49 // ----------
50 _plot = new t_worldPlot();
[5449]51 _tabWidget->addTab(_plot, "Stations");
[4836]52
[5422]53 // Tool Bar
54 // --------
[5445]55 QToolBar* toolBar = new QToolBar("t_monitor_ToolBar");
[5422]56 addToolBar(Qt::BottomToolBarArea, toolBar);
[5430]57
[5422]58 QAction* actStartThrift = new QAction("Start Thrift", 0);
59 toolBar->addAction(actStartThrift);
60 connect(actStartThrift, SIGNAL(triggered()), this, SLOT(slotStartThrift()));
61
[5430]62 QAction* actStopThrift = new QAction("Stop Thrift", 0);
63 toolBar->addAction(actStopThrift);
64 connect(actStopThrift, SIGNAL(triggered()), this, SLOT(slotStopThrift()));
65
[5452]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
[5410]75 // Thrift Client;
[5415]76 // --------------
[5422]77 _thriftClient = 0;
[5427]78 _results = 0;
[4836]79}
80
81// Destructor
82/////////////////////////////////////////////////////////////////////////////
[5445]83t_monitor::~t_monitor() {
[5431]84 slotStopThrift();
[5428]85 if (_results) {
86 while (!_results->empty()) {
87 delete _results->back();
88 _results->pop_back();
89 }
90 delete _results;
91 }
[4836]92}
93
[5422]94//
95/////////////////////////////////////////////////////////////////////////////
[5445]96void t_monitor::slotStartThrift() {
[5422]97 if (!_thriftClient) {
[5452]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);
[5431]104 connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
[5422]105 _thriftClient->start();
[5429]106 slotPlotResults();
[5422]107 }
108}
[4836]109
[5415]110//
111/////////////////////////////////////////////////////////////////////////////
[5445]112void t_monitor::slotStopThrift() {
[5431]113 if (_thriftClient) {
114 _thriftClient->stop();
[5430]115 _thriftClient = 0;
116 }
117}
118
119//
120/////////////////////////////////////////////////////////////////////////////
[5445]121void t_monitor::slotThriftFinished() {
[5431]122 sender()->deleteLater();
123 _thriftClient = 0;
124}
125
126//
127/////////////////////////////////////////////////////////////////////////////
[5445]128void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
[5429]129 QMutexLocker locker(&_mutex);
[5427]130 if (_results) {
131 while (!_results->empty()) {
132 delete _results->back();
133 _results->pop_back();
134 }
135 delete _results;
136 }
137 _results = results;
[5429]138}
139
140//
141/////////////////////////////////////////////////////////////////////////////
[5445]142void t_monitor::slotPlotResults() {
[5429]143 QMutexLocker locker(&_mutex);
[5436]144
[5429]145 if (_results) {
[5436]146 QList<t_worldPlot::t_point*> points;
[5429]147 for (unsigned ii = 0; ii < _results->size(); ii++) {
148 const t_thriftResult* result = _results->at(ii);
[5438]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
[5450]157 if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
[5438]158 double latDeg = ell[0] * 180.0 / M_PI;
159 double lonDeg = ell[1] * 180.0 / M_PI;
[5440]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);
[5438]162 points.append(point);
163 }
[5429]164 }
[5436]165 _plot->slotNewPoints(points);
[5439]166
167 QListIterator<t_worldPlot::t_point*> it(points);
168 while (it.hasNext()) {
169 delete it.next();
170 }
[5427]171 }
[5436]172
[5430]173 if (_thriftClient) {
174 QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
175 }
[5415]176}
Note: See TracBrowser for help on using the repository browser.