[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"
|
---|
[4836] | 34 |
|
---|
[4858] | 35 | using namespace std;
|
---|
[5001] | 36 | using namespace GnssCenter;
|
---|
[4858] | 37 |
|
---|
[5447] | 38 | Q_EXPORT_PLUGIN2(gnsscenter_monitor, t_monitorFactory)
|
---|
[5018] | 39 |
|
---|
[4836] | 40 | // Constructor
|
---|
| 41 | /////////////////////////////////////////////////////////////////////////////
|
---|
[5445] | 42 | t_monitor::t_monitor() : QMainWindow() {
|
---|
[4836] | 43 |
|
---|
[5449] | 44 | _tabWidget = new QTabWidget();
|
---|
| 45 | setCentralWidget(_tabWidget);
|
---|
| 46 |
|
---|
[5420] | 47 | // World Plot
|
---|
| 48 | // ----------
|
---|
| 49 | _plot = new t_worldPlot();
|
---|
[5449] | 50 | _tabWidget->addTab(_plot, "Stations");
|
---|
[4836] | 51 |
|
---|
[5422] | 52 | // Tool Bar
|
---|
| 53 | // --------
|
---|
[5445] | 54 | QToolBar* toolBar = new QToolBar("t_monitor_ToolBar");
|
---|
[5422] | 55 | addToolBar(Qt::BottomToolBarArea, toolBar);
|
---|
[5430] | 56 |
|
---|
[5422] | 57 | QAction* actStartThrift = new QAction("Start Thrift", 0);
|
---|
| 58 | toolBar->addAction(actStartThrift);
|
---|
| 59 | connect(actStartThrift, SIGNAL(triggered()), this, SLOT(slotStartThrift()));
|
---|
| 60 |
|
---|
[5430] | 61 | QAction* actStopThrift = new QAction("Stop Thrift", 0);
|
---|
| 62 | toolBar->addAction(actStopThrift);
|
---|
| 63 | connect(actStopThrift, SIGNAL(triggered()), this, SLOT(slotStopThrift()));
|
---|
| 64 |
|
---|
[5410] | 65 | // Thrift Client;
|
---|
[5415] | 66 | // --------------
|
---|
[5422] | 67 | _thriftClient = 0;
|
---|
[5427] | 68 | _results = 0;
|
---|
[4836] | 69 | }
|
---|
| 70 |
|
---|
| 71 | // Destructor
|
---|
| 72 | /////////////////////////////////////////////////////////////////////////////
|
---|
[5445] | 73 | t_monitor::~t_monitor() {
|
---|
[5431] | 74 | slotStopThrift();
|
---|
[5428] | 75 | if (_results) {
|
---|
| 76 | while (!_results->empty()) {
|
---|
| 77 | delete _results->back();
|
---|
| 78 | _results->pop_back();
|
---|
| 79 | }
|
---|
| 80 | delete _results;
|
---|
| 81 | }
|
---|
[4836] | 82 | }
|
---|
| 83 |
|
---|
[5422] | 84 | //
|
---|
| 85 | /////////////////////////////////////////////////////////////////////////////
|
---|
[5445] | 86 | void t_monitor::slotStartThrift() {
|
---|
[5422] | 87 | if (!_thriftClient) {
|
---|
| 88 | _thriftClient = new t_thriftClient(this);
|
---|
[5431] | 89 | connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
|
---|
[5422] | 90 | _thriftClient->start();
|
---|
[5429] | 91 | slotPlotResults();
|
---|
[5422] | 92 | }
|
---|
| 93 | }
|
---|
[4836] | 94 |
|
---|
[5415] | 95 | //
|
---|
| 96 | /////////////////////////////////////////////////////////////////////////////
|
---|
[5445] | 97 | void t_monitor::slotStopThrift() {
|
---|
[5431] | 98 | if (_thriftClient) {
|
---|
| 99 | _thriftClient->stop();
|
---|
[5430] | 100 | _thriftClient = 0;
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | //
|
---|
| 105 | /////////////////////////////////////////////////////////////////////////////
|
---|
[5445] | 106 | void t_monitor::slotThriftFinished() {
|
---|
[5431] | 107 | sender()->deleteLater();
|
---|
| 108 | _thriftClient = 0;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | //
|
---|
| 112 | /////////////////////////////////////////////////////////////////////////////
|
---|
[5445] | 113 | void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
|
---|
[5429] | 114 | QMutexLocker locker(&_mutex);
|
---|
[5427] | 115 | if (_results) {
|
---|
| 116 | while (!_results->empty()) {
|
---|
| 117 | delete _results->back();
|
---|
| 118 | _results->pop_back();
|
---|
| 119 | }
|
---|
| 120 | delete _results;
|
---|
| 121 | }
|
---|
| 122 | _results = results;
|
---|
[5429] | 123 | }
|
---|
| 124 |
|
---|
| 125 | //
|
---|
| 126 | /////////////////////////////////////////////////////////////////////////////
|
---|
[5445] | 127 | void t_monitor::slotPlotResults() {
|
---|
[5429] | 128 | QMutexLocker locker(&_mutex);
|
---|
[5436] | 129 |
|
---|
[5429] | 130 | if (_results) {
|
---|
[5436] | 131 | QList<t_worldPlot::t_point*> points;
|
---|
[5429] | 132 | for (unsigned ii = 0; ii < _results->size(); ii++) {
|
---|
| 133 | const t_thriftResult* result = _results->at(ii);
|
---|
[5438] | 134 |
|
---|
| 135 | double xyz[3];
|
---|
| 136 | xyz[0] = result->_x;
|
---|
| 137 | xyz[1] = result->_y;
|
---|
| 138 | xyz[2] = result->_z;
|
---|
| 139 |
|
---|
| 140 | double ell[3];
|
---|
| 141 |
|
---|
[5450] | 142 | if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
|
---|
[5438] | 143 | double latDeg = ell[0] * 180.0 / M_PI;
|
---|
| 144 | double lonDeg = ell[1] * 180.0 / M_PI;
|
---|
[5440] | 145 | QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
|
---|
| 146 | t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
|
---|
[5438] | 147 | points.append(point);
|
---|
| 148 | }
|
---|
[5429] | 149 | }
|
---|
[5436] | 150 | _plot->slotNewPoints(points);
|
---|
[5439] | 151 |
|
---|
| 152 | QListIterator<t_worldPlot::t_point*> it(points);
|
---|
| 153 | while (it.hasNext()) {
|
---|
| 154 | delete it.next();
|
---|
| 155 | }
|
---|
[5427] | 156 | }
|
---|
[5436] | 157 |
|
---|
[5430] | 158 | if (_thriftClient) {
|
---|
| 159 | QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
|
---|
| 160 | }
|
---|
[5415] | 161 | }
|
---|