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