...
This commit is contained in:
parent
89d67fd95c
commit
d5dd260007
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.14)
|
|||||||
|
|
||||||
# set(CMAKE_BUILD_TYPE Release)
|
# set(CMAKE_BUILD_TYPE Release)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
@ -122,7 +122,8 @@ add_library(${CNTR_PROTO_LIB} STATIC ${CNTR_PROTO_LIB_SRC})
|
|||||||
set(MOUNT_SERVER_APP_SRC mount.h mount_state.h mount_server.cpp comm_server.h comm_server_endpoint.h comm_server_configfile.h mount_astrom.h
|
set(MOUNT_SERVER_APP_SRC mount.h mount_state.h mount_server.cpp comm_server.h comm_server_endpoint.h comm_server_configfile.h mount_astrom.h
|
||||||
mount_astrom_default.h)
|
mount_astrom_default.h)
|
||||||
set(MOUNT_SERVER_APP mount_server)
|
set(MOUNT_SERVER_APP mount_server)
|
||||||
add_executable(${MOUNT_SERVER_APP} ${MOUNT_SERVER_APP_SRC})
|
add_executable(${MOUNT_SERVER_APP} ${MOUNT_SERVER_APP_SRC}
|
||||||
|
mcc_coord.h)
|
||||||
# target_include_directories(${MOUNT_SERVER_APP} PUBLIC ${ERFA_INCLUDE_DIR})
|
# target_include_directories(${MOUNT_SERVER_APP} PUBLIC ${ERFA_INCLUDE_DIR})
|
||||||
target_link_libraries(${MOUNT_SERVER_APP} ${CNTR_PROTO_LIB} spdlog::spdlog_header_only ERFA_LIB)
|
target_link_libraries(${MOUNT_SERVER_APP} ${CNTR_PROTO_LIB} spdlog::spdlog_header_only ERFA_LIB)
|
||||||
|
|
||||||
|
|||||||
189
cxx/mcc_coord.h
Normal file
189
cxx/mcc_coord.h
Normal file
@ -0,0 +1,189 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "mcc_traits.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
namespace mcc
|
||||||
|
{
|
||||||
|
|
||||||
|
/* MCC-LIBRARY COORDINATES REPRESENTATION DEFINITIONS AND CLASS */
|
||||||
|
|
||||||
|
constexpr double operator""_rads(long double val) // angle in radians (no conversion)
|
||||||
|
{
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr double operator""_degs(long double val) // angle in degrees
|
||||||
|
{
|
||||||
|
return val * std::numbers::pi / 180.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr double operator""_dms(const char* s, size_t size) // as a string "DEGREES:MINUTES:SECONDS"
|
||||||
|
{
|
||||||
|
auto res = utils::parsAngleString(std::span{s, size});
|
||||||
|
if (res.has_value()) {
|
||||||
|
return res.value() * std::numbers::pi / 180.0;
|
||||||
|
} else {
|
||||||
|
throw std::invalid_argument("invalid sexagesimal representation");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr double operator""_hms(const char* s, size_t size) // as a string "HOURS:MINUTES:SECONDS"
|
||||||
|
{
|
||||||
|
auto res = utils::parsAngleString(std::span{s, size}, true);
|
||||||
|
if (res.has_value()) {
|
||||||
|
return res.value() * std::numbers::pi / 180.0;
|
||||||
|
} else {
|
||||||
|
throw std::invalid_argument("invalid sexagesimal representation");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// tags for MccCoordinate class construction
|
||||||
|
|
||||||
|
struct MccRadianTag {
|
||||||
|
};
|
||||||
|
struct MccDegreeTag {
|
||||||
|
};
|
||||||
|
static constexpr MccDegreeTag mcc_degrees{};
|
||||||
|
struct MccHMSTag {
|
||||||
|
};
|
||||||
|
static constexpr MccHMSTag mcc_hms{};
|
||||||
|
|
||||||
|
|
||||||
|
// coordinate representation class
|
||||||
|
|
||||||
|
class MccCoordinate
|
||||||
|
{
|
||||||
|
double _angleInRads{0.0};
|
||||||
|
int _precision{2};
|
||||||
|
|
||||||
|
public:
|
||||||
|
MccCoordinate() = default;
|
||||||
|
|
||||||
|
// by default angle is in radians
|
||||||
|
MccCoordinate(std::convertible_to<double> auto const& val, const MccRadianTag tag = MccRadianTag{})
|
||||||
|
: _angleInRads(val)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// construct angle in degrees, e.g.:
|
||||||
|
// auto ang = MccCoordinate{180.0, mcc_degrees};
|
||||||
|
MccCoordinate(std::convertible_to<double> auto const& val, const MccDegreeTag tag)
|
||||||
|
{
|
||||||
|
_angleInRads = val * std::numbers::pi / 180.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// constuct angle from sexagesimal representation, e.g.:
|
||||||
|
// auto ang = MccCoordinate{"-12:34:56.789"}; // from degrees:minutes:seconds
|
||||||
|
MccCoordinate(traits::mcc_input_char_range auto const& val)
|
||||||
|
{
|
||||||
|
auto res = utils::parsAngleString(val);
|
||||||
|
if (res.has_value()) {
|
||||||
|
_angleInRads = res.value() * std::numbers::pi / 180.0;
|
||||||
|
} else {
|
||||||
|
throw std::invalid_argument("invalid sexagesimal representation");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// construct angle from sexagesimal representation, e.g.:
|
||||||
|
// auto ang = MccCoordinate{"01:23:45.6789", mcc_hms}; // from hours:minutes:seconds
|
||||||
|
MccCoordinate(traits::mcc_input_char_range auto const& val, const MccHMSTag)
|
||||||
|
{
|
||||||
|
auto res = utils::parsAngleString(val, true);
|
||||||
|
if (res.has_value()) {
|
||||||
|
_angleInRads = res.value() * std::numbers::pi / 180.0;
|
||||||
|
} else {
|
||||||
|
throw std::invalid_argument("invalid sexagesimal representation");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
operator double() const
|
||||||
|
{
|
||||||
|
return _angleInRads;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T degrees() const
|
||||||
|
{
|
||||||
|
return _angleInRads * 180.0 / std::numbers::pi;
|
||||||
|
}
|
||||||
|
|
||||||
|
double degrees() const
|
||||||
|
{
|
||||||
|
return degrees<double>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <traits::mcc_output_char_range T>
|
||||||
|
T sexagesimal(bool hms, int prec = 2) const
|
||||||
|
{
|
||||||
|
return utils::rad2sxg(_angleInRads, hms, prec >= 0 ? prec : _precision);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string sexagesimal(bool hms, int prec = 2) const
|
||||||
|
{
|
||||||
|
return sexagesimal<std::string>(hms, prec);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend MccCoordinate operator+(const MccCoordinate& left, const MccCoordinate& right)
|
||||||
|
{
|
||||||
|
return left._angleInRads + right._angleInRads;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend MccCoordinate operator-(const MccCoordinate& left, const MccCoordinate& right)
|
||||||
|
{
|
||||||
|
return left._angleInRads + right._angleInRads;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
MccCoordinate operator*(T&& scalar)
|
||||||
|
requires std::is_arithmetic_v<std::remove_cvref_t<T>>
|
||||||
|
{
|
||||||
|
return _angleInRads * scalar;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
MccCoordinate operator/(T&& scalar)
|
||||||
|
requires std::is_arithmetic_v<std::remove_cvref_t<T>>
|
||||||
|
{
|
||||||
|
return _angleInRads / scalar;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
MccCoordinate operator-() // unary '-'
|
||||||
|
requires std::is_arithmetic_v<std::remove_cvref_t<T>>
|
||||||
|
{
|
||||||
|
return -_angleInRads;
|
||||||
|
}
|
||||||
|
|
||||||
|
MccCoordinate& operator+=(const MccCoordinate& v)
|
||||||
|
{
|
||||||
|
_angleInRads += v._angleInRads;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
MccCoordinate& operator-=(const MccCoordinate& v)
|
||||||
|
{
|
||||||
|
_angleInRads += v._angleInRads;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
MccCoordinate& operator*=(T&& scalar)
|
||||||
|
requires std::is_arithmetic_v<std::remove_cvref_t<T>>
|
||||||
|
{
|
||||||
|
_angleInRads *= scalar;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
MccCoordinate& operator/=(T&& scalar)
|
||||||
|
requires std::is_arithmetic_v<std::remove_cvref_t<T>>
|
||||||
|
{
|
||||||
|
_angleInRads /= scalar;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace mcc
|
||||||
90
cxx/mount.h
90
cxx/mount.h
@ -10,6 +10,7 @@
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include "spdlog/sinks/null_sink.h"
|
#include "spdlog/sinks/null_sink.h"
|
||||||
|
|
||||||
|
#include "mcc_coord.h"
|
||||||
#include "mcc_spdlog.h"
|
#include "mcc_spdlog.h"
|
||||||
#include "mcc_traits.h"
|
#include "mcc_traits.h"
|
||||||
#include "mount_astrom.h"
|
#include "mount_astrom.h"
|
||||||
@ -45,6 +46,7 @@ concept mcc_mount_state_c = requires(T t, const T t_const) {
|
|||||||
} // namespace traits
|
} // namespace traits
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* SOME BASIC DATA STRUCTURES DEFINITIONS */
|
/* SOME BASIC DATA STRUCTURES DEFINITIONS */
|
||||||
|
|
||||||
// meteo parameters (e.g. to compute refraction)
|
// meteo parameters (e.g. to compute refraction)
|
||||||
@ -195,32 +197,48 @@ public:
|
|||||||
_geoLocation.store(geoloc);
|
_geoLocation.store(geoloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSiteLatitude(auto const& lat)
|
void setSiteLatitude(const MccCoordinate& lat)
|
||||||
{
|
{
|
||||||
auto v = utils::parsAngleString(lat);
|
auto st = _geoLocation.load();
|
||||||
if (v.has_value()) {
|
st.latitude = lat;
|
||||||
auto st = _geoLocation.load();
|
logInfo("Set current site latitude to {} radians", st.latitude);
|
||||||
st.latitude = v.value() * utils::deg2radCoeff; // to radians
|
_geoLocation.store(st);
|
||||||
logInfo("Set current site latitude to {} radians", st.latitude);
|
|
||||||
_geoLocation.store(st);
|
|
||||||
} else {
|
|
||||||
logError("Invalid user latitude value! Do not change the current value!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSiteLongitude(auto const& lon)
|
void setSiteLongitude(const MccCoordinate& lon)
|
||||||
{
|
{
|
||||||
auto v = utils::parsAngleString(lon);
|
auto st = _geoLocation.load();
|
||||||
if (v.has_value()) {
|
st.longitude = lon;
|
||||||
auto st = _geoLocation.load();
|
logInfo("Set current site longitude to {} radians", st.longitude);
|
||||||
st.longitude = v.value() * utils::deg2radCoeff; // to radians
|
_geoLocation.store(st);
|
||||||
logInfo("Set current site longitude to {} radians", st.longitude);
|
|
||||||
_geoLocation.store(st);
|
|
||||||
} else {
|
|
||||||
logError("Invalid user longitude value! Do not change the current value!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void setSiteLatitude(auto const& lat)
|
||||||
|
// {
|
||||||
|
// auto v = utils::parsAngleString(lat);
|
||||||
|
// if (v.has_value()) {
|
||||||
|
// auto st = _geoLocation.load();
|
||||||
|
// st.latitude = v.value() * utils::deg2radCoeff; // to radians
|
||||||
|
// logInfo("Set current site latitude to {} radians", st.latitude);
|
||||||
|
// _geoLocation.store(st);
|
||||||
|
// } else {
|
||||||
|
// logError("Invalid user latitude value! Do not change the current value!");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void setSiteLongitude(auto const& lon)
|
||||||
|
// {
|
||||||
|
// auto v = utils::parsAngleString(lon);
|
||||||
|
// if (v.has_value()) {
|
||||||
|
// auto st = _geoLocation.load();
|
||||||
|
// st.longitude = v.value() * utils::deg2radCoeff; // to radians
|
||||||
|
// logInfo("Set current site longitude to {} radians", st.longitude);
|
||||||
|
// _geoLocation.store(st);
|
||||||
|
// } else {
|
||||||
|
// logError("Invalid user longitude value! Do not change the current value!");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
void setSiteElevation(MccMountSiteInfo::mnt_site_elev_t elev)
|
void setSiteElevation(MccMountSiteInfo::mnt_site_elev_t elev)
|
||||||
{
|
{
|
||||||
auto st = _geoLocation.load();
|
auto st = _geoLocation.load();
|
||||||
@ -249,22 +267,34 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// prohibited zone related methods
|
/* prohibited zone related methods */
|
||||||
|
|
||||||
bool pzCheck(traits::mcc_real_or_char_range auto const& xcoord, traits::mcc_real_or_char_range auto const& ycoord)
|
// returns a time to reach the prohibited area:
|
||||||
|
// 0 - already in the zone
|
||||||
|
// std::chrono::sys_time<>::max() - never reach the zone
|
||||||
|
// the kind of cordinates (e.g. IRCS or apparent, equatorial or horizontal) is a subject of implementation
|
||||||
|
auto pzTimeTo(const MccCoordinate& xcoord,
|
||||||
|
const MccCoordinate& ycoord,
|
||||||
|
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
|
||||||
{
|
{
|
||||||
return true;
|
using d_t = std::remove_cvref_t<decltype(utc)>::duration;
|
||||||
}
|
|
||||||
|
|
||||||
auto pzPredict(traits::mcc_systime_c auto const& time_point,
|
|
||||||
traits::mcc_real_or_char_range auto const& xcoord,
|
|
||||||
traits::mcc_real_or_char_range auto const& ycoord)
|
|
||||||
{
|
|
||||||
using d_t = std::remove_cvref_t<decltype(time_point)>::duration;
|
|
||||||
|
|
||||||
return d_t::max();
|
return d_t::max();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns a time to exit the prohibited area:
|
||||||
|
// 0 - already out of the zone
|
||||||
|
// std::chrono::sys_time<>::max() - the zone itself
|
||||||
|
// the kind of cordinates (e.g. IRCS or apparent, equatorial or horizontal) is a subject of implementation
|
||||||
|
auto pzTimeFrom(const MccCoordinate& xcoord,
|
||||||
|
const MccCoordinate& ycoord,
|
||||||
|
traits::mcc_systime_c auto const& utc = std::chrono::system_clock::now())
|
||||||
|
{
|
||||||
|
using d_t = std::remove_cvref_t<decltype(utc)>::duration;
|
||||||
|
|
||||||
|
return d_t{0};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// IERS databases updater
|
// IERS databases updater
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ namespace mcc
|
|||||||
|
|
||||||
class MccMountAbstractState
|
class MccMountAbstractState
|
||||||
{
|
{
|
||||||
std::function<void()> _getMountStateFunc{[]() {}};
|
std::function<void()> _getMountDataFunc{[]() {}};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef std::error_code mount_state_error_t;
|
typedef std::error_code mount_state_error_t;
|
||||||
@ -34,7 +34,7 @@ public:
|
|||||||
std::convertible_to<exit_callback_t> auto&& exit_callback,
|
std::convertible_to<exit_callback_t> auto&& exit_callback,
|
||||||
std::convertible_to<error_callback_t> auto&& error_callback)
|
std::convertible_to<error_callback_t> auto&& error_callback)
|
||||||
{
|
{
|
||||||
_getMountStateFunc = [&mount_ptr, this]() { auto mstate = mount_ptr->getMountData(); };
|
_getMountDataFunc = [&mount_ptr, this]() { auto mstate = mount_ptr->getMountData(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ public:
|
|||||||
|
|
||||||
std::string_view ident() const
|
std::string_view ident() const
|
||||||
{
|
{
|
||||||
return "MCC-ABSTRACT-MOUNT-STATE";
|
return "MCC-MOUNT-ABSTRACT-STATE";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -51,6 +51,12 @@ public:
|
|||||||
|
|
||||||
void exit() {}
|
void exit() {}
|
||||||
|
|
||||||
|
// #ifdef __cpp_explicit_this_parameter
|
||||||
|
// #if __cpp_explicit_this_parameter >= 202110L
|
||||||
|
// void aaa() {}
|
||||||
|
// #endif
|
||||||
|
// #endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enter_callback_t _enterCallback{[](const mount_state_error_t&) {}};
|
enter_callback_t _enterCallback{[](const mount_state_error_t&) {}};
|
||||||
exit_callback_t _exitCallback{[](const mount_state_error_t&) {}};
|
exit_callback_t _exitCallback{[](const mount_state_error_t&) {}};
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstring>
|
||||||
#include <format>
|
#include <format>
|
||||||
#include <numbers>
|
#include <numbers>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
@ -147,6 +148,11 @@ static std::optional<double> parsAngleString(R&& r, bool hms = false)
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::optional<double> parsAngleString(const char* s, bool hms = false)
|
||||||
|
{
|
||||||
|
return parsAngleString(std::span{s, std::strlen(s)}, hms);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static constexpr auto deg2radCoeff = std::numbers::pi / 180.0;
|
static constexpr auto deg2radCoeff = std::numbers::pi / 180.0;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user