Skip to content

Commit 3d3b872

Browse files
sbasu107cursoragent
andcommitted
Decode 2-byte floats using nominal min/max scaling.
Map fixed-point CAN payloads back to physical units so cell_group voltages and other 2-byte signals no longer read as raw uint16 garbage. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 9a0572f commit 3d3b872

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/decoder.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,22 @@ int decoder_extract(const signal_def_t *sig,
8585
double v; memcpy(&v, raw, 8);
8686
out->value = v;
8787
} else if (nb == 2) {
88-
/* Some entries in format.json declare 'float' with 2 bytes
89-
* (e.g. pack_voltage). Treat as unsigned 16-bit scalar. */
88+
/* 2-byte floats are fixed-point values scaled across the
89+
* signal's nominal min/max range (see encode_signal.py). */
9090
uint16_t v; memcpy(&v, raw, 2);
91-
out->value = (double)v;
91+
double span = sig->nom_max - sig->nom_min;
92+
if (span > 0.0) {
93+
out->value = sig->nom_min + ((double)v / 65535.0) * span;
94+
} else {
95+
out->value = (double)v;
96+
}
9297
} else { /* nb == 1 */
93-
out->value = (double)raw[0];
98+
double span = sig->nom_max - sig->nom_min;
99+
if (span > 0.0) {
100+
out->value = sig->nom_min + ((double)raw[0] / 255.0) * span;
101+
} else {
102+
out->value = (double)raw[0];
103+
}
94104
}
95105
return 0;
96106
}

0 commit comments

Comments
 (0)