REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
protocol_oob.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#ifdef ARDUINO
8
9#include <ArduinoJson.h>
10#include <QNEthernetClient.h>
11
12#include "carrier/carrier.h"
13#include "daq/daq.h"
14#include "run/run.h"
15
16namespace client {
17
19 // TODO: is only public for some hacky fake data streaming for now
20public:
21 // TODO: This can become invalid on disconnects
22 // TODO: Possibly needs locking/synchronizing with other writes
23 Print &target; // net::EthernetClient &client;
24 DynamicJsonDocument &envelope_out;
25
26public:
27 RunStateChangeNotificationHandler(Print &target, DynamicJsonDocument &envelopeOut)
28 : target(target), envelope_out(envelopeOut) {}
29
30 void handle(run::RunStateChange change, const run::Run &run) override;
31};
32
45public:
46 // TODO: This can become invalid on disconnects
47 // TODO: Possibly needs locking/synchronizing with other writes
49 Print &target; // net::EthernetClient &client;
50
51private:
52 // TODO: At least de-duplicate some strings, so it doesn't explode the second someone touches it.
53 static constexpr decltype(auto) MESSAGE_START =
54 R"({ "type": "run_data", "msg": { "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "entity": ["XX-XX-XX-XX-XX-XX", "0"], "data": [)";
55 static constexpr decltype(auto) MESSAGE_END = "]}}";
56 static constexpr size_t BUFFER_LENGTH_STATIC = sizeof(MESSAGE_START) - sizeof('\0');
57 static constexpr size_t BUFFER_IDX_RUN_ID = 38;
58 static constexpr size_t BUFFER_LENGTH_RUN_ID = 32 + 4;
59 static constexpr size_t BUFFER_IDX_ENTITY_ID = 89;
60 static constexpr size_t BUFFER_LENGTH_ENTITY_ID = 12 + 5;
61 static constexpr size_t BUFFER_LENGTH =
62 BUFFER_LENGTH_STATIC + daq::stream::details::BUFFER_SIZE / 2 * sizeof("[sD.FFF]") + sizeof(MESSAGE_END);
63 char str_buffer[BUFFER_LENGTH]{};
64
65 size_t actual_buffer_length = BUFFER_LENGTH;
66
67public:
69
70 static size_t calculate_inner_buffer_length(size_t inner_count);
71 static size_t calculate_outer_buffer_position(size_t outer_count, size_t inner_count);
72 static size_t calculate_total_buffer_length(size_t outer_count, size_t inner_count);
73
74 void prepare(run::Run &run) override;
75 void handle(volatile uint32_t *data, size_t outer_count, size_t inner_count, const run::Run &run) override;
76 void stream(volatile uint32_t *buffer, run::Run &run) override;
77};
78
86 Print &target;
87
88 void handle(uint16_t* data, size_t outer_count, size_t inner_count, const run::Run &run);
89};
90
91} // namespace client
92
93#endif // ARDUINO
Top-level hierarchy controlled by a single microcontroller.
Definition carrier.h:38
This class allows to compose a specific JSON message without using ArduinoJSON.
RunDataNotificationHandler(carrier::Carrier &carrier, Print &target)
void handle(volatile uint32_t *data, size_t outer_count, size_t inner_count, const run::Run &run) override
void prepare(run::Run &run) override
void stream(volatile uint32_t *buffer, run::Run &run) override
static size_t calculate_total_buffer_length(size_t outer_count, size_t inner_count)
static size_t calculate_inner_buffer_length(size_t inner_count)
static size_t calculate_outer_buffer_position(size_t outer_count, size_t inner_count)
void handle(run::RunStateChange change, const run::Run &run) override
RunStateChangeNotificationHandler(Print &target, DynamicJsonDocument &envelopeOut)
Definition run.h:47
uint32_t
Definition flasher.cpp:195
Definition run.h:14
Variant of RunDataNotificationHandler using utils::StreamingJson.
void handle(uint16_t *data, size_t outer_count, size_t inner_count, const run::Run &run)