10#include <mode/counters.h>
11#include <run/manager.h>
12#include <run/registry.h>
13#include <run/handlers.h>
14#include <utils/logging.h>
15#include <protocol/protocol.h>
17FLASHMEM utils::status run::RunManager::prepare_run(JsonObjectConst msg_in, Stream &io) {
18 LOG_ALWAYS(
"run::RunManager::prepare_run");
19 if (!msg_in.containsKey(
"id"))
20 return utils::status(-1,
"Need a run ID, must be a UUID");
27 auto json_run_config = msg_in[
"config"].as<JsonObjectConst>();
29 bool calibrate = json_run_config[
"calibrate"] |
false;
30 bool compat_streaming = json_run_config[
"streaming"] |
false;
31 bool enable_state_change_handler = json_run_config[
"enable_state_change_handler"] |
true;
32 bool enable_data_handler = json_run_config[
"enable_data_handler"] |
true;
33 bool enable_alt_data_handler = json_run_config[
"enable_alt_data_handler"] |
false;
35 const char* default_runner_type = compat_streaming ?
"flexio" :
"sleep";
37 std::string run_type = msg_in[
"run_type"] | default_runner_type;
38 auto ®istry = run::drivers::Registry::get();
39 current_run = registry.create(run_type);
42 if(run_type == default_runner_type) {
43 LOG_ALWAYS(
"Default runner is not part of registry. Will default to first available driver.");
44 current_run = registry.create_any();
46 return utils::status(-2,
"Run Driver Registry is empty.");
49 return utils::status(-3,
"Requested run_type is not available.");
53 current_run->from_json(msg_in);
55 if(enable_state_change_handler) {
56 auto& envelope_out = msg::JsonLinesProtocol::get().envelope_out;
57 current_run->state_change_handler =
new run::RunStateChangeNotificationHandler(io, *envelope_out);
60 if(enable_data_handler) {
61 current_run->data_handler =
new run::RunDataNotificationHandler(io);
64 if(enable_alt_data_handler) {
65 current_run->alt_data_handler =
new run::StreamingRunDataNotificationHandler{io};
69 LOG_ALWAYS(
"Calibrating routes for run...")
71 LOG_ERROR("Error during self-calibration. Continue with reduced accuracy.");
77FLASHMEM
void run::RunManager::start_run(const
msg::Request& req, Stream &io) {
78 auto status = prepare_run(req.msg_in, io);
80 msg::StreamingJsonResponse::empty_envelope(io, req,
status);
84 auto json_run_config = req.msg_in[
"config"].as<JsonObjectConst>();
85 bool repetitive = json_run_config[
"repetitive"] |
false;
91FLASHMEM utils::status run::RunManager::stop_run(JsonObjectConst msg_in, JsonObject &msg_out) {
93 return utils::status::success();
96FLASHMEM
void run::drivers::DynamicRegistry::write_handler_names_to(JsonArray &target) {
97 for (
auto const &kv : entries) {
if(((src) >=(0x60000000) &&(src)<(0x60000000)+(0x800000)))
static constexpr int success