mirror of
https://github.com/merbanan/rtl_433.git
synced 2026-05-19 07:15:15 -04:00
Replace debug_output with verbose in decoders
This commit is contained in:
committed by
Christian W. Zuckschwerdt
parent
96a14e6f5f
commit
eedd027299
@@ -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_ */
|
||||
|
||||
@@ -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++)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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; n<NUM_BYTES; ++n) {
|
||||
sprintf(str_raw+n*2, "%02X", bytes[n]);
|
||||
@@ -116,7 +116,7 @@ static int danfoss_cfr_callback(r_device *decoder, bitbuffer_t *bitbuffer)
|
||||
if (bytes[0] != 0x02 // Somewhat redundant to header search, but checks last bits
|
||||
|| crc_calc != (((uint16_t)bytes[8] << 8) | bytes[9])
|
||||
) {
|
||||
if (debug_output) fprintf(stderr, "Danfoss: Prefix or CRC error.\n");
|
||||
if (decoder->verbose) fprintf(stderr, "Danfoss: Prefix or CRC error.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<sizeof(b); n++) { sprintf(raw_str+n*3, "%02x ", b[n]); }
|
||||
fprintf(stderr, "Fineoffset_WH25: Raw: %s @ bit_offset [%u]\n", raw_str, bit_offset);
|
||||
@@ -351,7 +351,7 @@ static int fineoffset_WH25_callback(r_device *decoder, bitbuffer_t *bitbuffer) {
|
||||
}
|
||||
bitsum = (bitsum << 4) | (bitsum >> 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; n<sizeof(buffer); n++) { sprintf(raw_str + n * 3, "%02x ", buffer[n]); }
|
||||
fprintf(stderr, "Fineoffset_WH0530: Raw %s\n", raw_str);
|
||||
@@ -424,7 +424,7 @@ static int fineoffset_WH0530_callback(r_device *decoder, bitbuffer_t *bitbuffer)
|
||||
uint8_t crc = crc8(buffer, 6, 0x31, 0);
|
||||
uint8_t checksum = buffer[0] + buffer[1] + buffer[2] + buffer[3] + buffer[4] + buffer[5] + buffer[6];
|
||||
if (crc != buffer[6] || checksum != buffer[7]) {
|
||||
if (debug_output) {
|
||||
if (decoder->verbose) {
|
||||
fprintf(stderr, "Fineoffset_WH0530: Checksum error: %02x %02x\n", crc, checksum);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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++;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<BITBUF_COLS;k++) { // Reverse nibbles
|
||||
msg[k] = (msg[k] & 0xF0) >> 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]);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 = ");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
|
||||
extern int debug_output;
|
||||
|
||||
int pulse_demod_pcm(const pulse_data_t *pulses, r_device *device)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user