REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
carrier.h
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#pragma once
6
7#include "protocol/handler.h"
8
9#include "carrier/carrier.h"
10#include "ota/flasher.h" // reboot()
11
12namespace msg {
13namespace handlers {
14
15using namespace carrier;
16
25
28public:
30
31 int handle(JsonObjectConst msg_in, JsonObject &msg_out) override {
32 // Attention: We do not use carrier.user_set_config (which is actually Entity::user_set_config)
33 // because we want to expose a few "goodies" at Carrier level
34 utils::status result = carrier.user_set_extended_config(msg_in, msg_out);
35 if(!result)
36 msg_out["error"] = result.msg;
37 return error(result.code);
38 }
39};
40
43public:
45
46 int handle(JsonObjectConst msg_in, JsonObject &msg_out) override {
47 utils::status result = carrier.user_get_config(msg_in, msg_out);
48 if(!result)
49 msg_out["error"] = result.msg;
50 return error(result.code);
51 }
52};
53
56public:
58
59 int handle(JsonObjectConst msg_in, JsonObject &msg_out) override {
60 auto entities_obj = msg_out.createNestedObject("entities");
61 carrier.classifier_to_json(entities_obj);
62 return success;
63 }
64};
65
68public:
70
71 int handle(JsonObjectConst msg_in, JsonObject &msg_out) override {
72 utils::status result = carrier.user_reset_config(msg_in, msg_out);
73 if(!result)
74 msg_out["error"] = result.msg;
75 return error(result.code);
76 }
77};
78
80public:
82
83 int handle(JsonObjectConst msg_in, JsonObject &msg_out) override {
84 utils::status result = carrier.user_get_overload_status(msg_in, msg_out);
85 if(!result)
86 msg_out["error"] = result.msg;
87 return error(result.code);
88 }
89};
90
91} // namespace handlers
92} // namespace msg
Top-level hierarchy controlled by a single microcontroller.
Definition carrier.h:38
CarrierMessageHandlerBase(Carrier &carrier)
Definition carrier.h:23
int handle(JsonObjectConst msg_in, JsonObject &msg_out) override
The actual handler method gets a message and returns a message next to the status code.
Definition carrier.h:46
int handle(JsonObjectConst msg_in, JsonObject &msg_out) override
The actual handler method gets a message and returns a message next to the status code.
Definition carrier.h:59
int handle(JsonObjectConst msg_in, JsonObject &msg_out) override
The actual handler method gets a message and returns a message next to the status code.
Definition carrier.h:83
A MessageHandler is a functor/closure like event handler.
Definition handler.h:21
constexpr int error(int internal_code)
Definition handler.h:32
static constexpr int success
Definition handler.h:24
int handle(JsonObjectConst msg_in, JsonObject &msg_out) override
The actual handler method gets a message and returns a message next to the status code.
Definition carrier.h:71
int handle(JsonObjectConst msg_in, JsonObject &msg_out) override
The actual handler method gets a message and returns a message next to the status code.
Definition carrier.h:31
A recoverable error, inspired from https://abseil.io/docs/cpp/guides/status and https://github....
Definition error.h:35
int code
Status code. 0 means success.
Definition error.h:37
std::string msg
Human readable error string.
Definition error.h:38
Definition carrier.h:12