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

Last change on this file since 5481 was 5481, checked in by mervart, 11 years ago
File size: 6.0 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"
[5455]31#include "dlgconf.h"
[5438]32#include "utils.h"
[5420]33#include "worldplot.h"
[5416]34#include "thriftclient.h"
[5452]35#include "settings.h"
[4836]36
[4858]37using namespace std;
[5001]38using namespace GnssCenter;
[4858]39
[5447]40Q_EXPORT_PLUGIN2(gnsscenter_monitor, t_monitorFactory)
[5018]41
[4836]42// Constructor
43/////////////////////////////////////////////////////////////////////////////
[5445]44t_monitor::t_monitor() : QMainWindow() {
[4836]45
[5449]46 _tabWidget = new QTabWidget();
47 setCentralWidget(_tabWidget);
48
[5420]49 // World Plot
50 // ----------
51 _plot = new t_worldPlot();
[5449]52 _tabWidget->addTab(_plot, "Stations");
[4836]53
[5422]54 // Tool Bar
55 // --------
[5445]56 QToolBar* toolBar = new QToolBar("t_monitor_ToolBar");
[5422]57 addToolBar(Qt::BottomToolBarArea, toolBar);
[5430]58
[5455]59 _actConfig = new QAction("Config", 0);
60 toolBar->addAction(_actConfig);
61 connect(_actConfig, SIGNAL(triggered()), this, SLOT(slotConfig()));
[5422]62
[5455]63 _actStartThrift = new QAction("Start", 0);
64 toolBar->addAction(_actStartThrift);
65 connect(_actStartThrift, SIGNAL(triggered()), this, SLOT(slotStartThrift()));
[5430]66
[5455]67 _actStopThrift = new QAction("Stop", 0);
68 toolBar->addAction(_actStopThrift);
69 connect(_actStopThrift, SIGNAL(triggered()), this, SLOT(slotStopThrift()));
70
[5410]71 // Thrift Client;
[5415]72 // --------------
[5422]73 _thriftClient = 0;
[5427]74 _results = 0;
[5474]75
76 // Read Settings, Set Title, Enable/Disable Actions
77 // ------------------------------------------------
78 readSettings();
79 setTitle();
80 enableActions();
[4836]81}
82
83// Destructor
84/////////////////////////////////////////////////////////////////////////////
[5445]85t_monitor::~t_monitor() {
[5431]86 slotStopThrift();
[5428]87 if (_results) {
88 while (!_results->empty()) {
89 delete _results->back();
90 _results->pop_back();
91 }
92 delete _results;
93 }
[4836]94}
95
[5474]96// Read Settings
97/////////////////////////////////////////////////////////////////////////////
98void t_monitor::readSettings() {
99 t_settings settings(pluginName);
[5478]100 _host = settings.value("host").toString().trimmed();
[5474]101 if (_host.isEmpty()) {
102 _host = "localhost";
103 }
104 _port = settings.value("port").toString();
105}
106
[5457]107// Set title
108/////////////////////////////////////////////////////////////////////////////
109void t_monitor::setTitle() {
[5474]110 if (_port.isEmpty()) {
[5470]111 setWindowTitle(QString(pluginName));
112 }
113 else {
[5474]114 setWindowTitle(QString(pluginName) + " " + _host + ':' + _port);
[5470]115 }
[5457]116}
117
[5474]118// Enable/Disable Actions
119/////////////////////////////////////////////////////////////////////////////
120void t_monitor::enableActions() {
[5475]121 if (_port.isEmpty()) {
122 _actConfig->setEnabled(true);
123 _actStartThrift->setEnabled(false);
124 _actStopThrift->setEnabled(false);
125 }
[5476]126 else if (_thriftClient) {
[5475]127 _actConfig->setEnabled(false);
128 _actStartThrift->setEnabled(false);
129 _actStopThrift->setEnabled(true);
130 }
131 else {
132 _actConfig->setEnabled(true);
133 _actStartThrift->setEnabled(true);
134 _actStopThrift->setEnabled(false);
135 }
[5474]136}
137
[5422]138//
139/////////////////////////////////////////////////////////////////////////////
[5455]140void t_monitor::slotConfig() {
141 t_dlgConf dlg(this);
142 dlg.exec();
[5474]143 readSettings();
[5457]144 setTitle();
[5474]145 enableActions();
[5455]146}
147
148//
149/////////////////////////////////////////////////////////////////////////////
[5480]150void t_monitor::slotMessage(QByteArray msg) {
[5481]151 QMessageBox::information(this, "Message", msg);
[5480]152}
153
154//
155/////////////////////////////////////////////////////////////////////////////
[5445]156void t_monitor::slotStartThrift() {
[5422]157 if (!_thriftClient) {
[5474]158 _thriftClient = new t_thriftClient(this, _host, _port.toInt());
[5431]159 connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
[5480]160 connect(_thriftClient, SIGNAL(message(QByteArray)), this, SLOT(slotMessage(QByteArray)));
[5422]161 _thriftClient->start();
[5429]162 slotPlotResults();
[5422]163 }
[5477]164 enableActions();
[5422]165}
[4836]166
[5415]167//
168/////////////////////////////////////////////////////////////////////////////
[5445]169void t_monitor::slotStopThrift() {
[5431]170 if (_thriftClient) {
171 _thriftClient->stop();
[5430]172 _thriftClient = 0;
173 }
[5477]174 enableActions();
[5430]175}
176
177//
178/////////////////////////////////////////////////////////////////////////////
[5445]179void t_monitor::slotThriftFinished() {
[5431]180 sender()->deleteLater();
181 _thriftClient = 0;
[5477]182 enableActions();
[5431]183}
184
185//
186/////////////////////////////////////////////////////////////////////////////
[5445]187void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
[5429]188 QMutexLocker locker(&_mutex);
[5427]189 if (_results) {
190 while (!_results->empty()) {
191 delete _results->back();
192 _results->pop_back();
193 }
194 delete _results;
195 }
196 _results = results;
[5429]197}
198
199//
200/////////////////////////////////////////////////////////////////////////////
[5445]201void t_monitor::slotPlotResults() {
[5429]202 QMutexLocker locker(&_mutex);
[5436]203
[5429]204 if (_results) {
[5436]205 QList<t_worldPlot::t_point*> points;
[5429]206 for (unsigned ii = 0; ii < _results->size(); ii++) {
207 const t_thriftResult* result = _results->at(ii);
[5438]208
209 double xyz[3];
210 xyz[0] = result->_x;
211 xyz[1] = result->_y;
212 xyz[2] = result->_z;
213
214 double ell[3];
215
[5450]216 if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
[5438]217 double latDeg = ell[0] * 180.0 / M_PI;
218 double lonDeg = ell[1] * 180.0 / M_PI;
[5440]219 QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
220 t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
[5438]221 points.append(point);
222 }
[5429]223 }
[5436]224 _plot->slotNewPoints(points);
[5439]225
226 QListIterator<t_worldPlot::t_point*> it(points);
227 while (it.hasNext()) {
228 delete it.next();
229 }
[5427]230 }
[5436]231
[5430]232 if (_thriftClient) {
233 QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
234 }
[5415]235}
Note: See TracBrowser for help on using the repository browser.