Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add device_fd argument #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cmake-build-debug/
/.idea/
/build/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "airspy"]
path = airspy
url = https://github.com/airspy/airspyone_host
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 0 additions & 15 deletions Makefile

This file was deleted.

10 changes: 8 additions & 2 deletions air.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <libairspy/airspy.h>
#include <airspy.h>
#include "adsbdec.h"

#define AIR_SAMPLE_RATE 20000000

int gain = 18;
int device_fd = -1;
uint32_t ampbuff[APBUFFSZ];

#define DECOFFSET (240*PULSEW)
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions airspy
Submodule airspy added at 0bccf3
37 changes: 37 additions & 0 deletions cmake/FindLIBUSB.cmake
Original file line number Diff line number Diff line change
@@ -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, <montel@kde.org>
#
# 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)
2 changes: 1 addition & 1 deletion crc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
#include <stddef.h>
#include <inttypes.h>
#include <crc.h>
#include "crc.h"

static const uint32_t error_table[112] = {
0x3935ea, 0x1c9af5, 0xf1b77e, 0x78dbbf, 0xc397db, 0x9e31e9, 0xb0e2f0, 0x587178,
Expand Down
10 changes: 7 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern int outmode;
extern int outformat;
extern char *filename;
extern int gain;
extern int device_fd;

extern int df, errcorr;

Expand All @@ -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");
Expand All @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down