[1932] | 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: bncFigure
|
---|
| 30 | *
|
---|
[7640] | 31 | * Purpose:
|
---|
[1932] | 32 | *
|
---|
| 33 | * Author: Perlt, Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 11-Nov-2009
|
---|
| 36 | *
|
---|
[7640] | 37 | * Changes:
|
---|
[1932] | 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
| 41 | #include <iostream>
|
---|
| 42 |
|
---|
[8252] | 43 | #include <QMapIterator>
|
---|
| 44 | #include <QPainter>
|
---|
| 45 | #include <QTimer>
|
---|
| 46 | #include <QUrl>
|
---|
| 47 | #include <QVariant>
|
---|
| 48 |
|
---|
[7640] | 49 | #include "bncfigure.h"
|
---|
[1932] | 50 | #include "bncsettings.h"
|
---|
| 51 |
|
---|
| 52 | using namespace std;
|
---|
| 53 |
|
---|
| 54 | // Constructor
|
---|
| 55 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 56 | bncFigure::bncFigure(QWidget *parent) : QWidget(parent) {
|
---|
[1933] | 57 | updateMountPoints();
|
---|
| 58 | slotNextAnimationFrame();
|
---|
[1956] | 59 | for (int ii = 0; ii <= 1000; ii++) {
|
---|
[1993] | 60 | _ran[0][ii] = qrand() % 255;
|
---|
[2139] | 61 | _ran[1][ii] = qrand() % 255;
|
---|
[1994] | 62 | _ran[2][ii] = qrand() % 255;
|
---|
[1956] | 63 | }
|
---|
[1933] | 64 | }
|
---|
| 65 |
|
---|
| 66 | // Destructor
|
---|
| 67 | ////////////////////////////////////////////////////////////////////////////
|
---|
[7640] | 68 | bncFigure::~bncFigure() {
|
---|
| 69 | QMapIterator<QByteArray, sumAndMean*> it(_bytes);
|
---|
| 70 | while (it.hasNext()) {
|
---|
| 71 | it.next();
|
---|
| 72 | delete it.value();
|
---|
| 73 | }
|
---|
[1933] | 74 | }
|
---|
| 75 |
|
---|
[7640] | 76 | //
|
---|
[1933] | 77 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 78 | void bncFigure::updateMountPoints() {
|
---|
| 79 | QMutexLocker locker(&_mutex);
|
---|
| 80 |
|
---|
| 81 | _counter = 0;
|
---|
[1936] | 82 | _maxRate = 0;
|
---|
[1933] | 83 |
|
---|
| 84 | QMapIterator<QByteArray, sumAndMean*> it1(_bytes);
|
---|
| 85 | while (it1.hasNext()) {
|
---|
| 86 | it1.next();
|
---|
| 87 | delete it1.value();
|
---|
| 88 | }
|
---|
| 89 | _bytes.clear();
|
---|
| 90 |
|
---|
[1932] | 91 | bncSettings settings;
|
---|
| 92 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 93 | while (it.hasNext()) {
|
---|
| 94 | QStringList hlp = it.next().split(" ");
|
---|
[7182] | 95 | if (hlp.size() <= 1) continue;
|
---|
[1932] | 96 | QUrl url(hlp[0]);
|
---|
[8204] | 97 | QByteArray staID = url.path().mid(1).toLatin1();
|
---|
[1932] | 98 | _bytes[staID] = new sumAndMean();
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[7640] | 102 | //
|
---|
[1932] | 103 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 104 | void bncFigure::slotNewData(const QByteArray staID, double nbyte) {
|
---|
| 105 | QMutexLocker locker(&_mutex);
|
---|
| 106 | QMap<QByteArray, sumAndMean*>::const_iterator it = _bytes.find(staID);
|
---|
| 107 | if (it != _bytes.end()) {
|
---|
[2007] | 108 | it.value()->_sum += nbyte*8.;
|
---|
[1932] | 109 | }
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[7640] | 112 | //
|
---|
[1932] | 113 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 114 | void bncFigure::slotNextAnimationFrame() {
|
---|
| 115 | QMutexLocker locker(&_mutex);
|
---|
[1934] | 116 |
|
---|
| 117 | const static int MAXCOUNTER = 10;
|
---|
| 118 |
|
---|
| 119 | ++_counter;
|
---|
| 120 |
|
---|
[1935] | 121 | // If counter reaches its maximal value, compute the mean rate
|
---|
| 122 | // -----------------------------------------------------------
|
---|
[1934] | 123 | if (_counter == MAXCOUNTER) {
|
---|
[1936] | 124 | _maxRate = 0.0;
|
---|
[1935] | 125 | QMapIterator<QByteArray, sumAndMean*> it(_bytes);
|
---|
| 126 | while (it.hasNext()) {
|
---|
| 127 | it.next();
|
---|
| 128 | it.value()->_mean = it.value()->_sum / _counter;
|
---|
[1936] | 129 | it.value()->_sum = 0.0;
|
---|
| 130 | if (it.value()->_mean > _maxRate) {
|
---|
| 131 | _maxRate = it.value()->_mean;
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
[1932] | 134 | _counter = 0;
|
---|
| 135 | }
|
---|
[1934] | 136 |
|
---|
[1932] | 137 | update();
|
---|
[1935] | 138 |
|
---|
[1932] | 139 | QTimer::singleShot(1000, this, SLOT(slotNextAnimationFrame()));
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[7640] | 142 | //
|
---|
[1932] | 143 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 144 | void bncFigure::paintEvent(QPaintEvent *) {
|
---|
[1936] | 145 |
|
---|
| 146 | int xMin = 0;
|
---|
| 147 | int xMax = 640;
|
---|
| 148 | int yMin = 0;
|
---|
[9124] | 149 | int yMax = 90;
|
---|
[1951] | 150 | float xLine = .60;
|
---|
[1936] | 151 |
|
---|
[1932] | 152 | QPainter painter(this);
|
---|
| 153 |
|
---|
[1960] | 154 | QFont font;
|
---|
[1963] | 155 | font.setPointSize(int(font.QFont::pointSize()*0.8));
|
---|
[1960] | 156 | painter.setFont(font);
|
---|
| 157 |
|
---|
[1936] | 158 | // y-axis
|
---|
| 159 | // ------
|
---|
[1951] | 160 | int yLength = int((yMax-yMin)*xLine) - (yMin+10);
|
---|
[1989] | 161 | painter.drawLine(xMin+60, int((yMax-yMin)*xLine), xMin+60, yMin+10);
|
---|
[1936] | 162 |
|
---|
[2007] | 163 | double maxRateRounded;
|
---|
[1938] | 164 | QString maxRateStr;
|
---|
[2007] | 165 | if (_maxRate < 1e3) {
|
---|
| 166 | maxRateRounded = int(_maxRate/200)*200 + 300;
|
---|
| 167 | maxRateStr = QString("%1 bps ").arg(int(maxRateRounded/200)*200);
|
---|
[1989] | 168 | painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 bps "));
|
---|
[1938] | 169 | }
|
---|
[2007] | 170 | else if (_maxRate < 1e6) {
|
---|
| 171 | maxRateRounded = int(_maxRate/1.e3)*1.e3 + 1500;
|
---|
| 172 | maxRateStr = QString("%1 kbps ").arg(int(maxRateRounded/1.e3));
|
---|
[1989] | 173 | painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 kbps "));
|
---|
[1938] | 174 | }
|
---|
| 175 | else {
|
---|
[2007] | 176 | maxRateRounded = int(_maxRate/1.e6)*1.e6 + 1500000;
|
---|
| 177 | maxRateStr = QString("%1 Mbps ").arg(int(maxRateRounded/1.e6));
|
---|
[1989] | 178 | painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+60,15,Qt::AlignRight,tr("0 Mbps "));
|
---|
[1938] | 179 | }
|
---|
| 180 |
|
---|
[1951] | 181 | if(_maxRate > 0.0) {
|
---|
[2007] | 182 | painter.drawText(0, yMin+20-5, xMin+60,15,Qt::AlignRight,maxRateStr);
|
---|
[1951] | 183 | }
|
---|
[1938] | 184 |
|
---|
[1936] | 185 | // x-axis
|
---|
| 186 | // ------
|
---|
[1989] | 187 | painter.drawLine(xMin+60, int((yMax-yMin)*xLine), xMax*3, int((yMax-yMin)*xLine));
|
---|
[1936] | 188 |
|
---|
| 189 | int anchor = 0;
|
---|
[1932] | 190 | QMapIterator<QByteArray, sumAndMean*> it(_bytes);
|
---|
| 191 | while (it.hasNext()) {
|
---|
| 192 | it.next();
|
---|
| 193 | QByteArray staID = it.key();
|
---|
[1936] | 194 |
|
---|
[1989] | 195 | int xx = xMin+80+anchor*12;
|
---|
[1936] | 196 |
|
---|
[1948] | 197 | if(_maxRate > 0.0) {
|
---|
[2007] | 198 | int yy = int(yLength * (it.value()->_mean / maxRateRounded));
|
---|
[1994] | 199 | QColor color = QColor::fromRgb(_ran[0][anchor],_ran[1][anchor],_ran[2][anchor],150);
|
---|
[7640] | 200 | painter.fillRect(xx-13, int((yMax-yMin)*xLine)-yy, 9, yy,
|
---|
[1956] | 201 | QBrush(color,Qt::SolidPattern));
|
---|
[1990] | 202 | painter.setPen(Qt::black);
|
---|
| 203 | if(it.value()->_mean<=0) {
|
---|
| 204 | painter.setPen(Qt::red);
|
---|
| 205 | }
|
---|
[1948] | 206 | }
|
---|
[1937] | 207 |
|
---|
[1990] | 208 | painter.save();
|
---|
| 209 | painter.translate(xx-13, int(yMax-yMin)*xLine+65);
|
---|
| 210 | painter.rotate(-90);
|
---|
[9124] | 211 | painter.drawText(-30,0,95,50,Qt::AlignRight,staID.left(10) + " ");
|
---|
[1990] | 212 | painter.restore();
|
---|
| 213 |
|
---|
[1936] | 214 | anchor++;
|
---|
[1932] | 215 | }
|
---|
| 216 | }
|
---|
| 217 |
|
---|