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

Make it possible to compile dump1090 without librtlsdr #77

Open
wants to merge 3 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
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ SHAREDIR=$(PREFIX)/share/$(PROGNAME)
EXTRACFLAGS=-DHTMLPATH=\"$(SHAREDIR)\"
endif

CFLAGS=-O2 -g -Wall -W `pkg-config --cflags librtlsdr`
LIBS=`pkg-config --libs librtlsdr` -lpthread -lm
# Set NORTLSDR to compile without librtlsdr e.g. "make NORTLSDR=1"
ifndef NORTLSDR
ifeq ($(shell pkg-config --exists librtlsdr || echo "F"), F)
$(warning librtlsdr not found - please install it, or build with "NORTLSDR=1" to build with RTL SDR support.)
endif
RTLSDR_CFLAGS=$(shell pkg-config --cflags librtlsdr)
RTLSDR_LDFLAGS=$(shell pkg-config --libs librtlsdr)
else
RTLSDR_CFLAGS=-DNORTLSDR
endif

CFLAGS=-O2 -g -Wall -W $(RTLSDR_CFLAGS)
LDFLAGS+=$(RTLSDR_LDFLAGS) -lpthread -lm
CC=gcc


Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Installation

Type "make".

To compile without RTL SDR support (your binaries will only be useable for
network operations), run "make NORTLSDR=1" instead.

Normal usage
---

Expand Down
22 changes: 21 additions & 1 deletion dump1090.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ void modesInit(void) {
// Prepare error correction tables
modesInitErrorInfo();
}

#ifndef NORTLSDR
//
// =============================== RTLSDR handling ==========================
//
Expand Down Expand Up @@ -286,6 +288,8 @@ void rtlsdrCallback(unsigned char *buf, uint32_t len, void *ctx) {
pthread_cond_signal(&Modes.data_cond);
pthread_mutex_unlock(&Modes.data_mutex);
}
#endif

//
//=========================================================================
//
Expand Down Expand Up @@ -351,9 +355,11 @@ void *readerThreadEntryPoint(void *arg) {
MODES_NOTUSED(arg);

if (Modes.filename == NULL) {
#ifndef NORTLSDR
rtlsdr_read_async(Modes.dev, rtlsdrCallback, NULL,
MODES_ASYNC_BUF_NUMBER,
MODES_ASYNC_BUF_SIZE);
#endif
} else {
readDataFromFile();
}
Expand Down Expand Up @@ -595,6 +601,8 @@ void backgroundTasks(void) {
}
}
}

#ifndef NORTLSDR
//
//=========================================================================
//
Expand Down Expand Up @@ -657,6 +665,8 @@ int verbose_device_search(char *s)
fprintf(stderr, "No matching devices found.\n");
return -1;
}
#endif

//
//=========================================================================
//
Expand All @@ -672,7 +682,11 @@ int main(int argc, char **argv) {
int more = j+1 < argc; // There are more arguments

if (!strcmp(argv[j],"--device-index") && more) {
#ifndef NORTLSDR
Modes.dev_index = verbose_device_search(argv[++j]);
#else
assert(!"Compiled without librtlsdr support");
#endif
} else if (!strcmp(argv[j],"--gain") && more) {
Modes.gain = (int) (atof(argv[++j])*10); // Gain is in tens of DBs
} else if (!strcmp(argv[j],"--enable-agc")) {
Expand Down Expand Up @@ -803,7 +817,11 @@ int main(int argc, char **argv) {
if (Modes.net_only) {
fprintf(stderr,"Net-only mode, no RTL device or file open.\n");
} else if (Modes.filename == NULL) {
#ifndef NORTLSDR
modesInitRTLSDR();
#else
assert(!"Compiled without librtlsdr support");
#endif
} else {
if (Modes.filename[0] == '-' && Modes.filename[1] == '\0') {
Modes.fd = STDIN_FILENO;
Expand Down Expand Up @@ -886,9 +904,11 @@ int main(int argc, char **argv) {
display_stats();
}

if (Modes.filename == NULL) {
if (Modes.filename == NULL && !Modes.net_only) {
#ifndef NORTLSDR
rtlsdr_cancel_async(Modes.dev); // Cancel rtlsdr_read_async will cause data input thread to terminate cleanly
rtlsdr_close(Modes.dev);
#endif
}
pthread_cond_destroy(&Modes.data_cond); // Thread cleanup
pthread_mutex_destroy(&Modes.data_mutex);
Expand Down
5 changes: 5 additions & 0 deletions dump1090.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
#include <ctype.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <assert.h>
#ifndef NORTLSDR
#include "rtl-sdr.h"
#endif
#include "anet.h"
#else
#include "winstubs.h" //Put everything Windows specific in here
Expand Down Expand Up @@ -263,7 +266,9 @@ struct { // Internal state
int dev_index;
int gain;
int enable_agc;
#ifndef NORTLSDR
rtlsdr_dev_t *dev;
#endif
int freq;
int ppm_error;

Expand Down
1 change: 0 additions & 1 deletion view1090.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "rtl-sdr.h"
#include "anet.h"
#else
#include "winstubs.h" //Put everything Windows specific in here
Expand Down