| 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 |
|
|---|
| 37 | using namespace std;
|
|---|
| 38 | using namespace GnssCenter;
|
|---|
| 39 |
|
|---|
| 40 | Q_EXPORT_PLUGIN2(gnsscenter_monitor, t_monitorFactory)
|
|---|
| 41 |
|
|---|
| 42 | // Constructor
|
|---|
| 43 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 44 | t_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 | // Window title
|
|---|
| 72 | // ------------
|
|---|
| 73 | setTitle();
|
|---|
| 74 |
|
|---|
| 75 | // Thrift Client;
|
|---|
| 76 | // --------------
|
|---|
| 77 | _thriftClient = 0;
|
|---|
| 78 | _results = 0;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | // Destructor
|
|---|
| 82 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 83 | t_monitor::~t_monitor() {
|
|---|
| 84 | slotStopThrift();
|
|---|
| 85 | if (_results) {
|
|---|
| 86 | while (!_results->empty()) {
|
|---|
| 87 | delete _results->back();
|
|---|
| 88 | _results->pop_back();
|
|---|
| 89 | }
|
|---|
| 90 | delete _results;
|
|---|
| 91 | }
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | // Set title
|
|---|
| 95 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 96 | void t_monitor::setTitle() {
|
|---|
| 97 | t_settings settings(pluginName);
|
|---|
| 98 | QString host = settings.value("host").toString();
|
|---|
| 99 | QString port = settings.value("port").toString();
|
|---|
| 100 | setWindowTitle(QString(pluginName) + ": " + host + ':' + port);
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | //
|
|---|
| 104 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 105 | void t_monitor::slotConfig() {
|
|---|
| 106 | t_dlgConf dlg(this);
|
|---|
| 107 | dlg.exec();
|
|---|
| 108 | setTitle();
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | //
|
|---|
| 112 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 113 | void t_monitor::slotStartThrift() {
|
|---|
| 114 | if (!_thriftClient) {
|
|---|
| 115 | t_settings settings(pluginName);
|
|---|
| 116 | QString host = settings.value("host").toString();
|
|---|
| 117 | int port = settings.value("port").toInt();
|
|---|
| 118 | _thriftClient = new t_thriftClient(this, host, port);
|
|---|
| 119 | connect(_thriftClient, SIGNAL(finished()), this, SLOT(slotThriftFinished()));
|
|---|
| 120 | _thriftClient->start();
|
|---|
| 121 | slotPlotResults();
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | //
|
|---|
| 126 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 127 | void t_monitor::slotStopThrift() {
|
|---|
| 128 | if (_thriftClient) {
|
|---|
| 129 | _thriftClient->stop();
|
|---|
| 130 | _thriftClient = 0;
|
|---|
| 131 | }
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | //
|
|---|
| 135 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 136 | void t_monitor::slotThriftFinished() {
|
|---|
| 137 | sender()->deleteLater();
|
|---|
| 138 | _thriftClient = 0;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | //
|
|---|
| 142 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 143 | void t_monitor::putThriftResults(std::vector<t_thriftResult*>* results) {
|
|---|
| 144 | QMutexLocker locker(&_mutex);
|
|---|
| 145 | if (_results) {
|
|---|
| 146 | while (!_results->empty()) {
|
|---|
| 147 | delete _results->back();
|
|---|
| 148 | _results->pop_back();
|
|---|
| 149 | }
|
|---|
| 150 | delete _results;
|
|---|
| 151 | }
|
|---|
| 152 | _results = results;
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | //
|
|---|
| 156 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 157 | void t_monitor::slotPlotResults() {
|
|---|
| 158 | QMutexLocker locker(&_mutex);
|
|---|
| 159 |
|
|---|
| 160 | if (_results) {
|
|---|
| 161 | QList<t_worldPlot::t_point*> points;
|
|---|
| 162 | for (unsigned ii = 0; ii < _results->size(); ii++) {
|
|---|
| 163 | const t_thriftResult* result = _results->at(ii);
|
|---|
| 164 |
|
|---|
| 165 | double xyz[3];
|
|---|
| 166 | xyz[0] = result->_x;
|
|---|
| 167 | xyz[1] = result->_y;
|
|---|
| 168 | xyz[2] = result->_z;
|
|---|
| 169 |
|
|---|
| 170 | double ell[3];
|
|---|
| 171 |
|
|---|
| 172 | if (t_utils::xyz2ell(xyz, ell) == t_CST::success) {
|
|---|
| 173 | double latDeg = ell[0] * 180.0 / M_PI;
|
|---|
| 174 | double lonDeg = ell[1] * 180.0 / M_PI;
|
|---|
| 175 | QString str = QString().sprintf("%d/%d", result->_nGPS, result->_nGLO);
|
|---|
| 176 | t_worldPlot::t_point* point = new t_worldPlot::t_point(str, latDeg, lonDeg);
|
|---|
| 177 | points.append(point);
|
|---|
| 178 | }
|
|---|
| 179 | }
|
|---|
| 180 | _plot->slotNewPoints(points);
|
|---|
| 181 |
|
|---|
| 182 | QListIterator<t_worldPlot::t_point*> it(points);
|
|---|
| 183 | while (it.hasNext()) {
|
|---|
| 184 | delete it.next();
|
|---|
| 185 | }
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | if (_thriftClient) {
|
|---|
| 189 | QTimer::singleShot(1000, this, SLOT(slotPlotResults()));
|
|---|
| 190 | }
|
|---|
| 191 | }
|
|---|