-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PATC parsing and usage implementation. * Refactored and removed remnants of development. Updated SOFTWARE_VERSION field. * Unit tests for ISP adjustment and PATC register. Overflow condition.
- Loading branch information
1 parent
99d3443
commit 8f8026c
Showing
20 changed files
with
429 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
#include "envisat_types.h" | ||
#include "patc.h" | ||
|
||
namespace alus::asar::envformat::ers { | ||
|
||
void RegisterPatc(const aux::Patc& patc); | ||
void AdjustIspSensingTime(mjd& isp_sensing_time, uint32_t sbt, uint32_t sbt_repeat, bool overflow = false); | ||
|
||
} // namespace alus::asar::envformat::ers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <filesystem> | ||
|
||
namespace alus::asar::envformat::aux { | ||
|
||
// Should not be under this module. An exception, as a surprise, there is a file format | ||
// which is NOT packaged into envisat format, nice. | ||
struct Patc { | ||
uint16_t cyclic_counter; | ||
char mission[2]; | ||
uint32_t orbit_number; | ||
int32_t epoch_1950; // Days | ||
int32_t milliseconds; | ||
uint32_t sbt_counter; | ||
uint32_t sbt_period; // Tick time value in nanoseconds | ||
}; | ||
|
||
Patc ParsePatc(const std::filesystem::path& file_loc); | ||
|
||
} // namespace alus::asar::envformat::aux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "ers_sbt.h" | ||
|
||
#include <cstdint> | ||
#include <stdexcept> | ||
|
||
#include <boost/date_time/posix_time/posix_time.hpp> | ||
|
||
#include "date_time_util.h" | ||
#include "envisat_types.h" | ||
#include "envisat_utils.h" | ||
#include "parse_util.h" | ||
#include "patc.h" | ||
|
||
namespace { | ||
|
||
bool patc_cor_set{false}; | ||
alus::asar::envformat::aux::Patc patc_cor{}; | ||
boost::posix_time::ptime patc_time_point; | ||
|
||
constexpr auto SBT_MAX{alus::asar::envformat::parseutil::MaxValueForBits<uint32_t, 32>()}; | ||
|
||
} // namespace | ||
|
||
namespace alus::asar::envformat::ers { | ||
|
||
void RegisterPatc(const aux::Patc& patc) { | ||
if (patc.epoch_1950 < 0) { | ||
throw std::runtime_error("Supplied PATC has negative epoch for days since 1950."); | ||
} | ||
|
||
if (patc.milliseconds < 0) { | ||
throw std::runtime_error("Supplied PATC has negative epoch for milliseconds."); | ||
} | ||
|
||
const auto epoch = alus::util::date_time::YYYYMMDD("19500101"); | ||
|
||
// Days between 19500101 and 19910101 | ||
if (patc.epoch_1950 < 14975) { | ||
const auto err_date = epoch + boost::posix_time::time_duration(patc.epoch_1950 * 24, 0, 0, 0); | ||
throw std::runtime_error( | ||
"Supplied PATC epoch days has value that is earlier than year 1990. Resulting date - " + | ||
to_simple_string(err_date)); | ||
} | ||
|
||
patc_cor = patc; | ||
patc_time_point = epoch + boost::posix_time::time_duration(patc.epoch_1950 * 24, 0, 0, 0); | ||
patc_time_point += boost::posix_time::milliseconds(patc.milliseconds); | ||
patc_cor_set = true; | ||
} | ||
|
||
void AdjustIspSensingTime(mjd& isp_sensing_time, uint32_t sbt, uint32_t, bool overflow) { | ||
if (!patc_cor_set) { | ||
return; | ||
} | ||
|
||
boost::posix_time::ptime adjusted_ptime; | ||
int64_t delta_count{}; | ||
if (sbt < patc_cor.sbt_counter && !overflow) { | ||
delta_count = static_cast<int64_t>(sbt) - patc_cor.sbt_counter; | ||
} | ||
else { | ||
delta_count = parseutil::CounterGap<uint32_t, SBT_MAX>(patc_cor.sbt_counter, sbt); | ||
} | ||
const int64_t nanoseconds_diff = static_cast<int64_t>(patc_cor.sbt_period) * delta_count; | ||
const auto microseconds_val = static_cast<int64_t>(nanoseconds_diff / 1000); | ||
adjusted_ptime = patc_time_point + boost::posix_time::microseconds(microseconds_val); | ||
|
||
isp_sensing_time = PtimeToMjd(adjusted_ptime); | ||
} | ||
|
||
} // namespace alus::asar::envformat::ers |
Oops, something went wrong.