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

+11 -2
View File
@@ -19,8 +19,17 @@ SignalInfo to_info(const udps_signal_t& s) {
info.unit = s.unit;
info.type_code = s.type_code;
info.quant_type = s.quant_type;
info.rows = s.num_rows;
info.cols = s.num_cols;
// Store the effective dimensions `udps_signal_num_elements` uses, so `SignalInfo::elements()`
// (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_max = s.range_max;
info.time_mode = s.time_mode;