REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
run.cpp
Go to the documentation of this file.
1// Copyright (c) 2024 anabrid GmbH
2// Contact: https://www.anabrid.com/licensing/
3// SPDX-License-Identifier: MIT OR GPL-2.0-or-later
4
5#include "run/run.h"
6
7#include "utils/logging.h"
8#include <utility>
9
10FLASHMEM run::RunConfig run::RunConfig::from_json(JsonObjectConst &json) {
11 // ATTENTION: ArduinoJSON cannot easily handle 64bit integers,
12 // cf. https://arduinojson.org/v6/api/config/use_long_long/
13 // Therefore, client libraries should make use of appropriate units
14 // which are summed here together.
15
16 uint64_t ic_time_ms = json["ic_time_ms"], ic_time_us = json["ic_time_us"], ic_time_ns = json["ic_time_ns"],
17 ic_time_def = json["ic_time"], // Nanoseconds per default
18
19 op_time_ms = json["op_time_ms"], op_time_us = json["op_time_us"], op_time_ns = json["op_time_ns"],
20 op_time_def = json["op_time"]; // Nanoseconds per default
21
22 uint64_t us = 1000, ms = 1'000'000;
23
24 run::RunConfig run;
25
26 run.ic_time = ic_time_def + ic_time_ns + us * ic_time_us + ms * ic_time_ms;
27 run.op_time = op_time_def + op_time_ns + us * op_time_us + ms * op_time_ms;
28
29 // LOG_MEV("ic_time_ns = %lld, op_time_ns=%lld", run.ic_time, run.op_time);
30
31 // default values for the following keys are given
32 // in the RunConfig class definition.
33
34 if (json.containsKey("halt_on_overload"))
35 run.halt_on_overload = json["halt_on_overload"];
36
37 if (json.containsKey("streaming"))
38 run.streaming = json["streaming"];
39
40 if (json.containsKey("repetitive"))
41 run.repetitive = json["repetitive"];
42
43 if (json.containsKey("write_run_state_changes"))
44 run.write_run_state_changes = json["write_run_state_changes"];
45
46 if (json.containsKey("calibrate"))
47 run.calibrate = json["calibrate"];
48
49 return run;
50}
51
52FLASHMEM
53run::Run::Run(std::string id, const run::RunConfig &config)
54 : id(std::move(id)), config(config), daq_config{} {}
55
56FLASHMEM
57run::Run::Run(std::string id, const run::RunConfig &config, const daq::DAQConfig &daq_config)
58 : id(std::move(id)), config(config), daq_config(daq_config) {}
59
60FLASHMEM
61run::Run run::Run::from_json(JsonObjectConst &json) {
62 auto json_run_config = json["config"].as<JsonObjectConst>();
63 auto run_config = RunConfig::from_json(json_run_config);
64 auto daq_config = daq::DAQConfig::from_json(json["daq_config"].as<JsonObjectConst>());
65 auto id = json["id"].as<std::string>();
66 if (id.size() != 32 + 4) {
67 id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
68 }
69 return {id, run_config, daq_config};
70}
71
72FLASHMEM
73run::RunStateChange run::Run::to(run::RunState new_state, unsigned int t) {
74 auto old = state;
75 state = new_state;
76 return {t, old, state};
77}
uint32_t uint32_t size
Definition flasher.cpp:63