From 7943d5e85abfb7d514d0debbf56c5fa98640bcd5 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Fri, 27 Oct 2023 17:45:59 +0800 Subject: [PATCH] update pre --- locale/lithium.pot | 162 ++--- locale/po/en_US.UTF-8/lithium.po | 40 +- src/LithiumApp.cpp | 11 + src/LithiumApp.hpp | 31 +- src/client/ascom/ascom_camera.cpp | 6 +- src/client/ascom/ascom_camera.hpp | 6 +- src/client/ascom/ascom_device.cpp | 6 +- src/client/ascom/ascom_device.hpp | 6 +- src/client/hydrogen/hydrogencamera.cpp | 792 ++++++++++------------ src/client/hydrogen/hydrogencamera.hpp | 233 ++++--- src/core/base/hydrogendevapi.cpp | 4 +- src/core/base/hydrogendevapis.cpp | 82 +++ src/core/base/hydrogendevapis.hpp | 59 ++ src/core/camera.cpp | 6 +- src/core/camera.hpp | 31 +- src/core/device.hpp | 12 +- src/core/filterwheel.cpp | 6 +- src/core/filterwheel.hpp | 6 +- src/core/focuser.cpp | 6 +- src/core/focuser.hpp | 6 +- src/core/guider.cpp | 6 +- src/core/guider.hpp | 6 +- src/core/solver.cpp | 6 +- src/core/solver.hpp | 6 +- src/core/telescope.cpp | 6 +- src/core/telescope.hpp | 6 +- src/modules/client/indiclient.hpp | 2 - src/modules/device/device_manager.cpp | 15 +- src/modules/error/error_code.hpp | 2 +- src/modules/io/compress.cpp | 8 +- src/modules/module/compiler.cpp | 2 +- src/modules/web/utils.cpp | 6 +- src/websocket/device/WsDeviceInstance.cpp | 5 + src/websocket/device/WsDeviceInstance.hpp | 140 +++- 34 files changed, 955 insertions(+), 772 deletions(-) create mode 100644 src/core/base/hydrogendevapis.cpp create mode 100644 src/core/base/hydrogendevapis.hpp diff --git a/locale/lithium.pot b/locale/lithium.pot index 6f7a3ab0..597c3aee 100644 --- a/locale/lithium.pot +++ b/locale/lithium.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Lithium \n" "Report-Msgid-Bugs-To: astro_air@126.com\n" -"POT-Creation-Date: 2023-10-19 02:44+0000\n" +"POT-Creation-Date: 2023-10-20 23:53+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,275 +17,251 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: /workspaces/Lithium/src/modules/device/device_manager.cpp:163 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:161 msgid "A device with name {} already exists, please choose a different name" msgstr "" -#: /workspaces/Lithium/src/modules/device/device_manager.cpp:190 -msgid "Trying to add a new camera instance : {}" -msgstr "" - -#: /workspaces/Lithium/src/modules/device/device_manager.cpp:192 -msgid "Added new camera {} instance successfully" -msgstr "" - -#: /workspaces/Lithium/src/modules/device/device_manager.cpp:197 -msgid "Trying to add a new telescope instance : {}" -msgstr "" - -#: /workspaces/Lithium/src/modules/device/device_manager.cpp:199 -msgid "Added new telescope instance successfully" -msgstr "" - -#: /workspaces/Lithium/src/modules/device/device_manager.cpp:204 -msgid "Trying to add a new Focuser instance : {}" -msgstr "" - -#: /workspaces/Lithium/src/modules/device/device_manager.cpp:206 -msgid "Added new focuser instance successfully" -msgstr "" - -#: /workspaces/Lithium/src/modules/device/indidevice_manager.cpp:266 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/indidevice_manager.cpp:266 msgid "Failed to run command: {}" msgstr "" -#: /workspaces/Lithium/src/modules/thread/thread.cpp:63 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:63 msgid "Failed to destroy ThreadManager: {}" msgstr "" -#: /workspaces/Lithium/src/modules/thread/thread.cpp:82 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:82 msgid "Thread manager has stopped, cannot add new thread" msgstr "" -#: /workspaces/Lithium/src/modules/thread/thread.cpp:100 -#: /workspaces/Lithium/src/modules/thread/thread.cpp:122 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:100 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:122 msgid "Unhandled exception in thread: {}" msgstr "" -#: /workspaces/Lithium/src/modules/thread/thread.cpp:128 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:128 msgid "Added thread: {}" msgstr "" -#: /workspaces/Lithium/src/modules/thread/thread.cpp:133 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:133 msgid "Failed to add thread {}: {}" msgstr "" -#: /workspaces/Lithium/src/modules/thread/thread.cpp:149 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:149 msgid "All threads joined" msgstr "" -#: /workspaces/Lithium/src/modules/thread/thread.cpp:153 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:153 msgid "Failed to join all threads: {}" msgstr "" -#: /workspaces/Lithium/src/modules/thread/thread.cpp:163 -#: /workspaces/Lithium/src/modules/thread/thread.cpp:180 -#: /workspaces/Lithium/src/modules/thread/thread.cpp:194 -#: /workspaces/Lithium/src/modules/thread/thread.cpp:205 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:163 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:180 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:194 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:205 msgid "Thread {} not found" msgstr "" -#: /workspaces/Lithium/src/modules/thread/thread.cpp:172 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:172 msgid "Thread {} joined" msgstr "" -#: /workspaces/Lithium/src/modules/thread/thread.cpp:184 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:184 msgid "Failed to join thread {}: {}" msgstr "" -#: /workspaces/Lithium/src/modules/thread/thread.cpp:210 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:210 msgid "Failed to check if thread {} is running: {}" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:75 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:75 msgid "Failed to create PowerShell process" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:85 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:85 msgid "Running command: {}" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:98 -#: /workspaces/Lithium/src/modules/system/process.cpp:122 -#: /workspaces/Lithium/src/modules/system/process.cpp:143 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:98 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:122 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:143 msgid "Failed to create process" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:108 -#: /workspaces/Lithium/src/modules/system/process.cpp:153 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:108 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:153 msgid "Process created: {} (PID: {})" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:132 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:132 msgid "Running script: {}" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:170 -#: /workspaces/Lithium/src/modules/system/process.cpp:182 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:170 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:182 msgid "Process terminated: {} (PID: {})" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:174 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:174 msgid "Failed to terminate process" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:190 -#: /workspaces/Lithium/src/modules/system/process.cpp:246 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:190 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:246 msgid "Process not found" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:205 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:205 msgid "Process not found by name: {}" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:212 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:212 msgid "Currently running processes:" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:216 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:216 msgid "{} (PID: {})" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:261 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:261 msgid "Process completed: {} (PID: {})" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:265 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:265 msgid "Failed to wait for process completion" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:271 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:271 #, c-format msgid "Process completed: %s (PID: %d)" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:276 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:276 msgid "All processes completed." msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:287 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:287 msgid "Failed to create process snapshot" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:328 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:328 msgid "Failed to open /proc directory" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:357 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:357 msgid "Failed to get process path" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:378 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:378 msgid "Failed to get process info length" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:385 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:385 msgid "Failed to allocate memory" msgstr "" -#: /workspaces/Lithium/src/modules/system/process.cpp:391 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:391 msgid "Failed to get process info" msgstr "" -#: /workspaces/Lithium/src/modules/system/pid.cpp:94 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:94 msgid "CreateToolhelp32Snapshot failed." msgstr "" -#: /workspaces/Lithium/src/modules/system/pid.cpp:113 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:113 msgid "Watching process with PID: {}" msgstr "" -#: /workspaces/Lithium/src/modules/system/pid.cpp:124 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:124 msgid "Process exited with code: {}" msgstr "" -#: /workspaces/Lithium/src/modules/system/pid.cpp:133 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:133 msgid "GetExitCodeProcess failed." msgstr "" -#: /workspaces/Lithium/src/modules/system/pid.cpp:143 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:143 msgid "OpenProcess failed." msgstr "" -#: /workspaces/Lithium/src/modules/system/pid.cpp:170 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:170 msgid "Process exited with status: {}" msgstr "" -#: /workspaces/Lithium/src/modules/system/pid.cpp:179 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:179 msgid "Process terminated by signal: {}" msgstr "" -#: /workspaces/Lithium/src/App.cpp:223 +#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:223 msgid "port the server running on" msgstr "" -#: /workspaces/Lithium/src/App.cpp:224 +#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:224 msgid "host the server running on" msgstr "" -#: /workspaces/Lithium/src/App.cpp:225 +#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:225 msgid "path to the config file" msgstr "" -#: /workspaces/Lithium/src/App.cpp:226 +#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:226 msgid "path to the modules directory" msgstr "" -#: /workspaces/Lithium/src/App.cpp:227 +#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:227 msgid "web panel" msgstr "" -#: /workspaces/Lithium/src/App.cpp:228 +#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:228 msgid "path to log file" msgstr "" -#: /workspaces/Lithium/src/App.cpp:230 +#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:230 msgid "Lithium Command Line Interface:" msgstr "" -#: /workspaces/Lithium/src/App.cpp:231 +#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:231 msgid "End." msgstr "" -#: /workspaces/Lithium/src/App.cpp:239 +#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:239 #, c-format msgid "Failed to parser command line : %s" msgstr "" -#: /workspaces/Lithium/src/App.cpp:260 +#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:260 #, c-format msgid "Command line server port : %d" msgstr "" -#: /workspaces/Lithium/src/App.cpp:266 +#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:266 #, c-format msgid "Set server port to %d" msgstr "" -#: /workspaces/Lithium/src/LithiumApp.cpp:67 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:70 msgid "Failed to load Lithium App , error : {}" msgstr "" -#: /workspaces/Lithium/src/LithiumApp.cpp:79 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:82 msgid "Get config value: {}" msgstr "" -#: /workspaces/Lithium/src/LithiumApp.cpp:85 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:88 msgid "Set {} to {}" msgstr "" -#: /workspaces/Lithium/src/LithiumApp.cpp:272 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:275 msgid "Failed to run chai command : {}" msgstr "" -#: /workspaces/Lithium/src/LithiumApp.cpp:290 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:293 msgid "Failed to run chai multi command {}" msgstr "" -#: /workspaces/Lithium/src/LithiumApp.cpp:303 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:306 msgid "Failed to load chaiscript file {}" msgstr "" -#: /workspaces/Lithium/src/LithiumApp.cpp:316 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:319 msgid "Failed to run chai script {}" msgstr "" diff --git a/locale/po/en_US.UTF-8/lithium.po b/locale/po/en_US.UTF-8/lithium.po index 44c660cc..7bf095a3 100644 --- a/locale/po/en_US.UTF-8/lithium.po +++ b/locale/po/en_US.UTF-8/lithium.po @@ -1,31 +1,7 @@ -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:163 +#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:161 msgid "A device with name {} already exists, please choose a different name" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:190 -msgid "Trying to add a new camera instance : {}" -msgstr "" - -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:192 -msgid "Added new camera {} instance successfully" -msgstr "" - -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:197 -msgid "Trying to add a new telescope instance : {}" -msgstr "" - -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:199 -msgid "Added new telescope instance successfully" -msgstr "" - -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:204 -msgid "Trying to add a new Focuser instance : {}" -msgstr "" - -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:206 -msgid "Added new focuser instance successfully" -msgstr "" - #: E:/msys64/home/Qrm/OpenAPT/src/modules/device/indidevice_manager.cpp:266 msgid "Failed to run command: {}" msgstr "" @@ -243,30 +219,30 @@ msgstr "" msgid "Set server port to %d" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:67 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:70 msgid "Failed to load Lithium App , error : {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:79 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:82 msgid "Get config value: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:85 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:88 msgid "Set {} to {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:272 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:275 msgid "Failed to run chai command : {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:290 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:293 msgid "Failed to run chai multi command {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:303 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:306 msgid "Failed to load chaiscript file {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:316 +#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:319 msgid "Failed to run chai script {}" msgstr "" diff --git a/src/LithiumApp.cpp b/src/LithiumApp.cpp index 654316b8..1de7df72 100644 --- a/src/LithiumApp.cpp +++ b/src/LithiumApp.cpp @@ -32,6 +32,17 @@ Description: Lithium App Enter #include "LithiumApp.hpp" #include "config.h" +#include "modules/thread/thread.hpp" +#include "modules/config/configor.hpp" +#include "modules/device/device_manager.hpp" +#include "modules/system/process.hpp" +#include "modules/task/task_manager.hpp" +#include "modules/task/task_generator.hpp" +#include "modules/task/task_stack.hpp" +#include "core/property/iproperty.hpp" +#include "modules/plugin/plugin_manager.hpp" +#include "modules/script/script_manager.hpp" + #include "loguru/loguru.hpp" #include "nlohmann/json.hpp" diff --git a/src/LithiumApp.hpp b/src/LithiumApp.hpp index 5f75e956..6ae8b486 100644 --- a/src/LithiumApp.hpp +++ b/src/LithiumApp.hpp @@ -35,20 +35,31 @@ Description: Lithium App Enter #include -#include "modules/thread/thread.hpp" -#include "modules/config/configor.hpp" -#include "modules/device/device_manager.hpp" -#include "modules/system/process.hpp" -#include "modules/task/task_manager.hpp" -#include "modules/task/task_generator.hpp" -#include "modules/task/task_stack.hpp" + #include "modules/server/message_bus.hpp" -#include "core/property/iproperty.hpp" -#include "modules/plugin/plugin_manager.hpp" -#include "modules/script/script_manager.hpp" + namespace Lithium { + namespace Thread + { + class ThreadManager; + } + + namespace Config + { + class ConfigManager; + } + + class DeviceManager; + class ScriptManager; + + namespace Process + { + class ProcessManager; + } + + class LithiumApp { diff --git a/src/client/ascom/ascom_camera.cpp b/src/client/ascom/ascom_camera.cpp index e67f0eb1..4817eb46 100644 --- a/src/client/ascom/ascom_camera.cpp +++ b/src/client/ascom/ascom_camera.cpp @@ -12,17 +12,17 @@ ASCOMCamera::~ASCOMCamera() DLOG_F(INFO, "ASCOMCamera Simulator Destructed"); } -bool ASCOMCamera::connect(const IParams ¶ms) +bool ASCOMCamera::connect(const nlohmann::json ¶ms) { return ASCOMDevice::connect(params); } -bool ASCOMCamera::disconnect(const IParams ¶ms) +bool ASCOMCamera::disconnect(const nlohmann::json ¶ms) { return ASCOMDevice::disconnect(params); } -bool ASCOMCamera::reconnect(const IParams ¶ms) +bool ASCOMCamera::reconnect(const nlohmann::json ¶ms) { return ASCOMDevice::reconnect(params); } diff --git a/src/client/ascom/ascom_camera.hpp b/src/client/ascom/ascom_camera.hpp index 88ecd2cf..be29efcd 100644 --- a/src/client/ascom/ascom_camera.hpp +++ b/src/client/ascom/ascom_camera.hpp @@ -10,9 +10,9 @@ class ASCOMCamera : public Camera, public ASCOMDevice ~ASCOMCamera(); public: - virtual bool connect(const IParams ¶ms) override; - virtual bool disconnect(const IParams ¶ms) override; - virtual bool reconnect(const IParams ¶ms) override; + virtual bool connect(const nlohmann::json ¶ms) override; + virtual bool disconnect(const nlohmann::json ¶ms) override; + virtual bool reconnect(const nlohmann::json ¶ms) override; public: virtual bool startExposure(const nlohmann::json ¶ms) override; diff --git a/src/client/ascom/ascom_device.cpp b/src/client/ascom/ascom_device.cpp index f309a186..50c99297 100644 --- a/src/client/ascom/ascom_device.cpp +++ b/src/client/ascom/ascom_device.cpp @@ -61,7 +61,7 @@ void ASCOMDevice::setBasicInfo(const std::string &address, const std::string &de #endif } -bool ASCOMDevice::connect(const IParams ¶ms) +bool ASCOMDevice::connect(const nlohmann::json ¶ms) { if (getConnected()) { @@ -78,7 +78,7 @@ bool ASCOMDevice::connect(const IParams ¶ms) return true; } -bool ASCOMDevice::disconnect(const IParams ¶ms) +bool ASCOMDevice::disconnect(const nlohmann::json ¶ms) { if (!getConnected()) { @@ -94,7 +94,7 @@ bool ASCOMDevice::disconnect(const IParams ¶ms) return true; } -bool ASCOMDevice::reconnect(const IParams ¶ms) +bool ASCOMDevice::reconnect(const nlohmann::json ¶ms) { if (!disconnect(params)) { diff --git a/src/client/ascom/ascom_device.hpp b/src/client/ascom/ascom_device.hpp index 00da88ef..bbb8cc2c 100644 --- a/src/client/ascom/ascom_device.hpp +++ b/src/client/ascom/ascom_device.hpp @@ -55,9 +55,9 @@ class ASCOMDevice : virtual public Device void setBasicInfo(const std::string &address, const std::string &device_type, const int &device_number); - virtual bool connect(const IParams ¶ms) override; - virtual bool disconnect(const IParams ¶ms) override; - virtual bool reconnect(const IParams ¶ms) override; + virtual bool connect(const nlohmann::json ¶ms) override; + virtual bool disconnect(const nlohmann::json ¶ms) override; + virtual bool reconnect(const nlohmann::json ¶ms) override; public: const std::string action(const std::string &action_name, const std::vector ¶meters); diff --git a/src/client/hydrogen/hydrogencamera.cpp b/src/client/hydrogen/hydrogencamera.cpp index de6a510a..ea76a797 100644 --- a/src/client/hydrogen/hydrogencamera.cpp +++ b/src/client/hydrogen/hydrogencamera.cpp @@ -33,9 +33,197 @@ Description: Hydorgen Camera #include "loguru/loguru.hpp" +HydrogenCamera::HydrogenCamera(const std::string &name) : Camera(name) +{ +} + +HydrogenCamera::~HydrogenCamera() +{ +} + +bool HydrogenCamera::connect(const nlohmann::json ¶ms) +{ + std::string name = params["name"]; + std::string hostname = params["host"]; + int port = params["port"]; + DLOG_F(INFO, "Trying to connect to {}", name); + setServer(hostname.c_str(), port); + // Receive messages only for our camera. + watchDevice(name.c_str()); + // Connect to server. + if (connectServer()) + { + DLOG_F(INFO, "{}: connectServer done ready", getDeviceName()); + connectDevice(name.c_str()); + return !is_ready.load(); + } + return false; +} + +bool HydrogenCamera::disconnect(const nlohmann::json ¶ms) +{ + DLOG_F(INFO, "%s is disconnected", getDeviceName()); + return true; +} + +bool HydrogenCamera::reconnect(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::isConnected() +{ + return true; +} + +bool HydrogenCamera::startExposure(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::abortExposure(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::getExposureStatus(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::getExposureResult(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::saveExposureResult(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::startVideo(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::stopVideo(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::getVideoStatus(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::getVideoResult(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::saveVideoResult(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::startCooling(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::stopCooling(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::isCoolingAvailable() +{ + return true; +} + +bool HydrogenCamera::getTemperature(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::getCoolingPower(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::setTemperature(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::setCoolingPower(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::getGain(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::setGain(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::isGainAvailable() +{ + return true; +} + +bool HydrogenCamera::getOffset(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::setOffset(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::isOffsetAvailable() +{ + return true; +} + +bool HydrogenCamera::getISO(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::setISO(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::isISOAvailable() +{ + return true; +} + +bool HydrogenCamera::getFrame(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::setFrame(const nlohmann::json ¶ms) +{ + return true; +} + +bool HydrogenCamera::isFrameSettingAvailable() +{ + return true; +} + void HydrogenCamera::newDevice(HYDROGEN::BaseDevice *dp) { - if (strcmp(dp->getDeviceName(), devicegetDeviceName().c_str()) == 0) + if (strcmp(dp->getDeviceName(), getDeviceName().c_str()) == 0) { camera_device = dp; } @@ -49,20 +237,19 @@ void HydrogenCamera::newSwitch(ISwitchVectorProperty *svp) if (name == "CONNECTION") { + connection_prop.reset(svp); if (auto connectswitch = IUFindSwitch(svp, "CONNECT"); connectswitch->s == ISS_ON) { setProperty("connect", true); - device_info["connect"] = true; is_connected.store(true); DLOG_F(INFO, "{} is connected", getDeviceName()); } else { - if (is_ready) + if (is_ready.load()) { ClearStatus(); setProperty("connect", false); - device_info["connect"] = false; is_connected.store(true); DLOG_F(INFO, "{} is disconnected", getDeviceName()); } @@ -70,21 +257,23 @@ void HydrogenCamera::newSwitch(ISwitchVectorProperty *svp) } else if (name == "DEBUG") { + debug_prop.reset(svp); if (auto debugswitch = IUFindSwitch(svp, "ENABLE"); debugswitch->s == ISS_ON) { setProperty("debug", true); - device_info["debug"] = true; + is_debug.store(true); DLOG_F(INFO, "DEBUG mode of {} is enabled", getDeviceName()); } else { setProperty("debug", false); - device_info["debug"] = false; + is_debug.store(false); DLOG_F(INFO, "DEBUG mode of {} is disabled", getDeviceName()); } } else if (name == "CCD_FRAME_TYPE") { + frame_type_prop.reset(svp); std::string type; if (auto lightswitch = IUFindSwitch(svp, "FRAME_LIGHT"); lightswitch->s == ISS_ON) type = "Light"; @@ -95,11 +284,12 @@ void HydrogenCamera::newSwitch(ISwitchVectorProperty *svp) else if (auto biasswitch = IUFindSwitch(svp, "FRAME_BIAS"); biasswitch->s == ISS_ON) type = "Bias"; setProperty("frame_type", type); - device_info["frame_type"] = type; - DLOG_F(INFO, "Current frame type of {} is {}", getDeviceName(), device_info["frame_type"].dump()); + frame.frame_type = type; + DLOG_F(INFO, "Current frame type of {} is {}", getDeviceName(), frame.frame_type); } else if (name == "CCD_TRANSFER_FORMAT") { + frame_format_prop.reset(svp); std::string format; if (auto fitsswitch = IUFindSwitch(svp, "FORMAT_FITS"); fitsswitch->s == ISS_ON) format = "Fits"; @@ -108,56 +298,60 @@ void HydrogenCamera::newSwitch(ISwitchVectorProperty *svp) else if (auto xisfswitch = IUFindSwitch(svp, "FORMAT_XISF"); xisfswitch->s == ISS_ON) format = "Xisf"; setProperty("frame_format", format); - device_info["frame_format"] = format; - DLOG_F(INFO, "Current frame format of {} is {}", getDeviceName(), device_info["frame_format"].dump()); + frame.frame_format = format; + DLOG_F(INFO, "Current frame format of {} is {}", getDeviceName(), frame.frame_format); } else if (name == "CCD_ABORT_EXPOSURE") { + abort_exposure_prop.reset(svp); if (auto abortswitch = IUFindSwitch(svp, "ABORT_EXPOSURE"); abortswitch->s == ISS_ON) { setProperty("is_exposure", false); - device_info["is_exposure"] = false; + is_exposure.store(false); DLOG_F(INFO, "{} is stopped", getDeviceName()); - is_exposuring = false; } } else if (name == "UPLOAD_MODE") { + image_upload_mode_prop.reset(svp); std::string mode; - if (auto clientswitch = IUFindSwitch(svp, "UPLOAD_CLIENT"); clientswitch->s == ISS_ON) mode = "Client"; else if (auto localswitch = IUFindSwitch(svp, "UPLOAD_LOCAL"); localswitch->s == ISS_ON) mode = "Local"; else if (auto bothswitch = IUFindSwitch(svp, "UPLOAD_BOTH"); bothswitch->s == ISS_ON) mode = "Both"; - - device_info["network"]["mode"] = mode; - DLOG_F(INFO, "Current upload mode of {} is {}", getDeviceName(), device_info["network"]["mode"].dump()); + frame.upload_mode = mode; + DLOG_F(INFO, "Current upload mode of {} is {}", getDeviceName(), frame.upload_mode); } else if (name == "CCD_FAST_TOGGLE") { - bool mode; - + fast_read_out_prop.reset(svp); if (auto enabledswitch = IUFindSwitch(svp, "HYDROGEN_ENABLED"); enabledswitch->s == ISS_ON) - mode = true; + { + setProperty("is_fastread", true); + frame.is_fastread.store(true); + DLOG_F(INFO, "Current fast readout mode of {} is enabled", getDeviceName()); + } else if (auto disabledswitch = IUFindSwitch(svp, "HYDROGEN_DISABLED"); disabledswitch->s == ISS_ON) - mode = false; - - device_info["frame"]["fast_read"] = mode; - DLOG_F(INFO, "Current readout mode of {} is {}", getDeviceName(), device_info["frame"]["fast_read"].dump()); + { + setProperty("is_fastread", false); + frame.is_fastread.store(false); + DLOG_F(INFO, "Current fast readout mode of {} is disabled", getDeviceName()); + } } else if (name == "CCD_VIDEO_STREAM") { + video_prop.reset(svp); if (auto onswitch = IUFindSwitch(svp, "STREAM_ON"); onswitch->s == ISS_ON) { - device_info["video"]["is_video"] = true; + setProperty("is_video", true); is_video.store(true); DLOG_F(INFO, "{} start video capture", getDeviceName()); } else if (auto offswitch = IUFindSwitch(svp, "STREAM_OFF"); offswitch->s == ISS_ON) { - device_info["video"]["is_video"] = false; + setProperty("is_video", false); is_video.store(false); DLOG_F(INFO, "{} stop video capture", getDeviceName()); } @@ -165,6 +359,40 @@ void HydrogenCamera::newSwitch(ISwitchVectorProperty *svp) else if (name == "FLIP") { } + else if (name == "CCD_COMPRESSION") + { + } + + else if (name == "CCD_CONTROLS") + { + } + else if (name == "CCD_CONTROLS_MODE") + { + } + // The following properties are for Toup Camera + else if (name == "TC_FAN_CONTROL") + { + } + else if (name == "TC_FAN_Speed") + { + } + else if (name == "TC_AUTO_WB") + { + } + else if (name == "TC_HEAT_CONTROL") + { + } + else if (name == "TC_HCG_CONTROL") + { + } + else if (name == "TC_LOW_NOISE_CONTROL") + { + } + /* + else if (PropName == "CCD_BINNING_MODE" && Proptype == HYDROGEN_SWITCH) + { + } + */ } void HydrogenCamera::newMessage(HYDROGEN::BaseDevice *dp, int messageID) @@ -195,68 +423,66 @@ void HydrogenCamera::newNumber(INumberVectorProperty *nvp) if (name == "CCD_EXPOSURE") { const double exposure = nvp->np->value; - device_info["exposure"]["current"] = exposure; + current_exposure.store(exposure); DLOG_F(INFO, "Current CCD_EXPOSURE for {} is {}", getDeviceName(), exposure); } else if (name == "CCD_INFO") { - pixel = IUFindNumber(ccdinfo_prop, "CCD_PIXEL_SIZE")->value; - pixel_x = IUFindNumber(ccdinfo_prop, "CCD_PIXEL_SIZE_X")->value; - pixel_y = IUFindNumber(ccdinfo_prop, "CCD_PIXEL_SIZE_Y")->value; - max_frame_x = IUFindNumber(ccdinfo_prop, "CCD_MAX_X")->value; - max_frame_y = IUFindNumber(ccdinfo_prop, "CCD_MAX_Y")->value; - pixel_depth = IUFindNumber(ccdinfo_prop, "CCD_BITSPERPIXEL")->value; - - device_info["frame"] = { - {"pixel_x", pixel_x}, - {"pixel_y", pixel_y}, - {"pixel_depth", pixel_depth}, - {"max_frame_x", max_frame_x}, - {"max_frame_y", max_frame_y}}; - DLOG_F(INFO, "{} pixel {} pixel_x {} pixel_y {} max_frame_x {} max_frame_y {} pixel_depth {}", getDeviceName(), pixel, pixel_x, pixel_y, max_frame_x, max_frame_y, pixel_depth); - } - else if (name == "BINNING") - { - indi_binning_x = IUFindNumber(nvp, "HOR_BIN"); - indi_binning_y = IUFindNumber(nvp, "VER_BIN"); - device_info["exposure"] = { - {"binning_x", indi_binning_x->value}, - {"binning_y", indi_binning_y->value}}; + ccdinfo_prop.reset(nvp); + frame.pixel.store(IUFindNumber(nvp, "CCD_PIXEL_SIZE")->value); + frame.pixel_x.store(IUFindNumber(nvp, "CCD_PIXEL_SIZE_X")->value); + frame.pixel_y.store(IUFindNumber(nvp, "CCD_PIXEL_SIZE_Y")->value); + frame.max_frame_x.store(IUFindNumber(nvp, "CCD_MAX_X")->value); + frame.max_frame_y.store(IUFindNumber(nvp, "CCD_MAX_Y")->value); + frame.pixel_depth.store(IUFindNumber(nvp, "CCD_BITSPERPIXEL")->value); + + DLOG_F(INFO, "{} pixel {} pixel_x {} pixel_y {} max_frame_x {} max_frame_y {} pixel_depth {}", + getDeviceName(), frame.pixel.load(), frame.pixel_x.load(), frame.pixel_y.load(), frame.max_frame_x.load(), frame.max_frame_y.load(), frame.pixel_depth.load()); + } + else if (name == "CCD_BINNING") + { + indi_binning_x.reset(IUFindNumber(nvp, "HOR_BIN")); + indi_binning_y.reset(IUFindNumber(nvp, "VER_BIN")); + frame.binning_x.store(indi_binning_x->value); + frame.binning_y.store(indi_binning_y->value); DLOG_F(INFO, "Current binning_x and y of {} are {} {}", getDeviceName(), indi_binning_x->value, indi_binning_y->value); } - else if (name == "FRAME") + else if (name == "CCD_FRAME") { - indi_frame_x = IUFindNumber(nvp, "X"); - indi_frame_y = IUFindNumber(nvp, "Y"); - indi_frame_width = IUFindNumber(nvp, "WIDTH"); - indi_frame_height = IUFindNumber(nvp, "HEIGHT"); + indi_frame_x.reset(IUFindNumber(nvp, "X")); + indi_frame_y.reset(IUFindNumber(nvp, "Y")); + indi_frame_width.reset(IUFindNumber(nvp, "WIDTH")); + indi_frame_height.reset(IUFindNumber(nvp, "HEIGHT")); + + frame.frame_x.store(indi_frame_x->value); + frame.frame_y.store(indi_frame_y->value); + frame.frame_height.store(indi_frame_height->value); + frame.frame_width.store(indi_frame_width->value); - device_info["frame"] = { - {"x", indi_frame_x->value}, - {"y", indi_frame_y->value}, - {"width", indi_frame_width->value}, - {"height", indi_frame_height->value}}; DLOG_F(INFO, "Current frame of {} are {} {} {} {}", getDeviceName(), indi_frame_width->value, indi_frame_y->value, indi_frame_width->value, indi_frame_height->value); } else if (name == "CCD_TEMPERATURE") { - current_temperature = IUFindNumber(nvp, "CCD_TEMPERATURE_VALUE")->value; - device_info["temperature"]["current"] = current_temperature; - DLOG_F(INFO, "Current temperature of {} is {}", getDeviceName(), current_temperature); + camera_temperature_prop.reset(nvp); + current_temperature.store(IUFindNumber(nvp, "CCD_TEMPERATURE_VALUE")->value); + DLOG_F(INFO, "Current temperature of {} is {}", getDeviceName(), current_temperature.load()); } else if (name == "CCD_GAIN") { - gain = IUFindNumber(nvp, "GAIN")->value; - device_info["exposure"]["gain"] = gain; - DLOG_F(INFO, "Current camera gain of {} is {}", getDeviceName(), gain); + gain_prop.reset(nvp); + current_gain.store(IUFindNumber(nvp, "GAIN")->value); + setProperty("gain", current_gain.load()); + DLOG_F(INFO, "Current camera gain of {} is {}", getDeviceName(), current_gain.load()); } else if (name == "CCD_OFFSET") { - offset = IUFindNumber(nvp, "OFFSET")->value; - device_info["exposure"]["offset"] = offset; - DLOG_F(INFO, "Current camera offset of {} is {}", getDeviceName(), offset); + offset_prop.reset(nvp); + current_offset.store(IUFindNumber(nvp, "OFFSET")->value); + setProperty("offset", current_offset.load()); + DLOG_F(INFO, "Current camera offset of {} is {}", getDeviceName(), current_offset.load()); } - else if (name == "POLLING_PERIOD") + /* + else if (name == "POLLING_PERIOD") { device_info["network"]["period"] = IUFindNumber(nvp, "PERIOD_MS")->value; DLOG_F(INFO, "Current period of {} is {}", getDeviceName(), device_info["network"]["period"].dump()); @@ -287,11 +513,60 @@ void HydrogenCamera::newNumber(INumberVectorProperty *nvp) device_info["video"]["avgfps"] = IUFindNumber(nvp, "AVG_FPS")->value; DLOG_F(INFO, "Current average fps of {} is {}", getDeviceName(), device_info["video"]["avgfps"].dump()); } + else if (PropName == "TC_HGC_SET" && Proptype == HYDROGEN_NUMBER) + { + } + else if (PropName == "CCD_LEVEL_RANGE" && Proptype == HYDROGEN_NUMBER) + { + } + + else if (PropName == "CCD_BLACK_BALANCE" && Proptype == HYDROGEN_NUMBER) + { + } + else if (PropName == "Firmware" && Proptype == HYDROGEN_NUMBER) + { + } + */ } void HydrogenCamera::newText(ITextVectorProperty *tvp) { - DLOG_F(INFO, "{} Received Text: {} = {}", getDeviceName(), tvp->name, tvp->tp->text); + const std::string name = tvp->name; + DLOG_F(INFO, "{} Received Text: {} = {}", getDeviceName(), name, tvp->tp->text); + + if (name == indi_camera_cmd + "CFA") + { + cfa_prop.reset(tvp); + cfa_type_prop.reset(IUFindText(tvp, "CFA_TYPE")); + if (cfa_type_prop && cfa_type_prop->text && *cfa_type_prop->text) + { + DLOG_F(INFO, "{} CFA_TYPE is {}", getDeviceName(), cfa_type_prop->text); + is_color = true; + setProperty("is_color", true); + } + else + { + setProperty("is_color", false); + } + } + else if (name == "DEVICE_PORT") + { + camera_prop.reset(tvp); + indi_camera_port = tvp->tp->text; + setProperty("port", indi_camera_port); + DLOG_F(INFO, "Current device port of {} is {}", getDeviceName(), camera_prop->tp->text); + } + else if (name == "DRIVER_INFO") + { + indi_camera_exec = IUFindText(tvp, "DRIVER_EXEC")->text; + indi_camera_version = IUFindText(tvp, "DRIVER_VERSION")->text; + indi_camera_interface = IUFindText(tvp, "DRIVER_INTERFACE")->text; + DLOG_F(INFO, "Camera Name : {} connected exec {}", getDeviceName(), getDeviceName(), indi_camera_exec); + } + else if (name == "ACTIVE_DEVICES") + { + active_device_prop.reset(tvp); + } } void HydrogenCamera::newBLOB(IBLOB *bp) @@ -301,9 +576,9 @@ void HydrogenCamera::newBLOB(IBLOB *bp) DLOG_F(INFO, "{} Received BLOB {} len = {} size = {}", getDeviceName(), bp->name, bp->bloblen, bp->size); - if (expose_prop) + if (exposure_prop) { - if (bp->name == indi_blobgetDeviceName().c_str()) + if (bp->name == indi_blob_name.c_str()) { // updateLastFrame(bp); } @@ -323,188 +598,29 @@ void HydrogenCamera::newProperty(HYDROGEN::Property *property) if (Proptype == HYDROGEN_BLOB) { - if (PropName == indi_blobgetDeviceName().c_str()) + if (PropName == indi_blob_name.c_str()) { has_blob = 1; // set option to receive blob and messages for the selected CCD - setBLOBMode(B_ALSO, devicegetDeviceName().c_str(), indi_blobgetDeviceName().c_str()); + setBLOBMode(B_ALSO, getDeviceName().c_str(), indi_blob_name.c_str()); #ifdef HYDROGEN_SHARED_BLOB_SUPPORT // Allow faster mode provided we don't modify the blob content or free/realloc it - enableDirectBlobAccess(devicegetDeviceName().c_str(), indi_blobgetDeviceName().c_str()); + enableDirectBlobAccess(getDeviceName().c_str(), indi_blob_name.c_str()); #endif } } - else if (PropName == indi_camera_cmd + "EXPOSURE" && Proptype == HYDROGEN_NUMBER) - { - expose_prop = property->getNumber(); - newNumber(expose_prop); - } - else if (PropName == indi_camera_cmd + "FRAME" && Proptype == HYDROGEN_NUMBER) - { - frame_prop = property->getNumber(); - newNumber(frame_prop); - } - else if (PropName == indi_camera_cmd + "FRAME_TYPE" && Proptype == HYDROGEN_SWITCH) - { - frame_type_prop = property->getSwitch(); - newSwitch(frame_type_prop); - } - else if (PropName == indi_camera_cmd + "BINNING" && Proptype == HYDROGEN_NUMBER) - { - binning_prop = property->getNumber(); - newNumber(binning_prop); - } - else if (PropName == indi_camera_cmd + "CFA" && Proptype == HYDROGEN_TEXT) - { - ITextVectorProperty *cfa_prop = property->getText(); - IText *cfa_type = IUFindText(cfa_prop, "CFA_TYPE"); - if (cfa_type && cfa_type->text && *cfa_type->text) - { - DLOG_F(INFO, "{} CFA_TYPE is {}", getDeviceName(), cfa_type->text); - is_color = true; - } - } - else if (PropName == indi_camera_cmd + "VIDEO_STREAM" && Proptype == HYDROGEN_SWITCH) - { - video_prop = property->getSwitch(); - newSwitch(video_prop); - } - else if (PropName == "STREAM_DELAY" && Proptype == HYDROGEN_NUMBER) - { - video_delay_prop = property->getNumber(); - newNumber(video_delay_prop); - } - else if (PropName == "STREAMING_EXPOSURE" && Proptype == HYDROGEN_NUMBER) - { - video_exposure_prop = property->getNumber(); - newNumber(video_exposure_prop); - } - else if (PropName == "FPS" && Proptype == HYDROGEN_NUMBER) - { - video_fps_prop = property->getNumber(); - newNumber(video_fps_prop); - } - else if (PropName == "DEVICE_PORT" && Proptype == HYDROGEN_TEXT) - { - camera_port = property->getText(); - device_info["network"]["port"] = camera_port->tp->text; - DLOG_F(INFO, "Current device port of {} is {}", getDeviceName(), camera_port->tp->text); - } - else if (PropName == "CONNECTION" && Proptype == HYDROGEN_SWITCH) - { - connection_prop = property->getSwitch(); - ISwitch *connectswitch = IUFindSwitch(connection_prop, "CONNECT"); - is_connected = (connectswitch->s == ISS_ON); - if (!is_connected) - { - connection_prop->sp->s = ISS_ON; - sendNewSwitch(connection_prop); - } - DLOG_F(INFO, "{} Connected {}", getDeviceName(), is_connected); - } - else if (PropName == "DRIVER_INFO" && Proptype == HYDROGEN_TEXT) - { - devicegetDeviceName() = IUFindText(property->getText(), "DRIVERgetDeviceName()")->text; - indi_camera_exec = IUFindText(property->getText(), "DRIVER_EXEC")->text; - indi_camera_version = IUFindText(property->getText(), "DRIVER_VERSION")->text; - indi_camera_interface = IUFindText(property->getText(), "DRIVER_INTERFACE")->text; - device_info["driver"]["name"] = devicegetDeviceName(); - device_info["driver"]["exec"] = indi_camera_exec; - device_info["driver"]["version"] = indi_camera_version; - device_info["driver"]["interfaces"] = indi_camera_interface; - DLOG_F(INFO, "Camera Name : {} connected exec {}", getDeviceName(), devicegetDeviceName(), indi_camera_exec); - } - else if (PropName == indi_camera_cmd + "INFO" && Proptype == HYDROGEN_NUMBER) - { - ccdinfo_prop = property->getNumber(); - newNumber(ccdinfo_prop); - } - else if (PropName == "DEBUG" && Proptype == HYDROGEN_SWITCH) - { - debug_prop = property->getSwitch(); - newSwitch(debug_prop); - } - else if (PropName == "POLLING_PERIOD" && Proptype == HYDROGEN_NUMBER) - { - polling_prop = property->getNumber(); - newNumber(polling_prop); - } - else if (PropName == "ACTIVE_DEVICES" && Proptype == HYDROGEN_TEXT) - { - active_device_prop = property->getText(); - newText(active_device_prop); - } - else if (PropName == "CCD_COMPRESSION" && Proptype == HYDROGEN_SWITCH) - { - compression_prop = property->getSwitch(); - newSwitch(compression_prop); - } - else if (PropName == "UPLOAD_MODE" && Proptype == HYDROGEN_SWITCH) - { - image_upload_mode_prop = property->getSwitch(); - newSwitch(image_upload_mode_prop); - } - else if (PropName == "CCD_FAST_TOGGLE" && Proptype == HYDROGEN_SWITCH) - { - fast_read_out_prop = property->getSwitch(); - newSwitch(fast_read_out_prop); - } - else if (PropName == "LIMITS" && Proptype == HYDROGEN_NUMBER) - { - camera_limit_prop = property->getNumber(); - newNumber(camera_limit_prop); - } - // The following properties are for ASI Camera - else if (PropName == "FLIP" && Proptype == HYDROGEN_SWITCH) - { - asi_image_flip_prop = property->getSwitch(); - newSwitch(asi_image_flip_prop); - } - else if (PropName == "CCD_CONTROLS" && Proptype == HYDROGEN_SWITCH) - { - } - else if (PropName == "CCD_CONTROLS_MODE" && Proptype == HYDROGEN_SWITCH) - { - } - // The following properties are for Toup Camera - else if (PropName == "TC_FAN_CONTROL" && Proptype == HYDROGEN_SWITCH) - { - } - else if (PropName == "TC_FAN_Speed" && Proptype == HYDROGEN_SWITCH) - { - } - else if (PropName == "TC_AUTO_WB" && Proptype == HYDROGEN_SWITCH) - { - } - else if (PropName == "TC_HEAT_CONTROL" && Proptype == HYDROGEN_SWITCH) - { - } - else if (PropName == "TC_HCG_CONTROL" && Proptype == HYDROGEN_SWITCH) - { - } - else if (PropName == "TC_HGC_SET" && Proptype == HYDROGEN_NUMBER) - { - } - else if (PropName == "TC_LOW_NOISE_CONTROL" && Proptype == HYDROGEN_SWITCH) - { - } - else if (PropName == "SIMULATION" && Proptype == HYDROGEN_SWITCH) - { - toupcam_simulation_prop = property->getSwitch(); - newSwitch(toupcam_simulation_prop); - } - else if (PropName == "CCD_LEVEL_RANGE" && Proptype == HYDROGEN_NUMBER) - { - } - else if (PropName == "CCD_BINNING_MODE" && Proptype == HYDROGEN_SWITCH) + else if (Proptype == HYDROGEN_NUMBER) { + newNumber(property->getNumber()); } - else if (PropName == "CCD_BLACK_BALANCE" && Proptype == HYDROGEN_NUMBER) + else if (Proptype == HYDROGEN_SWITCH) { + newSwitch(property->getSwitch()); } - else if (PropName == "Firmware" && Proptype == HYDROGEN_NUMBER) + else if (Proptype == HYDROGEN_TEXT) { + newText(property->getText()); } } @@ -533,13 +649,13 @@ void HydrogenCamera::removeDevice(HYDROGEN::BaseDevice *dp) void HydrogenCamera::ClearStatus() { connection_prop = nullptr; - expose_prop = nullptr; + exposure_prop = nullptr; frame_prop = nullptr; frame_type_prop = nullptr; ccdinfo_prop = nullptr; binning_prop = nullptr; video_prop = nullptr; - camera_port = nullptr; + camera_prop = nullptr; camera_device = nullptr; debug_prop = nullptr; polling_prop = nullptr; @@ -561,198 +677,4 @@ void HydrogenCamera::ClearStatus() asi_image_flip_ver_prop = nullptr; asi_controls_prop = nullptr; asi_controls_mode_prop = nullptr; -} - -HydrogenCamera::HydrogenCamera(const std::string &name) : Camera(name) -{ -} - -HydrogenCamera::~HydrogenCamera() -{ -} - -bool HydrogenCamera::connect(const IParams ¶ms) -{ - std::string name = params["name"]; - int port = std::stoi(params["port"]); - std::string hostname = params["host"]; - DLOG_F(INFO, "Trying to connect to {}", name); - setServer(hostname.c_str(), port); - // Receive messages only for our camera. - watchDevice(name.c_str()); - // Connect to server. - if (connectServer()) - { - DLOG_F(INFO, "{}: connectServer done ready = {}", getDeviceName(), is_ready); - connectDevice(name.c_str()); - return !is_ready; - } - return false; -} - -bool HydrogenCamera::connect(const IParams ¶ms) -{ - DLOG_F(INFO, "%s is connected", getDeviceName()); - return true; -} - -bool HydrogenCamera::disconnect(const IParams ¶ms) -{ - DLOG_F(INFO, "%s is disconnected", getDeviceName()); - return true; -} - -bool HydrogenCamera::reconnect(const IParams ¶ms) -{ - return true; -} - -bool HydrogenCamera::isConnected(const IParams ¶ms) -{ - return true; -} - -bool HydrogenCamera::startExposure(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::abortExposure(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::getExposureStatus(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::getExposureResult(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::saveExposureResult(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::startVideo(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::stopVideo(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::getVideoStatus(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::getVideoResult(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::saveVideoResult(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::startCooling(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::stopCooling(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::isCoolingAvailable() -{ - return true; -} - -bool HydrogenCamera::getTemperature(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::getCoolingPower(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::setTemperature(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::setCoolingPower(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::getGain(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::setGain(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::isGainAvailable() -{ - return true; -} - -bool HydrogenCamera::getOffset(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::setOffset(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::isOffsetAvailable() -{ - return true; -} - -bool HydrogenCamera::getISO(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::setISO(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::isISOAvailable() -{ - return true; -} - -bool HydrogenCamera::getFrame(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::setFrame(const nlohmann::json ¶ms) -{ - return true; -} - -bool HydrogenCamera::isFrameSettingAvailable() -{ - return true; } \ No newline at end of file diff --git a/src/client/hydrogen/hydrogencamera.hpp b/src/client/hydrogen/hydrogencamera.hpp index b7e728d2..60560852 100644 --- a/src/client/hydrogen/hydrogencamera.hpp +++ b/src/client/hydrogen/hydrogencamera.hpp @@ -35,123 +35,19 @@ Description: Hydrogen Camera class HydrogenCamera : public Camera, public LithiumIndiClient { - // Hydrogen Parameters -private: - // 连接属性 - ISwitchVectorProperty *connection_prop; - // 曝光属性 - INumberVectorProperty *expose_prop; - // 帧属性 - INumberVectorProperty *frame_prop; - // 温度属性 - INumberVectorProperty *temperature_prop; - // 增益属性 - INumberVectorProperty *gain_prop; - // 偏移属性 - INumberVectorProperty *offset_prop; - // 帧区域参数 - INumber *indi_frame_x; - INumber *indi_frame_y; - INumber *indi_frame_width; - INumber *indi_frame_height; - // 帧类型 - ISwitchVectorProperty *frame_type_prop; - // 图像类型 - ISwitchVectorProperty *image_type_prop; - // CCD 设备信息 - INumberVectorProperty *ccdinfo_prop; - // 二次取样属性 - INumberVectorProperty *binning_prop; - // 二次取样 X 轴 - INumber *indi_binning_x; - // 二次取样 Y 轴 - INumber *indi_binning_y; - // 视频属性 - ISwitchVectorProperty *video_prop; - // 视频延迟 - INumberVectorProperty *video_delay_prop; - // 视频曝光时间 - INumberVectorProperty *video_exposure_prop; - // 视频帧率 - INumberVectorProperty *video_fps_prop; - // 相机端口 - ITextVectorProperty *camera_port; - // 相机设备 - HYDROGEN::BaseDevice *camera_device; - // 调试模式 - ISwitchVectorProperty *debug_prop; - // 信息刷新间隔 - INumberVectorProperty *polling_prop; - // 已连接的辅助设备 - ITextVectorProperty *active_device_prop; - // 是否压缩 - ISwitchVectorProperty *compression_prop; - // 图像上传模式 - ISwitchVectorProperty *image_upload_mode_prop; - // 快速读出模式 - ISwitchVectorProperty *fast_read_out_prop; - // 相机限制 - INumberVectorProperty *camera_limit_prop; - - // 标志位 - bool is_ready; // 是否就绪 - bool has_blob; // 是否有 BLOB 数据 - - // Hydrogen 指令 - std::string indi_camera_cmd = "CCD_"; // Hydrogen 控制命令前缀 - std::string indi_blob_name; // BLOB 文件名 - std::string indi_camera_exec = ""; // Hydrogen 执行命令 - std::string indi_camera_version; - std::string indi_camera_interface; - - std::atomic_bool is_connected; - std::atomic_bool is_exposure; - std::atomic_bool is_video; - - nlohmann::json device_info; - -private: - // For Hydrogen Toupcamera - - ISwitchVectorProperty *toupcam_fan_control_prop; - - ISwitchVectorProperty *toupcam_heat_control_prop; - - ISwitchVectorProperty *toupcam_hcg_control_prop; - - ISwitchVectorProperty *toupcam_low_noise_control_prop; - - ISwitchVectorProperty *toupcam_simulation_prop; - - ISwitchVectorProperty *toupcam_binning_mode_prop; - - // For Hydrogen ZWOASI - - // 图像翻转 - ISwitchVectorProperty *asi_image_flip_prop; - // 图像翻转 - ISwitchVectorProperty *asi_image_flip_hor_prop; - ISwitchVectorProperty *asi_image_flip_ver_prop; - // 控制模式 - INumberVectorProperty *asi_controls_prop; - // 控制模式 - ISwitchVectorProperty *asi_controls_mode_prop; - - // For Hydrogen QHYCCD - public: // 构造函数 HydrogenCamera(const std::string &name); // 析构函数 ~HydrogenCamera(); - bool connect(const IParams ¶ms) override; + virtual bool connect(const nlohmann::json ¶ms) override; - bool disconnect(const IParams ¶ms) override; + virtual bool disconnect(const nlohmann::json ¶ms) override; - bool reconnect(const IParams ¶ms) override; + virtual bool reconnect(const nlohmann::json ¶ms) override; - bool isConnected(const IParams ¶ms) override; + virtual bool isConnected() override; public: /** @@ -386,4 +282,125 @@ class HydrogenCamera : public Camera, public LithiumIndiClient void IndiServerConnected() override; // Hydrogen 服务器断开连接 void IndiServerDisconnected(int exit_code) override; + + // Hydrogen Parameters +private: + // 连接属性 + std::shared_ptr connection_prop; + // 曝光属性 + std::shared_ptr exposure_prop; + // 停止曝光属性 + std::shared_ptr abort_exposure_prop; + // 帧属性 + std::shared_ptr frame_prop; + // 温度属性 + std::shared_ptr temperature_prop; + // 增益属性 + std::shared_ptr gain_prop; + // 偏移属性 + std::shared_ptr offset_prop; + // 帧区域参数 + std::shared_ptr indi_frame_x; + std::shared_ptr indi_frame_y; + std::shared_ptr indi_frame_width; + std::shared_ptr indi_frame_height; + // 帧类型 + std::shared_ptr frame_type_prop; + // 图像类型 + std::shared_ptr frame_format_prop; + // CCD 设备信息 + std::shared_ptr ccdinfo_prop; + // 二次取样属性 + std::shared_ptr binning_prop; + // 二次取样 X 轴 + std::shared_ptr indi_binning_x; + // 二次取样 Y 轴 + std::shared_ptr indi_binning_y; + // 视频属性 + std::shared_ptr video_prop; + // 视频延迟 + std::shared_ptr video_delay_prop; + // 视频曝光时间 + std::shared_ptr video_exposure_prop; + // 视频帧率 + std::shared_ptr video_fps_prop; + // 相机端口 + std::shared_ptr camera_prop; + // 相机设备 + HYDROGEN::BaseDevice *camera_device; + // 调试模式 + std::shared_ptr debug_prop; + // 信息刷新间隔 + std::shared_ptr polling_prop; + // 已连接的辅助设备 + std::shared_ptr active_device_prop; + // 是否压缩 + std::shared_ptr compression_prop; + // 图像上传模式 + std::shared_ptr image_upload_mode_prop; + // 快速读出模式 + std::shared_ptr fast_read_out_prop; + // 相机限制 + std::shared_ptr camera_limit_prop; + // 相机温度 + std::shared_ptr camera_temperature_prop; + + std::shared_ptr cfa_prop; + + std::shared_ptr cfa_type_prop; + + // 标志位 + std::atomic_bool is_ready; // 是否就绪 + std::atomic_bool has_blob; // 是否有 BLOB 数据 + std::atomic_bool is_debug; + std::atomic_bool is_connected; + std::atomic_bool is_exposure; + std::atomic_bool is_video; + bool is_color; + + std::atomic_int current_gain; + std::atomic_int current_offset; + std::atomic_int current_exposure; + std::atomic current_temperature; + + // Hydrogen 指令 + std::string indi_camera_cmd = "CCD_"; // Hydrogen 控制命令前缀 + std::string indi_blob_name; // BLOB 文件名 + std::string indi_camera_exec = ""; // Hydrogen 执行命令 + std::string indi_camera_version; + std::string indi_camera_interface; + std::string indi_camera_port; + + CameraFrame frame; + + std::atomic polling_period; + +private: + // For Hydrogen Toupcamera + + std::shared_ptr toupcam_fan_control_prop; + + std::shared_ptr toupcam_heat_control_prop; + + std::shared_ptr toupcam_hcg_control_prop; + + std::shared_ptr toupcam_low_noise_control_prop; + + std::shared_ptr toupcam_simulation_prop; + + std::shared_ptr toupcam_binning_mode_prop; + + // For Hydrogen ZWOASI + + // 图像翻转 + std::shared_ptr asi_image_flip_prop; + // 图像翻转 + std::shared_ptr asi_image_flip_hor_prop; + std::shared_ptr asi_image_flip_ver_prop; + // 控制模式 + std::shared_ptr asi_controls_prop; + // 控制模式 + std::shared_ptr asi_controls_mode_prop; + + // For Hydrogen QHYCCD }; \ No newline at end of file diff --git a/src/core/base/hydrogendevapi.cpp b/src/core/base/hydrogendevapi.cpp index c0121b40..3ab8c0fd 100644 --- a/src/core/base/hydrogendevapi.cpp +++ b/src/core/base/hydrogendevapi.cpp @@ -43,7 +43,7 @@ void IUSaveText(IText *tp, const char *newtext) { /* copy in fresh string */ size_t size = strlen(newtext) + 1; - tp->text = (char*)realloc((void*)tp->text, size); + tp->text = (char *)realloc((void *)tp->text, size); memcpy(tp->text, newtext, size); } @@ -740,7 +740,7 @@ int IUSnoopBLOB(XMLEle *root, IBLOBVectorProperty *bvp) { int base64datalen = pcdatalenXMLEle(ep); assert_mem(bp->blob = realloc(bp->blob, 3 * base64datalen / 4)); - bp->bloblen = from64tobits_fast((char*)bp->blob, pcdataXMLEle(ep), base64datalen); + bp->bloblen = from64tobits_fast((char *)bp->blob, pcdataXMLEle(ep), base64datalen); indi_strlcpy(bp->format, valuXMLAtt(fa), MAXHYDROGENFORMAT); bp->size = atoi(valuXMLAtt(sa)); } diff --git a/src/core/base/hydrogendevapis.cpp b/src/core/base/hydrogendevapis.cpp new file mode 100644 index 00000000..0492215c --- /dev/null +++ b/src/core/base/hydrogendevapis.cpp @@ -0,0 +1,82 @@ + +/** \section IUFindS */ + +/* find a member of an IText vector, else NULL */ +std::shared_ptr IUFindTextS(std::shared_ptr tvp, const char *name) +{ + for (int i = 0; i < tvp->ntp; i++) + if (strcmp(tvp->tp[i].name, name) == 0) + return (&tvp->tp[i]); + fprintf(stderr, "No IText '%s' in %s.%s\n", name, tvp->device, tvp->name); + return nullptr; +} + +/* find a member of an INumber vector, else NULL */ +std::shared_ptr IUFindNumberS(std::shared_ptr nvp, const char *name) +{ + for (int i = 0; i < nvp->nnp; i++) + if (strcmp(nvp->np[i].name, name) == 0) + return (&nvp->np[i]); + fprintf(stderr, "No INumber '%s' in %s.%s\n", name, nvp->device, nvp->name); + return nullptr; +} + +/* find a member of an ISwitch vector, else NULL */ +std::shared_ptr IUFindSwitchS(std::shared_ptr svp, const char *name) +{ + for (int i = 0; i < svp->nsp; i++) + if (strcmp(svp->sp[i].name, name) == 0) + return (&svp->sp[i]); + fprintf(stderr, "No ISwitch '%s' in %s.%s\n", name, svp->device, svp->name); + return nullptr; +} + +/* find a member of an ILight vector, else NULL */ +std::shared_ptr IUFindLightS(std::shared_ptr lvp, const char *name) +{ + for (int i = 0; i < lvp->nlp; i++) + if (strcmp(lvp->lp[i].name, name) == 0) + return (&lvp->lp[i]); + fprintf(stderr, "No ILight '%s' in %s.%s\n", name, lvp->device, lvp->name); + return nullptr; +} + +/* find a member of an IBLOB vector, else NULL */ +std::shared_ptr IUFindBLOBS(std::shared_ptr bvp, const char *name) +{ + for (int i = 0; i < bvp->nbp; i++) + if (strcmp(bvp->bp[i].name, name) == 0) + return (&bvp->bp[i]); + fprintf(stderr, "No IBLOB '%s' in %s.%s\n", name, bvp->device, bvp->name); + return nullptr; +} + +/* find an ON member of an ISwitch vector, else NULL. + * N.B. user must make sense of result with ISRule in mind. + */ +std::shared_ptr IUFindOnSwitchS(std::shared_ptr svp) +{ + for (int i = 0; i < svp->nsp; i++) + if (svp->sp[i].s == ISS_ON) + return (&svp->sp[i]); + /*fprintf(stderr, "No ISwitch On in %s.%s\n", svp->device, svp->name);*/ + return nullptr; +} + +/* Find index of the ON member of an ISwitchVectorProperty */ +int IUFindOnSwitchIndexS(std::shared_ptr svp) +{ + for (int i = 0; i < svp->nsp; i++) + if (svp->sp[i].s == ISS_ON) + return i; + return -1; +} + +/* Find name the ON member in the given states and names */ +const char *IUFindOnSwitchNameS(std::shared_ptr states, char *names[], int n) +{ + for (int i = 0; i < n; i++) + if (states[i] == ISS_ON) + return names[i]; + return nullptr; +} diff --git a/src/core/base/hydrogendevapis.hpp b/src/core/base/hydrogendevapis.hpp new file mode 100644 index 00000000..3c192369 --- /dev/null +++ b/src/core/base/hydrogendevapis.hpp @@ -0,0 +1,59 @@ + + /** @brief Find an IText member in a vector text property. + * @param tvp a pointer to a text vector property. + * @param name the name of the member to search for. + * @return a pointer to an IText member on match, or NULL if nothing is found. + */ + extern std::shared_ptr IUFindTextS(std::shared_ptr tvp, const char *name); + + /** @brief Find an INumber member in a number text property. + * @param nvp a pointer to a number vector property. + * @param name the name of the member to search for. + * @return a pointer to an INumber member on match, or NULL if nothing is found. + */ + extern std::shared_ptr IUFindNumberS(std::shared_ptr nvp, const char *name); + + /** @brief Find an ISwitch member in a vector switch property. + * @param svp a pointer to a switch vector property. + * @param name the name of the member to search for. + * @return a pointer to an ISwitch member on match, or NULL if nothing is found. + */ + extern std::shared_ptr IUFindSwitchS(std::shared_ptr svp, const char *name); + + /** @brief Find an ILight member in a vector Light property. + * @param lvp a pointer to a Light vector property. + * @param name the name of the member to search for. + * @return a pointer to an ILight member on match, or NULL if nothing is found. + */ + extern std::shared_ptr IUFindLightS(std::shared_ptr lvp, const char *name); + + /** @brief Find an IBLOB member in a vector BLOB property. + * @param bvp a pointer to a BLOB vector property. + * @param name the name of the member to search for. + * @return a pointer to an IBLOB member on match, or NULL if nothing is found. + */ + extern std::shared_ptr IUFindBLOBS(std::shared_ptr bvp, const char *name); + + /** @brief Returns the first ON switch it finds in the vector switch property. + * @note This is only valid for ISR_1OFMANY mode. That is, when only one switch out of many is allowed to be ON. Do not use this function if you can have multiple ON switches in the same vector property. + * @param sp a pointer to a switch vector property. + * @return a pointer to the \e first ON ISwitch member if found. If all switches are off, NULL is returned. + */ + extern std::shared_ptr IUFindOnSwitchS(std::shared_ptr svp); + + /** @brief Returns the index of first ON switch it finds in the vector switch property. + * @note This is only valid for ISR_1OFMANY mode. That is, when only one switch out of many is allowed to be ON. Do not use this function if you can have multiple ON switches in the same vector property. + * @param sp a pointer to a switch vector property. + * @return index to the \e first ON ISwitch member if found. If all switches are off, -1 is returned. + */ + extern int IUFindOnSwitchIndexS(std::shared_ptr svp); + + /** @brief Returns the name of the first ON switch it finds in the supplied arguments. + * @note This is only valid for ISR_1OFMANY mode. That is, when only one switch out of many is allowed to be ON. Do not use this function if you can have multiple ON switches in the same vector property. + * @note This is a convience function intended to be used in ISNewSwitch(...) function to find out ON switch name without having to change actual switch state via IUUpdateSwitch(..) + * @param states list of switch states passed by ISNewSwitch() + * @param names list of switch names passed by ISNewSwitch() + * @param n number of switches passed by ISNewSwitch() + * @return name of the \e first ON ISwitch member if found. If all switches are off, NULL is returned. + */ + extern const char *IUFindOnSwitchNameS(std::shared_ptr states, char *names[], int n); diff --git a/src/core/camera.cpp b/src/core/camera.cpp index 3fa4de56..b8baa096 100644 --- a/src/core/camera.cpp +++ b/src/core/camera.cpp @@ -44,19 +44,19 @@ Camera::~Camera() DLOG_F(INFO, "Camera Simulator Destructed"); } -bool Camera::connect(const IParams ¶ms) +bool Camera::connect(const nlohmann::json ¶ms) { DLOG_F(INFO, "%s is connected", getDeviceName()); return true; } -bool Camera::disconnect(const IParams ¶ms) +bool Camera::disconnect(const nlohmann::json ¶ms) { DLOG_F(INFO, "%s is disconnected", getDeviceName()); return true; } -bool Camera::reconnect(const IParams ¶ms) +bool Camera::reconnect(const nlohmann::json ¶ms) { return true; } diff --git a/src/core/camera.hpp b/src/core/camera.hpp index 6467e0bd..df1495d0 100644 --- a/src/core/camera.hpp +++ b/src/core/camera.hpp @@ -37,6 +37,31 @@ Description: Camera Simulator and Basic Definition #include "shared_memory.hpp" #endif +class CameraFrame +{ +public: + std::atomic_int binning_x; + std::atomic_int binning_y; + + std::atomic pixel; + std::atomic pixel_x; + std::atomic pixel_y; + std::atomic pixel_depth; + + std::atomic frame_x; + std::atomic frame_y; + std::atomic max_frame_x; + std::atomic max_frame_y; + + std::atomic_int frame_height; + std::atomic_int frame_width; + + std::string frame_type; + std::string frame_format; + std::string upload_mode; + std::atomic_bool is_fastread; +}; + class Camera : public Device { public: @@ -49,11 +74,11 @@ class Camera : public Device virtual ~Camera(); - virtual bool connect(const IParams ¶ms) override; + virtual bool connect(const nlohmann::json ¶ms) override; - virtual bool disconnect(const IParams ¶ms) override; + virtual bool disconnect(const nlohmann::json ¶ms) override; - virtual bool reconnect(const IParams ¶ms) override; + virtual bool reconnect(const nlohmann::json ¶ms) override; virtual bool isConnected() override; diff --git a/src/core/device.hpp b/src/core/device.hpp index 6687fa52..0c4b9dd6 100644 --- a/src/core/device.hpp +++ b/src/core/device.hpp @@ -57,11 +57,11 @@ class Device virtual ~Device(); public: - virtual bool connect(const IParams ¶ms) { return true; }; + virtual bool connect(const nlohmann::json ¶ms) { return true; }; - virtual bool disconnect(const IParams ¶ms) { return true; }; + virtual bool disconnect(const nlohmann::json ¶ms) { return true; }; - virtual bool reconnect(const IParams ¶ms) { return true; }; + virtual bool reconnect(const nlohmann::json ¶ms) { return true; }; virtual bool isConnected() { return true; } @@ -118,9 +118,9 @@ class Device std::shared_ptr deviceIOServer; public: - typedef bool (*ConnectFunc)(const IParams ¶ms); - typedef bool (*DisconnectFunc)(const IParams ¶ms); - typedef bool (*ReconnectFunc)(const IParams ¶ms); + typedef bool (*ConnectFunc)(const nlohmann::json ¶ms); + typedef bool (*DisconnectFunc)(const nlohmann::json ¶ms); + typedef bool (*ReconnectFunc)(const nlohmann::json ¶ms); typedef void (*InitFunc)(); typedef void (*InsertPropertyFunc)(const std::string &name, const std::any &value, const std::string &bind_get_func, const std::string &bind_set_func, const std::any &possible_values, PossibleValueType possible_type, bool need_check); typedef void (*SetPropertyFunc)(const std::string &name, const std::any &value); diff --git a/src/core/filterwheel.cpp b/src/core/filterwheel.cpp index 8bdce162..0d05a09b 100644 --- a/src/core/filterwheel.cpp +++ b/src/core/filterwheel.cpp @@ -44,19 +44,19 @@ Filterwheel::~Filterwheel() DLOG_F(INFO, "Filterwheel Simulator Destructed"); } -bool Filterwheel::connect(const IParams ¶ms) +bool Filterwheel::connect(const nlohmann::json ¶ms) { DLOG_F(INFO, "%s is connected", getDeviceName()); return true; } -bool Filterwheel::disconnect(const IParams ¶ms) +bool Filterwheel::disconnect(const nlohmann::json ¶ms) { DLOG_F(INFO, "%s is disconnected", getDeviceName()); return true; } -bool Filterwheel::reconnect(const IParams ¶ms) +bool Filterwheel::reconnect(const nlohmann::json ¶ms) { return true; } diff --git a/src/core/filterwheel.hpp b/src/core/filterwheel.hpp index 20a6dd8b..6ee56de4 100644 --- a/src/core/filterwheel.hpp +++ b/src/core/filterwheel.hpp @@ -39,11 +39,11 @@ class Filterwheel : virtual public Device Filterwheel(const std::string &name); ~Filterwheel(); - virtual bool connect(const IParams ¶ms) override; + virtual bool connect(const nlohmann::json ¶ms) override; - virtual bool disconnect(const IParams ¶ms) override; + virtual bool disconnect(const nlohmann::json ¶ms) override; - virtual bool reconnect(const IParams ¶ms) override; + virtual bool reconnect(const nlohmann::json ¶ms) override; virtual bool moveTo(const nlohmann::json ¶ms); }; \ No newline at end of file diff --git a/src/core/focuser.cpp b/src/core/focuser.cpp index f8d080af..af63762d 100644 --- a/src/core/focuser.cpp +++ b/src/core/focuser.cpp @@ -44,19 +44,19 @@ Focuser::~Focuser() DLOG_F(INFO, "Focuser Simulator Destructed"); } -bool Focuser::connect(const IParams ¶ms) +bool Focuser::connect(const nlohmann::json ¶ms) { DLOG_F(INFO, "%s is connected", getDeviceName()); return true; } -bool Focuser::disconnect(const IParams ¶ms) +bool Focuser::disconnect(const nlohmann::json ¶ms) { DLOG_F(INFO, "%s is disconnected", getDeviceName()); return true; } -bool Focuser::reconnect(const IParams ¶ms) +bool Focuser::reconnect(const nlohmann::json ¶ms) { return true; } diff --git a/src/core/focuser.hpp b/src/core/focuser.hpp index 5928d003..66585bc3 100644 --- a/src/core/focuser.hpp +++ b/src/core/focuser.hpp @@ -48,11 +48,11 @@ class Focuser : virtual public Device */ virtual ~Focuser(); - virtual bool connect(const IParams ¶ms) override; + virtual bool connect(const nlohmann::json ¶ms) override; - virtual bool disconnect(const IParams ¶ms) override; + virtual bool disconnect(const nlohmann::json ¶ms) override; - virtual bool reconnect(const IParams ¶ms) override; + virtual bool reconnect(const nlohmann::json ¶ms) override; protected: /** diff --git a/src/core/guider.cpp b/src/core/guider.cpp index a1eb77a2..54398497 100644 --- a/src/core/guider.cpp +++ b/src/core/guider.cpp @@ -44,19 +44,19 @@ Guider::~Guider() DLOG_F(INFO, "Guider Simulator Destructed"); } -bool Guider::connect(const IParams ¶ms) +bool Guider::connect(const nlohmann::json ¶ms) { DLOG_F(INFO, "%s is connected", getDeviceName()); return true; } -bool Guider::disconnect(const IParams ¶ms) +bool Guider::disconnect(const nlohmann::json ¶ms) { DLOG_F(INFO, "%s is disconnected", getDeviceName()); return true; } -bool Guider::reconnect(const IParams ¶ms) +bool Guider::reconnect(const nlohmann::json ¶ms) { return true; } \ No newline at end of file diff --git a/src/core/guider.hpp b/src/core/guider.hpp index e6c061a5..8074ca1a 100644 --- a/src/core/guider.hpp +++ b/src/core/guider.hpp @@ -48,9 +48,9 @@ class Guider : virtual public Device */ virtual ~Guider(); - virtual bool connect(const IParams ¶ms) override; + virtual bool connect(const nlohmann::json ¶ms) override; - virtual bool disconnect(const IParams ¶ms) override; + virtual bool disconnect(const nlohmann::json ¶ms) override; - virtual bool reconnect(const IParams ¶ms) override; + virtual bool reconnect(const nlohmann::json ¶ms) override; }; \ No newline at end of file diff --git a/src/core/solver.cpp b/src/core/solver.cpp index 60164989..5d4ac7a3 100644 --- a/src/core/solver.cpp +++ b/src/core/solver.cpp @@ -39,17 +39,17 @@ Solver::~Solver() { } -bool Solver::connect(const IParams ¶ms) +bool Solver::connect(const nlohmann::json ¶ms) { return true; } -bool Solver::disconnect(const IParams ¶ms) +bool Solver::disconnect(const nlohmann::json ¶ms) { return true; } -bool Solver::reconnect(const IParams ¶ms) +bool Solver::reconnect(const nlohmann::json ¶ms) { return true; } diff --git a/src/core/solver.hpp b/src/core/solver.hpp index d5a6b9d1..0f179d86 100644 --- a/src/core/solver.hpp +++ b/src/core/solver.hpp @@ -39,11 +39,11 @@ class Solver : virtual public Device Solver(const std::string &name); ~Solver(); - virtual bool connect(const IParams ¶ms) override; + virtual bool connect(const nlohmann::json ¶ms) override; - virtual bool disconnect(const IParams ¶ms) override; + virtual bool disconnect(const nlohmann::json ¶ms) override; - virtual bool reconnect(const IParams ¶ms) override; + virtual bool reconnect(const nlohmann::json ¶ms) override; public: virtual bool solve_image(const nlohmann::json ¶ms); diff --git a/src/core/telescope.cpp b/src/core/telescope.cpp index cf6f8358..a83a572d 100644 --- a/src/core/telescope.cpp +++ b/src/core/telescope.cpp @@ -44,19 +44,19 @@ Telescope::~Telescope() DLOG_F(INFO, "Telescope Simulator Destructed"); } -bool Telescope::connect(const IParams ¶ms) +bool Telescope::connect(const nlohmann::json ¶ms) { DLOG_F(INFO, "%s is connected", getDeviceName()); return true; } -bool Telescope::disconnect(const IParams ¶ms) +bool Telescope::disconnect(const nlohmann::json ¶ms) { DLOG_F(INFO, "%s is disconnected", getDeviceName()); return true; } -bool Telescope::reconnect(const IParams ¶ms) +bool Telescope::reconnect(const nlohmann::json ¶ms) { return true; } diff --git a/src/core/telescope.hpp b/src/core/telescope.hpp index 349293b4..ae3c0e14 100644 --- a/src/core/telescope.hpp +++ b/src/core/telescope.hpp @@ -47,11 +47,11 @@ class Telescope : virtual public Device */ virtual ~Telescope(); - virtual bool connect(const IParams ¶ms) override; + virtual bool connect(const nlohmann::json ¶ms) override; - virtual bool disconnect(const IParams ¶ms) override; + virtual bool disconnect(const nlohmann::json ¶ms) override; - virtual bool reconnect(const IParams ¶ms) override; + virtual bool reconnect(const nlohmann::json ¶ms) override; public: /** diff --git a/src/modules/client/indiclient.hpp b/src/modules/client/indiclient.hpp index 74e7f4ac..bba1c26d 100644 --- a/src/modules/client/indiclient.hpp +++ b/src/modules/client/indiclient.hpp @@ -65,7 +65,6 @@ class LithiumIndiClient : public HYDROGEN::BaseClient // must use this in LGuider2 rather than BaseClient::disconnectServer() bool DisconnectIndiServer(); -#if LITHIUM_VERSION_MAJOR >= 2 protected: // old deprecated interface INDI Version < 2.0.0 virtual void newDevice(LITHIUM::BaseDevice *dp) = 0; virtual void removeDevice(LITHIUM::BaseDevice *dp) = 0; @@ -121,7 +120,6 @@ class LithiumIndiClient : public HYDROGEN::BaseClient { return newMessage((LITHIUM::BaseDevice *)device, messageID); } -#endif }; #endif \ No newline at end of file diff --git a/src/modules/device/device_manager.cpp b/src/modules/device/device_manager.cpp index 60b31f4c..30c41af9 100644 --- a/src/modules/device/device_manager.cpp +++ b/src/modules/device/device_manager.cpp @@ -35,10 +35,6 @@ Description: Device Manager #include "server/message_bus.hpp" #include "thread/thread.hpp" -#include "core/device_exception.hpp" - -#include "nlohmann/json.hpp" - #include "core/camera.hpp" #include "core/telescope.hpp" #include "core/focuser.hpp" @@ -46,12 +42,10 @@ Description: Device Manager #include "core/solver.hpp" #include "core/guider.hpp" +#include "core/device_exception.hpp" #include "core/camera_utils.hpp" - #include "device_utils.hpp" -#include "loguru/loguru.hpp" - #ifdef __cpp_lib_format #include #else @@ -64,6 +58,9 @@ Description: Device Manager #include "config.h" +#include "loguru/loguru.hpp" +#include "magic_enum/magic_enum.hpp" +#include "nlohmann/json.hpp" // For DEVICE_FUNC @@ -225,9 +222,9 @@ namespace Lithium if (!logMsg.empty()) { - DLOG_F(INFO, logMsg); + DLOG_F(INFO, "{}", logMsg); } - DLOG_F(INFO, "Added new {} instance successfully", DeviceTypeToString(type)); + DLOG_F(INFO, "Added new {} instance successfully", magic_enum::enum_name(type)); } } catch (const std::exception &e) diff --git a/src/modules/error/error_code.hpp b/src/modules/error/error_code.hpp index cdcc4e14..7b11f403 100644 --- a/src/modules/error/error_code.hpp +++ b/src/modules/error/error_code.hpp @@ -81,4 +81,4 @@ enum class ServerError None, InvalidParameters, InvalidFormat -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/modules/io/compress.cpp b/src/modules/io/compress.cpp index faf24190..570a697e 100644 --- a/src/modules/io/compress.cpp +++ b/src/modules/io/compress.cpp @@ -38,6 +38,9 @@ Description: Compressor using ZLib #include #include #include +#ifdef __cpp_lib_format +#include +#endif #include "loguru/loguru.hpp" #include "libzippp/libzippp.h" @@ -174,7 +177,10 @@ namespace Lithium::File { // Size of the read/write buffer #ifdef __cpp_lib_format - std::string outfile_name = std::format("{}.gz", folder_name); + // TODO : Some strange bugs here + // 'format' is not a member of 'std'; did you mean 'fmt::v10::format'? + // std::string outfile_name = std::format("{}.gz", folder_name); + std::string outfile_name = fmt::format("{}.gz", folder_name); #else std::string outfile_name = fmt::format("{}.gz", folder_name); #endif diff --git a/src/modules/module/compiler.cpp b/src/modules/module/compiler.cpp index 2aa4e500..467f7d21 100644 --- a/src/modules/module/compiler.cpp +++ b/src/modules/module/compiler.cpp @@ -243,7 +243,7 @@ namespace Lithium // Write the command input DWORD bytesWritten; - if (!WriteFile(hStdoutWrite, input, input.size(), &bytesWritten, NULL)) + if (!WriteFile(hStdoutWrite, input.c_str(), input.size(), &bytesWritten, NULL)) { LOG_F(ERROR, "Failed to write input for shell command: {}", command); return exitCode; diff --git a/src/modules/web/utils.cpp b/src/modules/web/utils.cpp index 48e516ca..75f4a431 100644 --- a/src/modules/web/utils.cpp +++ b/src/modules/web/utils.cpp @@ -249,13 +249,13 @@ bool CheckAndKillProgramOnPort(int port) #ifdef _WIN32 #ifdef __cpp_lib_format - ret = std::system(std::format("taskkill /F /PID {}", pid_str)); + ret = std::system(std::format("taskkill /F /PID {}", pid_str).c_str()); #else - ret = std::system(fmt::format("taskkill /F /PID {}", pid_str)); + ret = std::system(fmt::format("taskkill /F /PID {}", pid_str).c_str()); #endif #else #ifdef __cpp_lib_format - int ret = std::system(std::format("kill {}", pid_str)); + int ret = std::system(std::format("kill {}", pid_str).c_str()); #else int ret = std::system(fmt::format("kill {}", pid_str).c_str()); #endif diff --git a/src/websocket/device/WsDeviceInstance.cpp b/src/websocket/device/WsDeviceInstance.cpp index 39f46914..eb34d297 100644 --- a/src/websocket/device/WsDeviceInstance.cpp +++ b/src/websocket/device/WsDeviceInstance.cpp @@ -211,6 +211,11 @@ void WsDeviceInstance::getProperty(const json &m_params) sendMessage("hello"); } +void WsDeviceInstance::getProperties(const json &m_params) +{ + +} + void WsDeviceInstance::runTask(const json &m_params) { } diff --git a/src/websocket/device/WsDeviceInstance.hpp b/src/websocket/device/WsDeviceInstance.hpp index a5068443..9f0fbea3 100644 --- a/src/websocket/device/WsDeviceInstance.hpp +++ b/src/websocket/device/WsDeviceInstance.hpp @@ -57,83 +57,181 @@ using json = nlohmann::json; class WsDeviceHub; // FWD +/** + * @brief Class representing an instance of a WebSocket device. + * + */ class WsDeviceInstance : public oatpp::websocket::AsyncWebSocket::Listener { public: + /** + * @brief Construct a new WsDeviceInstance object. + * + * @param socket Shared pointer to the AsyncWebSocket object. + * @param hub Shared pointer to the WsDeviceHub object. + * @param device_name Name of the device. + * @param userId Id of the user. + */ WsDeviceInstance(const std::shared_ptr &socket, const std::shared_ptr &hub, const oatpp::String &device_name, v_int32 userId); + /** + * @brief Destroy the WsDeviceInstance object. + * + */ ~WsDeviceInstance(); /** - * Send message to WsDeviceInstance (to user). - * @param message + * @brief Send a message to the WsDeviceInstance (to user). + * + * @param message The message to be sent. */ void sendMessage(const oatpp::String &message); + /** + * @brief Send a binary message to the WsDeviceInstance (to user). + * + * @param binary_message Pointer to the binary message. + * @param size Size of the binary message. + */ void sendBinaryMessage(void *binary_message, int size); /** - * Get hub of the WsDeviceInstance. - * @return + * @brief Get the hub of the WsDeviceInstance. + * + * @return Shared pointer to the WsDeviceHub object. */ std::shared_ptr getHub(); /** - * Get WsDeviceInstance device_name. - * @return + * @brief Get the name of the WsDeviceInstance device. + * + * @return The name of the device. */ oatpp::String getDeviceName(); /** - * Get WsDeviceInstance userId. - * @return + * @brief Get the id of the WsDeviceInstance user. + * + * @return The id of the user. */ v_int32 getUserId(); public: + /** + * @brief Set a property of the WsDeviceInstance. + * + * @param m_params JSON object containing the property to be set. + */ void setProperty(const json &m_params); + + /** + * @brief Get a property of the WsDeviceInstance. + * + * @param m_params JSON object containing the property to be retrieved. + */ void getProperty(const json &m_params); + + /** + * @brief Get all properties of the WsDeviceInstance. + * + * @param m_params JSON object containing the request. + */ + void getProperties(const json &m_params); + + /** + * @brief Run a task on the WsDeviceInstance. + * + * @param m_params JSON object containing the task to be run. + */ void runTask(const json &m_params); + + /** + * @brief Run a function on the WsDeviceInstance. + * + * @param m_params JSON object containing the function to be run. + */ void runFunc(const json &m_params); public: // WebSocket Listener methods + /** + * @brief Handle a ping message received by the WebSocket. + * + * @param socket Shared pointer to the AsyncWebSocket object. + * @param message The ping message received. + * @return CoroutineStarter object. + */ CoroutineStarter onPing(const std::shared_ptr &socket, const oatpp::String &message) override; + + /** + * @brief Handle a pong message received by the WebSocket. + * + * @param socket Shared pointer to the AsyncWebSocket object. + * @param message The pong message received. + * @return CoroutineStarter object. + */ CoroutineStarter onPong(const std::shared_ptr &socket, const oatpp::String &message) override; + + /** + * @brief Handle the WebSocket being closed. + * + * @param socket Shared pointer to the AsyncWebSocket object. + * @param code The close code. + * @param message The close message. + * @return CoroutineStarter object. + */ CoroutineStarter onClose(const std::shared_ptr &socket, v_uint16 code, const oatpp::String &message) override; + + /** + * @brief Handle a message received by the WebSocket. + * + * @param socket Shared pointer to the AsyncWebSocket object. + * @param opcode The opcode of the message. + * @param data Pointer to the message data. + * @param size The size of the message data. + * @return CoroutineStarter object. + */ CoroutineStarter readMessage(const std::shared_ptr &socket, v_uint8 opcode, p_char8 data, oatpp::v_io_size size) override; private: /** - * Buffer for messages. Needed for multi-frame messages. + * @brief Buffer for messages. Needed for multi-frame messages. + * */ oatpp::data::stream::BufferOutputStream m_messageBuffer; /** - * Lock for synchronization of writes to the web socket. + * @brief Lock for synchronization of writes to the WebSocket. + * */ oatpp::async::Lock m_writeLock; std::unique_ptr m_CommandDispatcher; + /** + * @brief Register a function handler for the VCommandDispatcher. + * + * @tparam ClassType The class type of the handler. + * @param name The name of the function. + * @param handler The function handler. + */ template void LiRegisterFunc(const std::string &name, void (ClassType::*handler)(const json &)) { m_CommandDispatcher->RegisterHandler(name, handler, this); } - bool LiRunFunc(const std::string &name, const json ¶ms) - { - if (m_CommandDispatcher->HasHandler(name)) - { - m_CommandDispatcher->Dispatch(name, params); - return true; - } - return false; - } + /** + * @brief Run a function on the VCommandDispatcher. + * + * @param name The name of the function to be run. + * @param params JSON object containing the parameters for the function. + * @return True if the function was run successfully, false otherwise. + */ + bool LiRunFunc(const std::string &name, const json ¶ms); private: std::shared_ptr m_socket; @@ -143,10 +241,10 @@ class WsDeviceInstance : public oatpp::websocket::AsyncWebSocket::Listener private: /** - * Inject async executor object. + * @brief Inject async executor object. + * */ OATPP_COMPONENT(std::shared_ptr, m_asyncExecutor); - }; #endif // WSDEVICEINSTANCE_HPP