REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
daq.h
Go to the documentation of this file.
1// Copyright (c) 2024 anabrid GmbH
2// Contact: https://www.anabrid.com/licensing/
3//
4// SPDX-License-Identifier: MIT OR GPL-2.0-or-later
5
6#pragma once
7
8#include "daq/daq.h"
9#include "protocol/handler.h"
10
11namespace msg {
12namespace handlers {
13
16public:
17 int handle(JsonObjectConst msg_in, JsonObject &msg_out) override {
18 std::array<float, daq::NUM_CHANNELS> data{};
19
20 auto do_sample_avg = msg_in["sample_avg"];
21 if (do_sample_avg) {
22 data = daq::average(daq::sample, do_sample_avg["size_samples"], do_sample_avg["avg_us"]);
23 } else {
24 data = daq::sample();
25 }
26
27 if (msg_in.containsKey("channel")) {
28 uint8_t channel = msg_in["channel"];
29 if (channel < 0 || channel >= daq::NUM_CHANNELS) {
30 msg_out["error"] = "Channel has to be a single number.";
31 return error(1);
32 }
33
34 msg_out["data"] = data[channel];
35 return error(0);
36 } else {
37 auto data_json = msg_out.createNestedArray("data");
38 copyArray(data.data(), data.size(), data_json);
39 return error(0);
40 }
41 }
42};
43
44} // namespace handlers
45} // namespace msg
A MessageHandler is a functor/closure like event handler.
Definition handler.h:21
constexpr int error(int internal_code)
Definition handler.h:32
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 daq.h:17
constexpr uint8_t NUM_CHANNELS
Number of channels available in the daq system.
Definition base.h:15
std::array< T, NUM_CHANNELS > average(std::array< T, NUM_CHANNELS >(*sample_function)(), size_t samples=100, unsigned int delay_us=33)
Acquire an averaged sample (either raw or float).
Definition daq.h:96
std::array< float, NUM_CHANNELS > sample()
Acquire one one-demand sample. Can not be used during a continuous acquisition.
Definition daq.cpp:519
Definition carrier.h:12