source: ntrip/trunk/BNC/bncfigure.cpp@ 1938

Last change on this file since 1938 was 1938, checked in by mervart, 14 years ago

* empty log message *

File size: 4.8 KB
Line 
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) {
51 updateMountPoints();
52 slotNextAnimationFrame();
53}
54
55// Destructor
56////////////////////////////////////////////////////////////////////////////
57bncFigure::~bncFigure() {
58}
59
60//
61////////////////////////////////////////////////////////////////////////////
62void bncFigure::updateMountPoints() {
63 QMutexLocker locker(&_mutex);
64
65 _counter = 0;
66 _maxRate = 0;
67
68 QMapIterator<QByteArray, sumAndMean*> it1(_bytes);
69 while (it1.hasNext()) {
70 it1.next();
71 delete it1.value();
72 }
73 _bytes.clear();
74
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////////////////////////////////////////////////////////////////////////////
87void 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////////////////////////////////////////////////////////////////////////////
97void bncFigure::slotNextAnimationFrame() {
98 QMutexLocker locker(&_mutex);
99
100 const static int MAXCOUNTER = 10;
101
102 ++_counter;
103
104 // If counter reaches its maximal value, compute the mean rate
105 // -----------------------------------------------------------
106 if (_counter == MAXCOUNTER) {
107 _maxRate = 0.0;
108 QMapIterator<QByteArray, sumAndMean*> it(_bytes);
109 while (it.hasNext()) {
110 it.next();
111 it.value()->_mean = it.value()->_sum / _counter;
112 it.value()->_sum = 0.0;
113 if (it.value()->_mean > _maxRate) {
114 _maxRate = it.value()->_mean;
115 }
116 }
117 _counter = 0;
118 }
119
120 update();
121
122 QTimer::singleShot(1000, this, SLOT(slotNextAnimationFrame()));
123}
124
125//
126////////////////////////////////////////////////////////////////////////////
127void bncFigure::paintEvent(QPaintEvent *) {
128
129 int xMin = 0;
130 int xMax = 640;
131 int yMin = 0;
132 int yMax = 180;
133
134 QPainter painter(this);
135
136 // y-axis
137 // ------
138 int yLength = (yMax-40) - (yMin+10);
139 painter.drawLine(xMin+50, yMax-40, xMin+50, yMin+10);
140 painter.drawText(xMin+40, yMax-40, tr("0"));
141
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
153 painter.drawText(xMin+20, yMin+25, maxRateStr);
154
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
164 QMapIterator<QByteArray, sumAndMean*> it(_bytes);
165 while (it.hasNext()) {
166 it.next();
167 QByteArray staID = it.key();
168
169 int xx = xMin+100+anchor*40;
170 int yy = int(yLength * (it.value()->_mean / _maxRate));
171
172 painter.drawText(xx, yMax-10, staID.left(4));
173
174 painter.fillRect(xx, yMax-40-yy, 30, yy,
175 QBrush(Qt::blue,Qt::SolidPattern));
176
177 anchor++;
178 }
179}
180
Note: See TracBrowser for help on using the repository browser.