...
This commit is contained in:
@@ -10,10 +10,39 @@
|
||||
|
||||
|
||||
#include "mcc_astrom_iers.h"
|
||||
#include "mcc_mount_concepts.h"
|
||||
#include "mcc_mount_coord.h"
|
||||
|
||||
// #include "mcc_mount_astrom.h"
|
||||
#include "mcc_mount_concepts.h"
|
||||
|
||||
namespace mcc::astrom::erfa
|
||||
{
|
||||
enum class MccMountAstromEngineERFAErrorCode : int {
|
||||
ERROR_OK = 0,
|
||||
ERROR_INVALID_INPUT_ARG,
|
||||
ERROR_JULDATE_INVALID_YEAR,
|
||||
ERROR_JULDATE_INVALID_MONTH,
|
||||
ERROR_BULLETINA_OUT_OF_RANGE,
|
||||
ERROR_LEAPSECONDS_OUT_OF_RANGE,
|
||||
ERROR_DUBIOUS_YEAR,
|
||||
ERROR_UNACCEPTABLE_DATE,
|
||||
ERROR_UPDATE_LEAPSECONDS,
|
||||
ERROR_UPDATE_BULLETINA,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace std
|
||||
{
|
||||
|
||||
template <>
|
||||
class is_error_code_enum<mcc::astrom::erfa::MccMountAstromEngineERFAErrorCode> : public true_type
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
|
||||
|
||||
namespace mcc::astrom::erfa
|
||||
{
|
||||
@@ -22,6 +51,62 @@ namespace mcc::astrom::erfa
|
||||
#include <erfam.h>
|
||||
|
||||
|
||||
/* error category definition */
|
||||
|
||||
// error category
|
||||
struct MccMountAstromEngineERFACategory : public std::error_category {
|
||||
MccMountAstromEngineERFACategory() : std::error_category() {}
|
||||
|
||||
const char* name() const noexcept
|
||||
{
|
||||
return "ADC_GENERIC_DEVICE";
|
||||
}
|
||||
|
||||
std::string message(int ec) const
|
||||
{
|
||||
MccMountAstromEngineERFAErrorCode err = static_cast<MccMountAstromEngineERFAErrorCode>(ec);
|
||||
|
||||
switch (err) {
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_OK:
|
||||
return "OK";
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_INVALID_INPUT_ARG:
|
||||
return "invalid argument";
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_JULDATE_INVALID_YEAR:
|
||||
return "invalid year number";
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_JULDATE_INVALID_MONTH:
|
||||
return "invalid month number";
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_BULLETINA_OUT_OF_RANGE:
|
||||
return "time point is out of range";
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_LEAPSECONDS_OUT_OF_RANGE:
|
||||
return "time point is out of range";
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_DUBIOUS_YEAR:
|
||||
return "dubious year";
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_UNACCEPTABLE_DATE:
|
||||
return "unacceptable date";
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_UPDATE_LEAPSECONDS:
|
||||
return "leap seconds update error";
|
||||
case MccMountAstromEngineERFAErrorCode::ERROR_UPDATE_BULLETINA:
|
||||
return "bulletin A update error";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
static const MccMountAstromEngineERFACategory& get()
|
||||
{
|
||||
static const MccMountAstromEngineERFACategory constInst;
|
||||
return constInst;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
inline std::error_code make_error_code(MccMountAstromEngineERFAErrorCode ec)
|
||||
{
|
||||
return std::error_code(static_cast<int>(ec), MccMountAstromEngineERFACategory::get());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* A concept for ERFA-library compatible type to represent anglular quantities */
|
||||
template <typename T>
|
||||
concept mcc_erfa_angle_t = std::constructible_from<T, double> && std::convertible_to<T, double>;
|
||||
@@ -29,32 +114,10 @@ concept mcc_erfa_angle_t = std::constructible_from<T, double> && std::convertibl
|
||||
template <mcc_erfa_angle_t AngleT = MccAngle>
|
||||
class MccMountAstromEngineERFA
|
||||
{
|
||||
protected:
|
||||
static constexpr std::array engineErrorString = {"OK",
|
||||
"invalid argument",
|
||||
"invalid year",
|
||||
"invalid month",
|
||||
"time point is out of range",
|
||||
"time point is out of range",
|
||||
"dubious year",
|
||||
"unacceptable year",
|
||||
"leap seconds update error",
|
||||
"bulletin A update error"};
|
||||
|
||||
public:
|
||||
static constexpr double DEFAULT_WAVELENGTH = 0.55; // default observed wavelength in mkm
|
||||
enum error_t : size_t {
|
||||
ERROR_OK = 0,
|
||||
ERROR_INVALID_INPUT_ARG,
|
||||
ERROR_JULDATE_INVALID_YEAR,
|
||||
ERROR_JULDATE_INVALID_MONTH,
|
||||
ERROR_BULLETINA_OUT_OF_RANGE,
|
||||
ERROR_LEAPSECONDS_OUT_OF_RANGE,
|
||||
ERROR_DUBIOUS_YEAR,
|
||||
ERROR_UNACCEPTABLE_DATE,
|
||||
ERROR_UPDATE_LEAPSECONDS,
|
||||
ERROR_UPDATE_BULLETINA,
|
||||
};
|
||||
|
||||
typedef std::error_code error_t;
|
||||
|
||||
|
||||
// meteo parameters (to compute refraction)
|
||||
@@ -140,10 +203,10 @@ public:
|
||||
std::lock_guard lock{_stateMutex};
|
||||
|
||||
if (!_currentState._leapSeconds.load(stream, comment_sym)) {
|
||||
return ERROR_UPDATE_LEAPSECONDS;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_UPDATE_LEAPSECONDS;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,10 +215,10 @@ public:
|
||||
std::lock_guard lock{_stateMutex};
|
||||
|
||||
if (!_currentState._leapSeconds.load(filename, comment_sym)) {
|
||||
return ERROR_UPDATE_LEAPSECONDS;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_UPDATE_LEAPSECONDS;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -164,10 +227,10 @@ public:
|
||||
std::lock_guard lock{_stateMutex};
|
||||
|
||||
if (!_currentState._bulletinA.load(stream, comment_sym)) {
|
||||
return ERROR_UPDATE_BULLETINA;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_UPDATE_BULLETINA;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -176,19 +239,13 @@ public:
|
||||
std::lock_guard lock{_stateMutex};
|
||||
|
||||
if (!_currentState._bulletinA.load(filename, comment_sym)) {
|
||||
return ERROR_UPDATE_BULLETINA;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_UPDATE_BULLETINA;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string errorString(error_t err) const
|
||||
{
|
||||
return engineErrorString[err];
|
||||
}
|
||||
|
||||
/* time-related methods */
|
||||
|
||||
// templated generic version
|
||||
@@ -203,10 +260,10 @@ public:
|
||||
static constexpr std::chrono::year MIN_YEAR = -4799y;
|
||||
|
||||
if (ymd.year() < MIN_YEAR) {
|
||||
return ERROR_JULDATE_INVALID_YEAR;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_JULDATE_INVALID_YEAR;
|
||||
}
|
||||
if (!ymd.month().ok()) {
|
||||
return ERROR_JULDATE_INVALID_MONTH;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_JULDATE_INVALID_MONTH;
|
||||
}
|
||||
|
||||
int64_t im = (unsigned)ymd.month();
|
||||
@@ -223,7 +280,7 @@ public:
|
||||
using fd_t = std::chrono::duration<double, std::ratio<86400>>; // fraction of day
|
||||
juldate.mjd = static_cast<double>(mjd_int) + std::chrono::duration_cast<fd_t>(time_point - dd).count();
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
error_t greg2jul(time_point_t time_point, juldate_t& juldate)
|
||||
@@ -242,14 +299,14 @@ public:
|
||||
if (tai_utc.has_value()) {
|
||||
tt.mjd += std::chrono::duration_cast<real_days_t>(tai_utc.value()).count();
|
||||
} else {
|
||||
return ERROR_LEAPSECONDS_OUT_OF_RANGE;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_LEAPSECONDS_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
|
||||
auto tt_tai = _currentState._bulletinA.TT_TAI();
|
||||
tt.mjd = juldate.mjd + std::chrono::duration_cast<real_days_t>(tt_tai).count();
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -270,7 +327,7 @@ public:
|
||||
if (dut1.has_value()) {
|
||||
ut1 += std::chrono::duration_cast<real_days_t>(dut1.value()).count();
|
||||
} else { // out of range
|
||||
return ERROR_BULLETINA_OUT_OF_RANGE;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_BULLETINA_OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,7 +345,7 @@ public:
|
||||
|
||||
juldate_t tt;
|
||||
auto err = terrestrialTime(juldate, tt);
|
||||
if (err != ERROR_OK) {
|
||||
if (err != MccMountAstromEngineERFAErrorCode::ERROR_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -297,7 +354,7 @@ public:
|
||||
gst += _currentState.lon;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -306,13 +363,13 @@ public:
|
||||
juldate_t tt;
|
||||
|
||||
auto err = terrestrialTime(juldate, tt);
|
||||
if (err != ERROR_OK) {
|
||||
if (err != MccMountAstromEngineERFAErrorCode::ERROR_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
eo = eraEo06a(tt.MJD0, tt.mjd);
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
/* atmospheric refraction-related methods */
|
||||
@@ -324,7 +381,7 @@ public:
|
||||
eraRefco(_currentState.meteo.pressure, _currentState.meteo.temperature, _currentState.meteo.humidity,
|
||||
_currentState.wavelength, &refr.refa, &refr.refb);
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -337,7 +394,7 @@ public:
|
||||
corr = ref_params.refa / tanALT + ref_params.refb / tanALT / tanALT / tanALT;
|
||||
}
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
/* coordinates conversional methods */
|
||||
@@ -357,12 +414,12 @@ public:
|
||||
auto dut1 = _currentState._bulletinA.DUT1(juldate.mjd);
|
||||
|
||||
if (!dut1.has_value()) {
|
||||
return ERROR_BULLETINA_OUT_OF_RANGE;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_BULLETINA_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
auto pol_pos = _currentState._bulletinA.polarCoords(juldate.mjd);
|
||||
if (!pol_pos.has_value()) {
|
||||
return ERROR_BULLETINA_OUT_OF_RANGE;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_BULLETINA_OUT_OF_RANGE;
|
||||
}
|
||||
const auto arcsec2rad = std::numbers::pi / 180 / 3600;
|
||||
pol_pos->x *= arcsec2rad;
|
||||
@@ -376,9 +433,9 @@ public:
|
||||
&oaz, &ozd, &oha, &odec, &ora, &eo_);
|
||||
|
||||
if (ret == 1) {
|
||||
return ERROR_DUBIOUS_YEAR;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_DUBIOUS_YEAR;
|
||||
} else if (ret == -1) {
|
||||
return ERROR_UNACCEPTABLE_DATE;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_UNACCEPTABLE_DATE;
|
||||
}
|
||||
|
||||
ra_app = ora;
|
||||
@@ -388,7 +445,7 @@ public:
|
||||
ha = oha;
|
||||
eo = eo_;
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -402,7 +459,7 @@ public:
|
||||
az = r_az;
|
||||
alt = r_alt;
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
error_t azalt2hadec(coord_t az, coord_t alt, coord_t& ha, coord_t& dec)
|
||||
@@ -416,7 +473,7 @@ public:
|
||||
ha = r_ha;
|
||||
dec = r_dec;
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -426,7 +483,7 @@ public:
|
||||
|
||||
pa = eraHd2pa(ha, dec, _currentState.lat);
|
||||
|
||||
return ERROR_OK;
|
||||
return MccMountAstromEngineERFAErrorCode::ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user