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