21#ifndef SEEKDAS_SEEKDAS_HPP
22#define SEEKDAS_SEEKDAS_HPP
30#include <initializer_list>
38#include "seekdas_ffi.h"
44class Error :
public std::runtime_error {
46 Error(
int code,
const std::string &message) : std::runtime_error(message), code_(
code) {}
48 int code() const noexcept {
return code_; }
72[[noreturn]]
inline void throw_error(
int rc) {
73 const char *m = seekdas_last_error();
74 std::string msg = (m && *m) ? m :
"seekdas error " + std::
to_string(rc);
76 case SEEKDAS_ERR_IO:
throw IoError(rc, msg);
79 case SEEKDAS_ERR_AT:
throw AtError(rc, msg);
80 case SEEKDAS_ERR_PARSE:
throw ParseError(rc, msg);
82 case SEEKDAS_ERR_DEVICE:
throw DeviceError(rc, msg);
83 case SEEKDAS_ERR_BUSY:
throw BusyError(rc, msg);
88inline int check(
int rc) {
89 if (rc < 0) throw_error(rc);
92inline std::uint32_t ms(std::chrono::milliseconds t) {
94 return c <= 0 ? 0u : c >= 0xFFFFFFFFll ? 0xFFFFFFFFu :
static_cast<std::uint32_t
>(c);
96inline std::string cstr(
const char *p, std::size_t n) {
98 while (k < n && p[k]) k++;
99 return std::string(p, k);
112enum class Channel :
int {
S0A,
S0B,
S0C,
S0D,
S1A,
S1B,
S1C,
S1D,
S2A,
S2B,
S2C,
S2D };
120 if (slot < 0 || slot > 2 || input < 0 || input > 3)
throw ArgumentError(SEEKDAS_ERR_ARGUMENT,
"slot 0..2, input 0..3");
121 return static_cast<Channel>(4 * slot + input);
125 return std::string{
'S', char(
'0' + i / 4), char(
'A' + i % 4)};
129 if (s.size() == 3 && (s[0] ==
'S' || s[0] ==
's') && s[1] >=
'0' && s[1] <=
'2') {
130 char in =
static_cast<char>(s[2] & ~0x20);
131 if (in >=
'A' && in <=
'D')
return channel(s[1] -
'0', in -
'A');
133 throw ArgumentError(SEEKDAS_ERR_ARGUMENT,
"not a channel name: '" + s +
"' (S0A..S2D)");
143 if (
bits > 0xFFFu)
throw ArgumentError(SEEKDAS_ERR_ARGUMENT,
"channel mask: 12 bits");
150 if (s < 0 || s > 2)
throw ArgumentError(SEEKDAS_ERR_ARGUMENT,
"slot 0..2");
152 m.bits_ = 0xFu << (4 * s);
155 std::uint32_t
bits() const noexcept {
return bits_; }
157 bool empty() const noexcept {
return bits_ == 0; }
158 int size() const noexcept {
int n = 0;
for (std::uint32_t b = bits_; b; b &= b - 1) n++;
return n; }
160 std::vector<Channel> v;
161 for (
int i = 0; i <
kChannels; i++)
if (bits_ >> i & 1u) v.push_back(
static_cast<Channel>(i));
169 std::uint32_t bits_ = 0;
176inline double code_to_volts(
Range r,
double code) {
return seekdas_code_to_volts(
static_cast<int>(r), code); }
182enum class Window :
int {
Ms1 = SEEKDAS_WINDOW_1MS,
Ms100 = SEEKDAS_WINDOW_100MS,
S1 = SEEKDAS_WINDOW_1S };
195 const T *
data() const noexcept {
return data_; }
196 std::size_t
size() const noexcept {
return size_; }
197 bool empty() const noexcept {
return size_ == 0; }
198 const T *
begin() const noexcept {
return data_; }
199 const T *
end() const noexcept {
return data_ + size_; }
200 const T &
operator[](std::size_t i)
const noexcept {
return data_[i]; }
201 const T &
at(std::size_t i)
const {
202 if (i >= size_)
throw std::out_of_range(
"seekdas::View index " + std::to_string(i) +
" >= " + std::to_string(size_));
207 const T *data_ =
nullptr;
208 std::size_t size_ = 0;
262 default:
return "done";
281inline AcqStatus acq(
const seekdas_acq_status &s) {
284 a.
group_points = {s.group_points[0], s.group_points[1]};
288inline RunSummary summary(
const seekdas_summary &s) {
291 r.stream = {s.stream.packets, s.stream.bytes, s.stream.duplicates, s.stream.nacks_sent, s.stream.seqs_requested,
292 s.stream.acks_sent, s.stream.heartbeats, s.stream.retransmitted};
295inline WindowStats window(
const seekdas_window_stats &w) {
return {w.mean, w.rms, w.min, w.max}; }
308 std::uint32_t taps = 0;
309 std::vector<std::int32_t> coef(64 * 32);
310 detail::check(seekdas_kernel_for_bandwidth(bandwidth_hz, &r, &taps, coef.data(), &k.
noise_gain));
311 coef.resize(64 *
static_cast<std::size_t
>(taps));
313 k.
taps =
static_cast<int>(taps);
326 if (!p_)
throw InternalError(SEEKDAS_ERR_INTERNAL,
"seekdas_config_new failed");
329 Config &
decimation(
int r) { detail::check(seekdas_config_decimation(p_.get(), u8(r)));
return *
this; }
331 Config &
bandwidth(
double hz) { detail::check(seekdas_config_bandwidth(p_.get(), hz));
return *
this; }
336 Config &
kernel_sinc(
int taps,
double fc,
double beta) { detail::check(seekdas_config_kernel_sinc(p_.get(), u32(taps), fc, beta));
return *
this; }
337 Config &
kernel_average(
int taps,
double width) { detail::check(seekdas_config_kernel_average(p_.get(), u32(taps), width));
return *
this; }
339 detail::check(seekdas_config_kernel_least_squares(p_.get(), u32(taps), fp, fs, u8(r)));
344 if (taps <= 0 || coef.size() != 64u *
static_cast<std::size_t
>(taps))
throw ArgumentError(SEEKDAS_ERR_ARGUMENT,
"kernel rows: 64 * taps values");
345 detail::check(seekdas_config_kernel_rows(p_.get(), coef.data(), u32(taps)));
348 Config &
time_calibration(
int ticks) { detail::check(seekdas_config_time_calibration(p_.get(), i16(ticks)));
return *
this; }
351 detail::check(seekdas_config_detector(p_.get(), d,
index(input),
static_cast<int>(edge), threshold, hysteresis, min_interval));
354 Config &
generator_period(
double samples) { detail::check(seekdas_config_generator_period(p_.get(), samples));
return *
this; }
355 Config &
generator_rate(
double points_per_second) { detail::check(seekdas_config_generator_rate(p_.get(), points_per_second));
return *
this; }
358 detail::check(seekdas_config_group(p_.get(), g, sources, channels.
bits(), timestamps ? 1 : 0));
362 Config &
points(std::uint32_t n) { detail::check(seekdas_config_points(p_.get(), n));
return *
this; }
363 Config &
packet_beats(
int beats) { detail::check(seekdas_config_packet_beats(p_.get(), u32(beats)));
return *
this; }
366 Config &
flush(std::chrono::microseconds t) { detail::check(seekdas_config_flush_us(p_.get(), u32(
static_cast<long long>(t.count()))));
return *
this; }
367 Config &
merge_delay(
int samples) { detail::check(seekdas_config_merge_delay(p_.get(), u32(samples)));
return *
this; }
368 void validate()
const { detail::check(seekdas_config_validate(p_.get())); }
370 const seekdas_config *
native() const noexcept {
return p_.get(); }
371 seekdas_config *
native() noexcept {
return p_.get(); }
374 struct Free {
void operator()(seekdas_config *p)
const noexcept { seekdas_config_free(p); } };
375 std::unique_ptr<seekdas_config, Free> p_;
376 static std::uint8_t u8(
int v) {
if (v < 0 || v > 255)
throw ArgumentError(SEEKDAS_ERR_ARGUMENT,
"value out of range");
return static_cast<std::uint8_t
>(v); }
377 static std::uint32_t u32(
long long v) {
if (v < 0 || v > 0xFFFFFFFFll)
throw ArgumentError(SEEKDAS_ERR_ARGUMENT,
"value out of range");
return static_cast<std::uint32_t
>(v); }
378 static std::int16_t i16(
int v) {
if (v < -32768 || v > 32767)
throw ArgumentError(SEEKDAS_ERR_ARGUMENT,
"value out of range");
return static_cast<std::int16_t
>(v); }
397 if (!p_)
throw InternalError(SEEKDAS_ERR_INTERNAL,
"seekdas_trigger_new failed");
401 detail::check(seekdas_trigger_target(p_.get(), channels.
bits(), points_per_channel));
406 detail::check(seekdas_trigger_conv(p_.get(),
index(input),
static_cast<int>(edge), threshold));
411 detail::check(seekdas_trigger_add_conv(p_.get(),
index(input),
static_cast<int>(edge), threshold, hysteresis, min_interval_samples));
416 int conv_count() const noexcept {
return seekdas_trigger_conv_count(p_.get()); }
418 Trigger &
bandwidth(
double hz) { detail::check(seekdas_trigger_bandwidth(p_.get(), hz));
return *
this; }
420 Trigger &
raw() { detail::check(seekdas_trigger_raw(p_.get()));
return *
this; }
421 Trigger &
timestamps(
bool on) { detail::check(seekdas_trigger_timestamps(p_.get(), on ? 1 : 0));
return *
this; }
423 if (beats < 0)
throw ArgumentError(SEEKDAS_ERR_ARGUMENT,
"packet beats 8..1020");
424 detail::check(seekdas_trigger_packet_beats(p_.get(),
static_cast<std::uint32_t
>(beats)));
429 if (ticks < -32768 || ticks > 32767)
throw ArgumentError(SEEKDAS_ERR_ARGUMENT,
"time calibration: 16 bit");
430 detail::check(seekdas_trigger_time_calibration(p_.get(),
static_cast<std::int16_t
>(ticks)));
434 void validate()
const { detail::check(seekdas_trigger_validate(p_.get())); }
436 const seekdas_trigger *
native() const noexcept {
return p_.get(); }
439 struct Free {
void operator()(seekdas_trigger *p)
const noexcept { seekdas_trigger_free(p); } };
440 std::unique_ptr<seekdas_trigger, Free> p_;
448 explicit Capture(seekdas_capture *p) : p_(p) {
449 if (!p_)
throw InternalError(SEEKDAS_ERR_INTERNAL,
"null capture");
451 std::size_t
points(
int group = 0) const noexcept {
return seekdas_capture_points(p_.get(), group); }
456 const std::int16_t *d = seekdas_capture_channel(p_.get(), group,
index(input), &n);
460 View<std::uint64_t> times(
int group = 0)
const { std::size_t n = 0;
auto d = seekdas_capture_times(p_.get(), group, &n);
return {d, n}; }
461 View<std::uint8_t> sources(
int group = 0)
const { std::size_t n = 0;
auto d = seekdas_capture_sources(p_.get(), group, &n);
return {d, n}; }
464 std::optional<std::uint64_t>
t0(
int group = 0)
const {
466 if (seekdas_capture_t0(p_.get(), group, &t) == 1)
return t;
471 detail::check(seekdas_capture_summary(p_.get(), &s));
472 return detail::summary(s);
475 void write_csv(
const std::string &path)
const { detail::check(seekdas_capture_write_csv(p_.get(), path.c_str())); }
477 const seekdas_capture *
native() const noexcept {
return p_.get(); }
480 struct Free {
void operator()(seekdas_capture *p)
const noexcept { seekdas_capture_free(p); } };
481 std::unique_ptr<seekdas_capture, Free> p_;
488 std::uint64_t
t0 = 0;
499 std::int16_t
value(std::size_t point,
int k)
const {
return values.at(point *
static_cast<std::size_t
>(
nchannels) +
static_cast<std::size_t
>(k)); }
511 std::string
ip =
"192.168.1.128";
522 explicit Device(
const std::string &ip =
"192.168.1.128", std::uint16_t host_port = 5000) {
523 seekdas_device *d =
nullptr;
524 detail::check(seekdas_open(ip.c_str(), host_port, &d));
528 seekdas_device *d =
nullptr;
535 seekdas_device_info i{};
536 detail::check(seekdas_get_info(p_.get(), &i));
540 r.
build_date = detail::cstr(i.build_date,
sizeof i.build_date);
541 r.
build_time = detail::cstr(i.build_time,
sizeof i.build_time);
545 double sample_rate_hz() {
double f = 0; detail::check(seekdas_sample_rate_hz(p_.get(), &f));
return f; }
547 seekdas_board_status b{};
548 detail::check(seekdas_board_status_get(p_.get(), &b));
552 r.
lasers = {b.lasers[0] != 0, b.lasers[1] != 0};
558 seekdas_net_status n{};
559 detail::check(seekdas_net_status_get(p_.get(), &n));
566 AcqStatus acq_status() { seekdas_acq_status s{}; detail::check(seekdas_acq_status_get(p_.get(), &s));
return detail::acq(s); }
569 std::uint32_t
read_reg(std::uint16_t addr) { std::uint32_t v = 0; detail::check(seekdas_reg_read(p_.get(), addr, &v));
return v; }
570 std::vector<std::uint32_t>
read_regs(std::uint16_t addr, std::size_t count) {
571 std::vector<std::uint32_t> v(count);
572 detail::check(seekdas_reg_read_many(p_.get(), addr, v.data(), count));
576 std::uint32_t
write_reg(std::uint16_t addr, std::uint32_t value) {
577 std::uint32_t rb = 0;
578 detail::check(seekdas_reg_write(p_.get(), addr, value, &rb));
584 seekdas_window_stats s{};
585 detail::check(seekdas_read_window(p_.get(),
static_cast<int>(w),
index(input), &s));
586 return detail::window(s);
589 if (decimation_log2 < 0 || decimation_log2 > 15)
throw ArgumentError(SEEKDAS_ERR_ARGUMENT,
"decimation 0..15");
591 detail::check(seekdas_raw_capture(p_.get(),
static_cast<std::uint8_t
>(decimation_log2), r.
samples.data()));
603 seekdas_trigger_state s{};
604 detail::check(seekdas_trigger_get_state(p_.get(), &s));
610 r.
conv_edges = {s.conv_edges[0], s.conv_edges[1], s.conv_edges[2], s.conv_edges[3]};
618 std::optional<Capture>
poll_trigger(std::chrono::milliseconds timeout) {
619 seekdas_capture *c =
nullptr;
620 if (detail::check(seekdas_trigger_wait(p_.get(), detail::ms(timeout), &c)) == 1)
return Capture(c);
626 using clock = std::chrono::steady_clock;
627 auto last = clock::now();
628 std::uint32_t have = 0;
630 if (
auto c =
poll_trigger(std::chrono::milliseconds(100)))
return std::move(*c);
632 if (now_points != have) { have = now_points; last = clock::now(); }
633 else if (clock::now() - last > idle_timeout)
634 throw TimeoutError(SEEKDAS_ERR_TIMEOUT,
"no CONV point for " + std::to_string(idle_timeout.count()) +
" ms (" +
635 std::to_string(have) +
" points so far); the run is still active");
640 seekdas_capture *c =
nullptr;
641 detail::check(seekdas_trigger_run(p_.get(), t.
native(), detail::ms(idle_timeout), &c));
645 void stop() { detail::check(seekdas_stop(p_.get())); }
652 seekdas_capture *c =
nullptr;
653 detail::check(seekdas_acquire_for(p_.get(), cfg.
native(), detail::ms(duration), &c));
657 void start() { detail::check(seekdas_start(p_.get())); }
658 std::optional<Packet>
recv(std::chrono::milliseconds timeout) {
660 if (detail::check(seekdas_recv(p_.get(), detail::ms(timeout), &p)) == 0)
return std::nullopt;
665 r.
values = {p.values,
static_cast<std::size_t
>(p.points) * p.channels};
666 std::size_t nt = p.has_time ? p.points : 0;
667 r.
times = {p.times, nt}; r.
sources = {p.sources, nt}; r.
bad = {p.bad, nt};
670 bool stream_finished() {
return detail::check(seekdas_stream_finished(p_.get())) == 1; }
671 RunSummary finish() { seekdas_summary s{}; detail::check(seekdas_finish(p_.get(), &s));
return detail::summary(s); }
677 if (
auto p =
recv(std::chrono::milliseconds(100))) on_packet(
static_cast<const Packet &
>(*p));
681 seekdas_device *
native() noexcept {
return p_.get(); }
684 struct Close {
void operator()(seekdas_device *p)
const noexcept { seekdas_close(p); } };
685 std::unique_ptr<seekdas_device, Close> p_;
695 if (s < 0 || s > 2)
throw ArgumentError(SEEKDAS_ERR_ARGUMENT,
"slot 0..2");
699 int code() const noexcept {
return code_; }
739 explicit At(
const std::string &port) {
740 seekdas_at *a =
nullptr;
741 detail::check(seekdas_at_open(port.c_str(), &a));
745 std::string
command(
const std::string &cmd, std::chrono::milliseconds timeout = std::chrono::milliseconds(0)) {
746 std::string r(64 * 1024,
'\0');
747 detail::check(seekdas_at_command(p_.get(), cmd.c_str(), detail::ms(timeout), &r[0], r.size()));
748 r.resize(std::strlen(r.c_str()));
751 void ping() { detail::check(seekdas_at_ping(p_.get())); }
753 seekdas_at_version v{};
754 detail::check(seekdas_at_get_version(p_.get(), &v));
756 r.
channels =
static_cast<int>(v.channels); r.
slots =
static_cast<int>(v.slots);
757 r.
pl_version = detail::cstr(v.pl_version,
sizeof v.pl_version);
758 r.
pl_build = detail::cstr(v.pl_build,
sizeof v.pl_build);
759 r.
app_version = detail::cstr(v.app_version,
sizeof v.app_version);
760 r.
app_build = detail::cstr(v.app_build,
sizeof v.app_build);
764 seekdas_at_status s{};
765 detail::check(seekdas_at_get_status(p_.get(), &s));
769 for (
int k = 0; k < 3; k++) { r.
taps[k] = s.taps[k]; r.
adc_aligned[k] = s.adc_aligned[k]; }
770 for (
int k = 0; k < 5; k++) r.
power[k] = s.power[k];
771 r.
lasers = {s.lasers[0] != 0, s.lasers[1] != 0};
773 r.
host_ip = detail::cstr(s.host_ip,
sizeof s.host_ip);
777 int done = 0, passed = 0;
779 detail::check(seekdas_at_selftest_result(p_.get(), &done, &passed, &r.
failed_items));
787 std::string rep(64 * 1024,
'\0');
788 detail::check(seekdas_at_run_selftest(p_.get(), &passed, &r.
failed_items, &rep[0], rep.size()));
789 rep.resize(std::strlen(rep.c_str()));
793 void set_lasers(
bool sfp0,
bool sfp1 =
false) { detail::check(seekdas_at_set_lasers(p_.get(), sfp0, sfp1)); }
794 void set_adc_power(
bool on) { detail::check(seekdas_at_set_adc_power(p_.get(), on)); }
798 detail::check(seekdas_at_get_ranges(p_.get(), v));
799 std::array<Range, kChannels> r{};
800 for (
int k = 0; k < kChannels; k++) r[static_cast<std::size_t>(k)] =
static_cast<Range>(v[k]);
805 seekdas_window_stats s{};
806 if (detail::check(seekdas_at_read(p_.get(),
index(input),
static_cast<int>(w), &s)) == 1)
return detail::window(s);
812 detail::check(seekdas_at_read_all(p_.get(),
static_cast<int>(w), s, valid));
813 std::array<std::optional<WindowStats>,
kChannels> r;
814 for (
int k = 0; k < kChannels; k++) if (valid[k]) r[static_cast<std::size_t>(k)] = detail::window(s[k]);
817 std::chrono::milliseconds
uptime() { std::uint64_t t = 0; detail::check(seekdas_at_uptime_ms(p_.get(), &t));
return std::chrono::milliseconds(t); }
818 std::string
host_ip() {
char b[64] = {}; detail::check(seekdas_at_get_host_ip(p_.get(), b,
sizeof b));
return b; }
819 void set_host_ip(
const std::string &ip) { detail::check(seekdas_at_set_host_ip(p_.get(), ip.c_str())); }
822 seekdas_conv_source s[4] = {};
824 detail::check(seekdas_at_conv_sources(p_.get(), s, 4, &n));
825 std::vector<ConvSource> r;
826 for (std::size_t k = 0; k < n && k < 4; k++) {
838 detail::check(seekdas_at_set_conv_sources(p_.get(), v.empty() ?
nullptr : v.data(), v.size()));
841 seekdas_conv_source s{};
844 detail::check(seekdas_at_add_conv_source(p_.get(), &s));
848 std::uint32_t
read_reg(std::uint16_t addr) { std::uint32_t v = 0; detail::check(seekdas_at_reg_read(p_.get(), addr, &v));
return v; }
849 std::uint32_t
write_reg(std::uint16_t addr, std::uint32_t value) { std::uint32_t rb = 0; detail::check(seekdas_at_reg_write(p_.get(), addr, value, &rb));
return rb; }
851 seekdas_at *
native() noexcept {
return p_.get(); }
854 struct Close {
void operator()(seekdas_at *p)
const noexcept { seekdas_at_close(p); } };
855 std::unique_ptr<seekdas_at, Close> p_;
std::string command(const std::string &cmd, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
any command (without line end); returns the lines before OK, joined by ' '; AtError on ERROR
SelftestResult run_selftest()
runs the self-test again (about 10 s; interrupts the data plane)
void set_host_ip(const std::string &ip)
seekdas_at * native() noexcept
At(const std::string &port)
"/dev/ttyACM0", "COM5"
std::optional< WindowStats > read(Channel input, Window w=Window::Ms1)
newest statistics window of one input; nothing if the data plane has no data
void set_conv_sources(const std::vector< Channel > &inputs)
AT+CONV=: replace the list (group 0, rising edge, threshold 1400, hysteresis 200); AtError while a ru...
std::uint32_t write_reg(std::uint16_t addr, std::uint32_t value)
std::vector< ConvSource > conv_sources()
CONV sources configured in the device (AT+CONV?).
std::array< Range, kChannels > ranges()
std::array< std::optional< WindowStats >, kChannels > read_all(Window w=Window::Ms1)
void add_conv_source(const ConvSource &c)
std::uint32_t read_reg(std::uint16_t addr)
register access over the serial port (about 10 ms per register)
std::chrono::milliseconds uptime()
void set_range(RangeTarget target, Range r)
void remove_conv_source(Channel c)
void set_lasers(bool sfp0, bool sfp1=false)
void set_adc_power(bool on)
SelftestResult selftest_result()
Result of a run. Points per group; a trigger run uses group 0. Move-only.
ChannelMask channels(int group=0) const
View< std::uint8_t > sources(int group=0) const
View< std::uint64_t > times(int group=0) const
per point: time in T/64 (T = sample period), source (0..3 = detector, 4 = generator); empty without t...
const seekdas_capture * native() const noexcept
std::optional< std::uint64_t > t0(int group=0) const
View< std::uint32_t > bad_points(int group=0) const
indices of invalid points (late or saturated); needs time stamps
View< std::int16_t > channel(Channel input, int group=0) const
all points of one input (empty if the input is not in the group)
void write_csv(const std::string &path) const
CSV: group,index,time,source,<inputs...>.
RunSummary summary() const
Capture(seekdas_capture *p)
std::size_t points(int group=0) const noexcept
A set of inputs (bit i = input i).
ChannelMask(std::initializer_list< Channel > cs) noexcept
static ChannelMask slot(int s)
static ChannelMask from_bits(std::uint32_t bits)
constexpr ChannelMask() noexcept=default
static ChannelMask all() noexcept
std::uint32_t bits() const noexcept
friend bool operator!=(ChannelMask a, ChannelMask b) noexcept
friend ChannelMask operator|(ChannelMask a, ChannelMask b) noexcept
bool contains(Channel c) const noexcept
bool empty() const noexcept
ChannelMask & operator|=(ChannelMask o) noexcept
friend bool operator==(ChannelMask a, ChannelMask b) noexcept
int size() const noexcept
std::vector< Channel > channels() const
Configuration of a run: decimation and kernel, edge detectors, internal generator,...
Config & merge_delay(int samples)
Config & time_calibration(int ticks)
Config & raw()
raw samples: r = 0 and the identity kernel (use with an integer generator period)
Config & generator_period(double samples)
Config & detector(int d, Channel input, Edge edge, int threshold, int hysteresis=200, std::uint32_t min_interval=0)
edge detector d (0..3) on an input; takes effect once a group lists it (source_detector(d))
Config & group(int g, std::uint32_t sources, ChannelMask channels, bool timestamps)
group 0 or 1: sources (source_detector(d) | kSourceGenerator), inputs, time word per point
Config & decimation(int r)
decimation by R = 2^r (0..4) in front of the resampling filter
const seekdas_config * native() const noexcept
Config & kernel_sinc(int taps, double fc, double beta)
Config & kernel_least_squares(int taps, double fp, double fs, int r)
Config & kernel_rows(const std::vector< std::int32_t > &coef, int taps)
own coefficients: 64 rows of taps values, coef[phase * taps + tap], Q1.16, each row summing to 65536
Config & packet_beats(int beats)
Config & kernel_identity()
seekdas_config * native() noexcept
Config & bandwidth(double hz)
decimation and kernel for a signal bandwidth (up to 20 MHz)
Config & points(std::uint32_t n)
points of both groups together after which the run stops; 0 = until stopped
Config & flush(std::chrono::microseconds t)
Config & generator_rate(double points_per_second)
Config & kernel_average(int taps, double width)
seekdas_device * native() noexcept
WindowStats read_window(Window w, Channel input)
-— monitoring outside the CONV path
DeviceInfo info()
-— identification and status
Device(const DeviceOptions &o)
std::vector< std::uint32_t > read_regs(std::uint16_t addr, std::size_t count)
BoardStatus board_status()
RunSummary stream(const Config &cfg, F &&on_packet)
configure, start, call on_packet(const Packet &) for every packet in sequence, finish
std::uint32_t read_reg(std::uint16_t addr)
-— registers (byte addresses, 32-bit words)
Capture acquire(const Config &cfg)
void start()
start with the configuration written by configure(); then recv() until stream_finished(),...
RawCapture raw_capture(int decimation_log2=0)
TriggerState trigger_state()
state of the trigger; may be called at any time, also while a run is active
std::optional< Capture > poll_trigger(std::chrono::milliseconds timeout)
receive the data of the started trigger for up to timeout: the complete capture once the whole run ha...
std::optional< Packet > recv(std::chrono::milliseconds timeout)
void configure(const Config &cfg)
-— full control: configuration, one-call runs, packet by packet all of these throw BusyError while a ...
void stop()
stop the run now (always allowed); the points produced so far are still delivered
Device(const std::string &ip="192.168.1.128", std::uint16_t host_port=5000)
connect to the device (checks the ID); the device then sends its data to this host
std::uint32_t write_reg(std::uint16_t addr, std::uint32_t value)
returns the value read back after the write
Capture acquire_for(const Config &cfg, std::chrono::milliseconds duration)
Capture wait_trigger(std::chrono::milliseconds idle_timeout=std::chrono::seconds(10))
wait for the whole run; throws TimeoutError if no point arrives for idle_timeout (no CONV edges?...
void start_trigger(const Trigger &t)
-— trigger: target + CONV inputs, start, state, data
double sample_rate_hz()
sample clock measured on the board (nominal 100e6); converts time stamps (T/64) to seconds
Capture run_trigger(const Trigger &t, std::chrono::milliseconds idle_timeout=std::chrono::seconds(10))
start, then wait for the whole run
Error(int code, const std::string &message)
int code() const noexcept
SEEKDAS_ERR_* of the C interface.
Target of At::set_range: one input, one slot, or all inputs.
int code() const noexcept
static RangeTarget slot(int s)
One trigger run: N points on each target channel, CONV edges from one to four analogue inputs.
Trigger & packet_beats(int beats)
int conv_count() const noexcept
Trigger & bandwidth(double hz)
filter by signal bandwidth (up to 20 MHz, the default)
Trigger & target(ChannelMask channels, std::uint32_t points_per_channel)
target: points_per_channel (>= 1) points on every channel of channels (at least one)
Trigger & add_conv(Channel input, Edge edge, int threshold, int hysteresis=200, std::uint32_t min_interval_samples=0)
add a CONV input (at most 4, merged in time); an input already in the list is changed in place
const seekdas_trigger * native() const noexcept
void validate() const
throws ArgumentError unless the target and a CONV input are set
Trigger & time_calibration(int ticks)
Trigger & timestamps(bool on)
Trigger & conv(Channel input, Edge edge, int threshold)
use this input as the only CONV source: edge, threshold in ADC codes (-8192..8191),...
Trigger & remove_conv(Channel input)
Trigger & raw()
no filter: the last raw sample before each CONV edge
Read-only view of an array owned by the library (Capture, Packet); valid as long as its owner.
std::size_t size() const noexcept
const T * data() const noexcept
const T & at(std::size_t i) const
std::vector< T > to_vector() const
const T & operator[](std::size_t i) const noexcept
const T * begin() const noexcept
const T * end() const noexcept
View(const T *data, std::size_t size)
bool empty() const noexcept
constexpr int index(Channel c) noexcept
constexpr std::uint32_t kSourceGenerator
std::string library_version()
Version of the underlying library, e.g. "0.2.0".
Window
Statistics windows of the bypass statistics.
constexpr int kRawSamples
samples per input of Device::raw_capture
KernelChoice kernel_for_bandwidth(double bandwidth_hz)
ChannelMask operator|(Channel a, Channel b) noexcept
constexpr int kChannels
12 inputs
Channel channel(int index)
double code_to_volts(Range r, double code)
ADC code -> volts with the typical sensitivity of the range (not calibrated per input; offset not cor...
Range
Input range of the analogue front end.
std::string to_string(Channel c)
Channel
Analogue inputs, left to right: slot 0..2, input A..D. Index = 4 * slot + input.
constexpr std::uint32_t source_detector(int d) noexcept
Source mask of a group (Config::group): edge detector d, or the internal generator.
Channel parse_channel(const std::string &s)
"S0A" .. "S2D" (case-insensitive)
Edge
Edge of a CONV input that produces an event.
std::array< std::uint32_t, 2 > group_points
std::uint32_t points
both groups
bool rejected
a START / configuration write was refused while busy (PL 0.2.1+)
Error(int code, const std::string &message)
the device answered ERROR to an AT command
Error(int code, const std::string &message)
std::array< bool, 3 > adc_aligned
std::array< bool, 2 > lasers
std::uint32_t fifo_errors
std::array< bool, 5 > power
IO_OK, CORE_PG, POSITIVE_PG, VIN_FAULT_N, SERVICE_IRQ_N.
std::array< int, 3 > taps
std::array< bool, 2 > lasers
std::array< bool, 3 > fifo_errors
int selftest_failed_items
std::array< bool, 3 > adc_aligned
an acquisition (trigger) is running: no new start and no configuration change until it is done or sto...
Error(int code, const std::string &message)
A CONV source as the management program lists it (AT+CONV?).
int group
0 or 1; -1 = in no group
the device reports an error state (lost points, wrong ID, ...)
Error(int code, const std::string &message)
std::string build_time
"2026-12-01", "09:05:53"
std::string version() const
int version_patch
PL firmware version.
std::uint16_t ctrl_port
device control port
bool set_host
point the device's data destination at this host
std::uint16_t host_port
local data port; 0 = chosen by the system
std::uint16_t data_port
device data port
std::chrono::milliseconds reg_timeout
per register request; 0 = 200 ms
internal error of the library
Error(int code, const std::string &message)
socket or serial port I/O error
Error(int code, const std::string &message)
What Config::bandwidth / Trigger::bandwidth choose for a signal bandwidth.
double noise_gain
output variance / input variance
int decimation_log2
R = 2^r.
std::vector< std::int32_t > coefficients
64 * taps, coefficients[phase * taps + tap], Q1.16
std::uint32_t retransmitted
std::uint32_t ddr_write_errors
std::uint32_t packets_sent
std::uint32_t acks_received
std::uint32_t ddr_read_errors
std::uint32_t nacks_received
std::uint32_t arp_failures
One point packet from Device::recv. The views are valid until the next call on the same Device.
std::uint64_t t0
time of the first point, T/64
View< std::uint64_t > times
per point, T/64; empty without time stamps
std::int16_t value(std::size_t point, int k) const
ChannelMask channels
inputs of the group
View< std::int16_t > values
values[p * nchannels + k]: k-th input of channels in ascending order
View< std::uint8_t > sources
int nchannels
values per point
std::uint32_t first_index
index of the first point within the run and group
an AT answer could not be parsed
Error(int code, const std::string &message)
received data does not follow the protocol
Error(int code, const std::string &message)
1024 raw samples of all inputs (Device::raw_capture).
View< std::int16_t > channel(Channel c) const
std::vector< std::int16_t > samples
std::uint32_t failed_items
std::string report
only from At::run_selftest
std::uint64_t retransmitted
std::uint64_t seqs_requested
no answer from the device in time; also: no data while waiting for a run
Error(int code, const std::string &message)
State of the trigger (Device::trigger_state).
std::array< std::uint32_t, 4 > conv_edges
bool start_allowed
a new trigger may be started now (= !running)
bool running
from the start until the last point is processed
ChannelMask channels
target channels
std::uint32_t points
points acquired so far on every target channel
bool rejected
a START or configuration write was refused during the run (PL 0.2.1+)
bool complete
the last run ended with all target points (not stopped early)
std::uint32_t target_points
N of the run (0 = unlimited).