minor: Add decoder_verbose function

This commit is contained in:
Christian W. Zuckschwerdt 2024-03-08 12:41:35 +01:00
parent f48fc95d7b
commit f862f46401
6 changed files with 21 additions and 16 deletions

View file

@ -47,6 +47,11 @@ void decoder_output_log(r_device *decoder, int level, data_t *data);
// be terse, a maximum msg length of 60 characters is supported on the decoder_log_ functions
// e.g. "FoobarCorp-XY3000: unexpected type code %02x"
/// Get the current verbosity level for the decoder.
///
/// @deprecated Should not be used, consider using only `decoder_log_` functions.
int decoder_verbose(r_device *decoder);
/// Output a log message.
void decoder_log(r_device *decoder, int level, char const *func, char const *msg);

View file

@ -115,6 +115,11 @@ static char *bitrow_asprint_bits(uint8_t const *bitrow, unsigned bit_len)
// variadic output functions
int decoder_verbose(r_device *decoder)
{
return decoder->verbose;
}
void decoder_log(r_device *decoder, int level, char const *func, char const *msg)
{
if (decoder->verbose >= level) {

View file

@ -111,9 +111,9 @@ static int decode_xc0324_message(r_device *decoder, bitbuffer_t *bitbuffer,
humidity = reverse8(b[4]);
// Create the data structure, ready for the decoder_output_data function.
// Separate production output (decoder->verbose == 0)
// from (simulated) deciphering stage output (decoder->verbose > 0)
if (!decoder->verbose) { // production output
// Separate production output (decoder_verbose == 0)
// from (simulated) deciphering stage output (decoder_verbose > 0)
if (!decoder_verbose(decoder)) { // production output
/* clang-format off */
*data = data_make(
"model", "Device Type", DATA_STRING, "Digitech-XC0324",
@ -178,9 +178,9 @@ static int digitech_xc0324_decode(r_device *decoder, bitbuffer_t *bitbuffer)
r, bitpos, events, &data);
if (ret > 0)
events += ret;
// Keep production output (decoder->verbose == 0) separate from
// (simulated) development stage output (decoder->verbose > 0)
if (events > 0 && !decoder->verbose) { // Production output
// Keep production output (decoder_verbose == 0) separate from
// (simulated) development stage output (decoder_verbose > 0)
if (events > 0 && !decoder_verbose(decoder)) { // Production output
data_append(data,
"message_num", "Message repeat count", DATA_INT, events, NULL);
decoder_output_data(decoder, data);

View file

@ -227,7 +227,7 @@ static int ert_idm_decode(r_device *decoder, bitbuffer_t *bitbuffer)
DifferentialConsumptionIntervals[j] = ((uint16_t)buffy[0] << 1) | (buffy[1] >> 7);
pos += 9;
}
if (decoder->verbose > 1) {
if (decoder_verbose(decoder) > 1) {
decoder_log(decoder, 2, __func__, "DifferentialConsumptionIntervals");
for (int j = 0; j < 47; j++) {
decoder_logf(decoder, 2, __func__, "%d", DifferentialConsumptionIntervals[j]);
@ -489,7 +489,7 @@ static int ert_netidm_decode(r_device *decoder, bitbuffer_t *bitbuffer)
// decoder_logf_bitrow(decoder, 0, __func__, buffy, 14, "%d %d", j, DifferentialConsumptionIntervals[j]);
pos += 14;
}
if (decoder->verbose) {
if (decoder_verbose(decoder)) {
decoder_log(decoder, 1, __func__, "DifferentialConsumptionIntervals");
for (int j = 0; j < 27; j++) {
decoder_logf(decoder, 1, __func__, "%d", DifferentialConsumptionIntervals[j]);

View file

@ -267,9 +267,7 @@ static int flex_callback(r_device *decoder, bitbuffer_t *bitbuffer)
}
}
if (decoder->verbose) {
decoder_log_bitbuffer(decoder, 1, params->name, bitbuffer, "");
}
decoder_log_bitbuffer(decoder, 1, params->name, bitbuffer, "");
// discard duplicates
if (params->unique) {
@ -571,7 +569,6 @@ static void parse_getter(const char *arg, struct flex_get *getter)
usage();
}
/*
if (decoder->verbose)
fprintf(stderr, "parse_getter() bit_offset: %d bit_count: %d mask: %lx name: %s\n",
getter->bit_offset, getter->bit_count, getter->mask, getter->name);
*/
@ -769,13 +766,11 @@ r_device *flex_create_device(char *spec)
}
/*
if (decoder->verbose) {
fprintf(stderr, "Adding flex decoder \"%s\"\n", params->name);
fprintf(stderr, "\tmodulation=%u, short_width=%.0f, long_width=%.0f, reset_limit=%.0f\n",
dev->modulation, dev->short_width, dev->long_width, dev->reset_limit);
fprintf(stderr, "\tmin_rows=%u, min_bits=%u, min_repeats=%u, invert=%u, reflect=%u, match_len=%u, preamble_len=%u\n",
params->min_rows, params->min_bits, params->min_repeats, params->invert, params->reflect, params->match_len, params->preamble_len);
}
*/
free(spec);

View file

@ -149,7 +149,7 @@ static int ttx201_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsigned row
data_type = (b[2] & 0x70) >> 4;
postmark = b[5];
if (decoder->verbose > 1) {
if (decoder_verbose(decoder) > 1) {
decoder_log(decoder, 0, __func__, "TTX201 received raw data");
decoder_log_bitbuffer(decoder, 0, __func__, bitbuffer, "");
decoder_logf(decoder, 0, __func__, "Data decoded:" \
@ -232,7 +232,7 @@ static int ttx201_callback(r_device *decoder, bitbuffer_t *bitbuffer)
ret = ttx201_decode(decoder, bitbuffer, row, 0);
if (ret > 0)
events += ret;
if (events && !decoder->verbose)
if (events && !decoder_verbose(decoder))
return events; // for now, break after first successful message
}
}