Skip to content

Commit c075e1a

Browse files
mikellerCopilot
andcommitted
Improve extraction of the signed int.
Co-authored-by: Copilot <[email protected]> Signed-off-by: Michael Keller <[email protected]>
1 parent 1d21b17 commit c075e1a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/hw_ostc_parser.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,10 @@ hw_ostc_parser_internal_foreach (hw_ostc_parser_t *parser, dc_sample_callback_t
12101210
}
12111211

12121212
unsigned int scrubberState = array_uint16_le(data + offset);
1213-
int scrubberTimeMinutes = (scrubberState & 0x0800) ? (-1 ^ 0x0FFF) | (scrubberState & 0x0FFF) : scrubberState & 0x0FFF; // extract 12 bit signed int
1213+
int scrubberTimeMinutes = scrubberState & 0x0FFF; // Extract the 12-bit value
1214+
if (scrubberState & 0x0800) { // Check if the sign bit is set
1215+
scrubberTimeMinutes -= 0x1000; // Perform sign extension
1216+
}
12141217
if (parser->first_scrubber_time_minutes == INT_MAX) {
12151218
parser->first_scrubber_time_minutes = scrubberTimeMinutes;
12161219
}
@@ -1222,7 +1225,6 @@ hw_ostc_parser_internal_foreach (hw_ostc_parser_t *parser, dc_sample_callback_t
12221225
.event.flags = SAMPLE_FLAGS_SEVERITY_STATE,
12231226
};
12241227

1225-
12261228
if (scrubberState & OSTC4_SCRUBBER_STATE_ERROR_FLAG) {
12271229
if (!parser->scrubber_error_reported) {
12281230
sample.event.flags = SAMPLE_FLAGS_SEVERITY_ALARM;

0 commit comments

Comments
 (0)