source: ntrip/trunk/BNC/src/bncfigurelate.cpp@ 10026

Last change on this file since 10026 was 9124, checked in by stuerze, 4 years ago

minor changes regarding latency check, ssr and long mountpoint names

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