From fdd48e174a92cc3f5dcd4f6917c13c87bf85aad1 Mon Sep 17 00:00:00 2001 From: Benjamin Larsson Date: Wed, 5 Dec 2018 16:14:02 +0100 Subject: [PATCH] inFactory: enable it by default with added checks --- src/devices/infactory.c | 43 +++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/devices/infactory.c b/src/devices/infactory.c index 5e0accd1..e438198c 100644 --- a/src/devices/infactory.c +++ b/src/devices/infactory.c @@ -23,24 +23,42 @@ * * # rtl_433 -f 434052000 -R 91 -F json:log.json * + * Payload looks like this: + * + * [00] { 4} 00 : 0000 + * [01] {40} 0f 30 5c e7 61 : 00001111 00110000 01011100 11100111 01100001 + * + * First row is actually the preample part. This is added to make the signal more unique. + * */ #include "decoder.h" static int infactory_callback(r_device *decoder, bitbuffer_t *bitbuffer) { - bitrow_t *bb = bitbuffer->bb; - uint8_t *b = bb[0]; + bitrow_t *bb; data_t *data; - - int id; - int humidity; - int temp; + uint8_t *b; + int id, humidity, temp; float temp_f; - if (bitbuffer->bits_per_row[0] != 40) { + if (bitbuffer->bits_per_row[0] != 4) { return 0; } + if (bitbuffer->bits_per_row[1] != 40) { + return 0; + } + bb = bitbuffer->bb; + + /* Check that 4 bits of preamble is 0 */ + b = bb[0]; + if (b[0]&0x0F) + return 0; + + /* Check that last 4 bits of message is 0x1 */ + b = bb[1]; + if (!(b[4]&0x0F)) + return 0; id = b[0]; humidity = (b[3] & 0x0F) * 10 + (b[4] >> 4); // BCD @@ -69,11 +87,12 @@ static char *output_fields[] = { r_device infactory = { .name = "inFactory", .modulation = OOK_PULSE_PPM, - .short_width = 2000, - .long_width = 4000, - .gap_limit = 5000, // Maximum gap size before new row of bits [us] - .reset_limit = 6000, // Maximum gap size before End Of Message [us]. + .short_width = 1850, + .long_width = 4050, + .gap_limit = 4000, // Maximum gap size before new row of bits [us] + .reset_limit = 8500, // Maximum gap size before End Of Message [us]. + .tolerance = 1000, .decode_fn = &infactory_callback, - .disabled = 1, + .disabled = 0, .fields = output_fields };