source: ntrip/trunk/BNC/src/ssrRefSig.cpp

Last change on this file was 11090, checked in by stuerze, 10 hours ago

Bias check is added in ssrQC, refernce signals are configurable now

File size: 6.3 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://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: t_ssrRefSig
30 *
31 * Purpose: Reference signals of the satellite clocks per GNSS
32 *
33 * -----------------------------------------------------------------------*/
34
35#include "ssrRefSig.h"
36#include "bncsettings.h"
37
38using namespace std;
39
40QMutex t_ssrRefSig::_mutex;
41bool t_ssrRefSig::_initialized = false;
42QMap<char, t_ssrRefSig::t_pair> t_ssrRefSig::_pairs;
43
44static const char* DEFAULT_REF_SIGNALS = "G:1W&2W R:1P&2P E:1C&5Q C:2I&6I J:1C&2L S:1C&5Q";
45
46// Frequency of a band of a system (e.g. 'C', '1' -> C1)
47////////////////////////////////////////////////////////////////////////////
48static t_frequency::type bandToFreq(char sys, char band) {
49 for (int ii = t_frequency::dummy + 1; ii < t_frequency::max; ii++) {
50 string str = t_frequency::toString(t_frequency::type(ii));
51 if (str.size() >= 2 && str[0] == sys && str[1] == band) {
52 return t_frequency::type(ii);
53 }
54 }
55 return t_frequency::dummy;
56}
57
58//
59////////////////////////////////////////////////////////////////////////////
60string t_ssrRefSig::t_pair::sig1() const {
61 string str = t_frequency::toString(frq1);
62 return str.size() >= 2 ? string(1, str[1]) + att1 : string();
63}
64
65//
66////////////////////////////////////////////////////////////////////////////
67string t_ssrRefSig::t_pair::sig2() const {
68 string str = t_frequency::toString(frq2);
69 return str.size() >= 2 ? string(1, str[1]) + att2 : string();
70}
71
72// Parse 'G:1W&2W C:1P&5P ...'
73////////////////////////////////////////////////////////////////////////////
74bool t_ssrRefSig::parse(const QString& str, QMap<char, t_pair>& pairs, QStringList* errors) {
75 bool ok = true;
76 QStringList items = str.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
77 for (const QString& item : items) {
78 QRegularExpressionMatch mm =
79 QRegularExpression("^([A-Z]):([0-9])([A-Z])&([0-9])([A-Z])$").match(item.trimmed());
80 t_pair pair;
81 char sys = 0;
82 if (mm.hasMatch()) {
83 sys = mm.captured(1)[0].toLatin1();
84 pair.frq1 = bandToFreq(sys, mm.captured(2)[0].toLatin1());
85 pair.att1 = mm.captured(3)[0].toLatin1();
86 pair.frq2 = bandToFreq(sys, mm.captured(4)[0].toLatin1());
87 pair.att2 = mm.captured(5)[0].toLatin1();
88 }
89 if (sys == 0 || pair.frq1 == t_frequency::dummy || pair.frq2 == t_frequency::dummy ||
90 pair.frq1 == pair.frq2) {
91 ok = false;
92 if (errors) {
93 *errors << QString("reference signals '%1' invalid (unknown system or band, or format other than e.g. 'C:1P&5P'), ignored").arg(item);
94 }
95 continue;
96 }
97 pairs[sys] = pair;
98 }
99 return ok;
100}
101
102// (Re-)read the option
103////////////////////////////////////////////////////////////////////////////
104QStringList t_ssrRefSig::init() {
105 QMutexLocker locker(&_mutex);
106 QStringList errors;
107 _pairs.clear();
108 parse(DEFAULT_REF_SIGNALS, _pairs, 0);
109 bncSettings settings;
110 parse(settings.value("ssrRefSignals").toString(), _pairs, &errors);
111 _initialized = true;
112 return errors;
113}
114
115//
116////////////////////////////////////////////////////////////////////////////
117bool t_ssrRefSig::get(char sys, t_pair& pair) {
118 if (!_initialized) {
119 init();
120 }
121 QMutexLocker locker(&_mutex);
122 if (!_pairs.contains(sys)) {
123 return false;
124 }
125 pair = _pairs[sys];
126 return true;
127}
128
129// True if the system uses the default reference signals
130////////////////////////////////////////////////////////////////////////////
131bool t_ssrRefSig::isDefault(char sys) {
132 QMap<char, t_pair> defaults;
133 parse(DEFAULT_REF_SIGNALS, defaults, 0);
134 t_pair pair;
135 bool has = get(sys, pair);
136 if (!defaults.contains(sys)) {
137 return !has;
138 }
139 const t_pair& def = defaults[sys];
140 return has && pair.frq1 == def.frq1 && pair.att1 == def.att1 &&
141 pair.frq2 == def.frq2 && pair.att2 == def.att2;
142}
143
144// True if all systems use the default reference signals
145////////////////////////////////////////////////////////////////////////////
146bool t_ssrRefSig::allDefault() {
147 QMap<char, t_pair> defaults;
148 parse(DEFAULT_REF_SIGNALS, defaults, 0);
149 if (!_initialized) {
150 init();
151 }
152 QMutexLocker locker(&_mutex);
153 if (defaults.keys() != _pairs.keys()) {
154 return false;
155 }
156 for (char sys : defaults.keys()) {
157 const t_pair& p1 = defaults[sys];
158 const t_pair& p2 = _pairs[sys];
159 if (p1.frq1 != p2.frq1 || p1.att1 != p2.att1 || p1.frq2 != p2.frq2 || p1.att2 != p2.att2) {
160 return false;
161 }
162 }
163 return true;
164}
165
166//
167////////////////////////////////////////////////////////////////////////////
168QString t_ssrRefSig::defaultString() {
169 return DEFAULT_REF_SIGNALS;
170}
171
172// Current reference signals, e.g. for the logfile
173////////////////////////////////////////////////////////////////////////////
174QString t_ssrRefSig::currentString() {
175 if (!_initialized) {
176 init();
177 }
178 QMutexLocker locker(&_mutex);
179 QStringList items;
180 QString systems = "GRECJSI";
181 for (char sys : _pairs.keys()) {
182 if (!systems.contains(sys)) {
183 systems += sys;
184 }
185 }
186 for (QChar sys : systems) {
187 char cs = sys.toLatin1();
188 if (_pairs.contains(cs)) {
189 items << QString("%1:%2&%3").arg(sys).arg(_pairs[cs].sig1().c_str()).arg(_pairs[cs].sig2().c_str());
190 }
191 }
192 return items.join(" ");
193}
Note: See TracBrowser for help on using the repository browser.