source: normalise UDPS signal dimensions in to_info; comment tidy

This commit is contained in:
Martino Ferrari committed 2026-10-31 20:02:55 +01:00
1 parent 504bc193ea
commit 4ae91bd58b
3 files changed
+19 -10

No files matched your search

+6 -6
View File
@@ -366,8 +366,8 @@ std::uint32_t Acquisition::build_stamps(const Frame& frame, int time_signal,
if (time_source_ != 2 && time_signal >= 0 && if (time_source_ != 2 && time_signal >= 0 &&
time_signal < static_cast<int>(frame.num_signals)) { time_signal < static_cast<int>(frame.num_signals)) {
const SignalInfo& ts = frame.signals[time_signal]; const SignalInfo& ts = frame.signals[time_signal];
// How the client indexes a signal's values depends on its shape // How a frame indexes a signal's values depends on its shape
// (`udps_frame_value`): a scalar carries one value per batched cycle, so the // (`Frame::value`): a scalar carries one value per batched cycle, so the
// stamp of sample k is (sample=k, elem=0); a multi-element signal carries one // stamp of sample k is (sample=k, elem=0); a multi-element signal carries one
// *sample* of `elements` values per packet, so the stamp of sample k is // *sample* of `elements` values per packet, so the stamp of sample k is
// (sample=0, elem=k). Passing the scalar form for both is why FULL_ARRAY time // (sample=0, elem=k). Passing the scalar form for both is why FULL_ARRAY time
@@ -966,7 +966,7 @@ void Acquisition::on_data(const Frame& frame) {
const double raw = const double raw =
ch.elements > 1 ch.elements > 1
? frame.value(static_cast<std::uint32_t>(ch.signal), 0, ? frame.value(static_cast<std::uint32_t>(ch.signal), 0,
std::min<std::uint32_t>(k, ch.elements - 1)) std::min<std::uint32_t>(k, ch.elements - 1))
: frame.value(static_cast<std::uint32_t>(ch.signal), k, 0); : frame.value(static_cast<std::uint32_t>(ch.signal), k, 0);
// Every sample is read and accumulated even when only one in `period` is stored: // Every sample is read and accumulated even when only one in `period` is stored:
// that is the whole point of the filter. Skipping the read -- which is what the // that is the whole point of the filter. Skipping the read -- which is what the
@@ -1202,10 +1202,10 @@ void Acquisition::backfill_from(const Frame& frame, const Partition& part,
const double raw = const double raw =
channels[i].elements > 1 channels[i].elements > 1
? frame.value(static_cast<std::uint32_t>(channels[i].signal), 0, ? frame.value(static_cast<std::uint32_t>(channels[i].signal), 0,
std::min<std::uint32_t>(static_cast<std::uint32_t>(k), std::min<std::uint32_t>(static_cast<std::uint32_t>(k),
channels[i].elements - 1)) channels[i].elements - 1))
: frame.value(static_cast<std::uint32_t>(channels[i].signal), : frame.value(static_cast<std::uint32_t>(channels[i].signal),
static_cast<std::uint32_t>(k), 0); static_cast<std::uint32_t>(k), 0);
acc += raw * channels[i].gain + channels[i].offset; acc += raw * channels[i].gain + channels[i].offset;
} }
const f32 value = static_cast<f32>(acc / double(period)); const f32 value = static_cast<f32>(acc / double(period));
+2 -2
View File
@@ -31,8 +31,8 @@ class Acquisition : private SourceSink {
Acquisition(const Acquisition&) = delete; Acquisition(const Acquisition&) = delete;
Acquisition& operator=(const Acquisition&) = delete; Acquisition& operator=(const Acquisition&) = delete;
/// Opens the client (no socket until the first poll) and starts the thread. /// Opens the source (no socket until the first poll) and starts the thread.
/// Throws std::runtime_error when the client cannot be created. /// Throws std::runtime_error when the source cannot be created.
void start(); void start();
/// Stops the thread and destroys the client. Idempotent. /// Stops the thread and destroys the client. Idempotent.
void stop(); void stop();
+11 -2
View File
@@ -19,8 +19,17 @@ SignalInfo to_info(const udps_signal_t& s) {
info.unit = s.unit; info.unit = s.unit;
info.type_code = s.type_code; info.type_code = s.type_code;
info.quant_type = s.quant_type; info.quant_type = s.quant_type;
info.rows = s.num_rows; // Store the effective dimensions `udps_signal_num_elements` uses, so `SignalInfo::elements()`
info.cols = s.num_cols; // (rows * cols) gives the same count for any CONFIG, hostile or odd ones included: a zero
// dimension means 1 on its own (rows 0, cols 5 is 5 elements), and the product is clamped to
// UDPS_MAX_ELEMENTS, which also keeps rows * cols from overflowing uint32.
std::uint64_t rows = s.num_rows == 0 ? 1u : s.num_rows;
std::uint64_t cols = s.num_cols == 0 ? 1u : s.num_cols;
if (rows > UDPS_MAX_ELEMENTS) rows = UDPS_MAX_ELEMENTS;
if (cols > UDPS_MAX_ELEMENTS) cols = UDPS_MAX_ELEMENTS;
if (rows * cols > UDPS_MAX_ELEMENTS) cols = UDPS_MAX_ELEMENTS / rows;
info.rows = static_cast<std::uint32_t>(rows);
info.cols = static_cast<std::uint32_t>(cols);
info.range_min = s.range_min; info.range_min = s.range_min;
info.range_max = s.range_max; info.range_max = s.range_max;
info.time_mode = s.time_mode; info.time_mode = s.time_mode;