diff --git a/configure.ac b/configure.ac index c760787..a947e80 100644 --- a/configure.ac +++ b/configure.ac @@ -39,6 +39,9 @@ AC_CHECK_LIB(pthread, pthread_create, [LIBS="$LIBS -lpthread"]) dnl libmath (for rtl_fm) AC_CHECK_LIB(m, atan2, [LIBS="$LIBS -lm"]) +dnl libmath (for rtl_adsb) +AC_CHECK_LIB(m, sqrt, [LIBS="$LIBS -lm"]) + dnl librealtime (for rtl_test) AC_CHECK_LIB(rt, clock_gettime, [LIBS="$LIBS -lrt"]) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26bb39a..6b23395 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -100,6 +100,7 @@ target_link_libraries(rtl_adsb rtlsdr_shared ) if(UNIX) target_link_libraries(rtl_fm m) +target_link_libraries(rtl_adsb m) if(APPLE) target_link_libraries(rtl_test m) else() diff --git a/src/Makefile.am b/src/Makefile.am index 51e1b9f..5873807 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,4 +28,4 @@ rtl_eeprom_SOURCES = rtl_eeprom.c rtl_eeprom_LDADD = librtlsdr.la $(LIBM) rtl_adsb_SOURCES = rtl_adsb.c -rtl_adsb_LDADD = librtlsdr.la +rtl_adsb_LDADD = librtlsdr.la $(LIBM) diff --git a/src/rtl_adsb.c b/src/rtl_adsb.c index e3b738c..6dbb1bf 100644 --- a/src/rtl_adsb.c +++ b/src/rtl_adsb.c @@ -26,6 +26,7 @@ #include #include #include +#include #ifndef _WIN32 #include @@ -44,8 +45,6 @@ #ifdef _WIN32 #define sleep Sleep -#undef min -#undef max #endif #define ADSB_RATE 2000000 @@ -59,6 +58,9 @@ 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]; + /* todo, bundle these up in a struct */ uint8_t *buffer; int verbose_output = 0; @@ -88,6 +90,8 @@ void usage(void) "Streaming with netcat:\n" "\trtl_adsb | netcat -lp 8080\n" "\twhile true; do rtl_adsb | nc -lp 8080; done\n" + "Streaming with socat:\n" + "\trtl_adsb | socat -u - TCP4:sdrsharp.com:47806\n" "\n"); exit(1); } @@ -136,20 +140,34 @@ void display(int *frame, int len) fprintf(file, "--------------\n"); } -int magnitute(unsigned char *buf, int len) +void pyth_precompute(void) +{ + int x, y; + for (x=0; x<129; x++) { + for (y=0; y<129; y++) { + pyth[x][y] = (uint8_t)round(sqrt(x*x + y*y)); + }} +} + +inline uint8_t abs8(uint8_t x) +/* do not subtract 128 from the raw iq, this handles it */ +{ + if (x >= 128) { + return x - 128;} + return 128 - x; +} + +int magnitute(uint8_t *buf, int len) /* takes i/q, changes buf in place, returns new len */ { - int i, mag; + int i; for (i=0; i 255) { // todo, compression - mag = 255;} - buf[i/2] = (unsigned char)mag; + buf[i/2] = pyth[abs8(buf[i])][abs8(buf[i+1])]; } return len/2; } -inline unsigned char single_manchester(unsigned char a, unsigned char b, unsigned char c, unsigned char d) +inline uint8_t single_manchester(uint8_t a, uint8_t b, uint8_t c, uint8_t d) /* takes 4 consecutive real samples, return 0 or 1, 255 on error */ { int bit, bit_p; @@ -190,33 +208,33 @@ inline unsigned char single_manchester(unsigned char a, unsigned char b, unsigne return 255; } -inline unsigned char min(unsigned char a, unsigned char b) +inline uint8_t min8(uint8_t a, uint8_t b) { return ab ? a : b; } -inline int preamble(unsigned char *buf, int len, int i) +inline int preamble(uint8_t *buf, int len, int i) /* returns 0/1 for preamble at index i */ { int i2; - unsigned char low = 0; - unsigned char high = 255; + uint8_t low = 0; + uint8_t high = 255; for (i2=0; i2