| 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 | 8315 | 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 8313 times.
✗ Branch 2 not taken.
|
8315 | auto iter = std::ranges::find_if(m_navigationData, [&satNavData](const std::shared_ptr<SatNavData>& navData) { |
| 50 | 37473 | return navData->refTime == satNavData->refTime; | |
| 51 | }); | ||
| 52 |
2/2✓ Branch 2 taken 4663 times.
✓ Branch 3 taken 3653 times.
|
8313 | 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 3653 times.
✗ Branch 2 not taken.
|
3653 | iter = std::ranges::find_if(m_navigationData, [&satNavData](const std::shared_ptr<SatNavData>& navData) { |
| 59 | 22648 | return navData->refTime > satNavData->refTime; | |
| 60 | }); | ||
| 61 | |||
| 62 |
1/2✓ Branch 2 taken 3653 times.
✗ Branch 3 not taken.
|
3653 | m_navigationData.insert(iter, satNavData); |
| 63 | } | ||
| 64 | 8316 | } | |
| 65 | |||
| 66 | 21 | const std::vector<std::shared_ptr<SatNavData>>& Satellite::getNavigationData() const | |
| 67 | { | ||
| 68 | 21 | return m_navigationData; | |
| 69 | } | ||
| 70 | |||
| 71 | 303025 | std::shared_ptr<SatNavData> Satellite::searchNavigationData(const InsTime& time) const | |
| 72 | { | ||
| 73 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 303026 times.
|
303025 | if (m_navigationData.empty()) { return nullptr; } |
| 74 | |||
| 75 | 303026 | auto prevDiff = std::numeric_limits<long double>::max(); | |
| 76 | // auto diff = prevDiff; | ||
| 77 | |||
| 78 | 303026 | auto riter = m_navigationData.rbegin(); | |
| 79 |
2/2✓ Branch 3 taken 441834 times.
✓ Branch 4 taken 267054 times.
|
708894 | for (; riter != m_navigationData.rend(); riter++) |
| 80 | { | ||
| 81 |
1/2✓ Branch 3 taken 441834 times.
✗ Branch 4 not taken.
|
441834 | auto diff = std::abs(((*riter)->refTime - time).count()); |
| 82 |
2/2✓ Branch 0 taken 405870 times.
✓ Branch 1 taken 35970 times.
|
441840 | if (diff < prevDiff) |
| 83 | { | ||
| 84 | 405870 | prevDiff = diff; | |
| 85 | } | ||
| 86 | else | ||
| 87 | { | ||
| 88 | // diff = prevDiff; | ||
| 89 | 35970 | 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 | 303024 | return *(--riter); | |
| 116 | } | ||
| 117 | |||
| 118 | } // namespace NAV | ||
| 119 |