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

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