REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
base.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 <daq/base.h>
6
7FLASHMEM daq::DAQConfig::DAQConfig(uint8_t num_channels, unsigned int sample_rate)
8 : num_channels(num_channels), sample_rate(sample_rate) {
9 // CARE: num_channels must be power-of-two and the object should be checked with is_valid() afterwards
10}
11
12FLASHMEM daq::DAQConfig daq::DAQConfig::from_json(JsonObjectConst &&json) {
13 DAQConfig daq_config;
14 // Return default if no options are given
15 if (json.isNull())
16 return daq_config;
17 // Otherwise, parse DAQConfig from json
18 auto num_channels = json["num_channels"];
19 if (!num_channels.isNull() and num_channels.is<unsigned int>())
20 daq_config.num_channels = num_channels;
21 auto sample_rate = json["sample_rate"];
22 if (!sample_rate.isNull() and sample_rate.is<unsigned int>())
23 daq_config.sample_rate = sample_rate;
24 auto sample_op = json["sample_op"];
25 if (!sample_op.isNull() and sample_op.is<bool>())
26 daq_config.sample_op = sample_op;
27 auto sample_op_end = json["sample_op_end"];
28 if (!sample_op_end.isNull() and sample_op_end.is<bool>())
29 daq_config.sample_op_end = sample_op_end;
30 return daq_config;
31}
32
33uint8_t daq::DAQConfig::get_num_channels() const { return num_channels; }
34
35uint8_t daq::DAQConfig::get_num_channels_min_power_of_two() const {
36 // The internal DMA buffer can only work with row sizes that are a power-of-two.
37 // So for each possible number of channels N, return the smallest power-of-two >= N.
38 switch (num_channels) {
39 case 0:
40 return 0;
41 case 1:
42 return 1;
43 case 2:
44 return 2;
45 case 3:
46 case 4:
47 return 4;
48 case 5:
49 case 6:
50 case 7:
51 case 8:
52 default:
53 return 8;
54 }
55}
56
57unsigned int daq::DAQConfig::get_sample_rate() const { return sample_rate; }
58
59bool daq::DAQConfig::should_sample_op() const { return sample_op; }
60
61bool daq::DAQConfig::should_sample_op_end() const { return sample_op_end; }
62
63float daq::DAQConfig::index_to_time(size_t index) const {
64 return static_cast<float>(index) / static_cast<float>(sample_rate);
65}
FLASHMEM void index(awot::Request &req, awot::Response &res)
Definition server.cpp:120