From ef2a60fdd2f025031e0b01c8a8d125bc97fc95d7 Mon Sep 17 00:00:00 2001 From: Zhai Can Date: Mon, 22 Jan 2024 19:49:24 +0800 Subject: [PATCH 1/5] migrate to CMake project --- .gitignore | 2 ++ CMakeLists.txt | 16 ++++++++++++++++ Makefile | 15 --------------- crc.c | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 .gitignore create mode 100644 CMakeLists.txt delete mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e0d0ffa --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +cmake-build-debug/ +/.idea/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1794532 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +project(adsbdec) + +cmake_minimum_required(VERSION 3.5) + +add_library( + adsbdec-lib + demod.c + crc.c + output.c + air.c + valid.c +) + +add_executable(adsbdec main.c) +target_link_libraries(adsbdec-lib airspy usb-1.0 m) +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/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, From 5343993e45357b98f448d2b822190fa8e6dd3093 Mon Sep 17 00:00:00 2001 From: Zhai Can Date: Mon, 22 Jan 2024 19:54:51 +0800 Subject: [PATCH 2/5] add airspy submodule, and link against it Because `airspy_open_fd` doesn't exist in the latest release `1.0.10`. --- .gitmodules | 3 +++ CMakeLists.txt | 4 +++- airspy | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 airspy 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 index 1794532..0cb8565 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,8 @@ add_library( valid.c ) +add_subdirectory(airspy) + add_executable(adsbdec main.c) -target_link_libraries(adsbdec-lib airspy usb-1.0 m) +target_link_libraries(adsbdec-lib usb-1.0 m airspy-static) target_link_libraries(adsbdec adsbdec-lib) \ No newline at end of file diff --git a/airspy b/airspy new file mode 160000 index 0000000..0bccf3b --- /dev/null +++ b/airspy @@ -0,0 +1 @@ +Subproject commit 0bccf3b88830d3e5ec029cfb42b9d4c2f2ec8554 From 0831179359f5b125d3d1970357866f1b6feb6656 Mon Sep 17 00:00:00 2001 From: Zhai Can Date: Mon, 22 Jan 2024 20:08:48 +0800 Subject: [PATCH 3/5] find libusb using `find_package` --- .gitignore | 1 + CMakeLists.txt | 10 ++++++++-- cmake/FindLIBUSB.cmake | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 cmake/FindLIBUSB.cmake diff --git a/.gitignore b/.gitignore index e0d0ffa..14a9247 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ cmake-build-debug/ /.idea/ +/build/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 0cb8565..224594e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ project(adsbdec) -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) +set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +include(FindPackageHandleStandardArgs) add_library( adsbdec-lib @@ -13,6 +15,10 @@ add_library( add_subdirectory(airspy) +find_package(LIBUSB REQUIRED) + +include_directories(${LIBUSB_INCLUDE_DIR}) + add_executable(adsbdec main.c) -target_link_libraries(adsbdec-lib usb-1.0 m airspy-static) +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/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) From 0b0f4deca67ff38cddf36377b560607a88053d4a Mon Sep 17 00:00:00 2001 From: Zhai Can Date: Mon, 22 Jan 2024 20:09:18 +0800 Subject: [PATCH 4/5] use include dir from the airspy submodule --- CMakeLists.txt | 1 + air.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 224594e..d505144 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ 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}) diff --git a/air.c b/air.c index 30e9bd6..f200291 100644 --- a/air.c +++ b/air.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include "adsbdec.h" #define AIR_SAMPLE_RATE 20000000 From 8dde22d2188e3a9a0e709f551ffd058623079bc6 Mon Sep 17 00:00:00 2001 From: Zhai Can Date: Sat, 24 Feb 2024 17:16:30 +0800 Subject: [PATCH 5/5] update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d5fc6e2..30e3f8b 100644 --- a/README.md +++ b/README.md @@ -31,4 +31,9 @@ If you need that adsbdec act as server (like dump1090) : Need libusb and libairspy Just do -> make +```shell +mkdir build +cd build +cmake .. +make +```