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) {
|
---|
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;
|
---|
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 | ////////////////////////////////////////////////////////////////////////////
|
---|
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);
|
---|
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 | ////////////////////////////////////////////////////////////////////////////
|
---|
127 | void 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 | painter.drawLine(xMin+50, yMax-40, xMin+50, yMin+10);
|
---|
139 | painter.drawText(xMin+40, yMax-40, tr("0"));
|
---|
140 | painter.drawText(xMin+20, yMin+25, tr("100 %"));
|
---|
141 |
|
---|
142 | // x-axis
|
---|
143 | // ------
|
---|
144 | painter.drawLine(xMin+50, yMax-40, xMax-10, yMax-40);
|
---|
145 |
|
---|
146 | painter.drawText(xMin+10,yMax-10,
|
---|
147 | tr(QTime::currentTime().toString().toAscii()));
|
---|
148 |
|
---|
149 | int anchor = 0;
|
---|
150 |
|
---|
151 | QMapIterator<QByteArray, sumAndMean*> it(_bytes);
|
---|
152 | while (it.hasNext()) {
|
---|
153 | it.next();
|
---|
154 | QByteArray staID = it.key();
|
---|
155 | double vv = it.value()->_mean;
|
---|
156 |
|
---|
157 | int xx = xMin+100+anchor*40;
|
---|
158 |
|
---|
159 | painter.drawText(xx, yMax-10, staID);
|
---|
160 |
|
---|
161 | QRectF vrect(xx, yMax-40-vv, 30, vv);
|
---|
162 | QBrush xBrush(Qt::blue,Qt::SolidPattern);
|
---|
163 | painter.fillRect(vrect,xBrush);
|
---|
164 | painter.drawRect(vrect);
|
---|
165 | anchor++;
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|