INSTINCT Code Coverage Report


Directory: src/
File: Navigation/GNSS/Satellite/Satellite.cpp
Date: 2025-02-07 16:54:41
Exec Total Coverage
Lines: 21 33 63.6%
Functions: 5 11 45.5%
Branches: 11 40 27.5%

Line Branch Exec Source
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 "Satellite.hpp"
10
11 #include <limits>
12
13 namespace NAV
14 {
15
16 Orbit::Pos Satellite::calcSatellitePos(const InsTime& transTime) const
17 {
18 return searchNavigationData(transTime)->calcSatellitePos(transTime);
19 }
20
21 Orbit::PosVel Satellite::calcSatellitePosVel(const InsTime& transTime) const
22 {
23 return searchNavigationData(transTime)->calcSatellitePosVel(transTime);
24 }
25
26 Orbit::PosVelAccel Satellite::calcSatellitePosVelAccel(const InsTime& transTime) const
27 {
28 return searchNavigationData(transTime)->calcSatellitePosVelAccel(transTime);
29 }
30
31 double Satellite::calcSatellitePositionVariance(const InsTime& recvTime) const
32 {
33 return searchNavigationData(recvTime)->calcSatellitePositionVariance();
34 }
35
36 [[nodiscard]] Clock::Corrections Satellite::calcClockCorrections(const InsTime& recvTime, double dist, const Frequency& freq) const
37 {
38 return searchNavigationData(recvTime)->calcClockCorrections(recvTime, dist, freq);
39 }
40
41 bool Satellite::isHealthy(const InsTime& recvTime) const
42 {
43 return searchNavigationData(recvTime)->isHealthy();
44 }
45
46 8291 void Satellite::addSatNavData(const std::shared_ptr<SatNavData>& satNavData)
47 {
48 // First check if item with same time already exists
49
1/2
✓ Branch 1 taken 8291 times.
✗ Branch 2 not taken.
8291 auto iter = std::ranges::find_if(m_navigationData, [&satNavData](const std::shared_ptr<SatNavData>& navData) {
50 37476 return navData->refTime == satNavData->refTime;
51 });
52
2/2
✓ Branch 2 taken 4663 times.
✓ Branch 3 taken 3628 times.
8291 if (iter != m_navigationData.end()) // Item with this time does already exist, so we update this item
53 {
54 4663 *iter = satNavData;
55 }
56 else // Otherwise we insert the item into the list in a time sorted way
57 {
58
1/2
✓ Branch 1 taken 3628 times.
✗ Branch 2 not taken.
3628 iter = std::ranges::find_if(m_navigationData, [&satNavData](const std::shared_ptr<SatNavData>& navData) {
59 22647 return navData->refTime > satNavData->refTime;
60 });
61
62
1/2
✓ Branch 2 taken 3628 times.
✗ Branch 3 not taken.
3628 m_navigationData.insert(iter, satNavData);
63 }
64 8291 }
65
66 21 const std::vector<std::shared_ptr<SatNavData>>& Satellite::getNavigationData() const
67 {
68 21 return m_navigationData;
69 }
70
71 58194 std::shared_ptr<SatNavData> Satellite::searchNavigationData(const InsTime& time) const
72 {
73
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 58194 times.
58194 if (m_navigationData.empty()) { return nullptr; }
74
75 58194 auto prevDiff = std::numeric_limits<long double>::max();
76 // auto diff = prevDiff;
77
78 58194 auto riter = m_navigationData.rbegin();
79
2/2
✓ Branch 3 taken 196297 times.
✓ Branch 4 taken 22930 times.
219227 for (; riter != m_navigationData.rend(); riter++)
80 {
81
1/2
✓ Branch 3 taken 196297 times.
✗ Branch 4 not taken.
196297 auto diff = std::abs(((*riter)->refTime - time).count());
82
2/2
✓ Branch 0 taken 161033 times.
✓ Branch 1 taken 35264 times.
196297 if (diff < prevDiff)
83 {
84 161033 prevDiff = diff;
85 }
86 else
87 {
88 // diff = prevDiff;
89 35264 break;
90 }
91 }
92
93 // This limits the time the navigation data can be used
94 // switch (m_navigationData.front()->type)
95 // {
96 // case NAV::SatNavData::Type::GPSEphemeris:
97 // case NAV::SatNavData::Type::GalileoEphemeris:
98 // case NAV::SatNavData::Type::BeiDouEphemeris:
99 // case NAV::SatNavData::Type::IRNSSEphemeris:
100 // case NAV::SatNavData::Type::QZSSEphemeris:
101 // if (diff > InsTimeUtil::SECONDS_PER_HOUR * 2 + 1e-6)
102 // {
103 // return nullptr;
104 // }
105 // break;
106 // case NAV::SatNavData::Type::GLONASSEphemeris:
107 // case NAV::SatNavData::Type::SBASEphemeris:
108 // if (diff > InsTimeUtil::SECONDS_PER_MINUTE * 15 + 1e-6)
109 // {
110 // return nullptr;
111 // }
112 // break;
113 // }
114
115 58194 return *(--riter);
116 }
117
118 } // namespace NAV
119