[1972] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
| 3 | //
|
---|
| 4 | // Copyright (C) 2007
|
---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
| 8 | // http://www.fsv.cvut.cz
|
---|
| 9 | //
|
---|
| 10 | // Email: euref-ip@bkg.bund.de
|
---|
| 11 | //
|
---|
| 12 | // This program is free software; you can redistribute it and/or
|
---|
| 13 | // modify it under the terms of the GNU General Public License
|
---|
| 14 | // as published by the Free Software Foundation, version 2.
|
---|
| 15 | //
|
---|
| 16 | // This program is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU General Public License
|
---|
| 22 | // along with this program; if not, write to the Free Software
|
---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
| 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
| 26 | * BKG NTRIP Client
|
---|
| 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: bncFigureLate
|
---|
| 30 | *
|
---|
[9124] | 31 | * Purpose:
|
---|
[1972] | 32 | *
|
---|
| 33 | * Author: Perlt, Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 11-Nov-2009
|
---|
| 36 | *
|
---|
[9124] | 37 | * Changes:
|
---|
[1972] | 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
| 41 | #include <iostream>
|
---|
[8252] | 42 | #include <math.h>
|
---|
[1972] | 43 |
|
---|
[8252] | 44 | #include <QMapIterator>
|
---|
| 45 | #include <QPainter>
|
---|
| 46 | #include <QTimer>
|
---|
| 47 | #include <QUrl>
|
---|
| 48 | #include <QVariant>
|
---|
| 49 |
|
---|
[9124] | 50 | #include "bncfigurelate.h"
|
---|
[1972] | 51 | #include "bncsettings.h"
|
---|
| 52 |
|
---|
| 53 | using namespace std;
|
---|
| 54 |
|
---|
| 55 | // Constructor
|
---|
| 56 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 57 | bncFigureLate::bncFigureLate(QWidget *parent) : QWidget(parent) {
|
---|
| 58 | updateMountPoints();
|
---|
| 59 | slotNextAnimationFrame();
|
---|
| 60 | for (int ii = 0; ii <= 1000; ii++) {
|
---|
[1993] | 61 | _ran[0][ii] = qrand() % 255;
|
---|
| 62 | _ran[1][ii] = qrand() % 255;
|
---|
| 63 | _ran[2][ii] = qrand() % 100;
|
---|
[1972] | 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | // Destructor
|
---|
| 68 | ////////////////////////////////////////////////////////////////////////////
|
---|
[9124] | 69 | bncFigureLate::~bncFigureLate() {
|
---|
[1972] | 70 | }
|
---|
| 71 |
|
---|
[9124] | 72 | //
|
---|
[1972] | 73 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 74 | void bncFigureLate::updateMountPoints() {
|
---|
| 75 | QMutexLocker locker(&_mutex);
|
---|
| 76 |
|
---|
[1981] | 77 | _latency.clear();
|
---|
[1972] | 78 |
|
---|
| 79 | bncSettings settings;
|
---|
| 80 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 81 | while (it.hasNext()) {
|
---|
| 82 | QStringList hlp = it.next().split(" ");
|
---|
[7182] | 83 | if (hlp.size() <= 1) continue;
|
---|
[1972] | 84 | QUrl url(hlp[0]);
|
---|
[8204] | 85 | QByteArray staID = url.path().mid(1).toLatin1();
|
---|
[1981] | 86 | _latency[staID] = 0.0;
|
---|
[1972] | 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[9124] | 90 | //
|
---|
[1972] | 91 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1975] | 92 | void bncFigureLate::slotNewLatency(const QByteArray staID, double clate) {
|
---|
[1972] | 93 | QMutexLocker locker(&_mutex);
|
---|
[1981] | 94 | if (_latency.find(staID) != _latency.end()) {
|
---|
[1982] | 95 | _latency[staID] = fabs(clate)*1000.0;
|
---|
[1972] | 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[9124] | 99 | //
|
---|
[1972] | 100 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 101 | void bncFigureLate::slotNextAnimationFrame() {
|
---|
| 102 | QMutexLocker locker(&_mutex);
|
---|
| 103 | update();
|
---|
| 104 | QTimer::singleShot(1000, this, SLOT(slotNextAnimationFrame()));
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[9124] | 107 | //
|
---|
[1972] | 108 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 109 | void bncFigureLate::paintEvent(QPaintEvent *) {
|
---|
| 110 |
|
---|
| 111 | int xMin = 0;
|
---|
| 112 | int xMax = 640;
|
---|
| 113 | int yMin = 0;
|
---|
[9124] | 114 | int yMax = 90;
|
---|
[1972] | 115 | float xLine = .60;
|
---|
| 116 |
|
---|
| 117 | QPainter painter(this);
|
---|
| 118 |
|
---|
| 119 | QFont font;
|
---|
| 120 | font.setPointSize(int(font.QFont::pointSize()*0.8));
|
---|
| 121 | painter.setFont(font);
|
---|
| 122 |
|
---|
| 123 | // y-axis
|
---|
| 124 | // ------
|
---|
| 125 | int yLength = int((yMax-yMin)*xLine) - (yMin+10);
|
---|
[1989] | 126 | painter.drawLine(xMin+60, int((yMax-yMin)*xLine), xMin+60, yMin+10);
|
---|
[1972] | 127 |
|
---|
[1982] | 128 | double maxLate = 0.0;
|
---|
| 129 | QMapIterator<QByteArray, double> it1(_latency);
|
---|
| 130 | while (it1.hasNext()) {
|
---|
| 131 | it1.next();
|
---|
| 132 | if (it1.value() > maxLate) {
|
---|
| 133 | maxLate = it1.value();
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 |
|
---|
[2007] | 137 | double maxLateRounded;
|
---|
[1991] | 138 | QString maxLateStr;
|
---|
| 139 | if(maxLate < 1e3) {
|
---|
[2007] | 140 | maxLateRounded = int(maxLate/200)*200 + 300;
|
---|
| 141 | maxLateStr = QString("%1 ms ").arg(int(maxLateRounded/200)*200);
|
---|
[1991] | 142 | painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 ms "));
|
---|
| 143 | }
|
---|
[1996] | 144 | else if (maxLate < 6e4) {
|
---|
[2007] | 145 | maxLateRounded = int(maxLate/1.e3)*1.e3 + 1500;
|
---|
| 146 | maxLateStr = QString("%1 sec ").arg(int(maxLateRounded/1.e3));
|
---|
[1991] | 147 | painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 sec "));
|
---|
| 148 | }
|
---|
[1996] | 149 | else {
|
---|
[2007] | 150 | maxLateRounded = int(maxLate / 6.e4)*6.e4 + 90000;
|
---|
| 151 | maxLateStr = QString("%1 min ").arg(int(maxLateRounded/6.e4));
|
---|
[1996] | 152 | painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 min "));
|
---|
| 153 | }
|
---|
[1991] | 154 |
|
---|
[1982] | 155 | if(maxLate > 0.0) {
|
---|
[2007] | 156 | painter.drawText(0, yMin+20-5, xMin+60,15,Qt::AlignRight,maxLateStr);
|
---|
[1972] | 157 | }
|
---|
| 158 |
|
---|
| 159 | // x-axis
|
---|
| 160 | // ------
|
---|
[1989] | 161 | painter.drawLine(xMin+60, int((yMax-yMin)*xLine), xMax*3, int((yMax-yMin)*xLine));
|
---|
[1972] | 162 |
|
---|
| 163 | int anchor = 0;
|
---|
[1981] | 164 | QMapIterator<QByteArray, double> it(_latency);
|
---|
[1972] | 165 | while (it.hasNext()) {
|
---|
| 166 | it.next();
|
---|
| 167 | QByteArray staID = it.key();
|
---|
| 168 |
|
---|
[1989] | 169 | int xx = xMin+80+anchor*12;
|
---|
[1972] | 170 |
|
---|
[1982] | 171 | if(maxLate > 0.0) {
|
---|
[2007] | 172 | int yy = int(yLength * (it.value() / maxLateRounded));
|
---|
[1993] | 173 | QColor color = QColor::fromHsv(180,200,120+_ran[2][anchor]);
|
---|
[9124] | 174 | painter.fillRect(xx-13, int((yMax-yMin)*xLine)-yy, 9, yy, QBrush(color,Qt::SolidPattern));
|
---|
[1990] | 175 | painter.setPen(Qt::black);
|
---|
| 176 | if(it.value()<=0) {
|
---|
| 177 | painter.setPen(Qt::red);
|
---|
| 178 | }
|
---|
[1972] | 179 | }
|
---|
| 180 |
|
---|
[1990] | 181 | painter.save();
|
---|
| 182 | painter.translate(xx-13, int(yMax-yMin)*xLine+65);
|
---|
| 183 | painter.rotate(-90);
|
---|
[9124] | 184 | painter.drawText(-30,0,95,50,Qt::AlignRight,staID.left(10) + " ");
|
---|
[1990] | 185 | painter.restore();
|
---|
| 186 |
|
---|
[1972] | 187 | anchor++;
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 |
|
---|