0.5.1
Loading...
Searching...
No Matches
RinexObsFile.cpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#include "RinexObsFile.hpp"
10
11#include <fmt/ranges.h>
12
13#include "util/Eigen.hpp"
14
15#include "util/Logger.hpp"
18
19#include "util/StringUtil.hpp"
20
24
26
27namespace NAV
28{
29
31 : Node(typeStatic())
32{
33 LOG_TRACE("{}: called", name);
34
35 _hasConfig = true;
36 _guiConfigDefaultWindowSize = { 517, 118 };
37
39}
40
42{
43 LOG_TRACE("{}: called", nameId());
44}
45
47{
48 return "RinexObsFile";
49}
50
51std::string RinexObsFile::type() const
52{
53 return typeStatic();
54}
55
57{
58 return "Data Provider";
59}
60
62{
63 if (auto res = FileReader::guiConfig(R"(Rinex Obs (.obs .rnx .*o){.obs,.rnx,(.+[.]\d\d?[oO])},.*)",
64 { ".obs", ".rnx", "(.+[.]\\d\\d?[oO])" }, size_t(id), nameId()))
65 {
66 LOG_DEBUG("{}: Path changed to {}", nameId(), _path);
68 if (res == FileReader::PATH_CHANGED)
69 {
71 }
72 else
73 {
75 }
76 }
77 ImGui::Text("Supported versions: ");
78 std::ranges::for_each(_supportedVersions, [](double x) {
79 ImGui::SameLine();
80 ImGui::Text("%0.2f", x);
81 });
82
83 ImGui::Checkbox("Erase less precise codes", &_eraseLessPreciseCodes);
84 ImGui::SameLine();
85 gui::widgets::HelpMarker("Whether to remove less precise codes (e.g. if G1X (L1C combined) is present, don't use G1L (L1C pilot) and G1S (L1C data))");
86}
87
88[[nodiscard]] json RinexObsFile::save() const
89{
90 LOG_TRACE("{}: called", nameId());
91
92 json j;
93
94 j["FileReader"] = FileReader::save();
95 j["eraseLessPreciseCodes"] = _eraseLessPreciseCodes;
96
97 return j;
98}
99
101{
102 LOG_TRACE("{}: called", nameId());
103
104 if (j.contains("FileReader"))
105 {
106 FileReader::restore(j.at("FileReader"));
107 }
108 if (j.contains("eraseLessPreciseCodes"))
109 {
110 j.at("eraseLessPreciseCodes").get_to(_eraseLessPreciseCodes);
111 }
112}
113
115{
116 LOG_TRACE("{}: called", nameId());
117
118 return FileReader::initialize();
119}
120
122{
123 LOG_TRACE("{}: called", nameId());
124
126
127 _version = 0.0;
129 _obsDescription.clear();
130 _rcvClockOffsAppl = false;
131 _receiverInfo = {};
132}
133
135{
136 LOG_TRACE("{}: called", nameId());
137
139
140 return true;
141}
142
144{
145 auto extHeaderLabel = [](std::string line) {
146 // Remove any trailing non text characters
147 line.erase(std::ranges::find_if(line, [](int ch) { return std::iscntrl(ch); }), line.end());
148
149 return str::trim_copy(std::string_view(line).substr(60, 20));
150 };
151
152 std::filesystem::path filepath = getFilepath();
153
154 auto filestreamHeader = std::ifstream(filepath);
155 if (filestreamHeader.good())
156 {
157 std::string line;
158 // --------------------------------------- RINEX VERSION / TYPE ------------------------------------------
159 std::getline(filestreamHeader, line);
160 str::rtrim(line);
161 if (line.size() != 80)
162 {
163 LOG_ERROR("{}: Not a valid RINEX OBS file. Lines should be 80 characters long but the file has {}.", nameId(), line.size() - 1);
165 }
166
167 if (extHeaderLabel(line) != "RINEX VERSION / TYPE")
168 {
169 LOG_ERROR("{}: Not a valid RINEX OBS file. Could not read 'RINEX VERSION / TYPE' line.", nameId());
171 }
172
173 double version = std::stod(str::trim_copy(line.substr(0, 20))); // FORMAT: F9.2,11X
174 if (!_supportedVersions.contains(version))
175 {
176 LOG_ERROR("{}: RINEX version {} is not supported. Supported versions are [{}]", nameId(),
177 version, fmt::join(_supportedVersions.begin(), _supportedVersions.end(), ", "));
179 }
180
181 std::string fileType = str::trim_copy(line.substr(20, 20)); // FORMAT: A1,19X
182 if (fileType.at(0) != 'O')
183 {
184 LOG_ERROR("{}: Not a valid RINEX OBS file. File type '{}' not recognized.", nameId(), fileType);
187 }
188 std::string satSystem = str::trim_copy(line.substr(40, 20)); // FORMAT: A1,19X
189 if (SatelliteSystem::fromChar(satSystem.at(0)) == SatSys_None && satSystem.at(0) != 'M')
190 {
191 LOG_ERROR("{}: Not a valid RINEX OBS file. Satellite System '{}' not recognized.", nameId(), satSystem.at(0));
194 }
195 // ---------------------------------------- PGM / RUN BY / DATE ------------------------------------------
196 std::getline(filestreamHeader, line);
197 str::rtrim(line);
198 if (extHeaderLabel(line) != "PGM / RUN BY / DATE")
199 {
200 LOG_ERROR("{}: Not a valid RINEX OBS file. Could not read 'PGM / RUN BY / DATE' line.", nameId());
202 }
203
204 // ----------------------------------------- END OF HEADER -------------------------------------------
205 while (std::getline(filestreamHeader, line))
206 {
207 str::rtrim(line);
208 if (extHeaderLabel(line) == "END OF HEADER")
209 {
211 }
212 }
213 LOG_ERROR("{}: Not a valid RINEX NAV file. Could not read 'END OF HEADER' line.", nameId());
215 }
216
217 LOG_ERROR("{}: Could not determine file type because file could not be opened '{}' line.", nameId(), filepath.string());
219}
220
222{
223 LOG_TRACE("{}: called", nameId());
224
225 std::string line;
226
227 // --------------------------------------- RINEX VERSION / TYPE ------------------------------------------
228 getline(line);
229 _version = std::stod(str::trim_copy(line.substr(0, 20)));
230 LOG_DEBUG("{}: Version: {:3.2f}", nameId(), _version); // FORMAT: F9.2,11X
231 LOG_DEBUG("{}: SatSys : {}", nameId(), str::trim_copy(line.substr(40, 20))); // FORMAT: A1,19X
232
233 // #######################################################################################################
234 while (getline(line) && !eof())
235 {
236 if (line.size() < 60)
237 {
238 LOG_WARN("{}: Skipping header line because it does not include a header label: '{}'", nameId(), line);
239 continue;
240 }
241 auto headerLabel = str::trim_copy(line.substr(60, 20));
242 if (headerLabel == "PGM / RUN BY / DATE")
243 {
244 // Name of program creating current file
245 LOG_DATA("{}: Program: {}", nameId(), str::trim_copy(line.substr(0, 20))); // FORMAT: A20
246 // Name of agency creating current file
247 LOG_DATA("{}: Run by : {}", nameId(), str::trim_copy(line.substr(20, 20))); // FORMAT: A20
248 // Date and time of file creation
249 LOG_DATA("{}: Date : {}", nameId(), str::trim_copy(line.substr(40, 20))); // FORMAT: A20
250 }
251 else if (headerLabel == "COMMENT")
252 {
253 LOG_DATA("{}: Comment: {}", nameId(), line.substr(0, 60)); // FORMAT: A60
254 }
255 else if (headerLabel == "MARKER NAME")
256 {
257 auto markerName = str::trim_copy(line.substr(0, 60)); // FORMAT: A60
258 if (!markerName.empty())
259 {
260 LOG_DATA("{}: Marker name: {}", nameId(), markerName);
261 }
262 }
263 else if (headerLabel == "MARKER NUMBER")
264 {
265 auto markerNumber = str::trim_copy(line.substr(0, 20)); // FORMAT: A20
266 if (!markerNumber.empty())
267 {
268 LOG_DATA("{}: Marker number: {}", nameId(), markerNumber);
269 }
270 }
271 else if (headerLabel == "MARKER TYPE")
272 {
273 auto markerType = str::trim_copy(line.substr(0, 60)); // FORMAT: A20,40X
274 if (!markerType.empty())
275 {
276 LOG_DATA("{}: Marker type: {}", nameId(), markerType);
277 }
278 }
279 else if (headerLabel == "OBSERVER / AGENCY")
280 {
281 auto observer = str::trim_copy(line.substr(0, 20)); // FORMAT: A20,A40
282 auto agency = str::trim_copy(line.substr(20, 40));
283 if (!observer.empty() || !agency.empty())
284 {
285 LOG_DATA("{}: Observer '{}', Agency '{}'", nameId(), observer, agency);
286 }
287 }
288 else if (headerLabel == "REC # / TYPE / VERS")
289 {
290 auto receiverNumber = str::trim_copy(line.substr(0, 20)); // FORMAT: 3A20
291 auto receiverType = str::trim_copy(line.substr(20, 20));
292 auto receiverVersion = str::trim_copy(line.substr(40, 20));
293 if (!receiverNumber.empty() || !receiverType.empty() || !receiverVersion.empty())
294 {
295 LOG_DATA("{}: RecNum '{}', recType '{}', recVersion '{}'", nameId(),
296 receiverNumber, receiverType, receiverVersion);
297 }
298 }
299 else if (headerLabel == "ANT # / TYPE")
300 {
301 auto antennaNumber = str::trim_copy(line.substr(0, 20)); // FORMAT: 2A20
302 auto antennaType = str::trim_copy(line.substr(20, 20));
303 if (!antennaNumber.empty() || !antennaType.empty())
304 {
305 LOG_DATA("{}: antNum '{}', antType '{}'", nameId(), antennaNumber, antennaType);
306 }
307 if (!antennaType.empty() || antennaType != "Unknown")
308 {
309 _receiverInfo.antennaType = antennaType;
310 }
311 }
312 else if (headerLabel == "APPROX POSITION XYZ")
313 {
314 // Geocentric approximate marker position (Units: Meters, System: ITRS recommended)
315 // Optional for moving platforms
316 Eigen::Vector3d position_xyz{ std::stod(str::trim_copy(line.substr(0, 14))),
317 std::stod(str::trim_copy(line.substr(14, 14))),
318 std::stod(str::trim_copy(line.substr(28, 14))) }; // FORMAT: 3F14.4
319
320 LOG_DATA("{}: Approx Position XYZ: {} (not used yet)", nameId(), position_xyz.transpose());
321
322 _receiverInfo.e_approxPos = position_xyz;
323 }
324 else if (headerLabel == "ANTENNA: DELTA H/E/N")
325 {
326 // Antenna height: Height of the antenna reference point (ARP) above the marker [m]
327 double antennaHeight = std::stod(str::trim_copy(line.substr(0, 14))); // FORMAT: F14.4,
328 // Horizontal eccentricity of ARP relative to the marker (east) [m]
329 double antennaEccentricityEast = std::stod(str::trim_copy(line.substr(14, 14))); // FORMAT: 2F14.4,
330 // Horizontal eccentricity of ARP relative to the marker (north) [m]
331 double antennaEccentricityNorth = std::stod(str::trim_copy(line.substr(28, 14)));
332
333 LOG_DATA("{}: Antenna delta H/E/N: {}, {}, {} (not used yet)", nameId(),
334 antennaHeight, antennaEccentricityEast, antennaEccentricityNorth);
335
336 _receiverInfo.antennaDeltaNEU = Eigen::Vector3d(antennaEccentricityNorth, antennaEccentricityEast, antennaHeight);
337 }
338 else if (headerLabel == "ANTENNA: DELTA X/Y/Z")
339 {
340 // Position of antenna reference point for antenna on vehicle (m): XYZ vector in body-fixed coordinate system
341 [[maybe_unused]] Eigen::Vector3d antennaDeltaXYZ{ std::stod(str::trim_copy(line.substr(0, 14))),
342 std::stod(str::trim_copy(line.substr(14, 14))),
343 std::stod(str::trim_copy(line.substr(28, 14))) }; // FORMAT: 3F14.4
344
345 LOG_DATA("{}: Antenna Delta XYZ: {} (not used yet)", nameId(), antennaDeltaXYZ.transpose());
346 }
347 else if (headerLabel == "ANTENNA: PHASECENTER")
348 {
349 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "ANTENNA: PHASECENTER");
350 }
351 else if (headerLabel == "ANTENNA: B.SIGHT XYZ")
352 {
353 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "ANTENNA: B.SIGHT XYZ");
354 }
355 else if (headerLabel == "ANTENNA: ZERODIR AZI")
356 {
357 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "ANTENNA: ZERODIR AZI");
358 }
359 else if (headerLabel == "ANTENNA: ZERODIR XYZ")
360 {
361 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "ANTENNA: ZERODIR XYZ");
362 }
363 else if (headerLabel == "CENTER OF MASS: XYZ")
364 {
365 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "CENTER OF MASS: XYZ");
366 }
367 else if (headerLabel == "SYS / # / OBS TYPES")
368 {
369 // Satellite system code (G/R/E/J/C/I/S) - FORMAT: A1,
370 auto satSys = SatelliteSystem::fromChar(line.at(0));
371
372 // Number of different observation types for the specified satellite system - Format: 2X,I3,
373 size_t numSpecifications = std::stoul(line.substr(3, 3));
374
375 std::string debugOutput;
376 for (size_t n = 0, nLine = 1, i = 7; n < numSpecifications; n++, nLine++, i += 4)
377 {
378 // Observation descriptors: Type, Band, Attribute - FORMAT 13(1X,A3)
379
381 Frequency freq = NAV::vendor::RINEX::getFrequencyFromBand(satSys, line.at(i + 1) - '0');
382 auto attribute = line.at(i + 2);
383 if (freq == B01 && attribute == 'I') { freq = B02; }
384 Code code = Code::fromFreqAttr(freq, attribute);
385
386 _obsDescription[satSys].push_back(NAV::vendor::RINEX::ObservationDescription{ .type = type, .code = code });
387
388 debugOutput += fmt::format("({},{},{})", NAV::vendor::RINEX::obsTypeToChar(type), freq, code);
389
390 if (nLine == 13)
391 {
392 getline(line);
393 nLine = 0;
394 i = 3;
395 }
396 }
397
398 LOG_DATA("{}: Obs Type {} with {} specifications [{}]", nameId(),
399 satSys, numSpecifications, debugOutput);
400 }
401 else if (headerLabel == "SIGNAL STRENGTH UNIT")
402 {
403 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "SIGNAL STRENGTH UNIT");
404 }
405 else if (headerLabel == "INTERVAL")
406 {
407 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "INTERVAL");
408 }
409 else if (headerLabel == "TIME OF FIRST OBS")
410 {
411 [[maybe_unused]] auto year = std::stoi(line.substr(0, 6));
412 [[maybe_unused]] auto month = std::stoi(line.substr(6, 6));
413 [[maybe_unused]] auto day = std::stoi(line.substr(12, 6));
414 [[maybe_unused]] auto hour = std::stoi(line.substr(18, 6));
415 [[maybe_unused]] auto min = std::stoi(line.substr(24, 6));
416 [[maybe_unused]] auto sec = std::stold(line.substr(30, 13));
417 _timeSystem = TimeSystem::fromString(line.substr(30 + 13 + 5, 3));
418 LOG_DATA("{}: Time of first obs: {} GPST (originally in '{}' time)", nameId(),
419 InsTime{ static_cast<uint16_t>(year),
420 static_cast<uint16_t>(month),
421 static_cast<uint16_t>(day),
422 static_cast<uint16_t>(hour),
423 static_cast<uint16_t>(min),
424 sec,
426 .toYMDHMS(GPST),
427 std::string(_timeSystem));
428 }
429 else if (headerLabel == "TIME OF LAST OBS")
430 {
431 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "TIME OF LAST OBS");
432 }
433 else if (headerLabel == "RCV CLOCK OFFS APPL")
434 {
435 if (str::stoi(line.substr(0, 6), 0))
436 {
437 _rcvClockOffsAppl = true;
438 LOG_INFO("{}: Data (epoch, pseudorange, phase) corrected by the reported clock offset.", nameId());
439 }
440 LOG_TRACE("{}: Receiver clock offset applies: {}", nameId(), _rcvClockOffsAppl);
441 }
442 else if (headerLabel == "SYS / DCBS APPLIED")
443 {
444 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "SYS / DCBS APPLIED");
445 }
446 else if (headerLabel == "SYS / PCVS APPLIED")
447 {
448 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "SYS / PCVS APPLIED");
449 }
450 else if (headerLabel == "SYS / SCALE FACTOR")
451 {
452 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "SYS / SCALE FACTOR");
453 }
454 else if (headerLabel == "SYS / PHASE SHIFT")
455 {
456 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "SYS / PHASE SHIFT");
457 }
458 else if (headerLabel == "GLONASS SLOT / FRQ #")
459 {
460 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "GLONASS SLOT / FRQ #");
461 }
462 else if (headerLabel == "GLONASS COD/PHS/BIS")
463 {
464 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "GLONASS COD/PHS/BIS");
465 }
466 else if (headerLabel == "LEAP SECONDS")
467 {
468 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "LEAP SECONDS");
469 }
470 else if (headerLabel == "# OF SATELLITES")
471 {
472 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "# OF SATELLITES");
473 }
474 else if (headerLabel == "PRN / # OF OBS")
475 {
476 LOG_TRACE("{}: '{}' not implemented yet", nameId(), "PRN / # OF OBS");
477 }
478 else if (headerLabel == "END OF HEADER")
479 {
480 break;
481 }
482 else
483 {
484 LOG_WARN("{}: Unknown header label '{}' in line '{}'", nameId(), headerLabel, line);
485 }
486 }
487
488 if (_timeSystem == TimeSys_None) // If time system not set, try to apply default value
489 {
490 if (_obsDescription.size() == 1)
491 {
492 switch (SatelliteSystem_(_obsDescription.begin()->first))
493 {
494 case GPS:
496 break;
497 case GLO:
499 break;
500 case GAL:
502 break;
503 case QZSS:
505 break;
506 case BDS:
508 break;
509 case IRNSS:
511 break;
512 default:
513 LOG_CRITICAL("{}: Could not determine time system of the file because satellite system '{}' has no default.",
514 nameId(), SatelliteSystem(_obsDescription.begin()->first));
515 break;
516 }
517 }
518 else
519 {
520 LOG_CRITICAL("{}: Could not determine time system of the file.", nameId());
521 }
522 }
523}
524
525std::shared_ptr<const NodeData> RinexObsFile::pollData()
526{
527 std::string line;
528
529 InsTime epochTime;
530
531 // 0: OK | 1: power failure between previous and current epoch | > 1 : Special event
532 int epochFlag = -1;
533 size_t nSatellites = 0;
534 while (epochFlag != 0 && !eof() && getline(line)) // Read lines till epoch record with valid epoch flag
535 {
536 str::trim(line);
537
538 if (line.empty())
539 {
540 continue;
541 }
542 if (line.at(0) == '>') // EPOCH record - Record identifier: > - Format: A1,
543 {
544 auto year = std::stoi(line.substr(2, 4)); // Format: 1X,I4,
545 auto month = std::stoi(line.substr(7, 2)); // Format: 1X,I2.2,
546 auto day = std::stoi(line.substr(10, 2)); // Format: 1X,I2.2,
547 auto hour = std::stoi(line.substr(13, 2)); // Format: 1X,I2.2,
548 auto min = std::stoi(line.substr(16, 2)); // Format: 1X,I2.2,
549 auto sec = std::stold(line.substr(18, 11)); // Format: F11.7,2X,I1,
550 nSatellites = std::stoul(line.substr(29 + 3, 3)); // Format: I3,6X,F15.12
551
552 [[maybe_unused]] double recClkOffset = 0.0;
553 try
554 {
555 recClkOffset = line.size() >= 41 + 3 ? std::stod(line.substr(41, 15)) : 0.0; // Format: F15.12
556 }
557 catch (const std::exception& /* exception */)
558 {
559 LOG_DATA("{}: 'recClkOffset' not mentioned in file --> recClkOffset = {}", nameId(), recClkOffset);
560 }
562 {
563 sec -= recClkOffset;
564 }
565
566 epochTime = InsTime{ static_cast<uint16_t>(year), static_cast<uint16_t>(month), static_cast<uint16_t>(day),
567 static_cast<uint16_t>(hour), static_cast<uint16_t>(min), sec,
568 _timeSystem };
569
570 epochFlag = std::stoi(line.substr(31, 1)); // Format: 2X,I1,
571
572 LOG_DATA("{}: {}, epochFlag {}, numSats {}, recClkOffset {}", nameId(),
573 epochTime.toYMDHMS(), epochFlag, nSatellites, recClkOffset);
574 }
575 }
576 if (epochTime.empty())
577 {
578 return nullptr;
579 }
580
581 auto gnssObs = std::make_shared<GnssObs>();
582 gnssObs->insTime = epochTime;
583
584 // TODO: while loop till eof() or epochFlag == 0 (in case some other flags in the file)
585
586 size_t satCnt = 0;
587 while (!eof() && peek() != '>' && getline(line)) // Read observation records till line with '>'
588 {
589 if (line.empty())
590 {
591 continue;
592 }
593 auto satSys = SatelliteSystem::fromChar(line.at(0)); // Format: A1,
594 auto satNum = static_cast<uint8_t>(std::stoi(line.substr(1, 2))); // Format: I2.2,
595
596 LOG_DATA("{}: [{}] {}{}:", nameId(), gnssObs->insTime.toYMDHMS(GPST), char(satSys), satNum);
597
598 size_t curExtractLoc = 3;
599 for (const auto& obsDesc : _obsDescription.at(satSys))
600 {
601 if (line.size() < curExtractLoc + 14) // Remaining elements are all blank
602 {
603 break;
604 }
605
606 auto strObs = str::trim_copy(line.substr(curExtractLoc, 14)); // Format: F14.3
607 curExtractLoc += 14;
608 if (strObs.empty())
609 {
610 curExtractLoc += 2;
611 continue;
612 }
613 // Observation value depending on definition type
614 double observation{};
615 try
616 {
617 observation = std::stod(strObs);
618 }
619 catch (const std::exception& e)
620 {
621 if ((*gnssObs)({ obsDesc.code, satNum }).pseudorange)
622 {
623 if (obsDesc.type == NAV::vendor::RINEX::ObsType::L) // Phase
624 {
625 LOG_WARN("{}: observation of satSys = {} contains no carrier phase. This happens if the CN0 is so small that the PLL could not lock, even if the DLL has locked (= pseudorange available). The observation is still valid.", nameId(), char(satSys));
626 }
627 else if (obsDesc.type == NAV::vendor::RINEX::ObsType::D) // Doppler
628 {
629 LOG_WARN("{}: observation of satSys = {} contains no doppler.", nameId(), char(satSys));
630 }
631 }
632 continue;
633 }
634
635 // TODO: Springer Handbook of Global Navigation, p. 1211 prefer attributes over others and let user decide also which ones to take into the calculation
636
637 // Loss of lock indicator
638 // Bit 0 set: Lost lock between previous and current observation: Cycle slip possible.
639 // For phase observations only. Note: Bit 0 is the least significant bit.
640 // Bit 1 set: Half-cycle ambiguity/slip possible. Software not capable of handling half
641 // cycles should skip this observation. Valid for the current epoch only.
642 // Bit 2 set: Galileo BOC-tracking of an MBOC-modulated signal (may suffer from increased noise).
643 uint8_t LLI = 0;
644 if (line.size() > curExtractLoc)
645 {
646 char LLIc = line.at(curExtractLoc);
647 if (LLIc == ' ')
648 {
649 LLIc = '0';
650 }
651 LLI = static_cast<uint8_t>(LLIc - '0');
652 }
653 curExtractLoc++; // Go over Loss of lock indicator (LLI)
654
655 // Signal Strength Indicator (SSI)
656 //
657 // Carrier to Noise ratio(RINEX) | Carrier to Noise ratio(dbHz)
658 // 1 (minimum possible signal strength) | < 12
659 // 2 | 12-17
660 // 3 | 18-23
661 // 4 | 24-29
662 // 5 (average/good S/N ratio) | 30-35
663 // 6 | 36-41
664 // 7 | 42-47
665 // 8 | 48-53
666 // 9 (maximum possible signal strength) | ≥ 54
667 // 0 or blank: not known, don't care | -
668 uint8_t SSI = 0;
669 if (line.size() > curExtractLoc)
670 {
671 char SSIc = line.at(curExtractLoc);
672 if (SSIc == ' ')
673 {
674 SSIc = '0';
675 }
676 SSI = static_cast<uint8_t>(SSIc - '0');
677 }
678 curExtractLoc++; // Go over Signal Strength Indicator (SSI)
679
680 switch (obsDesc.type)
681 {
682 case NAV::vendor::RINEX::ObsType::C: // Code / Pseudorange
683 (*gnssObs)({ obsDesc.code, satNum }).pseudorange = { .value = observation,
684 .SSI = SSI };
685 break;
686 case NAV::vendor::RINEX::ObsType::L: // Phase
687 (*gnssObs)({ obsDesc.code, satNum }).carrierPhase = { .value = observation,
688 .SSI = SSI,
689 .LLI = LLI };
690 break;
691 case NAV::vendor::RINEX::ObsType::D: // Doppler
692 (*gnssObs)({ obsDesc.code, satNum }).doppler = observation;
693 break;
694 case NAV::vendor::RINEX::ObsType::S: // Raw signal strength(carrier to noise ratio)
695 (*gnssObs)({ obsDesc.code, satNum }).CN0 = observation;
696 break;
700 LOG_WARN("{}: ObsType {} not supported", nameId(), size_t(obsDesc.type));
701 break;
702 }
703
704 gnssObs->satData(SatId{ satSys, satNum }).frequencies |= obsDesc.code.getFrequency();
705
706 LOG_DATA("{}: {}-{}-{}: {}, LLI {}, SSI {}", nameId(),
707 NAV::vendor::RINEX::obsTypeToChar(obsDesc.type), obsDesc.code, satNum,
708 observation, LLI, SSI);
709
710 if (_eraseLessPreciseCodes) { eraseLessPreciseCodes(gnssObs, obsDesc.code.getFrequency(), satNum); }
711 }
712
713 if (gnssObs->data.back().pseudorange)
714 {
715 if (!gnssObs->data.back().carrierPhase)
716 {
717 LOG_DATA("{}: A data record at epoch {} (plus leap seconds) contains Pseudorange, but is missing carrier phase.", nameId(), epochTime.toYMDHMS());
718 }
719 if (!gnssObs->data.back().doppler)
720 {
721 LOG_DATA("{}: A data record at epoch {} (plus leap seconds) contains Pseudorange, but is missing doppler.", nameId(), epochTime.toYMDHMS());
722 }
723 if (!gnssObs->data.back().CN0)
724 {
725 LOG_DATA("{}: A data record at epoch {} (plus leap seconds) contains Pseudorange, but is missing raw signal strength(carrier to noise ratio).", nameId(), epochTime.toYMDHMS());
726 }
727 }
728 satCnt++;
729 }
730 if (satCnt != nSatellites)
731 {
732 LOG_WARN("{}: [{}] {} satellites read, but epoch header specified {} satellites", nameId(), gnssObs->insTime.toYMDHMS(GPST), satCnt, nSatellites);
733 }
734
735 gnssObs->receiverInfo = _receiverInfo;
736
738 return gnssObs;
739}
740
741void RinexObsFile::eraseLessPreciseCodes(const std::shared_ptr<NAV::GnssObs>& gnssObs, const Frequency& freq, uint16_t satNum) // NOLINT(readability-convert-member-functions-to-static)
742{
743 auto eraseLessPrecise = [&](const Code& third, const Code& second, const Code& prime) {
744 auto eraseSatDataWithCode = [&](const Code& code) {
745 LOG_DATA("{}: Searching for {}-{}", nameId(), code, satNum);
746 auto iter = std::ranges::find_if(gnssObs->data, [code, satNum](const GnssObs::ObservationData& idData) {
747 return idData.satSigId == SatSigId{ code, satNum };
748 });
749 if (iter != gnssObs->data.end())
750 {
751 LOG_DATA("{}: Erasing {}-{}", nameId(), code, satNum);
752 gnssObs->data.erase(iter);
753 }
754 };
755
756 if (gnssObs->contains({ prime, satNum }))
757 {
758 eraseSatDataWithCode(second);
759 eraseSatDataWithCode(third);
760 }
761 else if (gnssObs->contains({ second, satNum }))
762 {
763 eraseSatDataWithCode(third);
764 }
765 };
766
767 switch (SatelliteSystem_(freq.getSatSys()))
768 {
769 case GPS:
770 eraseLessPrecise(Code::G1S, Code::G1L, Code::G1X); ///< L1C (data, pilot, combined)
771 eraseLessPrecise(Code::G2S, Code::G2L, Code::G2X); ///< L2C-code (medium, long, combined)
772 eraseLessPrecise(Code::G5I, Code::G5Q, Code::G5X); ///< L5 (data, pilot, combined)
773 break;
774 case GAL:
775 eraseLessPrecise(Code::E1B, Code::E1C, Code::E1X); ///< OS (data, pilot, combined)
776 eraseLessPrecise(Code::E5I, Code::E5Q, Code::E5X); ///< E5a (data, pilot, combined)
777 eraseLessPrecise(Code::E6B, Code::E6C, Code::E6X); ///< E6 (data, pilot, combined)
778 eraseLessPrecise(Code::E7I, Code::E7Q, Code::E7X); ///< E5b (data, pilot, combined)
779 eraseLessPrecise(Code::E8I, Code::E8Q, Code::E8X); ///< E5 AltBOC (data, pilot, combined)
780 break;
781 case GLO:
782 eraseLessPrecise(Code::R3I, Code::R3Q, Code::R3X); ///< L3 (data, pilot, combined)
783 eraseLessPrecise(Code::R4A, Code::R4B, Code::R4X); ///< G1a (data, pilot, combined)
784 eraseLessPrecise(Code::R6A, Code::R6B, Code::R6X); ///< G2a (data, pilot, combined)
785 break;
786 case BDS:
787 eraseLessPrecise(Code::B1D, Code::B1P, Code::B1X); ///< B1 (data, pilot, combined)
788 eraseLessPrecise(Code::B2I, Code::B2Q, Code::B2X); ///< B1I(OS), B1Q, combined
789 eraseLessPrecise(Code::B5D, Code::B5P, Code::B5X); ///< B2a (data, pilot, combined)
790 eraseLessPrecise(Code::B6I, Code::B6Q, Code::B6X); ///< B3I, B3Q, combined
791 eraseLessPrecise(Code::B7I, Code::B7Q, Code::B7X); ///< B2I(OS), B2Q, combined
792 eraseLessPrecise(Code::B7D, Code::B7P, Code::B7Z); ///< B2b (data, pilot, combined)
793 eraseLessPrecise(Code::B8D, Code::B8P, Code::B8X); ///< B2 (B2a+B2b) (data, pilot, combined)
794 break;
795 case QZSS:
796 eraseLessPrecise(Code::J1S, Code::J1L, Code::J1X); ///< L1C (data, pilot, combined)
797 eraseLessPrecise(Code::J2S, Code::J2L, Code::J2X); ///< L2C-code (medium, long, combined)
798 eraseLessPrecise(Code::J5I, Code::J5Q, Code::J5X); ///< L5 (data, pilot, combined)
799 eraseLessPrecise(Code::J5D, Code::J5P, Code::J5Z); ///< L5 (data, pilot, combined)
800 eraseLessPrecise(Code::J6S, Code::J6L, Code::J6X); ///< LEX signal (short, long, combined)
801 break;
802 case IRNSS:
803 eraseLessPrecise(Code::I5B, Code::I5C, Code::I5X); ///< RS (data, pilot, combined)
804 eraseLessPrecise(Code::I9B, Code::I9C, Code::I9X); ///< RS (data, pilot, combined)
805 break;
806 case SBAS:
807 eraseLessPrecise(Code::S5I, Code::S5Q, Code::S5X); ///< L5 (data, pilot, combined)
808 break;
809 case SatSys_None:
810 break;
811 }
812}
813
814} // namespace NAV
Code definitions.
Vector space operations.
Save/Load the Nodes.
nlohmann::json json
json namespace
GNSS Observation messages.
Text Help Marker (?) with Tooltip.
Utility class for logging to console and file.
#define LOG_CRITICAL(...)
Critical Event, which causes the program to work entirely and throws an exception.
Definition Logger.hpp:75
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
Definition Logger.hpp:67
#define LOG_DATA
All output which occurs repeatedly every time observations are received.
Definition Logger.hpp:29
#define LOG_ERROR
Error occurred, which stops part of the program to work, but not everything.
Definition Logger.hpp:73
#define LOG_WARN
Error occurred, but a fallback option exists and program continues to work normally.
Definition Logger.hpp:71
#define LOG_INFO
Info to the user on the state of the program.
Definition Logger.hpp:69
#define LOG_TRACE
Detailled info to trace the execution of the program. Should not be called on functions which receive...
Definition Logger.hpp:65
Functions to work with RINEX.
File reader for RINEX Observation messages.
GNSS Satellite System.
Utility functions for working with std::strings.
Enumerate for GNSS Codes.
Definition Code.hpp:89
@ E6B
GAL E6 - Data.
Definition Code.hpp:128
@ R3X
GLO L3 - Combined.
Definition Code.hpp:145
@ B7I
BeiDou B2b (BDS-2) - B2I(OS)
Definition Code.hpp:166
@ R6A
GLO G2a - L2CSI (data)
Definition Code.hpp:149
@ J2L
QZSS L2 - L2C-code (long)
Definition Code.hpp:182
@ G1L
GPS L1 - L1C-P (pilot)
Definition Code.hpp:98
@ B6Q
BeiDou B3 - B3Q.
Definition Code.hpp:163
@ I5X
IRNSS L5 - RS (combined)
Definition Code.hpp:199
@ J6L
QZSS L6 - L6P LEX signal (long)
Definition Code.hpp:191
@ E7I
GAL E5b - Data.
Definition Code.hpp:132
@ E5Q
GAL E5a - Pilot.
Definition Code.hpp:125
@ B5P
BeiDou B2a - Pilot(P)
Definition Code.hpp:160
@ B7D
BeiDou B2b (BDS-3) - Data (D)
Definition Code.hpp:169
@ B5X
BeiDou B2a - D+P.
Definition Code.hpp:161
@ S5Q
SBAS L5 - Pilot.
Definition Code.hpp:207
@ G1X
GPS L1 - L1C-(D+P) (combined)
Definition Code.hpp:99
@ E1B
GAL E1 - OS (data)
Definition Code.hpp:120
@ J5I
QZSS L5 - Data.
Definition Code.hpp:184
@ J5P
QZSS L5S - Q.
Definition Code.hpp:188
@ G2X
GPS L2 - L2C(M+L) (combined)
Definition Code.hpp:109
@ J6X
QZSS L6 - L6(D+P) LEX signal (combined)
Definition Code.hpp:192
@ J5D
QZSS L5S - I.
Definition Code.hpp:187
@ E6X
GAL E6 - Combined (B+C)
Definition Code.hpp:130
@ J1L
QZSS L1 - L1C (pilot)
Definition Code.hpp:178
@ J1S
QZSS L1 - L1C (data)
Definition Code.hpp:177
@ I5C
IRNSS L5 - RS (pilot)
Definition Code.hpp:198
@ J5Z
QZSS L5S - I+Q.
Definition Code.hpp:189
@ I5B
IRNSS L5 - RS (data)
Definition Code.hpp:197
@ J1X
QZSS L1 - L1C (combined)
Definition Code.hpp:179
@ E8X
GAL E5(a+b) - AltBOC (combined)
Definition Code.hpp:137
@ G5X
GPS L5 - Combined.
Definition Code.hpp:117
@ E5I
GAL E5a - Data.
Definition Code.hpp:124
@ R3Q
GLO L3 - Pilot.
Definition Code.hpp:144
@ J5Q
QZSS L5 - Pilot.
Definition Code.hpp:185
@ R3I
GLO L3 - Data.
Definition Code.hpp:143
@ B1P
BeiDou B1 - Pilot(P)
Definition Code.hpp:154
@ J2X
QZSS L2 - L2C-code (combined)
Definition Code.hpp:183
@ B1D
BeiDou B1 - Data (D)
Definition Code.hpp:153
@ G2L
GPS L2 - L2C(L) (long)
Definition Code.hpp:108
@ R6B
GLO G2a - L2OCp (pilot)
Definition Code.hpp:150
@ I9X
IRNSS S - RS (combined)
Definition Code.hpp:203
@ E7X
GAL E5b - Combined.
Definition Code.hpp:134
@ B8X
BeiDou B2 (B2a+B2b) - D+P.
Definition Code.hpp:174
@ B2Q
BeiDou B1-2 - B1Q.
Definition Code.hpp:157
@ R4X
GLO G1a - L1OCd+L1OCp (combined)
Definition Code.hpp:148
@ J5X
QZSS L5 - Combined.
Definition Code.hpp:186
@ B8D
BeiDou B2 (B2a+B2b) - Data (D)
Definition Code.hpp:172
@ E8I
GAL E5(a+b) - AltBOC (data)
Definition Code.hpp:135
@ G5Q
GPS L5 - Pilot.
Definition Code.hpp:116
@ B7P
BeiDou B2b (BDS-3) - Pilot(P)
Definition Code.hpp:170
@ S5X
SBAS L5 - Combined.
Definition Code.hpp:208
@ E8Q
GAL E5(a+b) - AltBOC (pilot)
Definition Code.hpp:136
@ B5D
BeiDou B2a - Data (D)
Definition Code.hpp:159
@ J6S
QZSS L6 - L6D LEX signal (short)
Definition Code.hpp:190
@ R4B
GLO G1a - L1OCp (pilot)
Definition Code.hpp:147
@ G5I
GPS L5 - Data.
Definition Code.hpp:115
@ S5I
SBAS L5 - Data.
Definition Code.hpp:206
@ B6X
BeiDou B3 - B3I, B3Q, combined.
Definition Code.hpp:164
@ B7X
BeiDou B2b (BDS-2) - B2I(OS), B2Q, combined.
Definition Code.hpp:168
@ E1X
GAL E1 - OS(B+C) (combined)
Definition Code.hpp:122
@ B2I
BeiDou B1-2 - B1I(OS)
Definition Code.hpp:156
@ E6C
GAL E6 - Pilot.
Definition Code.hpp:129
@ B7Q
BeiDou B2b (BDS-2) - B2Q.
Definition Code.hpp:167
@ R6X
GLO G2a - L2CSI+L2OCp (combined)
Definition Code.hpp:151
@ G1S
GPS L1 - L1C-D (data)
Definition Code.hpp:97
@ I9C
IRNSS S - RS (pilot)
Definition Code.hpp:202
@ B2X
BeiDou B1-2 - B1I(OS), B1Q, combined.
Definition Code.hpp:158
@ B7Z
BeiDou B2b (BDS-3) - D+P.
Definition Code.hpp:171
@ E7Q
GAL E5b - Pilot.
Definition Code.hpp:133
@ B8P
BeiDou B2 (B2a+B2b) - Pilot(P)
Definition Code.hpp:173
@ B6I
BeiDou B3 - B3I.
Definition Code.hpp:162
@ B1X
BeiDou B1 - D+P.
Definition Code.hpp:155
@ E1C
GAL E1 - OS (pilot)
Definition Code.hpp:121
@ G2S
GPS L2 - L2C(M) (medium)
Definition Code.hpp:107
@ I9B
IRNSS S - RS (data)
Definition Code.hpp:201
@ E5X
GAL E5a - Combined.
Definition Code.hpp:126
@ J2S
QZSS L2 - L2C-code (medium)
Definition Code.hpp:181
@ R4A
GLO G1a - L1OCd (data)
Definition Code.hpp:146
static Code fromFreqAttr(Frequency freq, char attribute)
Generates a Code from frequency and attribute.
Definition Code.cpp:299
bool initialize()
Initialize the file reader.
void restore(const json &j)
Restores the node from a json object.
auto peek()
Looking ahead in the stream.
std::string _path
Path to the file.
FileType
File Type Enumeration.
@ ASCII
Ascii text data.
@ NONE
Not specified.
auto eof() const
Check whether the end of file is reached.
std::filesystem::path getFilepath()
Returns the path of the file.
@ PATH_CHANGED
The path changed and exists.
GuiResult guiConfig(const char *vFilters, const std::vector< std::string > &extensions, size_t id, const std::string &nameId)
ImGui config.
void resetReader()
Moves the read cursor to the start.
auto & getline(std::string &str)
Reads a line from the filestream.
json save() const
Saves the node into a json object.
void deinitialize()
Deinitialize the file reader.
Frequency definition for different satellite systems.
Definition Frequency.hpp:59
static std::string type()
Returns the type of the data class.
Definition GnssObs.hpp:151
The class is responsible for all time-related tasks.
Definition InsTime.hpp:710
constexpr InsTime_YMDHMS toYMDHMS(TimeSystem timesys=UTC, int digits=-1) const
Converts this time object into a different format.
Definition InsTime.hpp:871
constexpr bool empty() const
Checks if the Time object has a value.
Definition InsTime.hpp:1089
bool doDeinitialize(bool wait=false)
Asks the node worker to deinitialize the node.
Definition Node.cpp:465
ImVec2 _guiConfigDefaultWindowSize
Definition Node.hpp:522
Node(std::string name)
Constructor.
Definition Node.cpp:29
OutputPin * CreateOutputPin(const char *name, Pin::Type pinType, const std::vector< std::string > &dataIdentifier, OutputPin::PinData data=static_cast< void * >(nullptr), int idx=-1)
Create an Output Pin object.
Definition Node.cpp:278
std::string nameId() const
Node name and id.
Definition Node.cpp:323
std::string name
Name of the Node.
Definition Node.hpp:507
bool doReinitialize(bool wait=false)
Asks the node worker to reinitialize the node.
Definition Node.cpp:420
void invokeCallbacks(size_t portIndex, const std::shared_ptr< const NodeData > &data)
Calls all registered callbacks on the specified output port.
Definition Node.cpp:179
bool _hasConfig
Flag if the config window should be shown.
Definition Node.hpp:525
void eraseLessPreciseCodes(const std::shared_ptr< GnssObs > &gnssObs, const Frequency &freq, uint16_t satNum)
Removes less precise codes (e.g. if G1X (L1C combined) is present, don't use G1L (L1C pilot) and G1S ...
static const std::set< double > _supportedVersions
Supported RINEX versions.
double _version
Version of the RINEX file.
void restore(const json &j) override
Restores the node from a json object.
void deinitialize() override
Deinitialize the node.
std::string type() const override
String representation of the Class Type.
TimeSystem _timeSystem
Time system of all observations in the file.
bool _rcvClockOffsAppl
Receiver clock offset app.
json save() const override
Saves the node into a json object.
void guiConfig() override
ImGui config window which is shown on double click.
RinexObsFile()
Default constructor.
bool initialize() override
Initialize the node.
static std::string category()
String representation of the Class Category.
static constexpr size_t OUTPUT_PORT_INDEX_GNSS_OBS
Flow (GnssObs)
FileType determineFileType() override
Determines the type of the file.
GnssObs::ReceiverInfo _receiverInfo
Receiver Info transmitted with the observation.
~RinexObsFile() override
Destructor.
bool resetNode() override
Resets the node. Moves the read cursor to the start.
bool _eraseLessPreciseCodes
Whether to remove less precise codes (e.g. if G1X (L1C combined) is present, don't use G1L (L1C pilot...
void readHeader() override
Read the Header of the file.
std::shared_ptr< const NodeData > pollData()
Polls the data from the file.
static std::string typeStatic()
String representation of the Class Type.
std::unordered_map< SatelliteSystem, std::vector< NAV::vendor::RINEX::ObservationDescription > > _obsDescription
Observation description. [Key]: Satellite System, [Value]: List with descriptions.
static TimeSystem fromString(const std::string &typeString)
Construct new object from std::string.
void ApplyChanges()
Signals that there have been changes to the flow.
void HelpMarker(const char *desc, const char *symbol="(?)")
Text Help Marker, e.g. '(?)', with Tooltip.
int stoi(const String &str, int default_value, std::size_t *pos=nullptr, int base=10) noexcept
Interprets a value in the string str.
static std::string trim_copy(std::string s)
Trim from both ends (copying)
static void rtrim(std::string &s)
Trim from end (in place)
static void trim(std::string &s)
Trim from both ends (in place)
ObsType
Observation types of the 'SYS / # / OBS TYPES' header.
@ X
Receiver channel numbers.
@ S
Raw signal strength(carrier to noise ratio)
@ I
Ionosphere phase delay.
char obsTypeToChar(ObsType type)
Converts an ObsType to char.
Frequency getFrequencyFromBand(SatelliteSystem satSys, int band)
Get the Frequency from the provided satellite system and band in the 'SYS / # / OBS TYPES' header.
ObsType obsTypeFromChar(char c)
Converts a character to an ObsType.
@ IRNSST
Indian Regional Navigation Satellite System Time.
@ BDT
BeiDou Time.
@ GLNT
GLONASS Time (GLONASST)
@ TimeSys_None
No Time system.
@ QZSST
Quasi-Zenith Satellite System Time.
@ GPST
GPS Time.
@ UTC
Coordinated Universal Time.
@ B02
Beidou B1-2 (B1I) (1561.098 MHz).
Definition Frequency.hpp:42
@ B01
Beidou B1 (1575.42 MHz).
Definition Frequency.hpp:41
SatelliteSystem_
Satellite System enumeration.
@ GPS
Global Positioning System.
@ QZSS
Quasi-Zenith Satellite System.
@ GLO
Globalnaja nawigazionnaja sputnikowaja sistema (GLONASS)
@ GAL
Galileo.
@ SBAS
Satellite Based Augmentation System.
@ BDS
Beidou.
@ SatSys_None
No Satellite system.
@ IRNSS
Indian Regional Navigation Satellite System.
Stores the satellites observations.
Definition GnssObs.hpp:47
@ Flow
NodeData Trigger.
Definition Pin.hpp:52
Identifies a satellite (satellite system and number)
Satellite System type.
static SatelliteSystem fromChar(char typeChar)
Construct new object from char.
Description of the observations from the 'SYS / # / OBS TYPES' header.