From eedd027299726bf062f2d3b41eff7b2b8e28db89 Mon Sep 17 00:00:00 2001 From: "Christian W. Zuckschwerdt" Date: Mon, 26 Nov 2018 17:24:26 +0100 Subject: [PATCH] Replace debug_output with verbose in decoders --- include/decoder.h | 3 -- src/devices/acurite.c | 36 ++++++------- src/devices/alecto.c | 4 +- src/devices/ambient_weather.c | 2 +- src/devices/ambientweather_tx8300.c | 2 +- src/devices/ambientweather_wh31e.c | 6 +-- src/devices/bresser_3ch.c | 4 +- src/devices/danfoss.c | 8 +-- src/devices/dish_remote_6_3.c | 2 +- src/devices/dsc.c | 14 ++--- src/devices/efergy_optical.c | 6 +-- src/devices/elv.c | 10 ++-- src/devices/fineoffset.c | 18 +++---- src/devices/fineoffset_wh1080.c | 2 +- src/devices/flex.c | 10 ++-- src/devices/fordremote.c | 2 +- src/devices/inovalley-kw9015b.c | 2 +- src/devices/interlogix.c | 8 +-- src/devices/intertechno.c | 2 +- src/devices/kedsum.c | 2 +- src/devices/lacrosse.c | 10 ++-- src/devices/lacrosse_TX141TH_Bv2.c | 2 +- src/devices/lacrosse_tx35.c | 4 +- src/devices/lacrossews.c | 12 ++--- src/devices/lightwave_rf.c | 4 +- src/devices/m_bus.c | 59 ++++++++++----------- src/devices/maverick_et73x.c | 2 +- src/devices/new_template.c | 8 +-- src/devices/nexus.c | 2 +- src/devices/oregon_scientific.c | 72 +++++++++++++------------- src/devices/oregon_scientific_sl109h.c | 6 +-- src/devices/philips.c | 10 ++-- src/devices/radiohead_ask.c | 14 ++--- src/devices/s3318p.c | 2 +- src/devices/schraeder.c | 4 +- src/devices/simplisafe.c | 2 +- src/devices/steelmate.c | 2 +- src/devices/thermopro_tp12.c | 2 +- src/devices/tpms_pmv107j.c | 6 +-- src/devices/tpms_toyota.c | 2 +- src/devices/ttx201.c | 10 ++-- src/devices/vaillant_vrt340f.c | 8 +-- src/devices/wssensor.c | 2 +- src/devices/wt0124.c | 2 +- src/devices/wt450.c | 6 +-- src/devices/x10_sec.c | 2 +- src/pulse_demod.c | 1 + 47 files changed, 201 insertions(+), 198 deletions(-) diff --git a/include/decoder.h b/include/decoder.h index a954c838..cd2eb212 100644 --- a/include/decoder.h +++ b/include/decoder.h @@ -23,7 +23,4 @@ #define FSK_PULSE_PWM 17 // FSK, Pulse Width Modulation. Short pulses = 1, Long = 0 #define FSK_PULSE_MANCHESTER_ZEROBIT 18 // FSK, Manchester encoding -extern int debug_output; -extern float sample_file_pos; - #endif /* INCLUDE_DECODER_H_ */ diff --git a/src/devices/acurite.c b/src/devices/acurite.c index 107a3c5b..2e8b19c1 100644 --- a/src/devices/acurite.c +++ b/src/devices/acurite.c @@ -228,7 +228,7 @@ static int acurite_rain_gauge_callback(r_device *decoder, bitbuffer_t *bitbuffer float total_rain = ((bb[0][1]&0xf)<<8)+ bb[0][2]; total_rain /= 2; // Sensor reports number of bucket tips. Each bucket tip is .5mm - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stdout, "AcuRite Rain Gauge Total Rain is %2.1fmm\n", total_rain); fprintf(stdout, "Raw Message "); bitrow_print(bb[0], bitbuffer->bits_per_row[0]); @@ -524,7 +524,7 @@ static int acurite_6045_decode(r_device *decoder, bitrow_t bb, int browlen) // FIXME - temporarily leaving the old output for ease of debugging // and backward compatibility. Remove when doing a "1.0" release. - if (debug_output) { + if (decoder->verbose) { printf("%s Acurite lightning 0x%04X Ch %c Msg Type 0x%02x: %.1f F %d %% RH Strikes %d Distance %d L_status 0x%02x -", time_str, sensor_id, channel, message_type, tempf, humidity, strike_count, strike_distance, l_status); for (int i=0; i < browlen; i++) { @@ -587,7 +587,7 @@ static int acurite_txr_callback(r_device *decoder, bitbuffer_t *bitbuf) local_time_str(0, time_str); bitbuffer_invert(bitbuf); - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr,"acurite_txr\n"); bitbuffer_print(bitbuf); } @@ -596,13 +596,13 @@ static int acurite_txr_callback(r_device *decoder, bitbuffer_t *bitbuf) browlen = (bitbuf->bits_per_row[brow] + 7)/8; bb = bitbuf->bb[brow]; - if (debug_output > 1) + if (decoder->verbose > 1) fprintf(stderr,"acurite_txr: row %d bits %d, bytes %d \n", brow, bitbuf->bits_per_row[brow], browlen); if ((bitbuf->bits_per_row[brow] < ACURITE_TXR_BITLEN || bitbuf->bits_per_row[brow] > ACURITE_5N1_BITLEN + 1) && bitbuf->bits_per_row[brow] != ACURITE_6045_BITLEN) { - if (debug_output > 1 && bitbuf->bits_per_row[brow] > 16) + if (decoder->verbose > 1 && bitbuf->bits_per_row[brow] > 16) fprintf(stderr,"acurite_txr: skipping wrong len\n"); continue; } @@ -613,7 +613,7 @@ static int acurite_txr_callback(r_device *decoder, bitbuffer_t *bitbuf) browlen--; if (!acurite_checksum(bb,browlen - 1)) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "%s Acurite bad checksum:", time_str); for (uint8_t i = 0; i < browlen; i++) fprintf(stderr," 0x%02x",bb[i]); @@ -622,7 +622,7 @@ static int acurite_txr_callback(r_device *decoder, bitbuffer_t *bitbuf) continue; } - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "acurite_txr Parity: "); for (uint8_t i = 0; i < browlen; i++) { fprintf(stderr,"%d",byteParity(bb[i])); @@ -670,7 +670,7 @@ static int acurite_txr_callback(r_device *decoder, bitbuffer_t *bitbuf) // The 5-n-1 weather sensor messages are 8 bytes. if (browlen == ACURITE_5N1_BITLEN / 8) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "Acurite 5n1 raw msg: %02X %02X %02X %02X %02X %02X %02X %02X\n", bb[0], bb[1], bb[2], bb[3], bb[4], bb[5], bb[6], bb[7]); } @@ -840,12 +840,12 @@ static int acurite_986_callback(r_device *decoder, bitbuffer_t *bitbuf) for (uint16_t brow = 0; brow < bitbuf->num_rows; ++brow) { - if (debug_output > 1) + if (decoder->verbose > 1) fprintf(stderr,"acurite_986: row %d bits %d, bytes %d \n", brow, bitbuf->bits_per_row[brow], browlen); if (bitbuf->bits_per_row[brow] < 39 || bitbuf->bits_per_row[brow] > 43 ) { - if (debug_output > 1 && bitbuf->bits_per_row[brow] > 16) + if (decoder->verbose > 1 && bitbuf->bits_per_row[brow] > 16) fprintf(stderr,"acurite_986: skipping wrong len\n"); continue; } @@ -862,7 +862,7 @@ static int acurite_986_callback(r_device *decoder, bitbuffer_t *bitbuf) for (uint8_t i = 0; i < browlen; i++) br[i] = reverse8(bb[i]); - if (debug_output > 0) { + if (decoder->verbose) { fprintf(stderr,"Acurite 986 reversed: "); for (uint8_t i = 0; i < browlen; i++) fprintf(stderr," %02x",br[i]); @@ -884,7 +884,7 @@ static int acurite_986_callback(r_device *decoder, bitbuffer_t *bitbuf) crcc = crc8le(br, 4, 0x07, 0); if (crcc != crc) { - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr,"%s Acurite 986 sensor bad CRC: %02x -", time_str, crc8le(br, 4, 0x07, 0)); for (uint8_t i = 0; i < browlen; i++) @@ -896,7 +896,7 @@ static int acurite_986_callback(r_device *decoder, bitbuffer_t *bitbuf) // problem with the device or demodulator // Add 1 (0x80 because message is LSB) and retry CRC. if (crcc == (crc | 0x80)) { - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr,"%s Acurite 986 CRC fix %02x - %02x\n", time_str,crc,crcc); } @@ -911,7 +911,7 @@ static int acurite_986_callback(r_device *decoder, bitbuffer_t *bitbuf) tempc = fahrenheit2celsius(tempf); // only for debug/old-style output - if (debug_output) + if (decoder->verbose) printf("%s Acurite 986 sensor 0x%04x - %d%c: %3.1f C %d F\n", time_str, sensor_id, sensor_num, sensor_type, tempc, tempf); @@ -987,7 +987,7 @@ static int acurite_606_callback(r_device *decoder, bitbuffer_t *bitbuf) local_time_str(0, time_str); - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr,"acurite_606\n"); bitbuffer_print(bitbuf); } @@ -1040,7 +1040,7 @@ static int acurite_00275rm_callback(r_device *decoder, bitbuffer_t *bitbuf) local_time_str(0, time_str); bitbuffer_invert(bitbuf); - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr,"acurite_00275rm\n"); bitbuffer_print(bitbuf); } @@ -1050,7 +1050,7 @@ static int acurite_00275rm_callback(r_device *decoder, bitbuffer_t *bitbuf) if (bitbuf->bits_per_row[brow] != 88) continue; if (nsignal>=3) continue; memcpy(signal[nsignal], bitbuf->bb[brow], 11); - if (debug_output) { + if (decoder->verbose) { fprintf(stderr,"acurite_00275rm: "); for (int i=0; i<11; i++) fprintf(stderr," %02x",signal[nsignal][i]); fprintf(stderr,"\n"); @@ -1069,7 +1069,7 @@ static int acurite_00275rm_callback(r_device *decoder, bitbuffer_t *bitbuf) } // CRC check fails? if ((crc=crc16(&(signal[0][0]), 11/*len*/, 0xb2/*poly*/, 0xd0/*seed*/)) != 0) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr,"%s Acurite 00275rm sensor bad CRC: %02x -", time_str, crc); for (uint8_t i = 0; i < 11; i++) diff --git a/src/devices/alecto.c b/src/devices/alecto.c index 053b7af0..4325c114 100644 --- a/src/devices/alecto.c +++ b/src/devices/alecto.c @@ -85,7 +85,7 @@ static int alectov1_callback(r_device *decoder, bitbuffer_t *bitbuffer) { /* Quit if checksum does not work out */ if (csum != (bb[1][4] >> 4) || csum2 != (bb[5][4] >> 4)) { //fprintf(stdout, "\nAlectoV1 CRC error"); - if(debug_output) { + if(decoder->verbose) { fprintf(stderr, "%s AlectoV1 Checksum/Parity error\n", time_str); @@ -168,7 +168,7 @@ static int alectov1_callback(r_device *decoder, bitbuffer_t *bitbuffer) { NULL); decoder_output_data(decoder, data); } - if (debug_output){ + if (decoder->verbose){ fprintf(stdout, "Checksum = %01x (calculated %01x)\n", bb[1][4] >> 4, csum); fprintf(stdout, "Received Data = "); bitrow_print(bb[1], 40); diff --git a/src/devices/ambient_weather.c b/src/devices/ambient_weather.c index a21d2efa..318f7bdd 100644 --- a/src/devices/ambient_weather.c +++ b/src/devices/ambient_weather.c @@ -31,7 +31,7 @@ ambient_weather_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsigned row, uint8_t calculated = lfsr_digest8(b, 5, 0x98, 0x3e) ^ 0x64; if (expected != calculated) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "Checksum error in Ambient Weather message. Expected: %02x Calculated: %02x\n", expected, calculated); fprintf(stderr, "Message: "); bitrow_print(b, 48); diff --git a/src/devices/ambientweather_tx8300.c b/src/devices/ambientweather_tx8300.c index 9e559810..cc022012 100644 --- a/src/devices/ambientweather_tx8300.c +++ b/src/devices/ambientweather_tx8300.c @@ -51,7 +51,7 @@ static int ambientweather_tx8300_callback(r_device *decoder, bitbuffer_t *bitbuf /* length check */ if (74 != bitbuffer->bits_per_row[0]) { - if( debug_output > 1) + if( decoder->verbose > 1) fprintf(stderr, "AmbientWeather-TX8300: wrong size (%i bits)\n", bitbuffer->bits_per_row[0]); return 0; } diff --git a/src/devices/ambientweather_wh31e.c b/src/devices/ambientweather_wh31e.c index 2b015aba..6492d1e8 100644 --- a/src/devices/ambientweather_wh31e.c +++ b/src/devices/ambientweather_wh31e.c @@ -59,20 +59,20 @@ static int ambientweather_wh31e_callback(r_device *decoder, bitbuffer_t *bitbuff unsigned start_pos = bitbuffer_search(bitbuffer, row, 0, preamble, 28); if (start_pos == bitbuffer->bits_per_row[row]) continue; // no preamble detected, move to the next row - if (debug_output) + if (decoder->verbose) fprintf(stderr, "Ambient Weather WH31E detected, buffer is %d bits length\n", bitbuffer->bits_per_row[row]); // remove preamble and keep only 64 bits bitbuffer_extract_bytes(bitbuffer, row, start_pos + 24, b, 11 * 8); if (b[0] != 0x30) { - if (debug_output) + if (decoder->verbose) fprintf(stderr, "Ambient Weather WH31E unknown message type %02x (expected 0x30)\n", b[0]); continue; } c_crc = crc8(b, 5, 0x31, 0x00); if (c_crc != b[5]) { - if (debug_output) + if (decoder->verbose) fprintf(stderr, "Ambient Weather WH31E bad CRC: calculated %02x, received %02x\n", c_crc, b[5]); continue; } diff --git a/src/devices/bresser_3ch.c b/src/devices/bresser_3ch.c index ba99b292..deb79c9d 100644 --- a/src/devices/bresser_3ch.c +++ b/src/devices/bresser_3ch.c @@ -45,7 +45,7 @@ static int bresser_3ch_callback(r_device *decoder, bitbuffer_t *bitbuffer) { b[4] = ~b[4]; if (((b[0] + b[1] + b[2] + b[3] - b[4]) & 0xFF) != 0) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "Bresser 3CH checksum error\n"); } return 0; @@ -64,7 +64,7 @@ static int bresser_3ch_callback(r_device *decoder, bitbuffer_t *bitbuffer) { humidity = b[3]; if ((channel == 0) || (humidity > 100) || (temp_f < -20.0) || (temp_f > 160.0)) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "Bresser 3CH data error\n"); } return 0; diff --git a/src/devices/danfoss.c b/src/devices/danfoss.c index 2b7041a2..bfe57ec7 100644 --- a/src/devices/danfoss.c +++ b/src/devices/danfoss.c @@ -80,7 +80,7 @@ static int danfoss_cfr_callback(r_device *decoder, bitbuffer_t *bitbuffer) // Find a package unsigned bit_offset = bitbuffer_search(bitbuffer, 0, 112, HEADER, sizeof(HEADER)*8); // Normal index is 128, skip first 14 bytes to find faster if (bits-bit_offset < 126) { // Package should be at least 126 bits - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "Danfoss: short package. Header index: %u\n", bit_offset); bitbuffer_print(bitbuffer); } @@ -93,7 +93,7 @@ static int danfoss_cfr_callback(r_device *decoder, bitbuffer_t *bitbuffer) uint8_t nibble_h = danfoss_decode_nibble(bitrow_get_byte(bitbuffer->bb[0], n*12+bit_offset) >> 2); uint8_t nibble_l = danfoss_decode_nibble(bitrow_get_byte(bitbuffer->bb[0], n*12+bit_offset+6) >> 2); if (nibble_h > 0xF || nibble_l > 0xF) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "Danfoss: 6b/4b decoding error\n"); bitbuffer_print(bitbuffer); } @@ -103,7 +103,7 @@ static int danfoss_cfr_callback(r_device *decoder, bitbuffer_t *bitbuffer) } // Output raw decoded data for debug - if (debug_output) { + if (decoder->verbose) { char str_raw[NUM_BYTES*2+4]; // Add some extra space for line end for (unsigned n=0; nverbose) fprintf(stderr, "Danfoss: Prefix or CRC error.\n"); return 0; } diff --git a/src/devices/dish_remote_6_3.c b/src/devices/dish_remote_6_3.c index 718ae7b0..bb152aa5 100644 --- a/src/devices/dish_remote_6_3.c +++ b/src/devices/dish_remote_6_3.c @@ -100,7 +100,7 @@ static int dish_remote_6_3_callback(r_device *decoder, bitbuffer_t *bitbuffer) uint8_t button; char *button_string; - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr,"dish_remote_6_3_callback callback:\n"); bitbuffer_print(bitbuffer); } diff --git a/src/devices/dsc.c b/src/devices/dsc.c index 9104634c..7133f1b7 100644 --- a/src/devices/dsc.c +++ b/src/devices/dsc.c @@ -86,13 +86,13 @@ static int dsc_callback(r_device *decoder, bitbuffer_t *bitbuffer) int s_closed, s_event, s_tamper, s_battery_low; int s_xactivity, s_xtamper1, s_xtamper2, s_exception; - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr,"Possible DSC Contact: "); bitbuffer_print(bitbuffer); } for (int row = 0; row < bitbuffer->num_rows; row++) { - if (debug_output > 1 && bitbuffer->bits_per_row[row] > 0 ) { + if (decoder->verbose > 1 && bitbuffer->bits_per_row[row] > 0 ) { fprintf(stderr,"row %d bit count %d\n", row, bitbuffer->bits_per_row[row]); } @@ -106,7 +106,7 @@ static int dsc_callback(r_device *decoder, bitbuffer_t *bitbuffer) // will need to be changed as there may be more zero bit padding if (bitbuffer->bits_per_row[row] < 48 || bitbuffer->bits_per_row[row] > 70) { // should be 48 at most - if (debug_output > 1 && bitbuffer->bits_per_row[row] > 0) { + if (decoder->verbose > 1 && bitbuffer->bits_per_row[row] > 0) { fprintf(stderr,"DSC row %d invalid bit count %d\n", row, bitbuffer->bits_per_row[row]); } @@ -120,7 +120,7 @@ static int dsc_callback(r_device *decoder, bitbuffer_t *bitbuffer) (b[2] & 0x04) && // every 8 data bits (b[3] & 0x02) && (b[4] & 0x01))) { - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr, "DSC Invalid start/sync bits "); bitrow_print(b, 40); } @@ -133,8 +133,8 @@ static int dsc_callback(r_device *decoder, bitbuffer_t *bitbuffer) bytes[3] = ((b[3] & 0x01) << 7) | ((b[4] & 0xFE) >> 1); bytes[4] = ((b[5])); - // XXX change to debug_output - if (debug_output) { + // XXX change to decoder->verbose + if (decoder->verbose) { fprintf(stdout, "DSC Contact Raw Data: "); bitrow_print(bytes, 40); } @@ -144,7 +144,7 @@ static int dsc_callback(r_device *decoder, bitbuffer_t *bitbuffer) crc = bytes[4]; if (crc8le(bytes, DSC_CT_MSGLEN, DSC_CT_CRC_POLY, DSC_CT_CRC_INIT) != 0) { - if (debug_output) + if (decoder->verbose) fprintf(stderr,"DSC Contact bad CRC: %06X, Status: %02X, CRC: %02X\n", esn, status, crc); continue; diff --git a/src/devices/efergy_optical.c b/src/devices/efergy_optical.c index 4305b67b..29ad5136 100644 --- a/src/devices/efergy_optical.c +++ b/src/devices/efergy_optical.c @@ -63,7 +63,7 @@ static int efergy_optical_callback(r_device *decoder, bitbuffer_t *bitbuffer) { } } - if (debug_output) { + if (decoder->verbose) { fprintf(stdout,"Possible Efergy Optical: "); bitbuffer_print(bitbuffer); } @@ -83,7 +83,7 @@ static int efergy_optical_callback(r_device *decoder, bitbuffer_t *bitbuffer) { if (crc == csum1) { - if (debug_output) { + if (decoder->verbose) { fprintf(stdout, "Checksum OK :) :)\n"); fprintf(stdout, "Calculated crc is 0x%02X\n", crc); fprintf(stdout, "Received csum1 is 0x%02X\n", csum1); @@ -128,7 +128,7 @@ static int efergy_optical_callback(r_device *decoder, bitbuffer_t *bitbuffer) { else { - if (debug_output) + if (decoder->verbose) { fprintf(stdout, "Checksum not OK !!!\n"); fprintf(stdout, "Calculated crc is 0x%02X\n", crc); diff --git a/src/devices/elv.c b/src/devices/elv.c index c61724f1..76ed3ba3 100644 --- a/src/devices/elv.c +++ b/src/devices/elv.c @@ -81,7 +81,7 @@ static int ws2000_callback(r_device *decoder, bitbuffer_t *bitbuffer) { dec[0] = AD_POP (bb[0], 4, bit); bit+=4; stopbit= AD_POP (bb[0], 1, bit); bit+=1; if (!stopbit) { - if(debug_output) fprintf(stdout, "!stopbit\n"); + if(decoder->verbose) fprintf(stdout, "!stopbit\n"); return 0; } check_calculated ^= dec[0]; @@ -92,17 +92,17 @@ static int ws2000_callback(r_device *decoder, bitbuffer_t *bitbuffer) { dec[i] = AD_POP (bb[0], 4, bit); bit+=4; stopbit= AD_POP (bb[0], 1, bit); bit+=1; if (!stopbit) { - if(debug_output) fprintf(stdout, "!stopbit %i\n", bit); + if(decoder->verbose) fprintf(stdout, "!stopbit %i\n", bit); return 0; } check_calculated ^= dec[i]; sum_calculated += dec[i]; nibbles++; } - if(debug_output) { for (i = 0; i < nibbles; i++) fprintf(stdout, "%02X ", dec[i]); fprintf(stdout, "\n"); } + if(decoder->verbose) { for (i = 0; i < nibbles; i++) fprintf(stdout, "%02X ", dec[i]); fprintf(stdout, "\n"); } if (check_calculated) { - if(debug_output) fprintf(stdout, "check_calculated (%d) != 0\n", check_calculated); + if(decoder->verbose) fprintf(stdout, "check_calculated (%d) != 0\n", check_calculated); return 0; } @@ -111,7 +111,7 @@ static int ws2000_callback(r_device *decoder, bitbuffer_t *bitbuffer) { sum_calculated+=5; sum_calculated&=0xF; if (sum_received != sum_calculated) { - if(debug_output) fprintf(stdout, "sum_received (%d) != sum_calculated (%d) ", sum_received, sum_calculated); + if(decoder->verbose) fprintf(stdout, "sum_received (%d) != sum_calculated (%d) ", sum_received, sum_calculated); return 0; } diff --git a/src/devices/fineoffset.c b/src/devices/fineoffset.c index 0b1d3a4d..b49ca221 100644 --- a/src/devices/fineoffset.c +++ b/src/devices/fineoffset.c @@ -74,7 +74,7 @@ static int fineoffset_WH2_callback(r_device *decoder, bitbuffer_t *bitbuffer) { // Nibble 2 contains type, must be 0x04 -- or is this a (battery) flag maybe? please report. type = b[0] >> 4; if (type != 4) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "%s: Unknown type: %d\n", model, type); } return 0; @@ -179,7 +179,7 @@ static int fineoffset_WH24_callback(r_device *decoder, bitbuffer_t *bitbuffer) // Find a data package and extract data buffer bit_offset = bitbuffer_search(bitbuffer, 0, 0, preamble, sizeof(preamble) * 8) + sizeof(preamble) * 8; if (bit_offset + sizeof(b) * 8 > bitbuffer->bits_per_row[0]) { // Did not find a big enough package - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "Fineoffset_WH24: short package. Header index: %u\n", bit_offset); bitbuffer_print(bitbuffer); } @@ -191,7 +191,7 @@ static int fineoffset_WH24_callback(r_device *decoder, bitbuffer_t *bitbuffer) model = MODEL_WH65B; // nominal 12 bits postamble bitbuffer_extract_bytes(bitbuffer, 0, bit_offset, b, sizeof(b) * 8); - if (debug_output) { + if (decoder->verbose) { char raw_str[17 * 3 + 1]; for (unsigned n = 0; n < sizeof(b); n++) { sprintf(raw_str + n * 3, "%02x ", b[n]); @@ -209,7 +209,7 @@ static int fineoffset_WH24_callback(r_device *decoder, bitbuffer_t *bitbuffer) checksum += b[n]; } if (crc != b[15] || checksum != b[16]) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "Fineoffset_WH24: Checksum error: %02x %02x\n", crc, checksum); } return 0; @@ -329,7 +329,7 @@ static int fineoffset_WH25_callback(r_device *decoder, bitbuffer_t *bitbuffer) { // Find a data package and extract data payload bit_offset = bitbuffer_search(bitbuffer, 0, 320, preamble, sizeof(preamble) * 8) + sizeof(preamble) * 8; // Normal index is 367, skip some bytes to find faster if (bit_offset + sizeof(b) * 8 > bitbuffer->bits_per_row[0]) { // Did not find a big enough package - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "Fineoffset_WH25: short package. Header index: %u\n", bit_offset); bitbuffer_print(bitbuffer); } @@ -337,7 +337,7 @@ static int fineoffset_WH25_callback(r_device *decoder, bitbuffer_t *bitbuffer) { } bitbuffer_extract_bytes(bitbuffer, 0, bit_offset, b, sizeof(b) * 8); - if (debug_output) { + if (decoder->verbose) { char raw_str[8 * 3 + 1]; for (unsigned n=0; n> 4); // Swap nibbles if (checksum != b[6] || bitsum != b[7]) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "Fineoffset_WH25: Checksum error: %02x %02x\n", checksum, bitsum); } return 0; @@ -414,7 +414,7 @@ static int fineoffset_WH0530_callback(r_device *decoder, bitbuffer_t *bitbuffer) uint8_t buffer[8]; bitbuffer_extract_bytes(bitbuffer, 0, 7, buffer, sizeof(buffer) * 8); // Skip first 7 bits - if (debug_output) { + if (decoder->verbose) { char raw_str[8 * 3 + 1]; for (unsigned n=0; nverbose) { fprintf(stderr, "Fineoffset_WH0530: Checksum error: %02x %02x\n", crc, checksum); } return 0; diff --git a/src/devices/fineoffset_wh1080.c b/src/devices/fineoffset_wh1080.c index e387f077..77f319e8 100644 --- a/src/devices/fineoffset_wh1080.c +++ b/src/devices/fineoffset_wh1080.c @@ -283,7 +283,7 @@ static int fineoffset_wh1080_callback(r_device *decoder, bitbuffer_t *bitbuffer) return 0; } - if (debug_output) { + if (decoder->verbose) { bitrow_print(bbuf, (sens_msg - 1) * 8); } diff --git a/src/devices/flex.c b/src/devices/flex.c index c5097dae..90145abd 100644 --- a/src/devices/flex.c +++ b/src/devices/flex.c @@ -131,7 +131,7 @@ static int flex_callback(r_device *decoder, bitbuffer_t *bitbuffer, struct flex_ return 0; } - if (debug_output >= 1) { + if (decoder->verbose) { fprintf(stderr, "%s: ", params->name); bitbuffer_print(bitbuffer); } @@ -352,9 +352,11 @@ static void parse_getter(const char *arg, struct flex_get *getter) fprintf(stderr, "Bad flex spec, \"get\" missing name!\n"); usage(); } - if (debug_output) + /* + 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); + */ } r_device *flex_create_device(char *spec) @@ -534,13 +536,15 @@ r_device *flex_create_device(char *spec) if (params->min_bits > 0 && params->min_repeats < 1) params->min_repeats = 1; - if (debug_output >= 1) { + /* + if (decoder->verbose) { fprintf(stderr, "Adding flex decoder \"%s\"\n", params->name); fprintf(stderr, "\tmodulation=%u, short_limit=%.0f, long_limit=%.0f, reset_limit=%.0f\n", dev->modulation, dev->short_limit, dev->long_limit, dev->reset_limit); fprintf(stderr, "\tmin_rows=%u, min_bits=%u, min_repeats=%u, invert=%u, match_len=%u, preamble_len=%u\n", params->min_rows, params->min_bits, params->min_repeats, params->invert, params->match_len, params->preamble_len); } + */ free(spec); next_slot++; diff --git a/src/devices/fordremote.c b/src/devices/fordremote.c index a8eecce9..93949117 100644 --- a/src/devices/fordremote.c +++ b/src/devices/fordremote.c @@ -38,7 +38,7 @@ static int fordremote_callback(r_device *decoder, bitbuffer_t *bitbuffer) { continue; // no valid preamble } - if (debug_output) { + if (decoder->verbose) { bitbuffer_print(bitbuffer); } diff --git a/src/devices/inovalley-kw9015b.c b/src/devices/inovalley-kw9015b.c index ac360824..d6a61308 100644 --- a/src/devices/inovalley-kw9015b.c +++ b/src/devices/inovalley-kw9015b.c @@ -37,7 +37,7 @@ static int kw9015b_callback(r_device *decoder, bitbuffer_t *bitbuffer) { (reverse8(bb[i][3])>>4)+(reverse8(bb[i][3])&0x0F)); - if (debug_output >= 1) { + if (decoder->verbose) { fprintf(stdout, "\nSensor = Inovalley kw9015b, TFA Dostmann 30.3161 (Rain and temperature sensor)\n"); fprintf(stdout, "Device = %d\n", device); fprintf(stdout, "Temp = %f\n",fTemp); diff --git a/src/devices/interlogix.c b/src/devices/interlogix.c index 730e64ff..2f10d312 100644 --- a/src/devices/interlogix.c +++ b/src/devices/interlogix.c @@ -114,7 +114,7 @@ static int interlogix_callback(r_device *decoder, bitbuffer_t *bitbuffer) // search for preamble and exit if not found unsigned int bit_offset = bitbuffer_search(bitbuffer, row, 0, preamble, (sizeof preamble) * 8); if (bit_offset == bitbuffer->bits_per_row[row] || bitbuffer->num_rows != 1) { - if (debug_output > 1) + if (decoder->verbose > 1) fprintf(stderr, "Interlogix: Preamble not found, bit_offset: %d\n", bit_offset); return 0; } @@ -123,13 +123,13 @@ static int interlogix_callback(r_device *decoder, bitbuffer_t *bitbuffer) bit_offset += (sizeof preamble) * 8; if (bitbuffer->bits_per_row[row] - bit_offset < INTERLOGIX_MSG_BIT_LEN - 1) { - if (debug_output > 1) + if (decoder->verbose > 1) fprintf(stderr, "Interlogix: Found valid preamble but message size (%d) too small\n", bitbuffer->bits_per_row[row] - bit_offset); return 0; } if (bitbuffer->bits_per_row[row] - bit_offset > INTERLOGIX_MSG_BIT_LEN + 7) { - if (debug_output > 1) + if (decoder->verbose > 1) fprintf(stderr, "Interlogix: Found valid preamble but message size (%d) too long\n", bitbuffer->bits_per_row[row] - bit_offset); return 0; } @@ -157,7 +157,7 @@ static int interlogix_callback(r_device *decoder, bitbuffer_t *bitbuffer) int parity_error = parity ^ 0x3; // both parities are odd, i.e. 1 on success if (parity_error) { - if (debug_output) + if (decoder->verbose) fprintf(stderr, "Interlogix: Parity check failed (%d %d)\n", parity >> 1, parity & 1); return 0; } diff --git a/src/devices/intertechno.c b/src/devices/intertechno.c index 7da28aca..dcf4c5a4 100644 --- a/src/devices/intertechno.c +++ b/src/devices/intertechno.c @@ -22,7 +22,7 @@ static int intertechno_callback(r_device *decoder, bitbuffer_t *bitbuffer) if (bb[0][0] != 0 || (bb[1][0] != 0x56 && bb[1][0] != 0x69)) return 0; - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stdout, "Switch event:\n"); fprintf(stdout, "protocol = Intertechno\n"); fprintf(stdout, "rid = %x\n", b[0]); diff --git a/src/devices/kedsum.c b/src/devices/kedsum.c index 1cc4d3d3..875809af 100644 --- a/src/devices/kedsum.c +++ b/src/devices/kedsum.c @@ -61,7 +61,7 @@ static int kedsum_callback(r_device *decoder, bitbuffer_t *bitbuffer) { temperature_with_offset = (tnH<<8) | (tnM<<4) | tnL; temperature_f = (temperature_with_offset - 900) / 10.0; - if (debug_output) { + if (decoder->verbose) { fprintf(stdout, "Bitstream HEX = "); bitrow_print(b, 48); fprintf(stdout, "Humidity HEX = %02x\n", b[3]); diff --git a/src/devices/lacrosse.c b/src/devices/lacrosse.c index 1bf301ae..3f6a17e9 100644 --- a/src/devices/lacrosse.c +++ b/src/devices/lacrosse.c @@ -58,7 +58,7 @@ // Long bits = 0 // short bits = 1 // -static int lacrossetx_detect(uint8_t *pRow, uint8_t *msg_nybbles, int16_t rowlen) { +static int lacrossetx_detect(r_device *decoder, uint8_t *pRow, uint8_t *msg_nybbles, int16_t rowlen) { int i; uint8_t rbyte_no, rbit_no, mnybble_no, mbit_no; uint8_t bit, checksum, parity_bit, parity = 0; @@ -107,7 +107,7 @@ static int lacrossetx_detect(uint8_t *pRow, uint8_t *msg_nybbles, int16_t rowlen if (checksum == msg_nybbles[10] && (parity % 2 == 0)) { return 1; } else { - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stdout, "LaCrosse TX Checksum/Parity error: Comp. %d != Recv. %d, Parity %d\n", checksum, msg_nybbles[10], parity); @@ -137,7 +137,7 @@ static int lacrossetx_callback(r_device *decoder, bitbuffer_t *bitbuffer) { for (m = 0; m < BITBUF_ROWS; m++) { valid = 0; // break out the message nybbles into separate bytes - if (lacrossetx_detect(bb[m], msg_nybbles, bitbuffer->bits_per_row[m])) { + if (lacrossetx_detect(decoder, bb[m], msg_nybbles, bitbuffer->bits_per_row[m])) { msg_len = msg_nybbles[1]; msg_type = msg_nybbles[2]; @@ -155,7 +155,7 @@ static int lacrossetx_callback(r_device *decoder, bitbuffer_t *bitbuffer) { // message integrity. if (msg_nybbles[5] != msg_nybbles[8] || msg_nybbles[6] != msg_nybbles[9]) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "LaCrosse TX Sensor %02x, type: %d: message value mismatch int(%3.1f) != %d?\n", sensor_id, msg_type, msg_value, msg_value_int); @@ -187,7 +187,7 @@ static int lacrossetx_callback(r_device *decoder, bitbuffer_t *bitbuffer) { default: // @todo this should be reported/counted as exception, not considered debug - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "%s LaCrosse Sensor %02x: Unknown Reading type %d, % 3.1f (%d)\n", time_str, sensor_id, msg_type, msg_value, msg_value_int); diff --git a/src/devices/lacrosse_TX141TH_Bv2.c b/src/devices/lacrosse_TX141TH_Bv2.c index 20626a54..bb130fca 100644 --- a/src/devices/lacrosse_TX141TH_Bv2.c +++ b/src/devices/lacrosse_TX141TH_Bv2.c @@ -133,7 +133,7 @@ static int lacrosse_tx141th_bv2_callback(r_device *decoder, bitbuffer_t *bitbuff } if (0 == id || (device == LACROSSE_TX141TH && (0 == humidity || humidity > 100)) || temp_c < -40.0 || temp_c > 140.0) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "LaCrosse TX141-Bv2/TX141TH-Bv2 data error\n"); fprintf(stderr, "id: %i, humidity:%i, temp:%f\n", id, humidity, temp_c); } diff --git a/src/devices/lacrosse_tx35.c b/src/devices/lacrosse_tx35.c index 560c5f17..3667dad9 100644 --- a/src/devices/lacrosse_tx35.c +++ b/src/devices/lacrosse_tx35.c @@ -85,7 +85,7 @@ static int lacrosse_it(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t device unsigned int start_pos = bitbuffer_search(bitbuffer, brow, 0, preamble, 28); if (start_pos == bitbuffer->bits_per_row[brow]) continue; // no preamble detected, move to the next row - if (debug_output) + if (decoder->verbose) fprintf(stderr, "LaCrosse TX29/35 detected, buffer is %d bits length, device is TX%d\n", bitbuffer->bits_per_row[brow], device29or35); // remove preamble and keep only 64 bits bitbuffer_extract_bytes(bitbuffer, brow, start_pos, out, 64); @@ -99,7 +99,7 @@ static int lacrosse_it(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t device r_crc = out[7]; c_crc = crc8(&out[3], 4, LACROSSE_TX35_CRC_POLY, LACROSSE_TX35_CRC_INIT); if (r_crc != c_crc) { - if (debug_output) + if (decoder->verbose) fprintf(stderr, "%s LaCrosse TX29/35 bad CRC: calculated %02x, received %02x\n", time_str, c_crc, r_crc); // reject row diff --git a/src/devices/lacrossews.c b/src/devices/lacrossews.c index 774a2ca7..8778d5fe 100644 --- a/src/devices/lacrossews.c +++ b/src/devices/lacrossews.c @@ -26,7 +26,7 @@ #define LACROSSE_WS_BITLEN 52 -static int lacrossews_detect(uint8_t *pRow, uint8_t *msg_nybbles, int16_t rowlen) { +static int lacrossews_detect(r_device *decoder, uint8_t *pRow, uint8_t *msg_nybbles, int16_t rowlen) { int i; uint8_t rbyte_no, rbit_no, mnybble_no, mbit_no; uint8_t bit, checksum = 0, parity = 0; @@ -65,7 +65,7 @@ static int lacrossews_detect(uint8_t *pRow, uint8_t *msg_nybbles, int16_t rowlen return 1; else { local_time_str(0, time_str); - if (debug_output) { + if (decoder->verbose) { fprintf(stdout, "%s LaCrosse Packet Validation Failed error: Checksum Comp. %d != Recv. %d, Parity %d\n", time_str, checksum, msg_nybbles[12], parity); @@ -95,7 +95,7 @@ static int lacrossews_callback(r_device *decoder, bitbuffer_t *bitbuffer) { for (m = 0; m < BITBUF_ROWS; m++) { // break out the message nybbles into separate bytes - if (lacrossews_detect(bb[m], msg_nybbles, bitbuffer->bits_per_row[m])) { + if (lacrossews_detect(decoder, bb[m], msg_nybbles, bitbuffer->bits_per_row[m])) { ws_id = (msg_nybbles[0] << 4) + msg_nybbles[1]; msg_type = ((msg_nybbles[2] >> 1) & 0x4) + (msg_nybbles[2] & 0x3); @@ -109,7 +109,7 @@ static int lacrossews_callback(r_device *decoder, bitbuffer_t *bitbuffer) { local_time_str(0, time_str); - if (debug_output) + if (decoder->verbose) fprintf(stderr, "%1X%1X%1X%1X%1X%1X%1X%1X%1X%1X%1X%1X%1X ", msg_nybbles[0], msg_nybbles[1], msg_nybbles[2], msg_nybbles[3], msg_nybbles[4], msg_nybbles[5], msg_nybbles[6], msg_nybbles[7], @@ -164,7 +164,7 @@ static int lacrossews_callback(r_device *decoder, bitbuffer_t *bitbuffer) { wind_dir = msg_nybbles[9] * 22.5; wind_spd = (msg_nybbles[7] * 16 + msg_nybbles[8])/ 10.0; if(msg_nybbles[7] == 0xF && msg_nybbles[8] == 0xE) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "%s LaCrosse WS %02X-%02X: %s Not Connected\n", time_str, ws_id, sensor_id, msg_type == 3 ? "Wind":"Gust"); } @@ -182,7 +182,7 @@ static int lacrossews_callback(r_device *decoder, bitbuffer_t *bitbuffer) { } break; default: - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "%s LaCrosse WS %02X-%02X: Unknown data type %d, bcd %d bin %d\n", time_str, ws_id, sensor_id, msg_type, msg_value_bcd, msg_value_bin); diff --git a/src/devices/lightwave_rf.c b/src/devices/lightwave_rf.c index 74098355..5cd4f711 100644 --- a/src/devices/lightwave_rf.c +++ b/src/devices/lightwave_rf.c @@ -92,7 +92,7 @@ static int lightwave_rf_callback(r_device *decoder, bitbuffer_t *bitbuffer) { for(unsigned n=0; n<10; ++n) { // We have 10 bytes/nibbles int nibble = lightwave_rf_nibble_from_byte(bb[2][n]); if (nibble < 0) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "LightwaveRF. Nibble decode error %X, idx: %u\n", bb[2][n], n); bitbuffer_print(bitbuffer); } @@ -111,7 +111,7 @@ static int lightwave_rf_callback(r_device *decoder, bitbuffer_t *bitbuffer) { fprintf(stdout, "Command = %u\n", bb[3][1] & 0x0F); fprintf(stdout, "Parameter = %u\n", bb[3][0]); - if (debug_output) { + if (decoder->verbose) { bitbuffer_print(bitbuffer); fprintf(stderr, " Row 0 = Input, Row 1 = Zero bit stuffing, Row 2 = Stripped delimiters, Row 3 = Decoded nibbles\n"); } diff --git a/src/devices/m_bus.c b/src/devices/m_bus.c index 73195c4c..6a7d6d80 100644 --- a/src/devices/m_bus.c +++ b/src/devices/m_bus.c @@ -60,12 +60,13 @@ static int m_bus_decode_3of6_buffer(const bitrow_t bits, unsigned bit_offset, ui // Validate CRC -static int m_bus_crc_valid(const uint8_t* bytes, unsigned crc_offset) { +static int m_bus_crc_valid(r_device *decoder, const uint8_t *bytes, unsigned crc_offset) +{ static const uint16_t CRC_POLY = 0x3D65; uint16_t crc_calc = ~crc16_ccitt(bytes, crc_offset, CRC_POLY, 0); uint16_t crc_read = (((uint16_t)bytes[crc_offset] << 8) | bytes[crc_offset+1]); if (crc_calc != crc_read) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "M-Bus: CRC error: Calculated 0x%0X, Read: 0x%0X\n", (unsigned)crc_calc, (unsigned)crc_read); } return 0; @@ -130,8 +131,8 @@ typedef struct { uint8_t data[512]; } m_bus_data_t; - -static int m_bus_decode_format_a(const m_bus_data_t *in, m_bus_data_t *out, m_bus_block1_t *block1) { +static int m_bus_decode_format_a(r_device *decoder, const m_bus_data_t *in, m_bus_data_t *out, m_bus_block1_t *block1) +{ static const uint16_t BLOCK1A_SIZE = 12; // Size of Block 1, format A // Get Block 1 @@ -146,12 +147,12 @@ static int m_bus_decode_format_a(const m_bus_data_t *in, m_bus_data_t *out, m_bu out->length = block1->L-9; // Validate CRC - if (!m_bus_crc_valid(in->data, 10)) return 0; + if (!m_bus_crc_valid(decoder, in->data, 10)) return 0; // Check length of package is sufficient unsigned num_data_blocks = (block1->L-9+15)/16; // Data blocks are 16 bytes long + 2 CRC bytes (not counted in L) if ((block1->L < 9) || ((block1->L-9)+num_data_blocks*2 > in->length-BLOCK1A_SIZE)) { // add CRC bytes for each data block - if (debug_output) { fprintf(stderr, "M-Bus: Package too short for Length: %u\n", block1->L); } + if (decoder->verbose) { fprintf(stderr, "M-Bus: Package too short for Length: %u\n", block1->L); } return 0; } @@ -162,7 +163,7 @@ static int m_bus_decode_format_a(const m_bus_data_t *in, m_bus_data_t *out, m_bu uint8_t block_size = min(block1->L-9-n*16, 16)+2; // Maximum block size is 16 Data + 2 CRC // Validate CRC - if (!m_bus_crc_valid(in_ptr, block_size-2)) return 0; + if (!m_bus_crc_valid(decoder, in_ptr, block_size-2)) return 0; // Get block data memcpy(out_ptr, in_ptr, block_size); @@ -170,8 +171,8 @@ static int m_bus_decode_format_a(const m_bus_data_t *in, m_bus_data_t *out, m_bu return 1; } - -static int m_bus_decode_format_b(const m_bus_data_t *in, m_bus_data_t *out, m_bus_block1_t *block1) { +static int m_bus_decode_format_b(r_device *decoder, const m_bus_data_t *in, m_bus_data_t *out, m_bus_block1_t *block1) +{ static const uint16_t BLOCK1B_SIZE = 10; // Size of Block 1, format B static const uint16_t BLOCK2B_SIZE = 118; // Maximum size of Block 2, format B static const uint16_t BLOCK1_2B_SIZE = 128; @@ -189,12 +190,12 @@ static int m_bus_decode_format_b(const m_bus_data_t *in, m_bus_data_t *out, m_bu // Check length of package is sufficient if ((block1->L < 12) || (block1->L+1 > (int)in->length)) { // L includes all bytes except itself - if (debug_output) { fprintf(stderr, "M-Bus: Package too short for Length: %u\n", block1->L); } + if (decoder->verbose) { fprintf(stderr, "M-Bus: Package too short for Length: %u\n", block1->L); } return 0; } // Validate CRC - if (!m_bus_crc_valid(in->data, min(block1->L-1, (BLOCK1B_SIZE+BLOCK2B_SIZE)-2))) return 0; + if (!m_bus_crc_valid(decoder, in->data, min(block1->L-1, (BLOCK1B_SIZE+BLOCK2B_SIZE)-2))) return 0; // Get data from Block 2 memcpy(out->data, in->data+BLOCK1B_SIZE, (min(block1->L-11, BLOCK2B_SIZE-2))); @@ -203,7 +204,7 @@ static int m_bus_decode_format_b(const m_bus_data_t *in, m_bus_data_t *out, m_bu uint8_t L_OFFSET = BLOCK1B_SIZE+BLOCK2B_SIZE-1; // How much to subtract from L (127) if (block1->L > (L_OFFSET+2)) { // Any more data? (besided 2 extra CRC) // Validate CRC - if (!m_bus_crc_valid(in->data+BLOCK1B_SIZE+BLOCK2B_SIZE, block1->L-L_OFFSET-2)) return 0; + if (!m_bus_crc_valid(decoder, in->data+BLOCK1B_SIZE+BLOCK2B_SIZE, block1->L-L_OFFSET-2)) return 0; // Get Block 3 memcpy(out->data+(BLOCK2B_SIZE-2), in->data+BLOCK1B_SIZE+BLOCK2B_SIZE, block1->L-L_OFFSET-2); @@ -274,25 +275,25 @@ static int m_bus_mode_c_t_callback(r_device *decoder, bitbuffer_t *bitbuffer) { bit_offset += 8; // Format A if (next_byte == 0xCD) { - if (debug_output) { fprintf(stderr, "M-Bus: Mode C, Format A\n"); } + if (decoder->verbose) { fprintf(stderr, "M-Bus: Mode C, Format A\n"); } // Extract data data_in.length = (bitbuffer->bits_per_row[0]-bit_offset)/8; bitbuffer_extract_bytes(bitbuffer, 0, bit_offset, data_in.data, data_in.length*8); // Decode - if(!m_bus_decode_format_a(&data_in, &data_out, &block1)) return 0; + if(!m_bus_decode_format_a(decoder, &data_in, &data_out, &block1)) return 0; } // Format A // Format B else if (next_byte == 0x3D) { - if (debug_output) { fprintf(stderr, "M-Bus: Mode C, Format B\n"); } + if (decoder->verbose) { fprintf(stderr, "M-Bus: Mode C, Format B\n"); } // Extract data data_in.length = (bitbuffer->bits_per_row[0]-bit_offset)/8; bitbuffer_extract_bytes(bitbuffer, 0, bit_offset, data_in.data, data_in.length*8); // Decode - if(!m_bus_decode_format_b(&data_in, &data_out, &block1)) return 0; + if(!m_bus_decode_format_b(decoder, &data_in, &data_out, &block1)) return 0; } // Format B // Unknown Format else { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "M-Bus: Mode C, Unknown format: 0x%X\n", next_byte); bitbuffer_print(bitbuffer); } @@ -301,16 +302,16 @@ static int m_bus_mode_c_t_callback(r_device *decoder, bitbuffer_t *bitbuffer) { } // Mode C // Mode T else { - if (debug_output) { fprintf(stderr, "M-Bus: Mode T\n"); } - if (debug_output) { fprintf(stderr, "Experimental - Not tested\n"); } + if (decoder->verbose) { fprintf(stderr, "M-Bus: Mode T\n"); } + if (decoder->verbose) { fprintf(stderr, "Experimental - Not tested\n"); } // Extract data data_in.length = (bitbuffer->bits_per_row[0]-bit_offset)/12; // Each byte is encoded into 12 bits if(m_bus_decode_3of6_buffer(bitbuffer->bb[0], bit_offset, data_in.data, data_in.length) < 0) { - if (debug_output) fprintf(stderr, "M-Bus: Decoding error\n"); + if (decoder->verbose) fprintf(stderr, "M-Bus: Decoding error\n"); return 0; } // Decode - if(!m_bus_decode_format_a(&data_in, &data_out, &block1)) return 0; + if(!m_bus_decode_format_a(decoder, &data_in, &data_out, &block1)) return 0; } // Mode T m_bus_output_data(decoder, &data_out, &block1); @@ -337,13 +338,13 @@ static int m_bus_mode_r_callback(r_device *decoder, bitbuffer_t *bitbuffer) { } bit_offset += sizeof(PREAMBLE_RA)*8; // skip preamble - if (debug_output) { fprintf(stderr, "M-Bus: Mode R, Format A\n"); } - if (debug_output) { fprintf(stderr, "Experimental - Not tested\n"); } + if (decoder->verbose) { fprintf(stderr, "M-Bus: Mode R, Format A\n"); } + if (decoder->verbose) { fprintf(stderr, "Experimental - Not tested\n"); } // Extract data data_in.length = (bitbuffer->bits_per_row[0]-bit_offset)/8; bitbuffer_extract_bytes(bitbuffer, 0, bit_offset, data_in.data, data_in.length*8); // Decode - if(!m_bus_decode_format_a(&data_in, &data_out, &block1)) return 0; + if(!m_bus_decode_format_a(decoder, &data_in, &data_out, &block1)) return 0; m_bus_output_data(decoder, &data_out, &block1); return 1; @@ -375,19 +376,19 @@ static int m_bus_mode_f_callback(r_device *decoder, bitbuffer_t *bitbuffer) { bit_offset += 8; // Format A if (next_byte == 0x8D) { - if (debug_output) { fprintf(stderr, "M-Bus: Mode F, Format A\n"); } - if (debug_output) { fprintf(stderr, "Not implemented\n"); } + if (decoder->verbose) { fprintf(stderr, "M-Bus: Mode F, Format A\n"); } + if (decoder->verbose) { fprintf(stderr, "Not implemented\n"); } return 1; } // Format A // Format B else if (next_byte == 0x72) { - if (debug_output) { fprintf(stderr, "M-Bus: Mode F, Format B\n"); } - if (debug_output) { fprintf(stderr, "Not implemented\n"); } + if (decoder->verbose) { fprintf(stderr, "M-Bus: Mode F, Format B\n"); } + if (decoder->verbose) { fprintf(stderr, "Not implemented\n"); } return 1; } // Format B // Unknown Format else { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "M-Bus: Mode F, Unknown format: 0x%X\n", next_byte); bitbuffer_print(bitbuffer); } diff --git a/src/devices/maverick_et73x.c b/src/devices/maverick_et73x.c index b17ee1ec..e138fa62 100644 --- a/src/devices/maverick_et73x.c +++ b/src/devices/maverick_et73x.c @@ -75,7 +75,7 @@ static int maverick_et73x_callback(r_device *decoder, bitbuffer_t *bitbuffer) //digest is used to represent a session. This means, we get a new id if a reset or battery exchange is done. int id = lfsr_digest16(chk_data, 24, 0x8810, 0xdd38) ^ digest; - if (debug_output) + if (decoder->verbose) fprintf(stderr, "%s: pre %03x, flags %0x, t1 %d, t2 %d, digest %04x, chk_data %06x, digest xor'ed: %04x\n", __FUNCTION__, pre, flags, temp1, temp2, digest, chk_data, id); diff --git a/src/devices/new_template.c b/src/devices/new_template.c index 7da177a4..597e26dc 100644 --- a/src/devices/new_template.c +++ b/src/devices/new_template.c @@ -65,7 +65,7 @@ static int template_callback(r_device *decoder, bitbuffer_t *bitbuffer) * 1. Enable with -D -D (debug level of 2) * 2. Delete this block when your decoder is working */ - // if (debug_output > 1) { + // if (decoder->verbose > 1) { // fprintf(stderr,"new_tmplate callback:\n"); // bitbuffer_print(bitbuffer); // } @@ -151,7 +151,7 @@ static int template_callback(r_device *decoder, bitbuffer_t *bitbuffer) parity = (parity >> 1) ^ (parity & 0x1); // fold to 1 bit if (!parity) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "new_template parity check failed\n"); } return 0; @@ -161,7 +161,7 @@ static int template_callback(r_device *decoder, bitbuffer_t *bitbuffer) * Check message integrity (Checksum example) */ if (((b[0] + b[1] + b[2] + b[3] - b[4]) & 0xFF) != 0) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "new_template checksum error\n"); } return 0; @@ -176,7 +176,7 @@ static int template_callback(r_device *decoder, bitbuffer_t *bitbuffer) c_crc = crc8(b, MYDEVICE_BITLEN / 8, MYDEVICE_CRC_POLY, MYDEVICE_CRC_INIT); if (r_crc != c_crc) { // example debugging output - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "new_template bad CRC: calculated %02x, received %02x\n", c_crc, r_crc); } diff --git a/src/devices/nexus.c b/src/devices/nexus.c index 55f6f0b4..8c520a55 100644 --- a/src/devices/nexus.c +++ b/src/devices/nexus.c @@ -29,7 +29,7 @@ static int nexus_callback(r_device *decoder, bitbuffer_t *bitbuffer) { char time_str[LOCAL_TIME_BUFLEN]; - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr,"Possible Nexus: "); bitbuffer_print(bitbuffer); } diff --git a/src/devices/oregon_scientific.c b/src/devices/oregon_scientific.c index 98dd4482..cda58c57 100644 --- a/src/devices/oregon_scientific.c +++ b/src/devices/oregon_scientific.c @@ -60,9 +60,9 @@ unsigned int get_os_humidity(unsigned char *message, unsigned int sensor_id) { return humidity; } -float get_os_pressure(unsigned char *message, unsigned int sensor_id) { +float get_os_pressure(r_device *decoder, unsigned char *message, unsigned int sensor_id) { // sensor ID included to support sensors with pressure in different position/format - if (debug_output) + if (decoder->verbose) { fprintf(stdout," raw pressure data : %02x %02x\n",(int)message[8],(int)message[7]); } @@ -125,7 +125,7 @@ unsigned long long total(const unsigned char* d) { return val ; } -static int validate_os_checksum(unsigned char *msg, int checksum_nibble_idx) { +static int validate_os_checksum(r_device *decoder, unsigned char *msg, int checksum_nibble_idx) { // Oregon Scientific v2.1 and v3 checksum is a 1 byte 'sum of nibbles' checksum. // with the 2 nibbles of the checksum byte swapped. int i; @@ -145,7 +145,7 @@ static int validate_os_checksum(unsigned char *msg, int checksum_nibble_idx) { if (sum_of_nibbles == checksum) { return 0; } else { - if(debug_output) { + if(decoder->verbose) { fprintf(stderr, "Checksum error in Oregon Scientific message. Expected: %02x Calculated: %02x\n", checksum, sum_of_nibbles); fprintf(stderr, "Message: "); bitrow_print(msg, ((checksum_nibble_idx + 4) >> 1) * 8); @@ -154,13 +154,13 @@ static int validate_os_checksum(unsigned char *msg, int checksum_nibble_idx) { } } -static int validate_os_v2_message(unsigned char * msg, int bits_expected, int valid_v2_bits_received, +static int validate_os_v2_message(r_device *decoder, unsigned char * msg, int bits_expected, int valid_v2_bits_received, int nibbles_in_checksum) { // Oregon scientific v2.1 protocol sends each bit using the complement of the bit, then the bit for better error checking. Compare number of valid bits processed vs number expected if (bits_expected == valid_v2_bits_received) { - return (validate_os_checksum(msg, nibbles_in_checksum)); + return (validate_os_checksum(decoder, msg, nibbles_in_checksum)); } else { - if(debug_output) { + if(decoder->verbose) { fprintf(stderr, "Bit validation error on Oregon Scientific message. Expected %d bits, received error after bit %d \n", bits_expected, valid_v2_bits_received); fprintf(stderr, "Message: "); bitrow_print(msg, bits_expected); @@ -189,7 +189,7 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff unsigned int pattern = (unsigned int)(0x55990000>>pattern_index); unsigned int pattern2 = (unsigned int)(0xaa990000>>pattern_index); - if(debug_output) { + if(decoder->verbose) { fprintf(stdout, "OS v2.1 sync byte search - test_val=%08x pattern=%08x mask=%08x\n", sync_test_val, pattern, mask); } @@ -200,7 +200,7 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff // pattern_index indicates where sync nibble starts, so now we can find the start of the payload int start_byte = 5 + (pattern_index>>3); int start_bit = pattern_index & 0x07; - if(debug_output) { + if(decoder->verbose) { fprintf(stdout, "OS v2.1 Sync test val %08x found, starting decode at byte index %d bit %d\n", sync_test_val, start_byte, start_bit); } int bits_processed = 0; @@ -247,7 +247,7 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff int sensor_id = (msg[0] << 8) | msg[1]; if ((sensor_id == ID_THGR122N) || (sensor_id == ID_THGR968)){ - if (validate_os_v2_message(msg, 153, num_valid_v2_bits, 15) == 0) { + if (validate_os_v2_message(decoder, msg, 153, num_valid_v2_bits, 15) == 0) { data = data_make( "time", "", DATA_STRING, time_str, "brand", "", DATA_STRING, "OS", @@ -262,7 +262,7 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff } return 1; } else if (sensor_id == ID_WGR968) { - if (validate_os_v2_message(msg, 189, num_valid_v2_bits, 17) == 0) { + if (validate_os_v2_message(decoder, msg, 189, num_valid_v2_bits, 17) == 0) { float quadrant = (((msg[4] &0x0f)*10) + ((msg[4]>>4)&0x0f) + (((msg[5]>>4)&0x0f) * 100)); float avgWindspeed = ((msg[7]>>4)&0x0f) / 10.0F + (msg[7]&0x0f) *1.0F + ((msg[8]>>4)&0x0f) / 10.0F; float gustWindspeed = (msg[5]&0x0f) /10.0F + ((msg[6]>>4)&0x0f) *1.0F + (msg[6]&0x0f) / 10.0F; @@ -281,7 +281,7 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff } return 1; } else if (sensor_id == ID_BHTR968) { - if (validate_os_v2_message(msg, 185, num_valid_v2_bits, 19) == 0) { + if (validate_os_v2_message(decoder, msg, 185, num_valid_v2_bits, 19) == 0) { unsigned int comfort = msg[7] >>4; char *comfort_str="Normal"; if (comfort == 4) comfort_str = "Comfortable"; @@ -311,7 +311,7 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff } return 1; } else if (sensor_id == ID_RGR968) { - if (validate_os_v2_message(msg, 161, num_valid_v2_bits, 16) == 0) { + if (validate_os_v2_message(decoder, msg, 161, num_valid_v2_bits, 16) == 0) { float rain_rate = (((msg[4] &0x0f)*100)+((msg[4]>>4)*10) + ((msg[5]>>4)&0x0f)) /10.0F; float total_rain = (((msg[7]&0xf)*10000)+((msg[7]>>4)*1000) + ((msg[6]&0xf)*100)+((msg[6]>>4)*10) + (msg[5]&0xf))/10.0F; @@ -329,7 +329,7 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff } return 1; } else if (sensor_id == ID_THR228N && num_valid_v2_bits==153) { - if (validate_os_v2_message(msg, 153, num_valid_v2_bits, 12) == 0) { + if (validate_os_v2_message(decoder, msg, 153, num_valid_v2_bits, 12) == 0) { float temp_c = get_os_temperature(msg, sensor_id); data = data_make( @@ -345,7 +345,7 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff } return 1; } else if (sensor_id == ID_THN132N && num_valid_v2_bits==129) { - if (validate_os_v2_message(msg, 129, num_valid_v2_bits, 12) == 0) { + if (validate_os_v2_message(decoder, msg, 129, num_valid_v2_bits, 12) == 0) { float temp_c = get_os_temperature(msg, sensor_id); data = data_make( @@ -361,7 +361,7 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff } return 1; } else if ((sensor_id & 0x0fff) == ID_RTGN129 && num_valid_v2_bits==161) { - if (validate_os_v2_message(msg, 161, num_valid_v2_bits, 15) == 0) { + if (validate_os_v2_message(decoder, msg, 161, num_valid_v2_bits, 15) == 0) { float temp_c = get_os_temperature(msg, sensor_id); data = data_make( "time", "", DATA_STRING, time_str, @@ -377,7 +377,7 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff } return 1; } else if ((sensor_id & 0x0fff) == ID_RTGN318) { - if (num_valid_v2_bits==153 && (validate_os_v2_message(msg, 153, num_valid_v2_bits, 15) == 0)) { + if (num_valid_v2_bits==153 && (validate_os_v2_message(decoder, msg, 153, num_valid_v2_bits, 15) == 0)) { float temp_c = get_os_temperature(msg, sensor_id); data = data_make( "time", "", DATA_STRING, time_str, @@ -390,13 +390,13 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff "humidity", "Humidity", DATA_FORMAT, "%u %%", DATA_INT, get_os_humidity(msg, sensor_id), NULL); decoder_output_data(decoder, data); - } else if (num_valid_v2_bits==201 && (validate_os_v2_message(msg, 201, num_valid_v2_bits, 21) == 0)) { + } else if (num_valid_v2_bits==201 && (validate_os_v2_message(decoder, msg, 201, num_valid_v2_bits, 21) == 0)) { // RF Clock message ?? } return 1; } else if (sensor_id == ID_THN129) { - if ((validate_os_v2_message(msg, 137, num_valid_v2_bits, 12) == 0)) { + if ((validate_os_v2_message(decoder, msg, 137, num_valid_v2_bits, 12) == 0)) { float temp_c = get_os_temperature(msg, sensor_id); data = data_make( "time", "", DATA_STRING, time_str, @@ -412,9 +412,9 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff return 1; } else if (sensor_id == ID_BTHGN129) { - //if ((validate_os_v2_message(msg, 137, num_valid_v2_bits, 12) == 0)) { + //if ((validate_os_v2_message(decoder, msg, 137, num_valid_v2_bits, 12) == 0)) { float temp_c = get_os_temperature(msg, sensor_id); - float pressure = get_os_pressure(msg, sensor_id); + float pressure = get_os_pressure(decoder, msg, sensor_id); data = data_make( "time", "", DATA_STRING, time_str, "brand", "", DATA_STRING, "OS", @@ -431,7 +431,7 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff return 1; } else if (sensor_id == ID_UVR128 && num_valid_v2_bits==297) { - if ((validate_os_v2_message(msg, 297, num_valid_v2_bits, 12) == 0)) { + if ((validate_os_v2_message(decoder, msg, 297, num_valid_v2_bits, 12) == 0)) { int uvidx = get_os_uv(msg, sensor_id); data = data_make( "time", "", DATA_STRING, time_str, @@ -445,13 +445,13 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff } return 1; }else if (num_valid_v2_bits > 16) { - if(debug_output) { + if(decoder->verbose) { fprintf(stdout, "%d bit message received from unrecognized Oregon Scientific v2.1 sensor with device ID %x.\n", num_valid_v2_bits, sensor_id); fprintf(stdout, "Message: "); bitrow_print(msg, 20 * 8); } } else { - if(debug_output) { + if(decoder->verbose) { fprintf(stdout, "\nPossible Oregon Scientific v2.1 message, but sync nibble wasn't found\n"); fprintf(stdout, "Raw Data: "); bitrow_print(bb[0], bitbuffer->bits_per_row[0]); @@ -459,7 +459,7 @@ static int oregon_scientific_v2_1_parser(r_device *decoder, bitbuffer_t *bitbuff } } else { if (bb[0][3] != 0) { - if(debug_output) { + if(decoder->verbose) { int i; fprintf(stdout, "\nBadly formatted OS v2.1 message encountered.\n"); bitrow_print(bb[0], bitbuffer->bits_per_row[0]); @@ -525,7 +525,7 @@ static int oregon_scientific_v3_parser(r_device *decoder, bitbuffer_t *bitbuffer } int sensor_id = (msg[0] << 8) | msg[1]; if (sensor_id == ID_THGR810) { - if (validate_os_checksum(msg, 15) == 0) { + if (validate_os_checksum(decoder, msg, 15) == 0) { float temp_c = get_os_temperature(msg, sensor_id); int humidity = get_os_humidity(msg, sensor_id); data = data_make( @@ -542,7 +542,7 @@ static int oregon_scientific_v3_parser(r_device *decoder, bitbuffer_t *bitbuffer } return 1; //msg[k] = ((msg[k] & 0x0F) << 4) + ((msg[k] & 0xF0) >> 4); } else if (sensor_id == ID_THN802) { - if (validate_os_checksum(msg, 12) == 0) { + if (validate_os_checksum(decoder, msg, 12) == 0) { float temp_c = get_os_temperature(msg, sensor_id); data = data_make( "time", "", DATA_STRING, time_str, @@ -557,7 +557,7 @@ static int oregon_scientific_v3_parser(r_device *decoder, bitbuffer_t *bitbuffer } return 1; } else if (sensor_id == ID_UV800) { - if (validate_os_checksum(msg, 13) == 0) { // ok + if (validate_os_checksum(decoder, msg, 13) == 0) { // ok int uvidx = get_os_uv(msg, sensor_id); data = data_make( "time", "", DATA_STRING, time_str, @@ -571,7 +571,7 @@ static int oregon_scientific_v3_parser(r_device *decoder, bitbuffer_t *bitbuffer decoder_output_data(decoder, data); } } else if (sensor_id == ID_PCR800) { - if (validate_os_checksum(msg, 18) == 0) { + if (validate_os_checksum(decoder, msg, 18) == 0) { float rain_rate=get_os_rain_rate(msg, sensor_id); float total_rain=get_os_total_rain(msg, sensor_id); data = data_make( @@ -588,7 +588,7 @@ static int oregon_scientific_v3_parser(r_device *decoder, bitbuffer_t *bitbuffer } return 1; } else if (sensor_id == ID_PCR800a) { - if (validate_os_checksum(msg, 18) == 0) { + if (validate_os_checksum(decoder, msg, 18) == 0) { float rain_rate=get_os_rain_rate(msg, sensor_id); float total_rain=get_os_total_rain(msg, sensor_id); data = data_make( @@ -605,7 +605,7 @@ static int oregon_scientific_v3_parser(r_device *decoder, bitbuffer_t *bitbuffer } return 1; } else if (sensor_id == ID_WGR800) { - if (validate_os_checksum(msg, 17) == 0) { + if (validate_os_checksum(decoder, msg, 17) == 0) { float gustWindspeed = (msg[5]&0x0f) /10.0F + ((msg[6]>>4)&0x0f) *1.0F + (msg[6]&0x0f) * 10.0F; float avgWindspeed = ((msg[7]>>4)&0x0f) / 10.0F + (msg[7]&0x0f) *1.0F + ((msg[8]>>4)&0x0f) * 10.0F; float quadrant = (0x0f&(msg[4]>>4))*22.5F; @@ -625,7 +625,7 @@ return 1; return 1; } else if ((msg[0] == 0x20) || (msg[0] == 0x21) || (msg[0] == 0x22) || (msg[0] == 0x23) || (msg[0] == 0x24)) { // Owl CM160 Readings msg[0]=msg[0] & 0x0f; - if (validate_os_checksum(msg, 22) == 0) { + if (validate_os_checksum(decoder, msg, 22) == 0) { float rawAmp = (msg[4] >> 4 << 8 | (msg[3] & 0x0f )<< 4 | msg[3] >> 4); unsigned short int ipower = (rawAmp /(0.27*230)*1000); data = data_make( @@ -639,7 +639,7 @@ return 1; } } else if (msg[0] == 0x26) { // Owl CM180 readings msg[0]=msg[0] & 0x0f; - int valid = validate_os_checksum(msg, 23); + int valid = validate_os_checksum(decoder, msg, 23); int k; for (k=0; k> 4 | (msg[k] & 0x0F) << 4; @@ -668,7 +668,7 @@ return 1; decoder_output_data(decoder, data); } } else if ((msg[0] != 0) && (msg[1]!= 0)) { // sync nibble was found and some data is present... - if(debug_output) { + if(decoder->verbose) { fprintf(stderr, "Message received from unrecognized Oregon Scientific v3 sensor.\n"); fprintf(stderr, "Message: "); bitrow_print(msg, bitbuffer->bits_per_row[0]); @@ -676,7 +676,7 @@ return 1; bitrow_print(bb[0], bitbuffer->bits_per_row[0]); } } else if (bb[0][3] != 0 ) { - if(debug_output) { + if(decoder->verbose) { fprintf(stdout, "\nPossible Oregon Scientific v3 message, but sync nibble wasn't found\n"); fprintf(stdout, "Raw Data: "); bitrow_print(bb[0], bitbuffer->bits_per_row[0]); @@ -684,7 +684,7 @@ return 1; } } else { // Based on first couple of bytes, either corrupt message or something other than an Oregon Scientific v3 message - if(debug_output) { + if(decoder->verbose) { if (bb[0][3] != 0) { fprintf(stdout, "\nUnrecognized Msg in v3: "); bitrow_print(bb[0], bitbuffer->bits_per_row[0]); diff --git a/src/devices/oregon_scientific_sl109h.c b/src/devices/oregon_scientific_sl109h.c index e1b1786e..a250bb03 100644 --- a/src/devices/oregon_scientific_sl109h.c +++ b/src/devices/oregon_scientific_sl109h.c @@ -63,7 +63,7 @@ static int get_status(uint8_t fourth_byte) return (fourth_byte & 0x3C) >> 2; } -static int calculate_checksum(bitbuffer_t *bitbuffer, unsigned row_index, int channel) +static int calculate_checksum(r_device *decoder, bitbuffer_t *bitbuffer, unsigned row_index, int channel) { uint8_t calculated_checksum, actual_checksum; uint8_t sum = 0; @@ -78,7 +78,7 @@ static int calculate_checksum(bitbuffer_t *bitbuffer, unsigned row_index, int ch actual_checksum = bitbuffer->bb[row_index][0] >> 4; actual_expected_comparison = (calculated_checksum == actual_checksum); - if(debug_output & !actual_expected_comparison) { + if(decoder->verbose & !actual_expected_comparison) { fprintf(stderr, "Checksum error in Oregon Scientific SL109H message. Expected: %01x Calculated: %01x\n", actual_checksum, calculated_checksum); fprintf(stderr, "Message: "); bitbuffer_print(bitbuffer); @@ -107,7 +107,7 @@ static int oregon_scientific_sl109h_callback(r_device *decoder, bitbuffer_t *bit channel_bits = get_channel_bits(msg[0]); if( !((bitbuffer->bits_per_row[row_index] == SL109H_MESSAGE_LENGTH) - && calculate_checksum(bitbuffer, row_index, channel_bits)) ) continue; + && calculate_checksum(decoder, bitbuffer, row_index, channel_bits)) ) continue; local_time_str(0, time_str); diff --git a/src/devices/philips.c b/src/devices/philips.c index f9882468..3e352ea8 100644 --- a/src/devices/philips.c +++ b/src/devices/philips.c @@ -67,7 +67,7 @@ static int philips_callback(r_device *decoder, bitbuffer_t *bitbuffer) /* Correct number of rows? */ if (bitbuffer->num_rows != 1) { - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr, "%s %s: wrong number of rows (%d)\n", time_str, __func__, bitbuffer->num_rows); } @@ -76,7 +76,7 @@ static int philips_callback(r_device *decoder, bitbuffer_t *bitbuffer) /* Correct bit length? */ if (bitbuffer->bits_per_row[0] != PHILIPS_BITLEN) { - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr, "%s %s: wrong number of bits (%d)\n", time_str, __func__, bitbuffer->bits_per_row[0]); } @@ -87,7 +87,7 @@ static int philips_callback(r_device *decoder, bitbuffer_t *bitbuffer) /* Correct start sequence? */ if ((bb[0] >> 4) != PHILIPS_STARTNIBBLE) { - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr, "%s %s: wrong start nibble\n", time_str, __func__); } return 0; @@ -103,7 +103,7 @@ static int philips_callback(r_device *decoder, bitbuffer_t *bitbuffer) } /* If debug enabled, print the combined majority-wins packet */ - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr, "%s %s: combined packet = ", time_str, __func__); bitrow_print(packet, PHILIPS_PACKETLEN * 8); } @@ -111,7 +111,7 @@ static int philips_callback(r_device *decoder, bitbuffer_t *bitbuffer) /* Correct CRC? */ c_crc = crc4(packet, PHILIPS_PACKETLEN, 0x9, 1); /* Including the CRC nibble */ if (0 != c_crc) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "%s %s: CRC failed, calculated %x\n", time_str, __func__, c_crc); } diff --git a/src/devices/radiohead_ask.c b/src/devices/radiohead_ask.c index d25645ea..8fd10288 100644 --- a/src/devices/radiohead_ask.c +++ b/src/devices/radiohead_ask.c @@ -45,7 +45,7 @@ static uint8_t symbol_6to4(uint8_t symbol) return 0xFF; // Not found } -static int radiohead_ask_extract(bitbuffer_t *bitbuffer, uint8_t row, /*OUT*/ uint8_t *payload) +static int radiohead_ask_extract(r_device *decoder, bitbuffer_t *bitbuffer, uint8_t row, /*OUT*/ uint8_t *payload) { int len = bitbuffer->bits_per_row[row]; int msg_len = RH_ASK_MAX_MESSAGE_LEN; @@ -68,7 +68,7 @@ static int radiohead_ask_extract(bitbuffer_t *bitbuffer, uint8_t row, /*OUT*/ ui pos = bitbuffer_search(bitbuffer, row, 0, init_pattern, init_pattern_len); if (pos == len) { - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr, "RH ASK preamble not found\n"); } return 0; @@ -86,14 +86,14 @@ static int radiohead_ask_extract(bitbuffer_t *bitbuffer, uint8_t row, /*OUT*/ ui rxBits[0] &= 0x3F; uint8_t hi_nibble = symbol_6to4(rxBits[0]); if (hi_nibble > 0xF) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "Error on 6to4 decoding high nibble: %X\n", rxBits[0]); } return 0; } uint8_t lo_nibble = symbol_6to4(rxBits[1]); if (lo_nibble > 0xF) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "Error on 6to4 decoding low nibble: %X\n", rxBits[1]); } return 0; @@ -110,7 +110,7 @@ static int radiohead_ask_extract(bitbuffer_t *bitbuffer, uint8_t row, /*OUT*/ ui crc = (payload[msg_len - 1] << 8) | payload[msg_len - 2]; crc_recompute = ~crc16(payload, msg_len - 2, 0x8408, 0xFFFF); if (crc_recompute != crc) { - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "CRC error: %04X != %04X\n", crc_recompute, crc); } return 0; @@ -126,7 +126,7 @@ static int radiohead_ask_callback(r_device *decoder, bitbuffer_t *bitbuffer) uint8_t row = 0; // we are considering only first row int msg_len, data_len, header_to, header_from, header_id, header_flags; - msg_len = radiohead_ask_extract(bitbuffer, row, rh_payload); + msg_len = radiohead_ask_extract(decoder, bitbuffer, row, rh_payload); if (msg_len <= 0) { return msg_len; // pass error code on } @@ -166,7 +166,7 @@ static int sensible_living_callback(r_device *decoder, bitbuffer_t *bitbuffer) int msg_len, house_id, sensor_type, sensor_count, alarms; int module_id, sensor_value, battery_voltage; - msg_len = radiohead_ask_extract(bitbuffer, row, rh_payload); + msg_len = radiohead_ask_extract(decoder, bitbuffer, row, rh_payload); if (msg_len <= 0) { return msg_len; // pass error code on } diff --git a/src/devices/s3318p.c b/src/devices/s3318p.c index b9d916b9..7389bbda 100644 --- a/src/devices/s3318p.c +++ b/src/devices/s3318p.c @@ -93,7 +93,7 @@ static int s3318p_callback(r_device *decoder, bitbuffer_t *bitbuffer) { temperature_with_offset = ((b[2] & 0x0F) << 8) | (b[2] & 0xF0) | (b[1] & 0x0F); temperature_f = (temperature_with_offset - 900) / 10.0; - if (debug_output) { + if (decoder->verbose) { bitbuffer_print(bitbuffer); fprintf(stderr, "Sensor ID = %2x\n", sensor_id); fprintf(stdout, "Bitstream HEX = "); diff --git a/src/devices/schraeder.c b/src/devices/schraeder.c index 3f6512ce..d6019315 100644 --- a/src/devices/schraeder.c +++ b/src/devices/schraeder.c @@ -61,7 +61,7 @@ static int schraeder_callback(r_device *decoder, bitbuffer_t *bitbuffer) { pressure = b[5] * 25; temperature = b[6] - 50; - if (debug_output >= 1) { + if (decoder->verbose) { fprintf(stderr, "Schrader TPMS decoder\n"); bitbuffer_print(bitbuffer); fprintf(stderr, "id = 0x%X\n", serial_id); @@ -138,7 +138,7 @@ static int schrader_EG53MA4_callback(r_device *decoder, bitbuffer_t *bitbuffer) /* Get temperature value */ temperature = b[8]; - if (debug_output >= 1) { + if (decoder->verbose) { fprintf(stderr, "Schrader EG53MA4 TPMS decoder\n"); bitbuffer_print(bitbuffer); fprintf(stderr, "id = 0x%X\n", serial_id); diff --git a/src/devices/simplisafe.c b/src/devices/simplisafe.c index 4340938b..21fb2236 100644 --- a/src/devices/simplisafe.c +++ b/src/devices/simplisafe.c @@ -165,7 +165,7 @@ ss_sensor_callback(r_device *decoder, bitbuffer_t *bitbuffer) } else if (b[2] == 0x44) { return ss_keypad_commands(decoder, bitbuffer, row); } else { - if (debug_output) + if (decoder->verbose) fprintf(stderr, "Unknown Message Type: %02x\n", b[2]); return 0; } diff --git a/src/devices/steelmate.c b/src/devices/steelmate.c index 5647dfd9..873ba9dd 100644 --- a/src/devices/steelmate.c +++ b/src/devices/steelmate.c @@ -28,7 +28,7 @@ #include "decoder.h" static int steelmate_callback(r_device *decoder, bitbuffer_t *bitbuffer) { - //if (debug_output >= 1) { + //if (decoder->verbose) { // fprintf(stdout, "Steelmate TPMS decoder\n"); // bitbuffer_print(bitbuffer); // fprintf(stdout, "\n"); diff --git a/src/devices/thermopro_tp12.c b/src/devices/thermopro_tp12.c index 7a07b9d5..8baf5029 100644 --- a/src/devices/thermopro_tp12.c +++ b/src/devices/thermopro_tp12.c @@ -72,7 +72,7 @@ static int thermopro_tp12_sensor_callback(r_device *decoder, bitbuffer_t *bitbuf // or long-press its power button, it pairs with the first device ID it hears. device = bytes[0]; - if(debug_output) { + if(decoder->verbose) { // There is a mysterious checksum in bytes[4]. It may be the same as the checksum used by the TP-11, // which consisted of a lookup table containing, for each bit in the message, a byte to be xor-ed into // the checksum if the message bit was 1. It should be possible to solve for that table using Gaussian diff --git a/src/devices/tpms_pmv107j.c b/src/devices/tpms_pmv107j.c index 7c9ff79e..968bdfc6 100644 --- a/src/devices/tpms_pmv107j.c +++ b/src/devices/tpms_pmv107j.c @@ -41,13 +41,13 @@ static int tpms_pmv107j_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsign if (start_pos - bitpos < 67*2) { return 0; } - if (debug_output > 1) + if (decoder->verbose > 1) bitbuffer_print(&packet_bits); // realign the buffer, prepending 6 bits of 0. b[0] = packet_bits.bb[0][0] >> 6; bitbuffer_extract_bytes(&packet_bits, 0, 2, b + 1, 64); - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr, "Realigned: "); bitrow_print(b, 72); } @@ -69,7 +69,7 @@ static int tpms_pmv107j_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsign temperature_c = temp - 40.0; if (pressure1 != pressure2) { - if (debug_output) + if (decoder->verbose) fprintf(stderr, "Toyota TPMS pressure check error: %02x vs %02x\n", pressure1, pressure2); return 0; } diff --git a/src/devices/tpms_toyota.c b/src/devices/tpms_toyota.c index e71408fb..8cc34be9 100644 --- a/src/devices/tpms_toyota.c +++ b/src/devices/tpms_toyota.c @@ -58,7 +58,7 @@ static int tpms_toyota_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsigne pressure2 = b[7] ^ 0xff; if (pressure1 != pressure2) { - if (debug_output) + if (decoder->verbose) fprintf(stderr, "Toyota TPMS pressure check error: %02x vs %02x\n", pressure1, pressure2); return 0; } diff --git a/src/devices/ttx201.c b/src/devices/ttx201.c index 49b44d8d..f7ee5be5 100644 --- a/src/devices/ttx201.c +++ b/src/devices/ttx201.c @@ -103,7 +103,7 @@ ttx201_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsigned row, unsigned data_t *data; if (bits != MSG_PACKET_MIN_BITS && bits != MSG_PACKET_BITS) { - if (debug_output > 1) { + if (decoder->verbose > 1) { if (row == 0) { if (bits < MSG_PREAMBLE_BITS) { fprintf(stderr, "Short preamble: %d bits (expected %d)\n", @@ -124,7 +124,7 @@ ttx201_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsigned row, unsigned checksum_calculated = checksum_calculate(b); postmark = b[5]; - if (debug_output > 1) { + if (decoder->verbose > 1) { fprintf(stderr, "TTX201 received raw data: "); bitbuffer_print(bitbuffer); fprintf(stderr, "Data decoded:\n" \ @@ -147,14 +147,14 @@ ttx201_decode(r_device *decoder, bitbuffer_t *bitbuffer, unsigned row, unsigned } if (postmark != MSG_PACKET_POSTMARK) { - if (debug_output > 1) + if (decoder->verbose > 1) fprintf(stderr, "Packet #%d wrong postmark 0x%02x (expected 0x%02x).\n", row, postmark, MSG_PACKET_POSTMARK); return 0; } if (checksum != checksum_calculated) { - if (debug_output > 1) + if (decoder->verbose > 1) fprintf(stderr, "Packet #%d checksum error.\n", row); return 0; } @@ -189,7 +189,7 @@ ttx201_callback(r_device *decoder, bitbuffer_t *bitbuffer) if (MSG_MIN_ROWS <= bitbuffer->num_rows && bitbuffer->num_rows <= MSG_MAX_ROWS) { for (row = 0; row < bitbuffer->num_rows; ++row) { events += ttx201_decode(decoder, bitbuffer, row, 0); - if (events && !debug_output) return events; // for now, break after first successful message + if (events && !decoder->verbose) return events; // for now, break after first successful message } } diff --git a/src/devices/vaillant_vrt340f.c b/src/devices/vaillant_vrt340f.c index 96c964a9..d8285546 100644 --- a/src/devices/vaillant_vrt340f.c +++ b/src/devices/vaillant_vrt340f.c @@ -31,14 +31,14 @@ calculate_checksum(uint8_t *buff, int from, int to) { } static int -validate_checksum(uint8_t * msg, int from, int to, int cs_from, int cs_to) +validate_checksum(r_device *decoder, uint8_t * msg, int from, int to, int cs_from, int cs_to) { // Fields cs_from and cs_to hold the 2-byte checksum as signed int int16_t expected = msg[cs_from]*0x100+ msg[cs_to]; int16_t calculated = calculate_checksum(msg, from, to); if (expected != calculated) { - if (debug_output >= 1) { + if (decoder->verbose) { fprintf(stderr, "Checksum error in Vaillant VRT340f. Expected: %04x Calculated: %04x\n", expected, calculated); fprintf(stderr, "Message (data content of bytes %d-%d): ", from, to); bitrow_print(&msg[from], (to - from + 1) * 8); @@ -142,7 +142,7 @@ vaillant_vrt340_callback(r_device *decoder, bitbuffer_t *bitbuffer) // "Normal package": if ((bb[0][0] == 0x00) && (bb[0][1] == 0x00) && (bb[0][2] == 0x7e) && (128 <= bitcount && bitcount <= 131)) { - if (!validate_checksum (bb[0], /* Data from-to: */3,11, /*Checksum from-to:*/12,13)) { + if (!validate_checksum(decoder, bb[0], /* Data from-to: */3,11, /*Checksum from-to:*/12,13)) { return 0; } @@ -169,7 +169,7 @@ vaillant_vrt340_callback(r_device *decoder, bitbuffer_t *bitbuffer) // "RF detection package": if ((bb[0][0] == 0x00) && (bb[0][1] == 0x00) && (bb[0][2] == 0x7E) && (168 <= bitcount && bitcount <= 171)) { - if (!validate_checksum(bb[0], /* Data from-to: */3,16, /*Checksum from-to:*/17,18)) { + if (!validate_checksum(decoder, bb[0], /* Data from-to: */3,16, /*Checksum from-to:*/17,18)) { return 0; } diff --git a/src/devices/wssensor.c b/src/devices/wssensor.c index 09b4809e..7f7be6dc 100644 --- a/src/devices/wssensor.c +++ b/src/devices/wssensor.c @@ -56,7 +56,7 @@ static int wssensor_callback(r_device *decoder, bitbuffer_t *bitbuffer) { temperature_c = temperature / 10.0f; - if (debug_output) { + if (decoder->verbose) { fprintf(stdout, "Hyundai WS SENZOR received raw data:\n"); bitbuffer_print(bitbuffer); fprintf(stdout, "Sensor ID = %01d = 0x%02x\n", sensor_id, sensor_id); diff --git a/src/devices/wt0124.c b/src/devices/wt0124.c index 7c023f5f..c551c2c2 100644 --- a/src/devices/wt0124.c +++ b/src/devices/wt0124.c @@ -69,7 +69,7 @@ static int wt1024_callback(r_device *decoder, bitbuffer_t *bitbuffer) /* unk */ value = b[5]; - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "wt1024_callback:"); bitbuffer_print(bitbuffer); } diff --git a/src/devices/wt450.c b/src/devices/wt450.c index d3df808c..76b1c385 100644 --- a/src/devices/wt450.c +++ b/src/devices/wt450.c @@ -77,7 +77,7 @@ static int wt450_callback(r_device *decoder, bitbuffer_t *bitbuffer) { if ( bitbuffer->bits_per_row[0] != 36 ) { - if (debug_output) + if (decoder->verbose) fprintf(stderr, "%s wt450_callback: wrong size of bit per row %d\n", time_str, bitbuffer->bits_per_row[0]); @@ -86,7 +86,7 @@ static int wt450_callback(r_device *decoder, bitbuffer_t *bitbuffer) { if ( b[0]>>4 != 0xC ) { - if (debug_output) + if (decoder->verbose) { fprintf(stderr, "%s wt450_callback: wrong preamble\n", time_str); bitbuffer_print(bitbuffer); @@ -101,7 +101,7 @@ static int wt450_callback(r_device *decoder, bitbuffer_t *bitbuffer) { if ( parity ) { - if (debug_output) + if (decoder->verbose) { fprintf(stderr, "%s wt450_callback: wrong parity\n", time_str); bitbuffer_print(bitbuffer); diff --git a/src/devices/x10_sec.c b/src/devices/x10_sec.c index b4415290..170749f6 100644 --- a/src/devices/x10_sec.c +++ b/src/devices/x10_sec.c @@ -88,7 +88,7 @@ static int x10_sec_callback(r_device *decoder, bitbuffer_t *bitbuffer) { local_time_str(0, time_str); /* debug output */ - if (debug_output) { + if (decoder->verbose) { fprintf(stderr, "%20s X10SEC: id=%02x%02x code=%02x event_str=%s\n", time_str, b[0], b[4], b[2], event_str); bitbuffer_print(bitbuffer); } diff --git a/src/pulse_demod.c b/src/pulse_demod.c index 6bfcf4b9..1a9030ab 100644 --- a/src/pulse_demod.c +++ b/src/pulse_demod.c @@ -18,6 +18,7 @@ #include #include +extern int debug_output; int pulse_demod_pcm(const pulse_data_t *pulses, r_device *device) {