From c6a731a0dcff882edb4777a816865f525966464d Mon Sep 17 00:00:00 2001 From: Kyle Keen Date: Tue, 29 Jan 2013 20:31:49 -0500 Subject: rtl_adsb: 16 bit magnitudes Signed-off-by: Steve Markgraf --- src/rtl_adsb.c | 92 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 43 deletions(-) (limited to 'src/rtl_adsb.c') diff --git a/src/rtl_adsb.c b/src/rtl_adsb.c index 2fb7418..a625d31 100644 --- a/src/rtl_adsb.c +++ b/src/rtl_adsb.c @@ -54,16 +54,19 @@ #define DEFAULT_BUF_LENGTH (16 * 16384) #define AUTO_GAIN -100 +#define MESSAGEGO 253 +#define OVERWRITE 254 +#define BADSAMPLE 255 + static pthread_t demod_thread; static sem_t data_ready; static volatile int do_exit = 0; static rtlsdr_dev_t *dev = NULL; -/* look up table, could be made smaller */ -uint8_t pyth[129][129]; +uint16_t squares[256]; /* todo, bundle these up in a struct */ -uint8_t *buffer; +uint8_t *buffer; /* also abused for uint16_t */ int verbose_output = 0; int short_output = 0; double quality = 1.0; @@ -141,17 +144,7 @@ void display(int *frame, int len) fprintf(file, "--------------\n"); } -void pyth_precompute(void) -{ - int x, y; - double scale = 1.408 ; /* use the full 8 bits */ - for (x=0; x<129; x++) { - for (y=0; y<129; y++) { - pyth[x][y] = (uint8_t)round(scale * sqrt(x*x + y*y)); - }} -} - -inline uint8_t abs8(uint8_t x) +int abs8(int x) /* do not subtract 128 from the raw iq, this handles it */ { if (x >= 128) { @@ -159,18 +152,31 @@ inline uint8_t abs8(uint8_t x) return 128 - x; } +void squares_precompute(void) +/* equiv to abs(x-128) ^ 2 */ +{ + int i, j; + // todo, check if this LUT is actually any faster + for (i=0; i<256; i++) { + j = abs8(i); + squares[i] = (uint16_t)(j*j); + } +} + int magnitute(uint8_t *buf, int len) -/* takes i/q, changes buf in place, returns new len */ +/* takes i/q, changes buf in place (16 bit), returns new len (16 bit) */ { int i; + uint16_t *m; for (i=0; i b; @@ -181,9 +187,9 @@ inline uint8_t single_manchester(uint8_t a, uint8_t b, uint8_t c, uint8_t d) if (quality == 0.5) { if ( bit && bit_p && b > c) { - return 255;} + return BADSAMPLE;} if (!bit && !bit_p && b < c) { - return 255;} + return BADSAMPLE;} return bit; } @@ -196,7 +202,7 @@ inline uint8_t single_manchester(uint8_t a, uint8_t b, uint8_t c, uint8_t d) return 0;} if (!bit && !bit_p && c < b) { return 0;} - return 255; + return BADSAMPLE; } if ( bit && bit_p && c > b && d < a) { @@ -207,36 +213,36 @@ inline uint8_t single_manchester(uint8_t a, uint8_t b, uint8_t c, uint8_t d) return 0;} if (!bit && !bit_p && c < b && d > a) { return 0;} - return 255; + return BADSAMPLE; } -inline uint8_t min8(uint8_t a, uint8_t b) +inline uint16_t min16(uint16_t a, uint16_t b) { return ab ? a : b; } -inline int preamble(uint8_t *buf, int len, int i) +inline int preamble(uint16_t *buf, int i) /* returns 0/1 for preamble at index i */ { int i2; - uint8_t low = 0; - uint8_t high = 255; + uint16_t low = 0; + uint16_t high = 65535; for (i2=0; i2 allowed_errors) { - buf[i2] = 255; + buf[i2] = BADSAMPLE; break; } else { bit = a > b; /* these don't have to match the bit */ a = 0; - b = 255; + b = 65535; } } - buf[i] = buf[i+1] = 254; /* to be overwritten */ + buf[i] = buf[i+1] = OVERWRITE; buf[i2] = bit; } } } -void messages(uint8_t *buf, int len) +void messages(uint16_t *buf, int len) { int i, i2, start, preamble_found; int data_i, index, shift, frame_len; @@ -343,8 +349,8 @@ static void *demod_thread_fn(void *arg) while (!do_exit) { sem_wait(&data_ready); len = magnitute(buffer, DEFAULT_BUF_LENGTH); - manchester(buffer, len); - messages(buffer, len); + manchester((uint16_t*)buffer, len); + messages((uint16_t*)buffer, len); } rtlsdr_cancel_async(dev); return 0; @@ -363,7 +369,7 @@ int main(int argc, char **argv) int ppm_error = 0; char vendor[256], product[256], serial[256]; sem_init(&data_ready, 0, 0); - pyth_precompute(); + squares_precompute(); while ((opt = getopt(argc, argv, "d:g:p:e:Q:VS")) != -1) { -- cgit v1.2.3