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
35unsigned int daq::DAQConfig::get_sample_rate() const { return sample_rate; }
36
37bool daq::DAQConfig::should_sample_op() const { return sample_op; }
38
39bool daq::DAQConfig::should_sample_op_end() const { return sample_op_end; }
40
41FLASHMEM bool daq::DAQConfig::is_valid() const {
42 // Total effective samples per seconds is limited due to streaming speed
43 if (sample_rate * num_channels > 1'000'000 or sample_rate < 32)
44 return false;
45 // Number of channels must be power-of-two
46 if ((num_channels > 0) and ((num_channels & (num_channels - 1)) != 0))
47 return false;
48 return true;
49}
50
52 return static_cast<float>(index) / static_cast<float>(sample_rate);
53}
Data acquisition configuration.
Definition base.h:29
bool should_sample_op_end() const
Get whether to sample at the end of OP.
Definition base.cpp:39
bool should_sample_op() const
Get whether to sample during OP.
Definition base.cpp:37
static DAQConfig from_json(JsonObjectConst &&json)
Construct a configuration from a JsonObject.
Definition base.cpp:12
uint8_t get_num_channels() const
Get the configured number of channels.
Definition base.cpp:33
DAQConfig()=default
Construct a configuration using default values.
float index_to_time(size_t index) const
Convert a sample index to a time in seconds.
Definition base.cpp:51
bool is_valid() const
Check whether the configuration is valid.
Definition base.cpp:41
unsigned int get_sample_rate() const
Get the configured sample rate.
Definition base.cpp:35
FLASHMEM void index(awot::Request &req, awot::Response &res)
Definition server.cpp:120