Projects
domecam:swift
domecam
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 25
View file
domecam.changes
Changed
@@ -1,4 +1,9 @@ ------------------------------------------------------------------- +Sun Oct 9 14:51:12 UTC 2022 - Matwey V. Kornilov <matwey@sai.msu.ru> + +- Version 0.1.10 + +------------------------------------------------------------------- Fri Sep 30 11:33:28 UTC 2022 - Matwey V. Kornilov <matwey@sai.msu.ru> - Version 0.1.9
View file
domecam.spec
Changed
@@ -27,8 +27,12 @@ Source1: domecamd-user.conf BuildRequires: cmake BuildRequires: gcc-c++ -BuildRequires: libboost_program_options-devel -BuildRequires: libboost_system-devel +BuildRequires: libboost_container-devel-impl +BuildRequires: libboost_filesystem-devel-impl +BuildRequires: libboost_headers-devel-impl +BuildRequires: libboost_json-devel-impl +BuildRequires: libboost_program_options-devel-impl +BuildRequires: libboost_system-devel-impl BuildRequires: make BuildRequires: systemd-rpm-macros BuildRequires: sysuser-tools
View file
_service
Changed
@@ -3,7 +3,7 @@ <param name="url">http://curl.sai.msu.ru/hg/home/matwey/domecam/</param> <param name="scm">hg</param> <param name="versionformat">{latesttag}</param> - <param name="revision">0.1.9</param> + <param name="revision">0.1.10</param> </service> <service name="tar" mode="buildtime" /> <service name="recompress" mode="buildtime">
View file
domecam-0.1.9.obscpio/.hgtags -> domecam-0.1.10.obscpio/.hgtags
Changed
@@ -7,3 +7,4 @@ 3f19208b6ac21b2b2776f064440fb20d5f99170b 0.1.6 41a20f4ebd5e57689dc34e2b7f56e18609dadf14 0.1.7 efa87880dd80510c7274207a1df55793364749f3 0.1.8 +5bde06ef6c04b0a814e8bf9455fcccbda5b90cc8 0.1.9
View file
domecam-0.1.9.obscpio/CMakeLists.txt -> domecam-0.1.10.obscpio/CMakeLists.txt
Changed
@@ -1,5 +1,5 @@ cmake_minimum_required (VERSION 3.5) -project(domecam LANGUAGES C CXX VERSION 0.1.9) +project(domecam LANGUAGES C CXX VERSION 0.1.10) set(CMAKE_CXX_STANDARD 17) @@ -22,6 +22,9 @@ find_package(amqpcpp) find_package(Boost ${BOOST_REQUIRED_VERSION} COMPONENTS + container REQUIRED + filesystem REQUIRED + json REQUIRED program_options REQUIRED system REQUIRED) find_package(Threads REQUIRED) @@ -37,7 +40,7 @@ file(GLOB_RECURSE SOURCES src/*.cpp) add_library(domecam STATIC ${SOURCES}) -target_link_libraries(domecam Threads::Threads Boost::boost Boost::system Boost::program_options PkgConfig::ARAVIS PkgConfig::CFITSIO PkgConfig::LIBCURL PkgConfig::FFTW3F) +target_link_libraries(domecam Threads::Threads Boost::boost Boost::filesystem Boost::json Boost::program_options Boost::system PkgConfig::ARAVIS PkgConfig::CFITSIO PkgConfig::LIBCURL PkgConfig::FFTW3F) target_compile_definitions(domecam PRIVATE PROJECT_VERSION="${PROJECT_VERSION}") if(HAS_LTO_SUPPORT) set_property(TARGET domecam PROPERTY INTERPROCEDURAL_OPTIMIZATION True)
View file
domecam-0.1.9.obscpio/exe/domecam.cpp -> domecam-0.1.10.obscpio/exe/domecam.cpp
Changed
@@ -15,16 +15,15 @@ std::unique_ptr<executor> executor_; }; -namespace detail { -template<> struct load_impl<context> { -static context load_(const ptree& pt) { +context tag_invoke(boost::json::value_to_tag<context>, const boost::json::value& jv) { + using boost::json::value_to; + + const auto& obj = jv.as_object(); + return context{ - load<camera>(pt.get_child("camera")), - load<executor>(pt.get_child("executor")) - }; + value_to<camera>(obj.at("camera")), + value_to<std::unique_ptr<executor>>(obj.at("executor"))}; } -}; -} // detail class application: public abstract_application { public: @@ -49,7 +48,7 @@ application::~application() = default; int application::do_run(const boost::program_options::variables_map& va) { - auto ctx = load_json<context>(va[config_opt].as<std::string>()); + auto ctx = load_json<context>(boost::filesystem::path{va[config_opt].as<std::string>()}); std::cout << "Device Id: " << ctx.camera_.device_id() << std::endl; std::cout << "Vendor Id: " << ctx.camera_.vendor_id() << std::endl;
View file
domecam-0.1.9.obscpio/exe/domecamd/consumer.cpp -> domecam-0.1.10.obscpio/exe/domecamd/consumer.cpp
Changed
@@ -56,96 +56,94 @@ std::exception_ptr reason_; }; -struct domecamd_notify_finished { +struct domecamd_notify_finished_successed { + executor_result result_; +}; + +struct domecamd_notify_finished_failed { std::exception_ptr reason_; }; -namespace detail { -template<> struct load_impl<domecamd_request> { -static domecamd_request load_(const ptree& pt) { - const auto type = pt.get<std::string>("type"); +domecamd_request tag_invoke(boost::json::value_to_tag<domecamd_request>, const boost::json::value& jv) { + using boost::json::value_to; + + const auto& obj = jv.as_object(); + const auto& type = obj.at("type").as_string(); if (type == "ping") { return domecamd_request_ping{}; } else if (type == "schedule") { return domecamd_request_schedule{ - load<executor>(pt.get_child("executor")), - load<optional_camera_settings>(pt.get_child("camera_settings")) + value_to<std::unique_ptr<executor>>(obj.at("executor")), + value_to<optional_camera_settings>(obj.at("camera_settings")) }; } - throw std::runtime_error(std::string("Unknown request type ") + type); + throw std::runtime_error(std::string("Unknown request type ") + type.c_str()); } -}; -template<> struct save_impl<std::exception_ptr> { -static ptree save(const std::exception_ptr x) { - ptree pt; +boost::json::value error_to_value(const std::exception_ptr& p) { + using boost::json::value_from; - if (!x) return pt; + boost::json::value jv; try { - std::rethrow_exception(x); - } catch (const already_scheduled& e) { - pt.put("reason", "busy"); - pt.put("task", e.id()); + std::rethrow_exception(p); + } catch (const ::already_scheduled& e) { + jv = { + {"reason", "busy"}, + {"task", value_from(e.id())}}; } catch (const std::exception& e) { - pt.put("reason", e.what()); + jv = { + {"reason", e.what()}}; } catch (...) { - pt.put("reason", "unknown"); + jv = { + {"reason", "unknown"}}; } - return pt; + return jv; } -}; -template<> struct save_impl<domecamd_response_pong> { -static ptree save(const domecamd_response_pong& /*x*/) { - ptree pt; - pt.put("status", "pong"); - - return pt; +void tag_invoke(boost::json::value_from_tag, boost::json::value& jv, const domecamd_response_pong&) { + jv = { + {"status", "pong"}}; } -}; -template<> struct save_impl<domecamd_response_schedule> { -static ptree save(const domecamd_response_schedule& x) { - ptree pt; - - pt.put("status", x.reason_ ? "error" : "ok"); - if (x.reason_) { - pt.add_child("error", ::save(x.reason_)); - } +void tag_invoke(boost::json::value_from_tag, boost::json::value& jv, const domecamd_response_schedule& r) { + using boost::json::value_from; - return pt; -} -}; + jv = { + {"status", r.reason_ ? "error" : "ok"}}; -template<> struct save_impl<domecamd_response_error> { -static ptree save(const domecamd_response_error& x) { - ptree pt; + if (r.reason_) { + auto& obj = jv.as_object(); + obj["error"] = error_to_value(r.reason_); + } +} - pt.put("status", "error"); - pt.add_child("error", ::save(x.reason_)); +void tag_invoke(boost::json::value_from_tag, boost::json::value& jv, const domecamd_response_error& r) { + using boost::json::value_from; - return pt; + jv = { + {"status", "error"}, + {"error", error_to_value(r.reason_)}}; } -}; -template<> struct save_impl<domecamd_notify_finished> { -static ptree save(const domecamd_notify_finished& x) { - ptree pt; - - pt.put("status", x.reason_ ? "failed" : "succeeded"); - if (x.reason_) { - pt.add_child("error", ::save(x.reason_)); - } +void tag_invoke(boost::json::value_from_tag, boost::json::value& jv, const domecamd_notify_finished_successed& n) { + using boost::json::value_from; - return pt; + jv = { + {"status", "succeeded"}, + {"result", value_from(n.result_)}}; } -}; -} // detail +void tag_invoke(boost::json::value_from_tag, boost::json::value& jv, const domecamd_notify_finished_failed& n) { + using boost::json::value_from; + + jv = { + {"status", "failed"}, + {"error", error_to_value(n.reason_)}}; +} consumer::consumer(boost::asio::io_context& io_context, camera& c, const std::string& uri): @@ -268,8 +266,7 @@ }; try { - std::istringstream iss{std::string{message.body(), message.bodySize()}}; - auto request = load_json<domecamd_request>(iss); + auto request = load_json<domecamd_request>(std::string_view{message.body(), message.bodySize()}); std::visit(request_visitor{*this, correlation_id, reply_to}, request); } catch (...) { if (reply_to) { @@ -322,8 +319,12 @@ reply(std::string{"{}"}, routing_key_started, id, exchange_pubsub); } +void consumer::on_finished(const std::string& id, executor_result result) noexcept { + reply(domecamd_notify_finished_successed{std::move(result)}, routing_key_finished, id, exchange_pubsub); +} + void consumer::on_finished(const std::string& id, std::exception_ptr eptr) noexcept { - reply(domecamd_notify_finished{eptr}, routing_key_finished, id, exchange_pubsub); + reply(domecamd_notify_finished_failed{eptr}, routing_key_finished, id, exchange_pubsub); } constexpr const char consumer::exchange_dlx[];
View file
domecam-0.1.9.obscpio/exe/domecamd/main.cpp -> domecam-0.1.10.obscpio/exe/domecamd/main.cpp
Changed
@@ -23,16 +23,15 @@ std::string amqp_uri_; }; -namespace detail { -template<> struct load_impl<domecamd_context> { -static domecamd_context load_(const ptree& pt) { +domecamd_context tag_invoke(boost::json::value_to_tag<domecamd_context>, const boost::json::value& jv) { + using boost::json::value_to; + + const auto& obj = jv.as_object(); + return domecamd_context{ - load<camera>(pt.get_child("camera")), - pt.get<std::string>("amqp_uri") - }; + value_to<camera>(obj.at("camera")), + value_to<std::string>(obj.at("amqp_uri"))}; } -}; -} // detail class application: public abstract_application { public: @@ -70,7 +69,7 @@ application::~application() = default; int application::do_run(const boost::program_options::variables_map& va) { - auto ctx = load_json<domecamd_context>(va[config_opt].as<std::string>()); + auto ctx = load_json<domecamd_context>(boost::filesystem::path{va[config_opt].as<std::string>()}); consumer cmr{io_context_, ctx.camera_, ctx.amqp_uri_}; io_context_.run();
View file
domecam-0.1.9.obscpio/exe/domecamd/scheduler.cpp -> domecam-0.1.10.obscpio/exe/domecamd/scheduler.cpp
Changed
@@ -45,14 +45,10 @@ on_started(id); - t->executor_->run(camera_); + on_finished(id, t->executor_->run(camera_)); } catch (...) { on_finished(id, std::current_exception()); - - return; } - - on_finished(id); }); on_scheduled(t->id_);
View file
domecam-0.1.9.obscpio/include/exe/domecamd/consumer.h -> domecam-0.1.10.obscpio/include/exe/domecamd/consumer.h
Changed
@@ -43,7 +43,8 @@ void on_scheduled(const std::string& id) noexcept override; void on_started(const std::string& id) noexcept override; - void on_finished(const std::string& id, std::exception_ptr eptr = std::exception_ptr{}) noexcept override; + void on_finished(const std::string& id, executor_result result) noexcept override; + void on_finished(const std::string& id, std::exception_ptr eptr) noexcept override; private: AMQP::LibBoostAsioHandler amqp_handler_;
View file
domecam-0.1.9.obscpio/include/exe/domecamd/scheduler.h -> domecam-0.1.10.obscpio/include/exe/domecamd/scheduler.h
Changed
@@ -45,7 +45,8 @@ protected: virtual void on_scheduled(const std::string& id) noexcept = 0; virtual void on_started(const std::string& id) noexcept = 0; - virtual void on_finished(const std::string& id, std::exception_ptr eptr = std::exception_ptr{}) noexcept = 0; + virtual void on_finished(const std::string& id, executor_result result) noexcept = 0; + virtual void on_finished(const std::string& id, std::exception_ptr eptr) noexcept = 0; private: void schedule(const std::string& id, std::unique_ptr<executor>&& e, const optional_camera_settings& camera_settings);
View file
domecam-0.1.9.obscpio/include/executor/edge.h -> domecam-0.1.10.obscpio/include/executor/edge.h
Changed
@@ -9,6 +9,7 @@ #include <ostream> +#include <iofwd.h> #include <executorfwd.h> #include <executor/pupil.h> @@ -35,6 +36,7 @@ value_type focus; }; +void tag_invoke(boost::json::value_from_tag, boost::json::value&, const edge_executor_base::runner_result&); std::ostream& operator<<(std::ostream& stm, const edge_executor_base::runner_result& s); class edge_executor_base::runner_base:
View file
domecam-0.1.9.obscpio/include/executor/mean_pupil_mask.h -> domecam-0.1.10.obscpio/include/executor/mean_pupil_mask.h
Changed
@@ -18,6 +18,8 @@ class mean_pupil_mask_executor_base: protected fits_sink_mixin, protected pipeline_mixin { +public: + struct runner_result; protected: template<class SourceMixin> class runner; public: @@ -26,6 +28,17 @@ const std::size_t samples_; }; + +struct mean_pupil_mask_executor_base::runner_result { + using value_type = float; + + std::array<value_type, 2> center_mean; + value_type radius_mean; +}; + +void tag_invoke(boost::json::value_from_tag, boost::json::value&, const mean_pupil_mask_executor_base::runner_result&); +std::ostream& operator<<(std::ostream& stm, const mean_pupil_mask_executor_base::runner_result& s); + template<class SourceMixin> class mean_pupil_mask_executor_base::runner: public SourceMixin, @@ -64,7 +77,7 @@ accum_buffer_.clear(); } - void run(); + runner_result run(); private: typename mean_pipeline_type::buffer_type accum_buffer_; @@ -72,7 +85,7 @@ }; template<class SourceMixin> -void mean_pupil_mask_executor_base::runner<SourceMixin>::run() { +mean_pupil_mask_executor_base::runner_result mean_pupil_mask_executor_base::runner<SourceMixin>::run() { this->for_each([this] (const typename source_type::result_type& b) { pipeline_mixin::runner_mixin<mean_pipeline_type>::apply(accum_buffer_, static_cast<buffer_view<typename source_type::value_type, mean_pipeline_type::mempool_type::align>>(b)); @@ -81,6 +94,9 @@ const auto& r = pipeline_mixin::runner_mixin<pupil_mask_pipeline_type>::apply(accum_buffer_, rng_, nullptr); this->append_frame(r.second); this->commit(); + + const auto& edge_geom = r.first.edge; + return {edge_geom.center, edge_geom.radius}; }
View file
domecam-0.1.9.obscpio/include/executor/pupil.h -> domecam-0.1.10.obscpio/include/executor/pupil.h
Changed
@@ -49,6 +49,7 @@ std::array<value_type, 2> drift; }; +void tag_invoke(boost::json::value_from_tag, boost::json::value&, const pupil_executor_base::runner_result&); std::ostream& operator<<(std::ostream& stm, const pupil_executor_base::runner_result& s); struct pupil_executor_base::pupil_mixin_base {
View file
domecam-0.1.9.obscpio/include/executor_result.h -> domecam-0.1.10.obscpio/include/executor_result.h
Changed
@@ -9,12 +9,14 @@ #include <memory> +#include <iofwd.h> class executor_result { private: class abstract_impl { public: virtual ~abstract_impl() = 0; + virtual void value_from(boost::json::value& jv) const = 0; virtual std::ostream& print(std::ostream& stm) const = 0; }; @@ -24,12 +26,9 @@ template<class T> executor_result(const T&); template<class T> executor_result(T&&); - executor_result(const executor_result&) = delete; - executor_result(executor_result&&) = default; - executor_result& operator=(const executor_result&) = delete; - executor_result& operator=(executor_result&&) = default; - ~executor_result() = default; + operator bool () const { return static_cast<bool>(impl_); } + void value_from(boost::json::value& jv) const; std::ostream& print(std::ostream& stm) const; private: std::unique_ptr<abstract_impl> impl_; @@ -39,15 +38,12 @@ class executor_result::wrap_impl final: public executor_result::abstract_impl { public: - wrap_impl(const T&); - wrap_impl(T&&); + explicit wrap_impl(const T&); + explicit wrap_impl(T&&); - wrap_impl(const wrap_impl<T>&) = delete; - wrap_impl(wrap_impl<T>&&) = delete; - wrap_impl<T>& operator=(const wrap_impl<T>&) = delete; - wrap_impl<T>& operator=(wrap_impl<T>&&) = delete; ~wrap_impl() override final = default; + void value_from(boost::json::value& jv) const override final; std::ostream& print(std::ostream& stm) const override final; private: T data_; @@ -62,6 +58,13 @@ data_{std::move(data)} {} template<class T> +void executor_result::wrap_impl<T>::value_from(boost::json::value& jv) const { + using boost::json::value_from; + + jv = value_from(data_); +} + +template<class T> std::ostream& executor_result::wrap_impl<T>::print(std::ostream& stm) const { return stm << data_; } @@ -74,6 +77,10 @@ executor_result::executor_result(T&& data): impl_{new wrap_impl<T>{std::move(data)}} {} +inline void tag_invoke(boost::json::value_from_tag, boost::json::value& jv, const executor_result& r) { + r.value_from(jv); +} + inline std::ostream& operator<<(std::ostream& stm, const executor_result& r) { return r.print(stm); }
View file
domecam-0.1.9.obscpio/include/io.h -> domecam-0.1.10.obscpio/include/io.h
Changed
@@ -7,210 +7,54 @@ #ifndef _IO_H #define _IO_H -#include <iofwd.h> +#include <chrono> +#include <memory> +#include <variant> -#include <camera.h> #include <camera_settings.h> +#include <carriage.h> +#include <iofwd.h> #include <executor.h> -#include <algorithm> -#include <array> -#include <chrono> namespace detail { -using boost::property_tree::ptree; - -template<class T, class Period> struct load_impl<std::chrono::duration<T, Period>> { -static std::chrono::duration<T, Period> load_(const ptree& pt) { - return std::chrono::duration<T, Period>{load<T>(pt)}; -} -}; - -template<class T, std::size_t N> struct load_impl<std::array<T, N>> { -static std::array<T, N> load_(const ptree& pt) { - std::array<T, N> ret; - - /* Arrays are mapped to empty key */ - const auto range = pt.equal_range(""); - - if (std::distance(range.first, range.second) != N) { - throw std::runtime_error("Wrong number of elements in array"); - } - - std::transform(range.first, range.second, ret.begin(), [] (const std::pair<const std::string, const ptree&>& c) { - return load<T>(c.second); - }); - - return ret; -} -}; - -template<> struct load_impl<optional_camera_settings::packet_size_type> { -static optional_camera_settings::packet_size_type load_(const ptree& pt) { - if (pt.get_value<std::string>() == "auto") { - return optional_camera_settings::auto_tag{}; - } - - return load<camera_settings::packet_size_type>(pt); -} -}; - -template<> struct load_impl<optional_camera_settings::region_type> { -static optional_camera_settings::region_type load_(const ptree& pt) { - if (pt.get_value<std::string>() == "full") { - return optional_camera_settings::full_tag{}; - } - - return load<camera::region_type>(pt); -} -}; +template<class T, std::size_t... I> +std::array<T, sizeof...(I)> extract_array(const boost::json::array& arr, std::index_sequence<I...>) { + using boost::json::value_to; -template<> struct load_impl<camera::region_type> { -static camera::region_type load_(const ptree& pt) { - return camera::region_type{ - load<std::array<std::int32_t, 2>>(pt.get_child("offset")), - load<std::array<std::int32_t, 2>>(pt.get_child("size"))}; + return {value_to<T>(arr.at(I))...}; } -}; -template<> struct load_impl<camera> { -static camera load_(const ptree& pt) { - const auto it = pt.find("id"); - const auto id = (it != pt.not_found() ? it->second.get_value<std::string>() : pt.get<std::string>("name")); - camera cam(id); - - const optional_camera_settings default_settings{ - camera_settings::binning_type{2, 2}, - camera_settings::exposure_time_type{10000}, - 100.0, - 0.0, - optional_camera_settings::packet_size_type{optional_camera_settings::auto_tag{}}, - optional_camera_settings::region_type{optional_camera_settings::full_tag{}}, - ARV_PIXEL_FORMAT_MONO_12}; - - load<optional_camera_settings>(pt.get_child("settings")).or_else(default_settings).apply_to(cam); +} // detail - return cam; -} -}; +namespace std { -template<> struct load_impl<optional_camera_settings> { -static optional_camera_settings load_(const ptree& pt) { - auto binning = load<optional_camera_settings::binning_type>(pt.get_child_optional("binning")); - if (!binning) { - if (pt.find("binning_x") != pt.not_found() || pt.find("binning_y") != pt.not_found()) { - using value_type = camera::binning_type::value_type; - - const auto x = pt.get<value_type>("binning_x"); - const auto y = pt.get<value_type>("binning_y"); - binning = camera::binning_type{x, y}; - } - } - - return optional_camera_settings{ - binning, - load<optional_camera_settings::exposure_time_type>(pt.get_child_optional("exposure_time")), - load<optional_camera_settings::frame_rate_type>(pt.get_child_optional("frame_rate")), - load<optional_camera_settings::gain_type>(pt.get_child_optional("gain")), - load<optional_camera_settings::packet_size_type>(pt.get_child_optional("packet_size")), - load<optional_camera_settings::region_type>(pt.get_child_optional("region")), - {} // configuring pixel_format is not supported atm - }; +template<class T, std::size_t N> +array<T, N> +tag_invoke(boost::json::value_to_tag<array<T, N>>, const boost::json::value& jv) { + return detail::extract_array<T>(jv.as_array(), std::make_index_sequence<N>{}); } -}; -template<> struct load_impl<abstract_carriage::direction> { -static abstract_carriage::direction load_(const ptree& pt) { - const auto direction = pt.get_value<std::string>(); - - if (direction == "cw" || direction == "forward") { - return abstract_carriage::direction::cw; - } else if (direction == "ccw" || direction == "backward") { - return abstract_carriage::direction::ccw; - } +namespace chrono { - throw std::runtime_error(std::string("Unknown direction type ") + direction); -} -}; - -template<> struct load_impl<executor> { -static std::unique_ptr<executor> load_(const ptree& pt) { - const auto type = pt.get<std::string>("type"); - - if (type == "raw") { - return std::unique_ptr<executor>{new raw_executor(pt.get<std::string>("filename"), pt.get<std::size_t>("frames_number"))}; - } else if (type == "raw_scan") { - return std::unique_ptr<executor>{new raw_scan_executor(pt.get<std::string>("filename"), pt.get<std::size_t>("frames_number"))}; - } else if (type == "grad") { - return std::unique_ptr<executor>{new grad_executor(pt.get<std::string>("filename"), pt.get<std::size_t>("frames_number"))}; - } else if (type == "binary") { - return std::unique_ptr<executor>{new binary_executor(pt.get<std::string>("filename"), pt.get<std::size_t>("frames_number"))}; - } else if (type == "pupil" || type == "edge" || type == "pupil_scan" || type == "edge_scan" || type == "pupil_mask") { - const auto frames_number = pt.get<std::size_t>("frames_number"); - const auto samples_number = pt.get<std::size_t>("samples_number", 60); - const auto force_initial = pt.get<bool>("force_initial", true); - - if (type == "pupil") { - return std::unique_ptr<executor>{new pupil_executor(frames_number, samples_number, force_initial)}; - } else if (type == "pupil_scan") { - return std::unique_ptr<executor>{new pupil_scan_executor(frames_number, samples_number, force_initial)}; - } else if (type == "edge" || type == "edge_scan") { - const auto loss_factor = pt.get<float>("loss_factor"); - - if (type == "edge") { - return std::unique_ptr<executor>{new edge_executor(frames_number, samples_number, force_initial, loss_factor)}; - } else if (type == "edge_scan") { - return std::unique_ptr<executor>{new edge_scan_executor(frames_number, samples_number, force_initial, loss_factor)}; - } - } else if (type == "pupil_mask") { - return std::unique_ptr<executor>{new pupil_mask_executor(pt.get<std::string>("filename"), frames_number, samples_number, force_initial)}; - } else if (type == "mean_pupil_mask") { - return std::unique_ptr<executor>{new mean_pupil_mask_executor(pt.get<std::string>("filename"), frames_number, samples_number)}; - } - } else if (type == "mean_raw") { - return std::unique_ptr<executor>{new mean_raw_executor(pt.get<std::string>("filename"), pt.get<std::size_t>("frames_number"))}; - } else if (type == "gain") { - return std::unique_ptr<executor>{new gain_executor(pt.get<std::string>("filename"), pt.get<std::size_t>("pairs_number"), pt.get<float>("exposure_step_scale"), pt.get<float>("exposure_step_bias"))}; - } else if (type == "carriage_run") { - return std::unique_ptr<executor>{new carriage_run_executor( - pt.get<std::uint16_t>("axis"), - pt.get<std::int16_t>("position"))}; - } else if (type == "carriage_track") { - return std::unique_ptr<executor>{new carriage_track_executor( - pt.get<std::uint16_t>("axis"), - load<abstract_carriage::direction>(pt.get_child("direction")))}; - } else if (type == "carriage_home") { - return std::unique_ptr<executor>{new carriage_home_executor( - pt.get<std::uint16_t>("axis"))}; - } else if (type == "clean" || type == "normalized_clean" || type == "relative_clean" || type == "acf") { - const auto& filename = pt.get<std::string>("filename"); - const auto& frames_number = pt.get<std::size_t>("frames_number"); - const auto& bias_filename = pt.get<std::string>("bias_filename");
View file
domecam-0.1.9.obscpio/include/iofwd.h -> domecam-0.1.10.obscpio/include/iofwd.h
Changed
@@ -7,66 +7,55 @@ #ifndef _IOFWD_H #define _IOFWD_H +#include <fstream> +#include <string_view> #include <optional> -#include <sstream> #include <utility> // std::forward -#include <boost/property_tree/ptree.hpp> -#include <boost/property_tree/json_parser.hpp> +#include <boost/filesystem.hpp> +#include <boost/json.hpp> -namespace detail { -template<class T> struct load_impl; -template<class T> struct save_impl; -// load1 -template<class T, class... Args> -inline auto load1(const boost::property_tree::ptree& pt, int, Args&&... args) -> - decltype(detail::load_impl<T>::load_(pt, std::forward<Args>(args)...)) { - return detail::load_impl<T>::load_(pt, std::forward<Args>(args)...); -} template<class T> -inline auto load1(const boost::property_tree::ptree& pt, ...) -> - decltype(pt.get_value<T>()) { - return pt.get_value<T>(); +auto load(const boost::json::value& jv) { + return boost::json::value_to<T>(jv); } -} // detail -template<class T, class... Args> inline auto load(const boost::property_tree::ptree& pt, Args&&... args) -> - decltype(detail::load1<T>(pt, static_cast<int>(0), std::forward<Args>(args)...)) { - return detail::load1<T>(pt, static_cast<int>(0), std::forward<Args>(args)...); +template<class T> +auto load(const boost::json::value* jv) { + return (jv == nullptr ? std::nullopt : std::optional(load<T>(*jv))); } -template<class T, class... Args> inline auto load(const boost::optional<const boost::property_tree::ptree&>& pt, Args&&... args) -> - std::optional<decltype(detail::load1<T>(*pt, static_cast<int>(0), std::forward<Args>(args)...))> { - typedef std::optional<decltype(detail::load1<T>(*pt, static_cast<int>(0), std::forward<Args>(args)...))> return_type; - if (pt) { - return return_type(detail::load1<T>(*pt, static_cast<int>(0), std::forward<Args>(args)...)); - } - return return_type(); +template<class T> +auto save(T&& t) { + return boost::json::value_from(std::forward<T>(t)); } -template<class T, class Source, class... Args> inline auto load_json(Source&& source, Args&&... args) -> - decltype(load<T>(std::declval<boost::property_tree::ptree>(), std::forward<Args>(args)...)) { - - using namespace boost::property_tree; +template<class T> +auto load_json(std::string_view sv) { + using boost::json::parse; - ptree pt; - read_json(std::forward<Source>(source), pt); - return load<T>(pt, std::forward<Args>(args)...); +#ifndef BOOST_JSON_STANDALONE + return load<T>(parse(boost::json::string_view{sv.data(), sv.size()})); +#else + return load<T>(parse(sv)); +#endif // BOOST_JSON_STANDALONE } -template<class T, class... Args> inline auto save(const T& x, Args&&... args) -> - decltype(detail::save_impl<T>::save(x, std::forward<Args>(args)...)) { - return detail::save_impl<T>::save(x, std::forward<Args>(args)...); -} +template<class T> +auto load_json(const boost::filesystem::path& path) -> + decltype(load_json<T>(std::string())) { -template<class T, class... Args> inline std::string save_json(const T& x, Args&&... args) { - using namespace boost::property_tree; + using char_type = typename std::string::value_type; - std::ostringstream oss{}; - write_json(oss, save(x, std::forward<Args>(args)...)); + std::ifstream ifs(path.string()); + std::string input(std::istreambuf_iterator<char_type>(ifs), {}); + return load_json<T>(std::string_view{input}); +} - return oss.str(); +template<class T> +auto save_json(T&& t) { + return boost::json::serialize(save(std::forward<T>(t))); } #endif // _IOFWD_H
View file
domecam-0.1.9.obscpio/src/executor/edge.cpp -> domecam-0.1.10.obscpio/src/executor/edge.cpp
Changed
@@ -14,6 +14,14 @@ #include <quadfit.h> +void tag_invoke(boost::json::value_from_tag, boost::json::value& jv, const edge_executor_base::runner_result& r) { + jv = { + {"entropy", + {"mean", r.entropy_mean}, + {"error", r.entropy_error}}, + {"focus", r.focus}}; +} + std::ostream& operator<<(std::ostream& stm, const edge_executor_base::runner_result& s) { stm << "Statistics:" << std::endl << "Mean: " << s.entropy_mean << std::endl
View file
domecam-0.1.9.obscpio/src/executor/mean_pupil_mask.cpp -> domecam-0.1.10.obscpio/src/executor/mean_pupil_mask.cpp
Changed
@@ -5,6 +5,24 @@ */ #include <executor/mean_pupil_mask.h> +#include <iofwd.h> + + +void tag_invoke(boost::json::value_from_tag, boost::json::value& jv, const mean_pupil_mask_executor_base::runner_result& r) { + using boost::json::value_from; + + jv = { + {"center", {{"mean", value_from(r.center_mean)}}}, + {"radius", {{"mean", value_from(r.radius_mean)}}}}; +} + +std::ostream& operator<<(std::ostream& stm, const mean_pupil_mask_executor_base::runner_result& s) { + stm << "Statistics:" << std::endl + << "Center\tX\tY\tRadius" << std::endl + << "Mean: " << std::get<0>(s.center_mean) << " " << std::get<1>(s.center_mean) << " " << s.radius_mean << std::endl; + + return stm; +} mean_pupil_mask_executor_base::mean_pupil_mask_executor_base(const std::string& target_uri, std::size_t samples_number): @@ -20,9 +38,7 @@ executor_result mean_pupil_mask_executor::run(camera& c) const { runner<source_mixin> r{*this, c}; - r.run(); - - return {}; + return r.run(); } @@ -31,7 +47,5 @@ mean_pupil_mask_executor_base(target_uri, samples_number) {} executor_result mean_pupil_mask_replay_executor::run(const fits::variant_image& vi) const { - vi.apply(runner_visitor<runner_type, mean_pupil_mask_replay_executor>{*this}); - - return {}; + return vi.apply(runner_visitor<runner_type, mean_pupil_mask_replay_executor, runner_result>{*this}); }
View file
domecam-0.1.9.obscpio/src/executor/pupil.cpp -> domecam-0.1.10.obscpio/src/executor/pupil.cpp
Changed
@@ -5,8 +5,22 @@ */ #include <executor/pupil.h> +#include <iofwd.h> +void tag_invoke(boost::json::value_from_tag, boost::json::value& jv, const pupil_executor_base::runner_result& r) { + using boost::json::value_from; + + jv = { + {"center", { + {"mean", value_from(r.center_mean)}, + {"error", value_from(r.center_error)}}}, + {"radius", { + {"mean", value_from(r.radius_mean)}, + {"error", value_from(r.radius_error)}}}, + {"drift", value_from(r.drift)}}; +} + std::ostream& operator<<(std::ostream& stm, const pupil_executor_base::runner_result& s) { stm << "Statistics:" << std::endl << "Center\tX\tY\tRadius" << std::endl
View file
domecam-0.1.9.obscpio/src/executor_result.cpp -> domecam-0.1.10.obscpio/src/executor_result.cpp
Changed
@@ -14,6 +14,11 @@ executor_result::executor_result(): impl_{nullptr} {} +void executor_result::value_from(boost::json::value& jv) const { + if (impl_) + impl_->value_from(jv); +} + std::ostream& executor_result::print(std::ostream& stm) const { return impl_ ? impl_->print(stm) : stm; }
View file
domecam-0.1.10.obscpio/src/io.cpp
Added
@@ -0,0 +1,193 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Copyright (C) 2017-2022 Matwey V. Kornilov <matwey.kornilov@gmail.com> + */ + +#include <io.h> + +abstract_carriage::direction tag_invoke(boost::json::value_to_tag<abstract_carriage::direction>, const boost::json::value& jv) { + using boost::json::value_to; + + const auto& direction = jv.as_string(); + + if (direction == "cw" || direction == "forward") { + return abstract_carriage::direction::cw; + } else if (direction == "ccw" || direction == "backward") { + return abstract_carriage::direction::ccw; + } + + throw std::runtime_error(std::string("Unknown direction type ") + direction.c_str()); +} + +std::unique_ptr<executor> tag_invoke(boost::json::value_to_tag<std::unique_ptr<executor>>, const boost::json::value& jv) { + using boost::json::value_to; + + const auto& obj = jv.as_object(); + const auto& type = obj.at("type").as_string(); + + if (type == "raw") { + return std::unique_ptr<executor>{new raw_executor{ + value_to<std::string>(obj.at("filename")), + value_to<std::size_t>(obj.at("frames_number"))}}; + } else if (type == "raw_scan") { + return std::unique_ptr<executor>{new raw_scan_executor{ + value_to<std::string>(obj.at("filename")), + value_to<std::size_t>(obj.at("frames_number"))}}; + } else if (type == "grad") { + return std::unique_ptr<executor>{new grad_executor{ + value_to<std::string>(obj.at("filename")), + value_to<std::size_t>(obj.at("frames_number"))}}; + } else if (type == "binary") { + return std::unique_ptr<executor>{new binary_executor{ + value_to<std::string>(obj.at("filename")), + value_to<std::size_t>(obj.at("frames_number"))}}; + } else if (type == "pupil" || type == "edge" || type == "pupil_scan" || type == "edge_scan" || type == "pupil_mask" || type == "mean_pupil_mask") { + const auto frames_number = value_to<std::size_t>(obj.at("frames_number")); + const auto samples_number = load<std::size_t>(obj.if_contains("samples_number")).value_or(60); + const auto force_initial = load<bool>(obj.if_contains("force_initial")).value_or(true); + + if (type == "pupil") { + return std::unique_ptr<executor>{new pupil_executor{frames_number, samples_number, force_initial}}; + } else if (type == "pupil_scan") { + return std::unique_ptr<executor>{new pupil_scan_executor{frames_number, samples_number, force_initial}}; + } else if (type == "edge" || type == "edge_scan") { + const auto loss_factor = value_to<float>(obj.at("loss_factor")); + + if (type == "edge") { + return std::unique_ptr<executor>{new edge_executor{frames_number, samples_number, force_initial, loss_factor}}; + } else if (type == "edge_scan") { + return std::unique_ptr<executor>{new edge_scan_executor{frames_number, samples_number, force_initial, loss_factor}}; + } + } else if (type == "pupil_mask") { + return std::unique_ptr<executor>{new pupil_mask_executor{ + value_to<std::string>(obj.at("filename")), + frames_number, samples_number, force_initial}}; + } else if (type == "mean_pupil_mask") { + return std::unique_ptr<executor>{new mean_pupil_mask_executor{ + value_to<std::string>(obj.at("filename")), + frames_number, samples_number}}; + } + } else if (type == "mean_raw") { + return std::unique_ptr<executor>{new mean_raw_executor{ + value_to<std::string>(obj.at("filename")), + value_to<std::size_t>(obj.at("frames_number"))}}; + } else if (type == "gain") { + return std::unique_ptr<executor>{new gain_executor{ + value_to<std::string>(obj.at("filename")), + value_to<std::size_t>(obj.at("pairs_number")), + value_to<float>(obj.at("exposure_step_scale")), + value_to<float>(obj.at("exposure_step_bias"))}}; + } else if (type == "carriage_run") { + return std::unique_ptr<executor>{new carriage_run_executor{ + value_to<std::uint16_t>(obj.at("axis")), + value_to<std::int16_t>(obj.at("position"))}}; + } else if (type == "carriage_track") { + return std::unique_ptr<executor>{new carriage_track_executor{ + value_to<std::uint16_t>(obj.at("axis")), + value_to<abstract_carriage::direction>(obj.at("direction"))}}; + } else if (type == "carriage_home") { + return std::unique_ptr<executor>{new carriage_home_executor{ + value_to<std::uint16_t>(obj.at("axis"))}}; + } else if (type == "clean" || type == "normalized_clean" || type == "relative_clean" || type == "acf") { + const auto& filename = value_to<std::string>(obj.at("filename")); + const auto& frames_number = value_to<std::size_t>(obj.at("frames_number")); + const auto& bias_filename = value_to<std::string>(obj.at("bias_filename")); + const auto& mask_filename = value_to<std::string>(obj.at("mask_filename")); + + if (type == "clean") { + return std::unique_ptr<executor>{new clean_executor{filename, frames_number, bias_filename, mask_filename}}; + } else if (type == "normalized_clean") { + return std::unique_ptr<executor>{new normalized_clean_executor{filename, frames_number, bias_filename, mask_filename}}; + } else if (type == "relative_clean" || type == "acf") { + const auto& pupil_filename = value_to<std::string>(obj.at("pupil_filename")); + + if (type == "relative_clean") { + return std::unique_ptr<executor>{new relative_clean_executor{filename, frames_number, bias_filename, pupil_filename, mask_filename}}; + } else if (type == "acf") { + const auto grid_size = value_to<std::size_t>(obj.at("grid_size")); + + return std::unique_ptr<executor>{new acf_executor{filename, frames_number, bias_filename, pupil_filename, mask_filename, grid_size}}; + } + } + } + + throw std::runtime_error(std::string("Unknown executor type ") + type.c_str()); +} + +optional_camera_settings::packet_size_type tag_invoke(boost::json::value_to_tag<optional_camera_settings::packet_size_type>, const boost::json::value& jv) { + using boost::json::value_to; + + if (jv.is_string() && jv.get_string() == "auto") { + return optional_camera_settings::auto_tag{}; + } + + return value_to<camera_settings::packet_size_type>(jv); +} + +camera_settings::region_type tag_invoke(boost::json::value_to_tag<camera_settings::region_type>, const boost::json::value& jv) { + using boost::json::value_to; + + const auto& obj = jv.as_object(); + + return camera_settings::region_type{ + value_to<std::array<std::int32_t, 2>>(obj.at("offset")), + value_to<std::array<std::int32_t, 2>>(obj.at("size"))}; +} + +optional_camera_settings::region_type tag_invoke(boost::json::value_to_tag<optional_camera_settings::region_type>, const boost::json::value& jv) { + using boost::json::value_to; + + if (jv.is_string() && jv.get_string() == "full") { + return optional_camera_settings::full_tag{}; + } + + return value_to<camera_settings::region_type>(jv); +} + +optional_camera_settings tag_invoke(boost::json::value_to_tag<optional_camera_settings>, const boost::json::value& jv) { + using boost::json::value_to; + + const auto& obj = jv.as_object(); + + auto binning = load<optional_camera_settings::binning_type>(obj.if_contains("binning")); + if (!binning && (obj.contains("binning_x") || obj.contains("binning_y"))) { + using value_type = camera::binning_type::value_type; + + const auto x = value_to<value_type>(obj.at("binning_x")); + const auto y = value_to<value_type>(obj.at("binning_y")); + binning = camera::binning_type{x, y}; + } + + return optional_camera_settings{ + binning, + load<optional_camera_settings::exposure_time_type>(obj.if_contains("exposure_time")), + load<optional_camera_settings::frame_rate_type>(obj.if_contains("frame_rate")), + load<optional_camera_settings::gain_type>(obj.if_contains("gain")), + load<optional_camera_settings::packet_size_type>(obj.if_contains("packet_size")), + load<optional_camera_settings::region_type>(obj.if_contains("region")), + {} // configuring pixel_format is not supported atm + }; +} + +camera tag_invoke(boost::json::value_to_tag<camera>, const boost::json::value& jv) { + using boost::json::value_to; + + const auto& obj = jv.as_object(); + const auto it = obj.find("id"); + const auto id = value_to<std::string>(it != obj.end() ? it->value() : obj.at("name")); + camera cam(id); + + const optional_camera_settings default_settings{ + camera_settings::binning_type{2, 2}, + camera_settings::exposure_time_type{10000}, + 100.0, + 0.0, + optional_camera_settings::packet_size_type{optional_camera_settings::auto_tag{}}, + optional_camera_settings::region_type{optional_camera_settings::full_tag{}}, + ARV_PIXEL_FORMAT_MONO_12}; + + value_to<optional_camera_settings>(obj.at("settings")).or_else(default_settings).apply_to(cam); + + return cam; +};
View file
domecam.obsinfo
Changed
@@ -1,3 +1,3 @@ name: domecam -version: 0.1.9 -mtime: 1664537478 +version: 0.1.10 +mtime: 1665326936
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.