[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 | *
|
---|
| 31 | * Purpose:
|
---|
| 32 | *
|
---|
| 33 | * Author: Perlt, Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 11-Nov-2009
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
| 41 | #include <iostream>
|
---|
| 42 |
|
---|
| 43 | #include "bncfigure.h"
|
---|
| 44 | #include "bncsettings.h"
|
---|
| 45 |
|
---|
| 46 | using namespace std;
|
---|
| 47 |
|
---|
| 48 | // Constructor
|
---|
| 49 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 50 | bncFigure::bncFigure(QWidget *parent) : QWidget(parent) {
|
---|
[1933] | 51 | updateMountPoints();
|
---|
| 52 | slotNextAnimationFrame();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | // Destructor
|
---|
| 56 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 57 | bncFigure::~bncFigure() {
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | //
|
---|
| 61 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 62 | void bncFigure::updateMountPoints() {
|
---|
| 63 | QMutexLocker locker(&_mutex);
|
---|
| 64 |
|
---|
| 65 | _counter = 0;
|
---|
[1936] | 66 | _maxRate = 0;
|
---|
[1933] | 67 |
|
---|
| 68 | QMapIterator<QByteArray, sumAndMean*> it1(_bytes);
|
---|
| 69 | while (it1.hasNext()) {
|
---|
| 70 | it1.next();
|
---|
| 71 | delete it1.value();
|
---|
| 72 | }
|
---|
| 73 | _bytes.clear();
|
---|
| 74 |
|
---|
[1932] | 75 | bncSettings settings;
|
---|
| 76 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 77 | while (it.hasNext()) {
|
---|
| 78 | QStringList hlp = it.next().split(" ");
|
---|
| 79 | QUrl url(hlp[0]);
|
---|
| 80 | QByteArray staID = url.path().mid(1).toAscii();
|
---|
| 81 | _bytes[staID] = new sumAndMean();
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | //
|
---|
| 86 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 87 | void bncFigure::slotNewData(const QByteArray staID, double nbyte) {
|
---|
| 88 | QMutexLocker locker(&_mutex);
|
---|
| 89 | QMap<QByteArray, sumAndMean*>::const_iterator it = _bytes.find(staID);
|
---|
| 90 | if (it != _bytes.end()) {
|
---|
| 91 | it.value()->_sum += nbyte;
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | //
|
---|
| 96 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 97 | void bncFigure::slotNextAnimationFrame() {
|
---|
| 98 | QMutexLocker locker(&_mutex);
|
---|
[1934] | 99 |
|
---|
| 100 | const static int MAXCOUNTER = 10;
|
---|
| 101 |
|
---|
| 102 | ++_counter;
|
---|
| 103 |
|
---|
[1935] | 104 | // If counter reaches its maximal value, compute the mean rate
|
---|
| 105 | // -----------------------------------------------------------
|
---|
[1934] | 106 | if (_counter == MAXCOUNTER) {
|
---|
[1936] | 107 | _maxRate = 0.0;
|
---|
[1935] | 108 | QMapIterator<QByteArray, sumAndMean*> it(_bytes);
|
---|
| 109 | while (it.hasNext()) {
|
---|
| 110 | it.next();
|
---|
| 111 | it.value()->_mean = it.value()->_sum / _counter;
|
---|
[1936] | 112 | it.value()->_sum = 0.0;
|
---|
| 113 | if (it.value()->_mean > _maxRate) {
|
---|
| 114 | _maxRate = it.value()->_mean;
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
[1932] | 117 | _counter = 0;
|
---|
| 118 | }
|
---|
[1934] | 119 |
|
---|
[1932] | 120 | update();
|
---|
[1935] | 121 |
|
---|
[1932] | 122 | QTimer::singleShot(1000, this, SLOT(slotNextAnimationFrame()));
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | //
|
---|
| 126 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 127 | void bncFigure::paintEvent(QPaintEvent *) {
|
---|
[1936] | 128 |
|
---|
| 129 | int xMin = 0;
|
---|
| 130 | int xMax = 640;
|
---|
| 131 | int yMin = 0;
|
---|
| 132 | int yMax = 180;
|
---|
| 133 |
|
---|
[1932] | 134 | QPainter painter(this);
|
---|
| 135 |
|
---|
[1936] | 136 | // y-axis
|
---|
| 137 | // ------
|
---|
[1937] | 138 | int yLength = (yMax-40) - (yMin+10);
|
---|
[1936] | 139 | painter.drawLine(xMin+50, yMax-40, xMin+50, yMin+10);
|
---|
[1949] | 140 | painter.drawText(xMin+30, yMax-40, tr("0"));
|
---|
[1936] | 141 |
|
---|
[1938] | 142 | QString maxRateStr;
|
---|
| 143 | if (8.0 * _maxRate < 1e3) {
|
---|
| 144 | maxRateStr = QString("%1 bps").arg(int(8.0 * _maxRate));
|
---|
| 145 | }
|
---|
| 146 | else if (8.0 * _maxRate < 1e6) {
|
---|
| 147 | maxRateStr = QString("%1 kbps").arg(int(8.0 * _maxRate / 1.e3));
|
---|
| 148 | }
|
---|
| 149 | else {
|
---|
| 150 | maxRateStr = QString("%1 Mbps").arg(int(8.0 * _maxRate / 1.e6));
|
---|
| 151 | }
|
---|
| 152 |
|
---|
[1949] | 153 | painter.drawText(xMin+0, yMin+25, maxRateStr);
|
---|
[1938] | 154 |
|
---|
[1936] | 155 | // x-axis
|
---|
| 156 | // ------
|
---|
| 157 | painter.drawLine(xMin+50, yMax-40, xMax-10, yMax-40);
|
---|
| 158 |
|
---|
| 159 | painter.drawText(xMin+10,yMax-10,
|
---|
| 160 | tr(QTime::currentTime().toString().toAscii()));
|
---|
| 161 |
|
---|
| 162 | int anchor = 0;
|
---|
| 163 |
|
---|
[1932] | 164 | QMapIterator<QByteArray, sumAndMean*> it(_bytes);
|
---|
| 165 | while (it.hasNext()) {
|
---|
| 166 | it.next();
|
---|
| 167 | QByteArray staID = it.key();
|
---|
[1936] | 168 |
|
---|
| 169 | int xx = xMin+100+anchor*40;
|
---|
| 170 |
|
---|
[1939] | 171 | painter.drawText(xx, yMax-10, staID.left(5));
|
---|
[1936] | 172 |
|
---|
[1948] | 173 | if(_maxRate > 0.0) {
|
---|
[1950] | 174 | int yy = int(yLength * (it.value()->_mean / _maxRate));
|
---|
[1948] | 175 | painter.fillRect(xx, yMax-40-yy, 30, yy,
|
---|
| 176 | QBrush(Qt::blue,Qt::SolidPattern));
|
---|
| 177 | }
|
---|
[1937] | 178 |
|
---|
[1936] | 179 | anchor++;
|
---|
[1932] | 180 | }
|
---|
| 181 | }
|
---|
| 182 |
|
---|