patch to 1.0.0-rc.36
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
#include <base64/Base64.h>
|
||||
#include <httplib/httplib.h>
|
||||
|
||||
#include "DectrisSimplonClient.h"
|
||||
|
||||
std::string to_string(SimplonState state) {
|
||||
@@ -17,11 +20,9 @@ std::string to_string(SimplonState state) {
|
||||
}
|
||||
}
|
||||
|
||||
DectrisSimplonClient::DectrisSimplonClient(const std::string &addr, uint16_t port)
|
||||
: cli(addr, port) {
|
||||
cli.set_connection_timeout(std::chrono::seconds(1));
|
||||
cli.set_read_timeout(std::chrono::minutes(20)); // Initialize or disarm might take a lot of time
|
||||
cli.set_write_timeout(std::chrono::minutes(20)); // Initialize or disarm might take a lot of time
|
||||
DectrisSimplonClient::DectrisSimplonClient(const std::string &addr, uint16_t in_port)
|
||||
: hostname(addr), port(in_port) {
|
||||
|
||||
}
|
||||
|
||||
void DectrisSimplonClient::SendDetectorCommand(SimplonDetectorCommand cmd) {
|
||||
@@ -44,7 +45,14 @@ void DectrisSimplonClient::SendDetectorCommand(SimplonDetectorCommand cmd) {
|
||||
break;
|
||||
}
|
||||
auto addr = GenAddr(SimplonModule::Detector, SimplonTask::Command, key);
|
||||
auto res = cli.Post(addr);
|
||||
|
||||
httplib::Client cli_cmd(hostname, port);
|
||||
cli_cmd.set_connection_timeout(std::chrono::milliseconds(500));
|
||||
cli_cmd.set_read_timeout(std::chrono::minutes(20)); // Initialize or disarm might take a lot of time
|
||||
cli_cmd.set_write_timeout(std::chrono::minutes(20)); // Initialize or disarm might take a lot of time
|
||||
|
||||
auto res = cli_cmd.Post(addr);
|
||||
|
||||
if (!res || res->status != httplib::StatusCode::OK_200) {
|
||||
std::string err_msg = "Command failed " + key + "; HTTP " + std::to_string(res->status);
|
||||
if (res && !res->body.empty())
|
||||
@@ -60,7 +68,13 @@ void DectrisSimplonClient::SetConfig(SimplonModule element, const std::string &k
|
||||
nlohmann::json j;
|
||||
j["value"] = value;
|
||||
|
||||
auto res = cli.Post(addr, j.dump(), "application/json");
|
||||
httplib::Client cli_cmd(hostname, port);
|
||||
cli_cmd.set_connection_timeout(std::chrono::seconds(1));
|
||||
cli_cmd.set_read_timeout(std::chrono::minutes(20)); // Initialize or disarm might take a lot of time
|
||||
cli_cmd.set_write_timeout(std::chrono::minutes(20)); // Initialize or disarm might take a lot of time
|
||||
|
||||
auto res = cli_cmd.Post(addr, j.dump(), "application/json");
|
||||
|
||||
if (!res || res->status != httplib::StatusCode::OK_200) {
|
||||
std::string err_msg = "Configure failed " + key + "; HTTP " + std::to_string(res->status);
|
||||
if (res && !res->body.empty())
|
||||
@@ -108,7 +122,11 @@ std::string DectrisSimplonClient::GenAddr(DectrisSimplonClient::SimplonModule el
|
||||
SimplonConfig
|
||||
DectrisSimplonClient::GetConfig(DectrisSimplonClient::SimplonModule element, DectrisSimplonClient::SimplonTask task,
|
||||
const std::string &key) {
|
||||
auto res = cli.Get(GenAddr(element, task, key));
|
||||
httplib::Client cli_simple(hostname, port);
|
||||
cli_simple.set_connection_timeout(std::chrono::milliseconds(500));
|
||||
cli_simple.set_read_timeout(std::chrono::seconds(1));
|
||||
cli_simple.set_write_timeout(std::chrono::seconds(1));
|
||||
auto res = cli_simple.Get(GenAddr(element, task, key));
|
||||
|
||||
if (!res) {
|
||||
throw JFJochException(JFJochExceptionCategory::SimplonError,
|
||||
@@ -291,3 +309,17 @@ float DectrisSimplonClient::GetHumidity() {
|
||||
float DectrisSimplonClient::GetTemperature() {
|
||||
return GetStatus(SimplonModule::Detector, "temperature");
|
||||
}
|
||||
|
||||
|
||||
std::vector<uint32_t> DectrisSimplonClient::GetPixelMask() {
|
||||
auto mask = GetDetCfg("pixel_mask");
|
||||
if (!mask.val.is_object() || !mask.val.contains("shape") || !mask.val.contains("data"))
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "No pixel mask");
|
||||
|
||||
auto shape = mask.val["shape"];
|
||||
|
||||
std::vector<uint32_t> pixel_mask(shape[0].get<int64_t>() * shape[1].get<int64_t>());
|
||||
macaron::Decode(mask.val["data"], pixel_mask);
|
||||
|
||||
return pixel_mask;
|
||||
}
|
||||
Reference in New Issue
Block a user