diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..14a9247 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +cmake-build-debug/ +/.idea/ +/build/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7e0af24 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "airspy"] + path = airspy + url = https://github.com/airspy/airspyone_host diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d505144 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,25 @@ +project(adsbdec) + +cmake_minimum_required(VERSION 3.10) +set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +include(FindPackageHandleStandardArgs) + +add_library( + adsbdec-lib + demod.c + crc.c + output.c + air.c + valid.c +) + +add_subdirectory(airspy) + +find_package(LIBUSB REQUIRED) + +include_directories(${LIBUSB_INCLUDE_DIR}) +include_directories(airspy/libairspy/src) + +add_executable(adsbdec main.c) +target_link_libraries(adsbdec-lib m airspy-static ${LIBUSB_LIBRARIES}) +target_link_libraries(adsbdec adsbdec-lib) \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 6ee2386..0000000 --- a/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -CFLAGS= -Wall -Ofast -march=native -pthread -I. `pkg-config --cflags libairspy` - -LIBS= -lm -pthread `pkg-config --libs libairspy libusb` - -adsbdec: demod.o main.o crc.o output.o air.o valid.o - $(CC) $(LDFLAGS) demod.o main.o crc.o output.o air.o valid.o $(LIBS) -o adsbdec - -install: adsbdec - sudo cp adsbdec /usr/local/bin - -uninstall: - sudo rm /usr/local/bin - -clean: - rm *.o adsbdec diff --git a/air.c b/air.c index 30e9bd6..d674f82 100644 --- a/air.c +++ b/air.c @@ -23,12 +23,13 @@ #include #include #include -#include +#include #include "adsbdec.h" #define AIR_SAMPLE_RATE 20000000 int gain = 18; +int device_fd = -1; uint32_t ampbuff[APBUFFSZ]; #define DECOFFSET (240*PULSEW) @@ -94,7 +95,12 @@ int initAirspy(void) struct timespec tp; /* init airspy */ - result = airspy_open(&device); + if (device_fd == -1) { + result = airspy_open(&device); + } else { + result = airspy_open_fd(&device, device_fd); + } + if (result != AIRSPY_SUCCESS) { fprintf(stderr, "airspy_open() failed: %s (%d)\n", airspy_error_name(result), result); diff --git a/airspy b/airspy new file mode 160000 index 0000000..0bccf3b --- /dev/null +++ b/airspy @@ -0,0 +1 @@ +Subproject commit 0bccf3b88830d3e5ec029cfb42b9d4c2f2ec8554 diff --git a/cmake/FindLIBUSB.cmake b/cmake/FindLIBUSB.cmake new file mode 100644 index 0000000..cc3fb92 --- /dev/null +++ b/cmake/FindLIBUSB.cmake @@ -0,0 +1,37 @@ +# - Try to find the freetype library +# Once done this defines +# +# LIBUSB_FOUND - system has libusb +# LIBUSB_INCLUDE_DIR - the libusb include directory +# LIBUSB_LIBRARIES - Link these to use libusb + +# Copyright (c) 2006, 2008 Laurent Montel, +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +if (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) + + # in cache already + set(LIBUSB_FOUND TRUE) + +else (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) + + find_package(PkgConfig) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_LIBUSB libusb-1.0) + endif(PKG_CONFIG_FOUND) + + FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h + PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS}) + + FIND_LIBRARY(LIBUSB_LIBRARIES NAMES usb-1.0 + PATHS ${PC_LIBUSB_LIBDIR} ${PC_LIBUSB_LIBRARY_DIRS}) + + include(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBUSB DEFAULT_MSG LIBUSB_LIBRARIES LIBUSB_INCLUDE_DIR) + + MARK_AS_ADVANCED(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES) + +endif (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) diff --git a/crc.c b/crc.c index 2978fe3..b42fc48 100644 --- a/crc.c +++ b/crc.c @@ -18,7 +18,7 @@ */ #include #include -#include +#include "crc.h" static const uint32_t error_table[112] = { 0x3935ea, 0x1c9af5, 0xf1b77e, 0x78dbbf, 0xc397db, 0x9e31e9, 0xb0e2f0, 0x587178, diff --git a/main.c b/main.c index 80b7299..348dae8 100644 --- a/main.c +++ b/main.c @@ -27,6 +27,7 @@ extern int outmode; extern int outformat; extern char *filename; extern int gain; +extern int device_fd; extern int df, errcorr; @@ -37,7 +38,7 @@ extern void print_stats(void); static void usage(void) { printf("adsbdec airspy ADSB decoder 1.0 Copyright (c) 2018 Thierry Leconte \n\n"); - printf("usage : adsbdec [-d] [-c] [-e] [-m] [-b] [-g 0-21 ] [-f filename] [-s addr[:port]] [-l addr[:port]]\n\n"); + printf("usage : adsbdec [-d] [-c] [-e] [-m] [-b] [-g 0-21 ] [-f filename] [-s addr[:port]] [-l addr[:port]] [-D device]\n\n"); printf ("By default receive samples from airspy and output long adsb frames in raw avr format on stdout\n"); printf("Options :\n"); @@ -49,7 +50,7 @@ static void usage(void) printf("\t-f : input from filename instead of airspy (raw signed 16 bits real format)\n"); printf ("\t-s addr[:port] : send ouput via TCP to server at address addr:port (default port : 30001)\n"); printf ("\t-l addr[:port] : listen to addr:port (default port : 30002) and accept a TCP connection where to send output \n"); - + printf("\t-D device : specify the device file descriptor to use\n"); } int main(int argc, char **argv) @@ -58,7 +59,7 @@ int main(int argc, char **argv) struct sigaction sigact; - while ((c = getopt(argc, argv, "cf:s:l:g:demb")) != EOF) { + while ((c = getopt(argc, argv, "cf:s:l:g:dembD:")) != EOF) { switch (c) { case 'f': filename = optarg; @@ -86,6 +87,9 @@ int main(int argc, char **argv) case 'b': outformat = 2; break; + case 'D': + device_fd = atoi(optarg); + break; default: usage(); return 1;