From 29d4a753ad9733168360ed97ea81b4662aea1de5 Mon Sep 17 00:00:00 2001 From: antirez Date: Sun, 1 Jan 2023 21:40:07 +0100 Subject: [PATCH] Initial signal processing code. --- signal.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/signal.c b/signal.c index 80d6cddee99..30465915bed 100644 --- a/signal.c +++ b/signal.c @@ -3,6 +3,10 @@ #include "app.h" +/* ============================================================================= + * Raw signal detection + * ===========================================================================*/ + /* Return the time difference between a and b, always >= 0 since * the absolute value is returned. */ uint32_t duration_delta(uint32_t a, uint32_t b) { @@ -119,4 +123,71 @@ void scan_for_signal(ProtoViewApp *app) { raw_samples_free(copy); } +/* ============================================================================= + * Decoding + * ===========================================================================*/ + +/* Set the 'bitpos' bit to value 'val', in the specified bitmap + * 'b' of len 'blen'. + * Out of range bits will silently be discarded. */ +void set_bit(uint8_t *b, uint32_t blen, uint32_t bitpos, bool val) { + uint32_t byte = bitpos/8; + uint32_t bit = bitpos&7; + if (byte >= blen) return; + if (val) + b[byte] |= 1<= blen) return 0; + return (b[byte] & (1< rate/2) numbits++; /* There is another one. */ + while(numbits--) set_bit(b,blen,bitpos++,s[j].level); + } + return bitpos; +}