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: bncFigureLate
|
---|
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 "bncfigurelate.h"
|
---|
44 | #include "bncsettings.h"
|
---|
45 |
|
---|
46 | using namespace std;
|
---|
47 |
|
---|
48 | // Constructor
|
---|
49 | ////////////////////////////////////////////////////////////////////////////
|
---|
50 | bncFigureLate::bncFigureLate(QWidget *parent) : QWidget(parent) {
|
---|
51 | updateMountPoints();
|
---|
52 | slotNextAnimationFrame();
|
---|
53 | for (int ii = 0; ii <= 1000; ii++) {
|
---|
54 | _rgb[0][ii] = qrand() % 255;
|
---|
55 | _rgb[2][ii] = qrand() % 255;
|
---|
56 | _rgb[1][ii] = qrand() % 255;
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | // Destructor
|
---|
61 | ////////////////////////////////////////////////////////////////////////////
|
---|
62 | bncFigureLate::~bncFigureLate() {
|
---|
63 | }
|
---|
64 |
|
---|
65 | //
|
---|
66 | ////////////////////////////////////////////////////////////////////////////
|
---|
67 | void bncFigureLate::updateMountPoints() {
|
---|
68 | QMutexLocker locker(&_mutex);
|
---|
69 |
|
---|
70 | _counter = 0;
|
---|
71 | _maxLate = 0;
|
---|
72 |
|
---|
73 | QMapIterator<QByteArray, sumAndMean*> it1(_bytes);
|
---|
74 | while (it1.hasNext()) {
|
---|
75 | it1.next();
|
---|
76 | delete it1.value();
|
---|
77 | }
|
---|
78 | _bytes.clear();
|
---|
79 |
|
---|
80 | bncSettings settings;
|
---|
81 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
82 | while (it.hasNext()) {
|
---|
83 | QStringList hlp = it.next().split(" ");
|
---|
84 | QUrl url(hlp[0]);
|
---|
85 | QByteArray staID = url.path().mid(1).toAscii();
|
---|
86 | _bytes[staID] = new sumAndMean();
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | //
|
---|
91 | ////////////////////////////////////////////////////////////////////////////
|
---|
92 | void bncFigureLate::slotNewLatency(const QByteArray staID, double clate) {
|
---|
93 | QMutexLocker locker(&_mutex);
|
---|
94 | QMap<QByteArray, sumAndMean*>::const_iterator it = _bytes.find(staID);
|
---|
95 | if (it != _bytes.end()) {
|
---|
96 | it.value()->_sum += fabs(clate)*1000.;
|
---|
97 | ++_counter;
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | //
|
---|
102 | ////////////////////////////////////////////////////////////////////////////
|
---|
103 | void bncFigureLate::slotNextAnimationFrame() {
|
---|
104 | QMutexLocker locker(&_mutex);
|
---|
105 |
|
---|
106 | const static int MAXCOUNTER = 10;
|
---|
107 |
|
---|
108 | //++_counter;
|
---|
109 |
|
---|
110 | // If counter reaches its maximal value, compute the mean value
|
---|
111 | // ------------------------------------------------------------
|
---|
112 | //if (_counter == MAXCOUNTER) {
|
---|
113 | if (_counter > MAXCOUNTER) {
|
---|
114 | _maxLate = 0.0;
|
---|
115 | QMapIterator<QByteArray, sumAndMean*> it(_bytes);
|
---|
116 | while (it.hasNext()) {
|
---|
117 | it.next();
|
---|
118 | it.value()->_mean = it.value()->_sum / _counter;
|
---|
119 | it.value()->_sum = 0.0;
|
---|
120 | if (it.value()->_mean > _maxLate) {
|
---|
121 | _maxLate = it.value()->_mean;
|
---|
122 | }
|
---|
123 | }
|
---|
124 | _counter = 0;
|
---|
125 | }
|
---|
126 |
|
---|
127 | update();
|
---|
128 |
|
---|
129 | QTimer::singleShot(1000, this, SLOT(slotNextAnimationFrame()));
|
---|
130 | }
|
---|
131 |
|
---|
132 | //
|
---|
133 | ////////////////////////////////////////////////////////////////////////////
|
---|
134 | void bncFigureLate::paintEvent(QPaintEvent *) {
|
---|
135 |
|
---|
136 | int xMin = 0;
|
---|
137 | int xMax = 640;
|
---|
138 | int yMin = 0;
|
---|
139 | int yMax = 140;
|
---|
140 | float xLine = .60;
|
---|
141 |
|
---|
142 | QPainter painter(this);
|
---|
143 |
|
---|
144 | QFont font;
|
---|
145 | font.setPointSize(int(font.QFont::pointSize()*0.8));
|
---|
146 | painter.setFont(font);
|
---|
147 |
|
---|
148 | // y-axis
|
---|
149 | // ------
|
---|
150 | int yLength = int((yMax-yMin)*xLine) - (yMin+10);
|
---|
151 | painter.drawLine(xMin+50, int((yMax-yMin)*xLine), xMin+50, yMin+10);
|
---|
152 |
|
---|
153 | QString maxLateStr;
|
---|
154 | maxLateStr = QString("%1 ms ").arg(int(_maxLate/200)*200);
|
---|
155 | painter.drawText(0, int((yMax-yMin)*xLine)-5, xMin+50,15,Qt::AlignRight,tr("0 ms "));
|
---|
156 |
|
---|
157 | if(_maxLate > 0.0) {
|
---|
158 | painter.drawText(0, yMin+25-5, xMin+50,15,Qt::AlignRight,maxLateStr);
|
---|
159 | }
|
---|
160 |
|
---|
161 | // x-axis
|
---|
162 | // ------
|
---|
163 | painter.drawLine(xMin+50, int((yMax-yMin)*xLine), xMax*3, int((yMax-yMin)*xLine));
|
---|
164 |
|
---|
165 | int anchor = 0;
|
---|
166 | QMapIterator<QByteArray, sumAndMean*> it(_bytes);
|
---|
167 | while (it.hasNext()) {
|
---|
168 | it.next();
|
---|
169 | QByteArray staID = it.key();
|
---|
170 |
|
---|
171 | int xx = xMin+70+anchor*12;
|
---|
172 | int yy = int(yLength * (it.value()->_mean / _maxLate));
|
---|
173 |
|
---|
174 | painter.save();
|
---|
175 | painter.translate(xx-13, int(yMax-yMin)*xLine+65);
|
---|
176 | painter.rotate(-90);
|
---|
177 | painter.drawText(0,0,65,50,Qt::AlignRight,staID.left(5) + " ");
|
---|
178 | painter.restore();
|
---|
179 |
|
---|
180 | if(_maxLate > 0.0) {
|
---|
181 | QColor color = QColor::fromRgb(_rgb[0][anchor],_rgb[1][anchor],_rgb[2][anchor]);
|
---|
182 | painter.fillRect(xx-13, int((yMax-yMin)*xLine)-yy, 9, yy,
|
---|
183 | QBrush(color,Qt::SolidPattern));
|
---|
184 | }
|
---|
185 |
|
---|
186 | anchor++;
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|