...
This commit is contained in:
@@ -6,6 +6,9 @@
|
||||
/* MOUNT TELEMETRY OBJECT CONCEPT AND POSSIBLE IMPLEMENTATION */
|
||||
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
|
||||
#include "mcc_mount_config.h"
|
||||
|
||||
namespace mcc
|
||||
{
|
||||
@@ -15,9 +18,11 @@ namespace traits
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
concept mcc_mount_telemetry_c = requires(T t) {
|
||||
concept mcc_mount_telemetry_c = requires(T t, const T t_const) {
|
||||
typename T::mount_telemetry_data_t;
|
||||
{ t.update() } -> std::same_as<typename T::mount_telemetry_data_t>;
|
||||
{ t.update() };
|
||||
|
||||
{ t_const.data() } -> std::same_as<typename T::mount_telemetry_data_t>;
|
||||
};
|
||||
|
||||
} // namespace traits
|
||||
@@ -31,6 +36,7 @@ public:
|
||||
typedef double mnt_coord_t;
|
||||
typedef double mnt_speed_t;
|
||||
typedef double time_point_t;
|
||||
typedef std::vector<double> refr_coeff_t;
|
||||
|
||||
// time-related
|
||||
std::chrono::system_clock::time_point utc;
|
||||
@@ -56,7 +62,9 @@ public:
|
||||
mnt_coord_t mntPosX, mntPosY;
|
||||
mnt_speed_t mntSpeedX, mntSpeedY;
|
||||
|
||||
// current refraction coefficient (for tagZD)
|
||||
// current refraction coefficients
|
||||
refr_coeff_t currRefrCoeffs;
|
||||
// current refraction correction (for tagZD)
|
||||
mnt_coord_t currRefr;
|
||||
|
||||
// PCS (pointing correction system) corrections
|
||||
@@ -64,16 +72,48 @@ public:
|
||||
mnt_coord_t pcsX, pcsY;
|
||||
};
|
||||
|
||||
template <MccMountType MOUNT_TYPE>
|
||||
MccMountTelemetry(MccMountConfig<MOUNT_TYPE>& mount_config)
|
||||
{
|
||||
// to be sure that mount_config is captured by reference
|
||||
const auto config_ptr = &mount_config;
|
||||
|
||||
_updateImpl = [config_ptr, this]() {
|
||||
mount_telemetry_data_t current_data;
|
||||
|
||||
// computing ...
|
||||
|
||||
|
||||
std::scoped_lock lock{_updateMutex};
|
||||
|
||||
_data = current_data;
|
||||
};
|
||||
}
|
||||
|
||||
virtual ~MccMountTelemetry() = default;
|
||||
|
||||
// update current data method
|
||||
mount_telemetry_data_t update()
|
||||
void update()
|
||||
{
|
||||
return _data;
|
||||
_updateImpl();
|
||||
}
|
||||
|
||||
mount_telemetry_data_t data(this auto&& self)
|
||||
{
|
||||
using self_t = decltype(self);
|
||||
|
||||
std::scoped_lock lock{std::forward<self_t>(self)._updateMutex};
|
||||
|
||||
return std::move(std::forward<self_t>(self)._data);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
mount_telemetry_data_t _data;
|
||||
mount_telemetry_data_t _data{};
|
||||
|
||||
std::function<void()> _updateImpl{};
|
||||
|
||||
std::mutex _updateMutex;
|
||||
};
|
||||
|
||||
} // namespace mcc
|
||||
|
||||
Reference in New Issue
Block a user