Skip to content

Commit d7eb110

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 d7eb110

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/hw_ostc_parser.c

Lines changed: 8 additions & 6 deletions
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,17 +1225,16 @@ 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) {
1228-
sample.event.flags = SAMPLE_FLAGS_SEVERITY_ALARM;
1229-
parser->scrubber_error_reported = true;
1230+
sample.event.flags = SAMPLE_FLAGS_SEVERITY_ALARM;
1231+
parser->scrubber_error_reported = true;
12301232
}
12311233
snprintf(buf, BUFLEN, "Scrubber exhausted: %d minutes remaining", scrubberTimeMinutes);
12321234
} else if (scrubberState & OSTC4_SCRUBBER_STATE_WARNING_FLAG) {
12331235
if (!parser->scrubber_warning_reported) {
1234-
sample.event.flags = SAMPLE_FLAGS_SEVERITY_WARN;
1235-
parser->scrubber_warning_reported = true;
1236+
sample.event.flags = SAMPLE_FLAGS_SEVERITY_WARN;
1237+
parser->scrubber_warning_reported = true;
12361238
}
12371239
snprintf(buf, BUFLEN, "Scrubber warning: %d minutes remaining", scrubberTimeMinutes);
12381240
} else {

0 commit comments

Comments
 (0)