From 4232eefc9e2ad48428fcffeaed8e97612fe87a39 Mon Sep 17 00:00:00 2001 From: "Christian W. Zuckschwerdt" Date: Sun, 8 Nov 2020 20:52:09 +0100 Subject: [PATCH] Fix Analyzer FSK/OOK hint (closes #1557) --- include/r_device.h | 2 +- src/pulse_analyzer.c | 12 ++++++------ src/sdr.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/r_device.h b/include/r_device.h index 4f793782..5613d2e1 100644 --- a/include/r_device.h +++ b/include/r_device.h @@ -15,7 +15,7 @@ enum modulation_types { OOK_PULSE_PIWM_DC = 11, ///< Level shift for each bit. Short interval = 1, Long = 0. OOK_PULSE_DMC = 9, ///< Level shift within the clock cycle. OOK_PULSE_PWM_OSV1 = 10, ///< Pulse Width Modulation. Oregon Scientific v1. - OOK_PULSE_NRZS = 19, ///< NRZS modulation + OOK_PULSE_NRZS = 12, ///< NRZS modulation FSK_DEMOD_MIN_VAL = 16, ///< Dummy. FSK demodulation must start at this value. FSK_PULSE_PCM = 16, ///< FSK, Pulse Code Modulation. FSK_PULSE_PWM = 17, ///< FSK, Pulse Width Modulation. Short pulses = 1, Long = 0. diff --git a/src/pulse_analyzer.c b/src/pulse_analyzer.c index 657f1b1a..697b7e18 100644 --- a/src/pulse_analyzer.c +++ b/src/pulse_analyzer.c @@ -270,7 +270,7 @@ void pulse_analyzer(pulse_data_t *data, int package_type) } else if (hist_pulses.bins_count == 1 && hist_gaps.bins_count > 1) { fprintf(stderr, "Pulse Position Modulation with fixed pulse width\n"); - device.modulation = OOK_PULSE_PPM; + device.modulation = OOK_PULSE_PPM; // TODO: there is not FSK_PULSE_PPM device.short_width = to_us * hist_gaps.bins[0].mean; device.long_width = to_us * hist_gaps.bins[1].mean; device.gap_limit = to_us * (hist_gaps.bins[1].max + 1); // Set limit above next lower gap @@ -278,7 +278,7 @@ void pulse_analyzer(pulse_data_t *data, int package_type) } else if (hist_pulses.bins_count == 2 && hist_gaps.bins_count == 1) { fprintf(stderr, "Pulse Width Modulation with fixed gap\n"); - device.modulation = OOK_PULSE_PWM; + device.modulation = (package_type == PULSE_DATA_FSK) ? FSK_PULSE_PWM : OOK_PULSE_PWM; device.short_width = to_us * hist_pulses.bins[0].mean; device.long_width = to_us * hist_pulses.bins[1].mean; device.tolerance = (device.long_width - device.short_width) * 0.4; @@ -286,7 +286,7 @@ void pulse_analyzer(pulse_data_t *data, int package_type) } else if (hist_pulses.bins_count == 2 && hist_gaps.bins_count == 2 && hist_periods.bins_count == 1) { fprintf(stderr, "Pulse Width Modulation with fixed period\n"); - device.modulation = OOK_PULSE_PWM; + device.modulation = (package_type == PULSE_DATA_FSK) ? FSK_PULSE_PWM : OOK_PULSE_PWM; device.short_width = to_us * hist_pulses.bins[0].mean; device.long_width = to_us * hist_pulses.bins[1].mean; device.tolerance = (device.long_width - device.short_width) * 0.4; @@ -294,7 +294,7 @@ void pulse_analyzer(pulse_data_t *data, int package_type) } else if (hist_pulses.bins_count == 2 && hist_gaps.bins_count == 2 && hist_periods.bins_count == 3) { fprintf(stderr, "Manchester coding\n"); - device.modulation = OOK_PULSE_MANCHESTER_ZEROBIT; + device.modulation = (package_type == PULSE_DATA_FSK) ? FSK_PULSE_MANCHESTER_ZEROBIT : OOK_PULSE_MANCHESTER_ZEROBIT; device.short_width = to_us * MIN(hist_pulses.bins[0].mean, hist_pulses.bins[1].mean); // Assume shortest pulse is half period device.long_width = 0; // Not used device.reset_limit = to_us * (hist_gaps.bins[hist_gaps.bins_count - 1].max + 1); // Set limit above biggest gap @@ -315,7 +315,7 @@ void pulse_analyzer(pulse_data_t *data, int package_type) && (abs(hist_gaps.bins[1].mean - 2*hist_pulses.bins[0].mean) <= hist_pulses.bins[0].mean/8) && (abs(hist_gaps.bins[2].mean - 3*hist_pulses.bins[0].mean) <= hist_pulses.bins[0].mean/8)) { fprintf(stderr, "Pulse Code Modulation (Not Return to Zero)\n"); - device.modulation = FSK_PULSE_PCM; + device.modulation = (package_type == PULSE_DATA_FSK) ? FSK_PULSE_PCM : OOK_PULSE_PCM_RZ; device.short_width = to_us * hist_pulses.bins[0].mean; // Shortest pulse is bit width device.long_width = to_us * hist_pulses.bins[0].mean; // Bit period equal to pulse length (NRZ) device.reset_limit = to_us * hist_pulses.bins[0].mean * 1024; // No limit to run of zeros... @@ -326,7 +326,7 @@ void pulse_analyzer(pulse_data_t *data, int package_type) histogram_sort_count(&hist_pulses); int p1 = hist_pulses.bins[1].mean; int p2 = hist_pulses.bins[2].mean; - device.modulation = OOK_PULSE_PWM; + device.modulation = (package_type == PULSE_DATA_FSK) ? FSK_PULSE_PWM : OOK_PULSE_PWM; device.short_width = to_us * (p1 < p2 ? p1 : p2); // Set to shorter pulse width device.long_width = to_us * (p1 < p2 ? p2 : p1); // Set to longer pulse width device.sync_width = to_us * hist_pulses.bins[0].mean; // Set to lowest count pulse width diff --git a/src/sdr.c b/src/sdr.c index fd7b371f..b11130d9 100644 --- a/src/sdr.c +++ b/src/sdr.c @@ -488,7 +488,7 @@ static void rtlsdr_read_cb(unsigned char *iq_buf, uint32_t len, void *ctx) }; if (len > 0) // prevent a crash in callback dev->rtlsdr_cb(&ev, dev->rtlsdr_cb_ctx); - // FIXME: we actually need to copy the buffer to prevent it going away on cancel_async + // NOTE: we actually need to copy the buffer to prevent it going away on cancel_async } static int rtlsdr_read_loop(sdr_dev_t *dev, sdr_event_cb_t cb, void *ctx, uint32_t buf_num, uint32_t buf_len)