SeekDAS S100M4X C++ SDK 0.2.0
seekdas.hpp: C++17 interface over the Rust SDK
Loading...
Searching...
No Matches
seekdas.hpp
Go to the documentation of this file.
1
21#ifndef SEEKDAS_SEEKDAS_HPP
22#define SEEKDAS_SEEKDAS_HPP
23
24#include <array>
25#include <chrono>
26#include <cmath>
27#include <cstddef>
28#include <cstdint>
29#include <cstring>
30#include <initializer_list>
31#include <memory>
32#include <optional>
33#include <stdexcept>
34#include <string>
35#include <utility>
36#include <vector>
37
38#include "seekdas_ffi.h"
39
40namespace seekdas {
41
42// ================================================================ errors
43
44class Error : public std::runtime_error {
45public:
46 Error(int code, const std::string &message) : std::runtime_error(message), code_(code) {}
48 int code() const noexcept { return code_; }
49private:
50 int code_;
51};
52
53struct IoError : Error { using Error::Error; };
55struct TimeoutError : Error { using Error::Error; };
57struct ProtocolError : Error { using Error::Error; };
59struct AtError : Error { using Error::Error; };
61struct ParseError : Error { using Error::Error; };
63struct ArgumentError : Error { using Error::Error; };
65struct DeviceError : Error { using Error::Error; };
67struct InternalError : Error { using Error::Error; };
69struct BusyError : Error { using Error::Error; };
70
71namespace detail {
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);
75 switch (rc) {
76 case SEEKDAS_ERR_IO: throw IoError(rc, msg);
77 case SEEKDAS_ERR_TIMEOUT: throw TimeoutError(rc, msg);
78 case SEEKDAS_ERR_PROTOCOL: throw ProtocolError(rc, msg);
79 case SEEKDAS_ERR_AT: throw AtError(rc, msg);
80 case SEEKDAS_ERR_PARSE: throw ParseError(rc, msg);
81 case SEEKDAS_ERR_ARGUMENT: throw ArgumentError(rc, msg);
82 case SEEKDAS_ERR_DEVICE: throw DeviceError(rc, msg);
83 case SEEKDAS_ERR_BUSY: throw BusyError(rc, msg);
84 default: throw InternalError(rc, msg);
85 }
86}
88inline int check(int rc) {
89 if (rc < 0) throw_error(rc);
90 return rc;
91}
92inline std::uint32_t ms(std::chrono::milliseconds t) {
93 auto c = t.count();
94 return c <= 0 ? 0u : c >= 0xFFFFFFFFll ? 0xFFFFFFFFu : static_cast<std::uint32_t>(c);
95}
96inline std::string cstr(const char *p, std::size_t n) {
97 std::size_t k = 0;
98 while (k < n && p[k]) k++;
99 return std::string(p, k);
100}
101} // namespace detail
102
104inline std::string library_version() { return seekdas_version(); }
105
106// ================================================================ channels, ranges, edges
107
108constexpr int kChannels = SEEKDAS_CHANNELS;
109constexpr int kRawSamples = SEEKDAS_RAW_SAMPLES;
110
112enum class Channel : int { S0A, S0B, S0C, S0D, S1A, S1B, S1C, S1D, S2A, S2B, S2C, S2D };
113
114constexpr int index(Channel c) noexcept { return static_cast<int>(c); }
115inline Channel channel(int index) {
116 if (index < 0 || index >= kChannels) throw ArgumentError(SEEKDAS_ERR_ARGUMENT, "channel index " + std::to_string(index) + " (0..11)");
117 return static_cast<Channel>(index);
118}
119inline Channel channel(int slot, int input) {
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);
122}
123inline std::string to_string(Channel c) {
124 int i = index(c);
125 return std::string{'S', char('0' + i / 4), char('A' + i % 4)};
126}
127
128inline Channel parse_channel(const std::string &s) {
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');
132 }
133 throw ArgumentError(SEEKDAS_ERR_ARGUMENT, "not a channel name: '" + s + "' (S0A..S2D)");
134}
135
138public:
139 constexpr ChannelMask() noexcept = default;
140 ChannelMask(Channel c) noexcept : bits_(1u << index(c)) {} // NOLINT: implicit on purpose
141 ChannelMask(std::initializer_list<Channel> cs) noexcept { for (Channel c : cs) bits_ |= 1u << index(c); }
142 static ChannelMask from_bits(std::uint32_t bits) {
143 if (bits > 0xFFFu) throw ArgumentError(SEEKDAS_ERR_ARGUMENT, "channel mask: 12 bits");
144 ChannelMask m;
145 m.bits_ = bits;
146 return m;
147 }
148 static ChannelMask all() noexcept { ChannelMask m; m.bits_ = SEEKDAS_MASK_ALL; return m; }
149 static ChannelMask slot(int s) {
150 if (s < 0 || s > 2) throw ArgumentError(SEEKDAS_ERR_ARGUMENT, "slot 0..2");
151 ChannelMask m;
152 m.bits_ = 0xFu << (4 * s);
153 return m;
154 }
155 std::uint32_t bits() const noexcept { return bits_; }
156 bool contains(Channel c) const noexcept { return bits_ >> index(c) & 1u; }
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; }
159 std::vector<Channel> channels() const {
160 std::vector<Channel> v;
161 for (int i = 0; i < kChannels; i++) if (bits_ >> i & 1u) v.push_back(static_cast<Channel>(i));
162 return v;
163 }
164 ChannelMask &operator|=(ChannelMask o) noexcept { bits_ |= o.bits_; return *this; }
165 friend ChannelMask operator|(ChannelMask a, ChannelMask b) noexcept { return a |= b; }
166 friend bool operator==(ChannelMask a, ChannelMask b) noexcept { return a.bits_ == b.bits_; }
167 friend bool operator!=(ChannelMask a, ChannelMask b) noexcept { return a.bits_ != b.bits_; }
168private:
169 std::uint32_t bits_ = 0;
170};
171inline ChannelMask operator|(Channel a, Channel b) noexcept { return ChannelMask(a) | ChannelMask(b); }
172
174enum class Range : int { V10 = 10, V5 = 5, V2 = 2 };
176inline double code_to_volts(Range r, double code) { return seekdas_code_to_volts(static_cast<int>(r), code); }
177
179enum class Edge : int { Rising = SEEKDAS_EDGE_RISING, Falling = SEEKDAS_EDGE_FALLING, Both = SEEKDAS_EDGE_BOTH };
180
182enum class Window : int { Ms1 = SEEKDAS_WINDOW_1MS, Ms100 = SEEKDAS_WINDOW_100MS, S1 = SEEKDAS_WINDOW_1S };
183
185constexpr std::uint32_t source_detector(int d) noexcept { return 1u << (d & 3); }
186constexpr std::uint32_t kSourceGenerator = SEEKDAS_SRC_GENERATOR;
187
188// ================================================================ value types
189
191template <class T> class View {
192public:
193 View() = default;
194 View(const T *data, std::size_t size) : data_(size ? data : nullptr), size_(data ? size : 0) {}
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_));
203 return data_[i];
204 }
205 std::vector<T> to_vector() const { return std::vector<T>(begin(), end()); }
206private:
207 const T *data_ = nullptr;
208 std::size_t size_ = 0;
209};
210
213 int channels = 0, slots = 0;
214 std::string build_date, build_time;
215 std::string version() const {
216 return std::to_string(version_major) + "." + std::to_string(version_minor) + "." + std::to_string(version_patch);
217 }
218};
219
221 bool power_good = false, running = false, selftest_done = false, selftest_passed = false;
222 std::array<bool, 3> adc_aligned{}, fifo_errors{};
223 std::array<bool, 2> lasers{};
225 std::uint32_t raw = 0;
226};
227
228struct NetStatus {
229 bool link_up = false;
230 std::uint32_t next_seq = 0, acked_seq = 0;
231 std::uint32_t packets_sent = 0, retransmitted = 0, nacks_received = 0, acks_received = 0;
232 std::uint32_t ddr_write_errors = 0, arp_failures = 0, ddr_read_errors = 0;
233};
234
235struct AcqStatus {
236 bool busy = false, done = false;
237 bool rejected = false;
238 std::uint32_t points = 0;
239 std::array<std::uint32_t, 2> group_points{};
240 std::uint32_t lost = 0, late = 0, dropped = 0;
241};
242
244 std::uint64_t packets = 0, bytes = 0, duplicates = 0, nacks_sent = 0, seqs_requested = 0, acks_sent = 0, heartbeats = 0, retransmitted = 0;
245};
246
251
253 double mean = 0, rms = 0, min = 0, max = 0;
254};
255
256enum class RunState { Idle = SEEKDAS_RUN_IDLE, Running = SEEKDAS_RUN_RUNNING, Done = SEEKDAS_RUN_DONE };
257
258inline const char *to_string(RunState s) {
259 switch (s) {
260 case RunState::Idle: return "idle";
261 case RunState::Running: return "running";
262 default: return "done";
263 }
264}
265
269 bool running = false;
270 bool start_allowed = false;
271 bool complete = false;
272 bool rejected = false;
273 std::uint32_t points = 0;
274 std::uint32_t target_points = 0;
276 std::array<std::uint32_t, 4> conv_edges{};// edges counted by the detectors since power-up
277 std::uint32_t lost = 0, late = 0, dropped = 0;
278};
279
280namespace detail {
281inline AcqStatus acq(const seekdas_acq_status &s) {
282 AcqStatus a;
283 a.busy = s.busy; a.done = s.done; a.rejected = s.rejected; a.points = s.points;
284 a.group_points = {s.group_points[0], s.group_points[1]};
285 a.lost = s.lost; a.late = s.late; a.dropped = s.dropped;
286 return a;
287}
288inline RunSummary summary(const seekdas_summary &s) {
289 RunSummary r;
290 r.device = acq(s.device);
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};
293 return r;
294}
295inline WindowStats window(const seekdas_window_stats &w) { return {w.mean, w.rms, w.min, w.max}; }
296} // namespace detail
297
301 int taps = 0;
302 std::vector<std::int32_t> coefficients;
303 double noise_gain = 0;
304};
305inline KernelChoice kernel_for_bandwidth(double bandwidth_hz) {
306 KernelChoice k;
307 std::uint8_t r = 0;
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));
312 k.decimation_log2 = r;
313 k.taps = static_cast<int>(taps);
314 k.coefficients = std::move(coef);
315 return k;
316}
317
318// ================================================================ acquisition set-up (full control)
319
323class Config {
324public:
325 Config() : p_(seekdas_config_new()) {
326 if (!p_) throw InternalError(SEEKDAS_ERR_INTERNAL, "seekdas_config_new failed");
327 }
328
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; }
333 Config &raw() { decimation(0); detail::check(seekdas_config_kernel_identity(p_.get())); return *this; }
334 Config &kernel_identity() { detail::check(seekdas_config_kernel_identity(p_.get())); return *this; }
335 Config &kernel_cubic() { detail::check(seekdas_config_kernel_cubic(p_.get())); 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; }
338 Config &kernel_least_squares(int taps, double fp, double fs, int r) {
339 detail::check(seekdas_config_kernel_least_squares(p_.get(), u32(taps), fp, fs, u8(r)));
340 return *this;
341 }
342
343 Config &kernel_rows(const std::vector<std::int32_t> &coef, int taps) {
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)));
346 return *this;
347 }
348 Config &time_calibration(int ticks) { detail::check(seekdas_config_time_calibration(p_.get(), i16(ticks))); return *this; }
350 Config &detector(int d, Channel input, Edge edge, int threshold, int hysteresis = 200, std::uint32_t min_interval = 0) {
351 detail::check(seekdas_config_detector(p_.get(), d, index(input), static_cast<int>(edge), threshold, hysteresis, min_interval));
352 return *this;
353 }
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; }
357 Config &group(int g, std::uint32_t sources, ChannelMask channels, bool timestamps) {
358 detail::check(seekdas_config_group(p_.get(), g, sources, channels.bits(), timestamps ? 1 : 0));
359 return *this;
360 }
361
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; }
364 Config &standard_mtu() { return packet_beats(SEEKDAS_BEATS_STD_MTU); }
365 Config &jumbo_packets() { return packet_beats(SEEKDAS_BEATS_JUMBO); }
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())); }
369
370 const seekdas_config *native() const noexcept { return p_.get(); }
371 seekdas_config *native() noexcept { return p_.get(); }
372
373private:
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); }
379};
380
381// ================================================================ trigger
382
394class Trigger {
395public:
396 Trigger() : p_(seekdas_trigger_new()) {
397 if (!p_) throw InternalError(SEEKDAS_ERR_INTERNAL, "seekdas_trigger_new failed");
398 }
399
400 Trigger &target(ChannelMask channels, std::uint32_t points_per_channel) {
401 detail::check(seekdas_trigger_target(p_.get(), channels.bits(), points_per_channel));
402 return *this;
403 }
404
405 Trigger &conv(Channel input, Edge edge, int threshold) {
406 detail::check(seekdas_trigger_conv(p_.get(), index(input), static_cast<int>(edge), threshold));
407 return *this;
408 }
409
410 Trigger &add_conv(Channel input, Edge edge, int threshold, int hysteresis = 200, std::uint32_t min_interval_samples = 0) {
411 detail::check(seekdas_trigger_add_conv(p_.get(), index(input), static_cast<int>(edge), threshold, hysteresis, min_interval_samples));
412 return *this;
413 }
414 Trigger &remove_conv(Channel input) { detail::check(seekdas_trigger_remove_conv(p_.get(), index(input))); return *this; }
415 Trigger &clear_conv() { detail::check(seekdas_trigger_clear_conv(p_.get())); return *this; }
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; }
422 Trigger &packet_beats(int beats) {
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)));
425 return *this;
426 }
427 Trigger &standard_mtu() { return packet_beats(SEEKDAS_BEATS_STD_MTU); }
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)));
431 return *this;
432 }
433
434 void validate() const { detail::check(seekdas_trigger_validate(p_.get())); }
435
436 const seekdas_trigger *native() const noexcept { return p_.get(); }
437
438private:
439 struct Free { void operator()(seekdas_trigger *p) const noexcept { seekdas_trigger_free(p); } };
440 std::unique_ptr<seekdas_trigger, Free> p_;
441};
442
443// ================================================================ results
444
446class Capture {
447public:
448 explicit Capture(seekdas_capture *p) : p_(p) {
449 if (!p_) throw InternalError(SEEKDAS_ERR_INTERNAL, "null capture");
450 }
451 std::size_t points(int group = 0) const noexcept { return seekdas_capture_points(p_.get(), group); }
452 ChannelMask channels(int group = 0) const { return ChannelMask::from_bits(seekdas_capture_channels(p_.get(), group)); }
454 View<std::int16_t> channel(Channel input, int group = 0) const {
455 std::size_t n = 0;
456 const std::int16_t *d = seekdas_capture_channel(p_.get(), group, index(input), &n);
457 return {d, n};
458 }
459
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}; }
463 View<std::uint32_t> bad_points(int group = 0) const { std::size_t n = 0; auto d = seekdas_capture_bad_points(p_.get(), group, &n); return {d, n}; }
464 std::optional<std::uint64_t> t0(int group = 0) const {
465 std::uint64_t t = 0;
466 if (seekdas_capture_t0(p_.get(), group, &t) == 1) return t;
467 return std::nullopt;
468 }
470 seekdas_summary s{};
471 detail::check(seekdas_capture_summary(p_.get(), &s));
472 return detail::summary(s);
473 }
474
475 void write_csv(const std::string &path) const { detail::check(seekdas_capture_write_csv(p_.get(), path.c_str())); }
476
477 const seekdas_capture *native() const noexcept { return p_.get(); }
478
479private:
480 struct Free { void operator()(seekdas_capture *p) const noexcept { seekdas_capture_free(p); } };
481 std::unique_ptr<seekdas_capture, Free> p_;
482};
483
485struct Packet {
486 std::uint32_t seq = 0;
487 std::uint32_t first_index = 0;
488 std::uint64_t t0 = 0;
489 std::uint32_t points = 0;
491 int nchannels = 0;
492 int group = 0;
493 bool last = false, retransmitted = false, has_time = false;
494 int run_id = 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)); }
500};
501
504 std::vector<std::int16_t> samples = std::vector<std::int16_t>(static_cast<std::size_t>(kChannels) * kRawSamples);
505 View<std::int16_t> channel(Channel c) const { return {samples.data() + static_cast<std::size_t>(index(c)) * kRawSamples, static_cast<std::size_t>(kRawSamples)}; }
506};
507
508// ================================================================ device (optical port, UDP)
509
511 std::string ip = "192.168.1.128";
512 std::uint16_t ctrl_port = 5001;
513 std::uint16_t data_port = 5000;
514 std::uint16_t host_port = 5000;
515 bool set_host = true;
516 std::chrono::milliseconds reg_timeout{0};
517};
518
519class Device {
520public:
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));
525 p_.reset(d);
526 }
527 explicit Device(const DeviceOptions &o) {
528 seekdas_device *d = nullptr;
529 detail::check(seekdas_open_ex(o.ip.c_str(), o.ctrl_port, o.data_port, o.host_port, o.set_host ? 1 : 0, detail::ms(o.reg_timeout), &d));
530 p_.reset(d);
531 }
532
535 seekdas_device_info i{};
536 detail::check(seekdas_get_info(p_.get(), &i));
537 DeviceInfo r;
538 r.version_major = i.version_major; r.version_minor = i.version_minor; r.version_patch = i.version_patch;
539 r.channels = i.channels; r.slots = i.slots;
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);
542 return r;
543 }
544
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));
549 BoardStatus r;
550 r.power_good = b.power_good; r.running = b.running; r.selftest_done = b.selftest_done; r.selftest_passed = b.selftest_passed;
551 for (int k = 0; k < 3; k++) { r.adc_aligned[k] = b.adc_aligned[k]; r.fifo_errors[k] = b.fifo_errors[k]; }
552 r.lasers = {b.lasers[0] != 0, b.lasers[1] != 0};
553 r.selftest_failed_items = b.selftest_failed_items;
554 r.raw = b.raw;
555 return r;
556 }
558 seekdas_net_status n{};
559 detail::check(seekdas_net_status_get(p_.get(), &n));
560 NetStatus r;
561 r.link_up = n.link_up; r.next_seq = n.next_seq; r.acked_seq = n.acked_seq; r.packets_sent = n.packets_sent;
562 r.retransmitted = n.retransmitted; r.nacks_received = n.nacks_received; r.acks_received = n.acks_received;
563 r.ddr_write_errors = n.ddr_write_errors; r.arp_failures = n.arp_failures; r.ddr_read_errors = n.ddr_read_errors;
564 return r;
565 }
566 AcqStatus acq_status() { seekdas_acq_status s{}; detail::check(seekdas_acq_status_get(p_.get(), &s)); return detail::acq(s); }
567
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));
573 return v;
574 }
575
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));
579 return rb;
580 }
581
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);
587 }
588 RawCapture raw_capture(int decimation_log2 = 0) {
589 if (decimation_log2 < 0 || decimation_log2 > 15) throw ArgumentError(SEEKDAS_ERR_ARGUMENT, "decimation 0..15");
590 RawCapture r;
591 detail::check(seekdas_raw_capture(p_.get(), static_cast<std::uint8_t>(decimation_log2), r.samples.data()));
592 return r;
593 }
594
600 void start_trigger(const Trigger &t) { detail::check(seekdas_trigger_start(p_.get(), t.native())); }
603 seekdas_trigger_state s{};
604 detail::check(seekdas_trigger_get_state(p_.get(), &s));
605 TriggerState r;
606 r.state = static_cast<RunState>(s.state);
607 r.running = s.running; r.start_allowed = s.start_allowed; r.complete = s.complete; r.rejected = s.rejected;
608 r.points = s.points; r.target_points = s.target_points;
609 r.channels = ChannelMask::from_bits(s.channel_mask);
610 r.conv_edges = {s.conv_edges[0], s.conv_edges[1], s.conv_edges[2], s.conv_edges[3]};
611 r.lost = s.lost; r.late = s.late; r.dropped = s.dropped;
612 return r;
613 }
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);
621 return std::nullopt;
622 }
623
625 Capture wait_trigger(std::chrono::milliseconds idle_timeout = std::chrono::seconds(10)) {
626 using clock = std::chrono::steady_clock;
627 auto last = clock::now();
628 std::uint32_t have = 0;
629 for (;;) {
630 if (auto c = poll_trigger(std::chrono::milliseconds(100))) return std::move(*c);
631 std::uint32_t now_points = trigger_state().points;
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");
636 }
637 }
638
639 Capture run_trigger(const Trigger &t, std::chrono::milliseconds idle_timeout = std::chrono::seconds(10)) {
640 seekdas_capture *c = nullptr;
641 detail::check(seekdas_trigger_run(p_.get(), t.native(), detail::ms(idle_timeout), &c));
642 return Capture(c);
643 }
644
645 void stop() { detail::check(seekdas_stop(p_.get())); }
646
649 void configure(const Config &cfg) { detail::check(seekdas_configure(p_.get(), cfg.native())); }
650 Capture acquire(const Config &cfg) { seekdas_capture *c = nullptr; detail::check(seekdas_acquire(p_.get(), cfg.native(), &c)); return Capture(c); }
651 Capture acquire_for(const Config &cfg, std::chrono::milliseconds duration) {
652 seekdas_capture *c = nullptr;
653 detail::check(seekdas_acquire_for(p_.get(), cfg.native(), detail::ms(duration), &c));
654 return Capture(c);
655 }
656
657 void start() { detail::check(seekdas_start(p_.get())); }
658 std::optional<Packet> recv(std::chrono::milliseconds timeout) {
659 seekdas_packet p{};
660 if (detail::check(seekdas_recv(p_.get(), detail::ms(timeout), &p)) == 0) return std::nullopt;
661 Packet r;
662 r.seq = p.seq; r.first_index = p.first_index; r.t0 = p.t0; r.points = p.points;
663 r.channels = ChannelMask::from_bits(p.channel_mask); r.nchannels = static_cast<int>(p.channels);
664 r.group = p.group; r.last = p.last; r.retransmitted = p.retransmitted; r.has_time = p.has_time; r.run_id = p.run_id;
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};
668 return r;
669 }
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); }
673 template <class F> RunSummary stream(const Config &cfg, F &&on_packet) {
674 configure(cfg);
675 start();
676 while (!stream_finished())
677 if (auto p = recv(std::chrono::milliseconds(100))) on_packet(static_cast<const Packet &>(*p));
678 return finish();
679 }
680
681 seekdas_device *native() noexcept { return p_.get(); }
682
683private:
684 struct Close { void operator()(seekdas_device *p) const noexcept { seekdas_close(p); } };
685 std::unique_ptr<seekdas_device, Close> p_;
686};
687
688// ================================================================ AT commands (serial port, 115200 8N1)
689
692public:
693 RangeTarget(Channel c) : code_(index(c)) {} // NOLINT: implicit on purpose
694 static RangeTarget slot(int s) {
695 if (s < 0 || s > 2) throw ArgumentError(SEEKDAS_ERR_ARGUMENT, "slot 0..2");
696 return RangeTarget(SEEKDAS_SLOT0 + s, 0);
697 }
698 static RangeTarget all() { return RangeTarget(SEEKDAS_ALL, 0); }
699 int code() const noexcept { return code_; }
700private:
701 RangeTarget(int code, int) : code_(code) {}
702 int code_;
703};
704
705struct AtVersion {
706 int channels = 0, slots = 0;
708};
709
710struct AtStatus {
712 std::uint32_t selftest = 0, fifo_errors = 0;
713 std::array<int, 3> taps{};
714 std::array<bool, 5> power{};
715 std::array<bool, 3> adc_aligned{};
716 std::array<bool, 2> lasers{};
717 bool adc_power = false, receivers_active = false, running = false;
718 std::string host_ip;
719};
720
722 bool done = false, passed = false;
723 std::uint32_t failed_items = 0;
724 std::string report;
725};
726
735
736class At {
737public:
739 explicit At(const std::string &port) {
740 seekdas_at *a = nullptr;
741 detail::check(seekdas_at_open(port.c_str(), &a));
742 p_.reset(a);
743 }
744
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()));
749 return r;
750 }
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));
755 AtVersion r;
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);
761 return r;
762 }
764 seekdas_at_status s{};
765 detail::check(seekdas_at_get_status(p_.get(), &s));
766 AtStatus r;
767 r.uptime_s = s.uptime_s; r.die_temperature_c = s.die_temperature_c; r.sample_clock_mhz = s.sample_clock_mhz;
768 r.selftest = s.selftest; r.fifo_errors = s.fifo_errors;
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};
772 r.adc_power = s.adc_power; r.receivers_active = s.receivers_active; r.running = s.running;
773 r.host_ip = detail::cstr(s.host_ip, sizeof s.host_ip);
774 return r;
775 }
777 int done = 0, passed = 0;
779 detail::check(seekdas_at_selftest_result(p_.get(), &done, &passed, &r.failed_items));
780 r.done = done; r.passed = passed;
781 return r;
782 }
783
785 int passed = 0;
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()));
790 r.done = true; r.passed = passed; r.report = std::move(rep);
791 return r;
792 }
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)); }
795 void set_range(RangeTarget target, Range r) { detail::check(seekdas_at_set_range(p_.get(), target.code(), static_cast<int>(r))); }
796 std::array<Range, kChannels> ranges() {
797 int v[kChannels] = {};
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]);
801 return r;
802 }
803
804 std::optional<WindowStats> read(Channel input, Window w = Window::Ms1) {
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);
807 return std::nullopt;
808 }
809 std::array<std::optional<WindowStats>, kChannels> read_all(Window w = Window::Ms1) {
810 seekdas_window_stats s[kChannels] = {};
811 std::uint8_t valid[kChannels] = {};
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]);
815 return r;
816 }
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())); }
821 std::vector<ConvSource> conv_sources() {
822 seekdas_conv_source s[4] = {};
823 std::size_t n = 0;
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++) {
827 ConvSource c;
828 c.channel = channel(s[k].channel); c.group = s[k].group; c.threshold = s[k].threshold; c.hysteresis = static_cast<int>(s[k].hysteresis);
829 c.edge = s[k].rising && s[k].falling ? Edge::Both : s[k].falling ? Edge::Falling : Edge::Rising;
830 r.push_back(c);
831 }
832 return r;
833 }
834
835 void set_conv_sources(const std::vector<Channel> &inputs) {
836 std::vector<int> v;
837 for (Channel c : inputs) v.push_back(index(c));
838 detail::check(seekdas_at_set_conv_sources(p_.get(), v.empty() ? nullptr : v.data(), v.size()));
839 }
841 seekdas_conv_source s{};
842 s.channel = index(c.channel); s.group = c.group; s.threshold = c.threshold; s.hysteresis = static_cast<std::uint32_t>(c.hysteresis);
843 s.rising = c.edge != Edge::Falling; s.falling = c.edge != Edge::Rising;
844 detail::check(seekdas_at_add_conv_source(p_.get(), &s));
845 }
846 void remove_conv_source(Channel c) { detail::check(seekdas_at_remove_conv_source(p_.get(), index(c))); }
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; }
850
851 seekdas_at *native() noexcept { return p_.get(); }
852
853private:
854 struct Close { void operator()(seekdas_at *p) const noexcept { seekdas_at_close(p); } };
855 std::unique_ptr<seekdas_at, Close> p_;
856};
857
858} // namespace seekdas
859
860#endif
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
Definition seekdas.hpp:745
SelftestResult run_selftest()
runs the self-test again (about 10 s; interrupts the data plane)
Definition seekdas.hpp:784
void set_host_ip(const std::string &ip)
Definition seekdas.hpp:819
seekdas_at * native() noexcept
Definition seekdas.hpp:851
At(const std::string &port)
"/dev/ttyACM0", "COM5"
Definition seekdas.hpp:739
std::optional< WindowStats > read(Channel input, Window w=Window::Ms1)
newest statistics window of one input; nothing if the data plane has no data
Definition seekdas.hpp:804
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...
Definition seekdas.hpp:835
std::uint32_t write_reg(std::uint16_t addr, std::uint32_t value)
Definition seekdas.hpp:849
std::vector< ConvSource > conv_sources()
CONV sources configured in the device (AT+CONV?).
Definition seekdas.hpp:821
std::array< Range, kChannels > ranges()
Definition seekdas.hpp:796
std::array< std::optional< WindowStats >, kChannels > read_all(Window w=Window::Ms1)
Definition seekdas.hpp:809
void add_conv_source(const ConvSource &c)
Definition seekdas.hpp:840
std::uint32_t read_reg(std::uint16_t addr)
register access over the serial port (about 10 ms per register)
Definition seekdas.hpp:848
std::chrono::milliseconds uptime()
Definition seekdas.hpp:817
AtStatus status()
Definition seekdas.hpp:763
AtVersion version()
Definition seekdas.hpp:752
std::string host_ip()
Definition seekdas.hpp:818
void ping()
Definition seekdas.hpp:751
void set_range(RangeTarget target, Range r)
Definition seekdas.hpp:795
void remove_conv_source(Channel c)
Definition seekdas.hpp:846
void set_lasers(bool sfp0, bool sfp1=false)
Definition seekdas.hpp:793
void set_adc_power(bool on)
Definition seekdas.hpp:794
SelftestResult selftest_result()
Definition seekdas.hpp:776
Result of a run. Points per group; a trigger run uses group 0. Move-only.
Definition seekdas.hpp:446
ChannelMask channels(int group=0) const
Definition seekdas.hpp:452
View< std::uint8_t > sources(int group=0) const
Definition seekdas.hpp:461
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...
Definition seekdas.hpp:460
const seekdas_capture * native() const noexcept
Definition seekdas.hpp:477
std::optional< std::uint64_t > t0(int group=0) const
Definition seekdas.hpp:464
View< std::uint32_t > bad_points(int group=0) const
indices of invalid points (late or saturated); needs time stamps
Definition seekdas.hpp:463
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)
Definition seekdas.hpp:454
void write_csv(const std::string &path) const
CSV: group,index,time,source,<inputs...>.
Definition seekdas.hpp:475
RunSummary summary() const
Definition seekdas.hpp:469
Capture(seekdas_capture *p)
Definition seekdas.hpp:448
std::size_t points(int group=0) const noexcept
Definition seekdas.hpp:451
A set of inputs (bit i = input i).
Definition seekdas.hpp:137
ChannelMask(std::initializer_list< Channel > cs) noexcept
Definition seekdas.hpp:141
static ChannelMask slot(int s)
Definition seekdas.hpp:149
static ChannelMask from_bits(std::uint32_t bits)
Definition seekdas.hpp:142
constexpr ChannelMask() noexcept=default
static ChannelMask all() noexcept
Definition seekdas.hpp:148
std::uint32_t bits() const noexcept
Definition seekdas.hpp:155
friend bool operator!=(ChannelMask a, ChannelMask b) noexcept
Definition seekdas.hpp:167
friend ChannelMask operator|(ChannelMask a, ChannelMask b) noexcept
Definition seekdas.hpp:165
bool contains(Channel c) const noexcept
Definition seekdas.hpp:156
bool empty() const noexcept
Definition seekdas.hpp:157
ChannelMask & operator|=(ChannelMask o) noexcept
Definition seekdas.hpp:164
friend bool operator==(ChannelMask a, ChannelMask b) noexcept
Definition seekdas.hpp:166
int size() const noexcept
Definition seekdas.hpp:158
std::vector< Channel > channels() const
Definition seekdas.hpp:159
Configuration of a run: decimation and kernel, edge detectors, internal generator,...
Definition seekdas.hpp:323
Config & jumbo_packets()
Definition seekdas.hpp:365
Config & merge_delay(int samples)
Definition seekdas.hpp:367
Config & time_calibration(int ticks)
Definition seekdas.hpp:348
Config & raw()
raw samples: r = 0 and the identity kernel (use with an integer generator period)
Definition seekdas.hpp:333
Config & generator_period(double samples)
Definition seekdas.hpp:354
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))
Definition seekdas.hpp:350
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
Definition seekdas.hpp:357
Config & decimation(int r)
decimation by R = 2^r (0..4) in front of the resampling filter
Definition seekdas.hpp:329
const seekdas_config * native() const noexcept
Definition seekdas.hpp:370
Config & kernel_sinc(int taps, double fc, double beta)
Definition seekdas.hpp:336
Config & kernel_least_squares(int taps, double fp, double fs, int r)
Definition seekdas.hpp:338
Config & standard_mtu()
Definition seekdas.hpp:364
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
Definition seekdas.hpp:343
Config & packet_beats(int beats)
Definition seekdas.hpp:363
Config & kernel_cubic()
Definition seekdas.hpp:335
Config & kernel_identity()
Definition seekdas.hpp:334
void validate() const
Definition seekdas.hpp:368
seekdas_config * native() noexcept
Definition seekdas.hpp:371
Config & bandwidth(double hz)
decimation and kernel for a signal bandwidth (up to 20 MHz)
Definition seekdas.hpp:331
Config & points(std::uint32_t n)
points of both groups together after which the run stops; 0 = until stopped
Definition seekdas.hpp:362
Config & flush(std::chrono::microseconds t)
Definition seekdas.hpp:366
Config & generator_rate(double points_per_second)
Definition seekdas.hpp:355
Config & kernel_average(int taps, double width)
Definition seekdas.hpp:337
seekdas_device * native() noexcept
Definition seekdas.hpp:681
WindowStats read_window(Window w, Channel input)
-— monitoring outside the CONV path
Definition seekdas.hpp:583
DeviceInfo info()
-— identification and status
Definition seekdas.hpp:534
Device(const DeviceOptions &o)
Definition seekdas.hpp:527
std::vector< std::uint32_t > read_regs(std::uint16_t addr, std::size_t count)
Definition seekdas.hpp:570
BoardStatus board_status()
Definition seekdas.hpp:546
bool stream_finished()
Definition seekdas.hpp:670
bool trigger_running()
Definition seekdas.hpp:614
RunSummary stream(const Config &cfg, F &&on_packet)
configure, start, call on_packet(const Packet &) for every packet in sequence, finish
Definition seekdas.hpp:673
std::uint32_t read_reg(std::uint16_t addr)
-— registers (byte addresses, 32-bit words)
Definition seekdas.hpp:569
Capture acquire(const Config &cfg)
Definition seekdas.hpp:650
void start()
start with the configuration written by configure(); then recv() until stream_finished(),...
Definition seekdas.hpp:657
NetStatus net_status()
Definition seekdas.hpp:557
RawCapture raw_capture(int decimation_log2=0)
Definition seekdas.hpp:588
TriggerState trigger_state()
state of the trigger; may be called at any time, also while a run is active
Definition seekdas.hpp:602
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...
Definition seekdas.hpp:618
std::optional< Packet > recv(std::chrono::milliseconds timeout)
Definition seekdas.hpp:658
void configure(const Config &cfg)
-— full control: configuration, one-call runs, packet by packet all of these throw BusyError while a ...
Definition seekdas.hpp:649
void stop()
stop the run now (always allowed); the points produced so far are still delivered
Definition seekdas.hpp:645
RunSummary finish()
Definition seekdas.hpp:671
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
Definition seekdas.hpp:522
std::uint32_t write_reg(std::uint16_t addr, std::uint32_t value)
returns the value read back after the write
Definition seekdas.hpp:576
Capture acquire_for(const Config &cfg, std::chrono::milliseconds duration)
Definition seekdas.hpp:651
AcqStatus acq_status()
Definition seekdas.hpp:566
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?...
Definition seekdas.hpp:625
void start_trigger(const Trigger &t)
-— trigger: target + CONV inputs, start, state, data
Definition seekdas.hpp:600
double sample_rate_hz()
sample clock measured on the board (nominal 100e6); converts time stamps (T/64) to seconds
Definition seekdas.hpp:545
Capture run_trigger(const Trigger &t, std::chrono::milliseconds idle_timeout=std::chrono::seconds(10))
start, then wait for the whole run
Definition seekdas.hpp:639
Error(int code, const std::string &message)
Definition seekdas.hpp:46
int code() const noexcept
SEEKDAS_ERR_* of the C interface.
Definition seekdas.hpp:48
Target of At::set_range: one input, one slot, or all inputs.
Definition seekdas.hpp:691
RangeTarget(Channel c)
Definition seekdas.hpp:693
int code() const noexcept
Definition seekdas.hpp:699
static RangeTarget all()
Definition seekdas.hpp:698
static RangeTarget slot(int s)
Definition seekdas.hpp:694
One trigger run: N points on each target channel, CONV edges from one to four analogue inputs.
Definition seekdas.hpp:394
Trigger & packet_beats(int beats)
Definition seekdas.hpp:422
Trigger & standard_mtu()
Definition seekdas.hpp:427
int conv_count() const noexcept
Definition seekdas.hpp:416
Trigger & bandwidth(double hz)
filter by signal bandwidth (up to 20 MHz, the default)
Definition seekdas.hpp:418
Trigger & target(ChannelMask channels, std::uint32_t points_per_channel)
target: points_per_channel (>= 1) points on every channel of channels (at least one)
Definition seekdas.hpp:400
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
Definition seekdas.hpp:410
const seekdas_trigger * native() const noexcept
Definition seekdas.hpp:436
void validate() const
throws ArgumentError unless the target and a CONV input are set
Definition seekdas.hpp:434
Trigger & time_calibration(int ticks)
Definition seekdas.hpp:428
Trigger & timestamps(bool on)
Definition seekdas.hpp:421
Trigger & clear_conv()
Definition seekdas.hpp:415
Trigger & conv(Channel input, Edge edge, int threshold)
use this input as the only CONV source: edge, threshold in ADC codes (-8192..8191),...
Definition seekdas.hpp:405
Trigger & remove_conv(Channel input)
Definition seekdas.hpp:414
Trigger & raw()
no filter: the last raw sample before each CONV edge
Definition seekdas.hpp:420
Read-only view of an array owned by the library (Capture, Packet); valid as long as its owner.
Definition seekdas.hpp:191
std::size_t size() const noexcept
Definition seekdas.hpp:196
const T * data() const noexcept
Definition seekdas.hpp:195
const T & at(std::size_t i) const
Definition seekdas.hpp:201
std::vector< T > to_vector() const
Definition seekdas.hpp:205
const T & operator[](std::size_t i) const noexcept
Definition seekdas.hpp:200
View()=default
const T * begin() const noexcept
Definition seekdas.hpp:198
const T * end() const noexcept
Definition seekdas.hpp:199
View(const T *data, std::size_t size)
Definition seekdas.hpp:194
bool empty() const noexcept
Definition seekdas.hpp:197
constexpr int index(Channel c) noexcept
Definition seekdas.hpp:114
constexpr std::uint32_t kSourceGenerator
Definition seekdas.hpp:186
std::string library_version()
Version of the underlying library, e.g. "0.2.0".
Definition seekdas.hpp:104
Window
Statistics windows of the bypass statistics.
Definition seekdas.hpp:182
constexpr int kRawSamples
samples per input of Device::raw_capture
Definition seekdas.hpp:109
KernelChoice kernel_for_bandwidth(double bandwidth_hz)
Definition seekdas.hpp:305
ChannelMask operator|(Channel a, Channel b) noexcept
Definition seekdas.hpp:171
constexpr int kChannels
12 inputs
Definition seekdas.hpp:108
Channel channel(int index)
Definition seekdas.hpp:115
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...
Definition seekdas.hpp:176
Range
Input range of the analogue front end.
Definition seekdas.hpp:174
std::string to_string(Channel c)
Definition seekdas.hpp:123
Channel
Analogue inputs, left to right: slot 0..2, input A..D. Index = 4 * slot + input.
Definition seekdas.hpp:112
constexpr std::uint32_t source_detector(int d) noexcept
Source mask of a group (Config::group): edge detector d, or the internal generator.
Definition seekdas.hpp:185
Channel parse_channel(const std::string &s)
"S0A" .. "S2D" (case-insensitive)
Definition seekdas.hpp:128
Edge
Edge of a CONV input that produces an event.
Definition seekdas.hpp:179
std::uint32_t late
Definition seekdas.hpp:240
std::array< std::uint32_t, 2 > group_points
Definition seekdas.hpp:239
std::uint32_t dropped
Definition seekdas.hpp:240
std::uint32_t lost
Definition seekdas.hpp:240
std::uint32_t points
both groups
Definition seekdas.hpp:238
bool rejected
a START / configuration write was refused while busy (PL 0.2.1+)
Definition seekdas.hpp:237
invalid argument
Definition seekdas.hpp:63
Error(int code, const std::string &message)
Definition seekdas.hpp:46
the device answered ERROR to an AT command
Definition seekdas.hpp:59
Error(int code, const std::string &message)
Definition seekdas.hpp:46
double sample_clock_mhz
Definition seekdas.hpp:711
std::array< bool, 3 > adc_aligned
Definition seekdas.hpp:715
std::string host_ip
Definition seekdas.hpp:718
std::array< bool, 2 > lasers
Definition seekdas.hpp:716
std::uint32_t selftest
Definition seekdas.hpp:712
double die_temperature_c
Definition seekdas.hpp:711
std::uint32_t fifo_errors
Definition seekdas.hpp:712
std::array< bool, 5 > power
IO_OK, CORE_PG, POSITIVE_PG, VIN_FAULT_N, SERVICE_IRQ_N.
Definition seekdas.hpp:714
std::array< int, 3 > taps
Definition seekdas.hpp:713
std::string app_version
Definition seekdas.hpp:707
std::string pl_build
Definition seekdas.hpp:707
std::string app_build
Definition seekdas.hpp:707
std::string pl_version
Definition seekdas.hpp:707
std::array< bool, 2 > lasers
Definition seekdas.hpp:223
std::array< bool, 3 > fifo_errors
Definition seekdas.hpp:222
std::uint32_t raw
Definition seekdas.hpp:225
std::array< bool, 3 > adc_aligned
Definition seekdas.hpp:222
an acquisition (trigger) is running: no new start and no configuration change until it is done or sto...
Definition seekdas.hpp:69
Error(int code, const std::string &message)
Definition seekdas.hpp:46
A CONV source as the management program lists it (AT+CONV?).
Definition seekdas.hpp:728
int group
0 or 1; -1 = in no group
Definition seekdas.hpp:730
the device reports an error state (lost points, wrong ID, ...)
Definition seekdas.hpp:65
Error(int code, const std::string &message)
Definition seekdas.hpp:46
std::string build_time
"2026-12-01", "09:05:53"
Definition seekdas.hpp:214
std::string version() const
Definition seekdas.hpp:215
std::string build_date
Definition seekdas.hpp:214
int version_patch
PL firmware version.
Definition seekdas.hpp:212
std::uint16_t ctrl_port
device control port
Definition seekdas.hpp:512
bool set_host
point the device's data destination at this host
Definition seekdas.hpp:515
std::uint16_t host_port
local data port; 0 = chosen by the system
Definition seekdas.hpp:514
std::uint16_t data_port
device data port
Definition seekdas.hpp:513
std::chrono::milliseconds reg_timeout
per register request; 0 = 200 ms
Definition seekdas.hpp:516
internal error of the library
Definition seekdas.hpp:67
Error(int code, const std::string &message)
Definition seekdas.hpp:46
socket or serial port I/O error
Definition seekdas.hpp:53
Error(int code, const std::string &message)
Definition seekdas.hpp:46
What Config::bandwidth / Trigger::bandwidth choose for a signal bandwidth.
Definition seekdas.hpp:299
double noise_gain
output variance / input variance
Definition seekdas.hpp:303
int decimation_log2
R = 2^r.
Definition seekdas.hpp:300
std::vector< std::int32_t > coefficients
64 * taps, coefficients[phase * taps + tap], Q1.16
Definition seekdas.hpp:302
std::uint32_t retransmitted
Definition seekdas.hpp:231
std::uint32_t ddr_write_errors
Definition seekdas.hpp:232
std::uint32_t acked_seq
Definition seekdas.hpp:230
std::uint32_t packets_sent
Definition seekdas.hpp:231
std::uint32_t acks_received
Definition seekdas.hpp:231
std::uint32_t ddr_read_errors
Definition seekdas.hpp:232
std::uint32_t nacks_received
Definition seekdas.hpp:231
std::uint32_t arp_failures
Definition seekdas.hpp:232
std::uint32_t next_seq
Definition seekdas.hpp:230
One point packet from Device::recv. The views are valid until the next call on the same Device.
Definition seekdas.hpp:485
std::uint64_t t0
time of the first point, T/64
Definition seekdas.hpp:488
View< std::uint64_t > times
per point, T/64; empty without time stamps
Definition seekdas.hpp:496
std::int16_t value(std::size_t point, int k) const
Definition seekdas.hpp:499
ChannelMask channels
inputs of the group
Definition seekdas.hpp:490
std::uint32_t points
Definition seekdas.hpp:489
View< std::int16_t > values
values[p * nchannels + k]: k-th input of channels in ascending order
Definition seekdas.hpp:495
std::uint32_t seq
Definition seekdas.hpp:486
View< std::uint8_t > sources
Definition seekdas.hpp:497
int nchannels
values per point
Definition seekdas.hpp:491
View< std::uint8_t > bad
Definition seekdas.hpp:498
std::uint32_t first_index
index of the first point within the run and group
Definition seekdas.hpp:487
an AT answer could not be parsed
Definition seekdas.hpp:61
Error(int code, const std::string &message)
Definition seekdas.hpp:46
received data does not follow the protocol
Definition seekdas.hpp:57
Error(int code, const std::string &message)
Definition seekdas.hpp:46
1024 raw samples of all inputs (Device::raw_capture).
Definition seekdas.hpp:503
View< std::int16_t > channel(Channel c) const
Definition seekdas.hpp:505
std::vector< std::int16_t > samples
Definition seekdas.hpp:504
StreamStats stream
Definition seekdas.hpp:249
std::uint32_t failed_items
Definition seekdas.hpp:723
std::string report
only from At::run_selftest
Definition seekdas.hpp:724
std::uint64_t retransmitted
Definition seekdas.hpp:244
std::uint64_t packets
Definition seekdas.hpp:244
std::uint64_t seqs_requested
Definition seekdas.hpp:244
std::uint64_t heartbeats
Definition seekdas.hpp:244
std::uint64_t duplicates
Definition seekdas.hpp:244
std::uint64_t bytes
Definition seekdas.hpp:244
std::uint64_t nacks_sent
Definition seekdas.hpp:244
std::uint64_t acks_sent
Definition seekdas.hpp:244
no answer from the device in time; also: no data while waiting for a run
Definition seekdas.hpp:55
Error(int code, const std::string &message)
Definition seekdas.hpp:46
State of the trigger (Device::trigger_state).
Definition seekdas.hpp:267
std::array< std::uint32_t, 4 > conv_edges
Definition seekdas.hpp:276
std::uint32_t dropped
Definition seekdas.hpp:277
std::uint32_t late
Definition seekdas.hpp:277
bool start_allowed
a new trigger may be started now (= !running)
Definition seekdas.hpp:270
bool running
from the start until the last point is processed
Definition seekdas.hpp:269
ChannelMask channels
target channels
Definition seekdas.hpp:275
std::uint32_t points
points acquired so far on every target channel
Definition seekdas.hpp:273
bool rejected
a START or configuration write was refused during the run (PL 0.2.1+)
Definition seekdas.hpp:272
bool complete
the last run ended with all target points (not stopped early)
Definition seekdas.hpp:271
std::uint32_t target_points
N of the run (0 = unlimited).
Definition seekdas.hpp:274
std::uint32_t lost
Definition seekdas.hpp:277
double max
ADC codes.
Definition seekdas.hpp:253