source: ntrip/trunk/BNC/src/bncfigure.cpp@ 7523

Last change on this file since 7523 was 7182, checked in by stuerze, 9 years ago

minor changes to prevent crash because of chenaged mountPoint entries

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