From a06fb730f954c153e9ce2ba40f1fbbbd5381ae68 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Fri, 22 Jan 2016 10:07:35 +0000 Subject: [PATCH] Convert decoder limits to float instead of int, to allow more precision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The (about to be submitted) emonTx decoder really needs to be allowed to specify a limit of 20.3µs, and neither '50 samples' (20µs) nor '51 samples' (24µs) will suffice. --- include/rtl_433.h | 6 +++--- src/pulse_demod.c | 4 ++-- src/pulse_detect.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/rtl_433.h b/include/rtl_433.h index a493fdee..e0f78d96 100755 --- a/include/rtl_433.h +++ b/include/rtl_433.h @@ -63,9 +63,9 @@ struct protocol_state { unsigned int modulation; /* pwm limits */ - int short_limit; - int long_limit; - int reset_limit; + float short_limit; + float long_limit; + float reset_limit; char *name; unsigned long demod_arg; }; diff --git a/src/pulse_demod.c b/src/pulse_demod.c index bf4e926e..8583b494 100644 --- a/src/pulse_demod.c +++ b/src/pulse_demod.c @@ -242,7 +242,7 @@ int pulse_demod_manchester_zerobit(const pulse_data_t *pulses, struct protocol_s for(unsigned n = 0; n < pulses->num_pulses; ++n) { // Falling edge is on end of pulse - if(pulses->pulse[n] + time_since_last > (device->short_limit + (device->short_limit>>1))) { + if(pulses->pulse[n] + time_since_last > (device->short_limit * 1.5)) { // Last bit was recorded more than short_limit*1.5 samples ago // so this pulse start must be a data edge (falling data edge means bit = 1) bitbuffer_add_bit(&bits, 1); @@ -266,7 +266,7 @@ int pulse_demod_manchester_zerobit(const pulse_data_t *pulses, struct protocol_s bitbuffer_add_bit(&bits, 0); // Prepare for new message with hardcoded 0 time_since_last = 0; // Rising edge is on end of gap - } else if(pulses->gap[n] + time_since_last > (device->short_limit + (device->short_limit>>1))) { + } else if(pulses->gap[n] + time_since_last > (device->short_limit * 1.5)) { // Last bit was recorded more than short_limit*1.5 samples ago // so this pulse end is a data edge (rising data edge means bit = 0) bitbuffer_add_bit(&bits, 0); diff --git a/src/pulse_detect.c b/src/pulse_detect.c index c684d1aa..dbb2a44b 100644 --- a/src/pulse_detect.c +++ b/src/pulse_detect.c @@ -502,7 +502,7 @@ void pulse_analyzer(pulse_data_t *data) } if(device.modulation) { - fprintf(stderr, "Attempting demodulation... short_limit: %u, long_limit: %u, reset_limit: %u, demod_arg: %lu\n", + fprintf(stderr, "Attempting demodulation... short_limit: %f, long_limit: %f, reset_limit: %f, demod_arg: %lu\n", device.short_limit, device.long_limit, device.reset_limit, device.demod_arg); data->gap[data->num_pulses-1] = device.reset_limit + 1; // Be sure to terminate package switch(device.modulation) {