#pragma once #include #include #include "asibfm700_common.h" #include "asibfm700_mount.h" // define serializer and deserializer for meteo parameters namespace mcc::impl { template <> struct MccSerializer : MccSerializerBase { constexpr static std::string_view serializerName{"ASIBFM700-ERFA-METEO-SERIALIZER"}; template error_t operator()(traits::mcc_output_char_range auto& output, asibfm700::Asibfm700CCTE::meteo_t const& value, ParamsT const& params = mcc_serialization_params_t{}) { std::vector vec{value.temperature, value.humidity, value.pressure}; auto err = MccSerializer{}(output, vec, params); if (err) { return mcc_deduced_err(err, MccSerializerErrorCode::ERROR_UNDERLYING_SERIALIZER); } return MccSerializerErrorCode::ERROR_OK; } }; template <> struct MccDeserializer : MccDeserializerBase { static constexpr std::string_view deserializerName{"ASIBFM700-ERFA-METEO-DESERIALIZER"}; template error_t operator()(traits::mcc_input_char_range auto const& input, asibfm700::Asibfm700CCTE::meteo_t& value, ParamsT const& params = mcc_serialization_params_t{}) { std::vector v; auto err = MccDeserializer{}(input, v, params); if (err) { return mcc_deduced_err(err, MccDeserializerErrorCode::ERROR_UNDERLYING_DESERIALIZER); } if (v.size() < 3) { return MccDeserializerErrorCode::ERROR_INVALID_SERIALIZED_VALUE; } value.temperature = v[0]; value.humidity = v[1]; value.pressure = v[2]; return MccDeserializerErrorCode::ERROR_OK; } }; } // namespace mcc::impl namespace asibfm700 { namespace details { template static constexpr auto merge_arrays(const std::array& arr1, const std::array& arr2) { constexpr auto N = N1 + N2; std::array res; for (size_t i = 0; i < N1; ++i) { res[i] = arr1[i]; } for (size_t i = N1; i < N; ++i) { res[i] = arr2[i - N1]; } return res; } } // namespace details // meteo parameters (ambient air temperature, humidity and atmosperic pressure) constexpr static std::string_view ASIBFM700_COMMPROTO_KEYWORD_METEO_STR{"METEO"}; // current site geodetic longtude and latitude constexpr static std::string_view ASIBFM700_COMMPROTO_KEYWORD_SITEGEO_STR{"SITEGEO"}; // reload mount configuration file constexpr static std::string_view ASIBFM700_COMMPROTO_KEYWORD_RELOADCFG_STR{"RELOADCFG"}; struct Asibfm700NetMessageValidKeywords { static constexpr std::array NETMSG_VALID_KEYWORDS = details::merge_arrays(mcc::network::MccNetMessageValidKeywords::NETMSG_VALID_KEYWORDS, std::array{ASIBFM700_COMMPROTO_KEYWORD_METEO_STR, ASIBFM700_COMMPROTO_KEYWORD_SITEGEO_STR, ASIBFM700_COMMPROTO_KEYWORD_RELOADCFG_STR}); // hashes of valid keywords static constexpr std::array NETMSG_VALID_KEYWORD_HASHES = [](std::index_sequence) { return std::array{mcc::utils::FNV1aHash(NETMSG_VALID_KEYWORDS[Is])...}; }(std::make_index_sequence()); constexpr static const size_t* isKeywordValid(std::string_view key) { const auto hash = mcc::utils::FNV1aHash(key); for (auto const& h : NETMSG_VALID_KEYWORD_HASHES) { if (h == hash) { return &h; } } return nullptr; } }; template using Asibfm700NetMessage = mcc::network::MccNetMessage; class Asibfm700MountNetServer : public mcc::network::MccGenericMountNetworkServer { using base_t = mcc::network::MccGenericMountNetworkServer; public: Asibfm700MountNetServer(asio::io_context& ctx, Asibfm700Mount& mount, std::shared_ptr logger); ~Asibfm700MountNetServer(); }; } // namespace asibfm700