Code cleanup / warnings:
- Makefile: * updated to warn about virtually anything * add detection of GCC/Clang - anet.c: * add static and __attribute__((__unused__)) - dump1090.c: * add static and __attribute__((__unused__)) * don't use empty parameter lists in forward-declarations * add some const * #if-0 unused variable with invalid initializer
This commit is contained in:
parent
d4be3b8a25
commit
da1ccc3f1c
68
Makefile
68
Makefile
@ -1,15 +1,71 @@
|
|||||||
CFLAGS?=-O2 -g -Wall -W $(shell pkg-config --cflags librtlsdr)
|
# warn about (roughly):
|
||||||
LDLIBS+=$(shell pkg-config --libs librtlsdr) -lpthread -lm
|
# * deviations from standard
|
||||||
|
# * global functions that are not exported
|
||||||
|
# * empty argument list in declarations
|
||||||
|
COM_WARNS= -Wall \
|
||||||
|
-Wextra \
|
||||||
|
-Wpedantic \
|
||||||
|
-Wmissing-declarations \
|
||||||
|
-Wdouble-promotion \
|
||||||
|
-Wnull-dereference \
|
||||||
|
-Wmissing-include-dirs \
|
||||||
|
-Wswitch-default \
|
||||||
|
-Wunused-parameter \
|
||||||
|
-Wuninitialized \
|
||||||
|
-Wshadow \
|
||||||
|
-Wbad-function-cast \
|
||||||
|
-Wcast-qual \
|
||||||
|
-Wcast-align \
|
||||||
|
-Wwrite-strings \
|
||||||
|
-Wstrict-prototypes \
|
||||||
|
-Wredundant-decls \
|
||||||
|
-Wnested-externs \
|
||||||
|
-Wincompatible-pointer-types
|
||||||
|
# TODO: These require some work.
|
||||||
|
# -Wconversion \
|
||||||
|
# -Wfloat-equal
|
||||||
|
GCC_WARNS= -Wchkp \
|
||||||
|
-Walloc-zero \
|
||||||
|
-Wduplicated-branches \
|
||||||
|
-Wduplicated-cond \
|
||||||
|
-Wc99-c11-compat \
|
||||||
|
-Wjump-misses-init \
|
||||||
|
-Wlogical-op \
|
||||||
|
-Wrestrict
|
||||||
|
CLANG_WARNS=
|
||||||
|
|
||||||
|
|
||||||
|
COM_OFLGS= -fstrict-aliasing \
|
||||||
|
-fstack-protector
|
||||||
|
GCC_OFLGS= -fdelete-null-pointer-checks \
|
||||||
|
-ftree-vrp \
|
||||||
|
-funsafe-loop-optimizations \
|
||||||
|
-flto-odr-type-merging
|
||||||
|
CLANG_OFLGS=
|
||||||
|
|
||||||
|
|
||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
|
CID=$(shell $(CC) -v 2>&1 | grep "version" | cut -d' ' -f1)
|
||||||
|
|
||||||
|
CFLAGS ?= -std=gnu99 -O2 -g
|
||||||
|
CFLAGS += $(COM_WARNS) $(COM_OFLGS)
|
||||||
|
ifeq "$(CID)" "gcc"
|
||||||
|
CFLAGS += $(GCC_WARNS) $(GCC_OFLGS)
|
||||||
|
else
|
||||||
|
CFLAGS += $(CLANG_WARNS) $(CLANG_OFLGS)
|
||||||
|
endif
|
||||||
|
|
||||||
|
CFLAGS += $(shell pkg-config --cflags librtlsdr)
|
||||||
|
LDLIBS += $(shell pkg-config --libs librtlsdr) -lpthread -lm
|
||||||
PROGNAME=dump1090
|
PROGNAME=dump1090
|
||||||
|
|
||||||
all: dump1090
|
all: $(PROGNAME)
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) $(CFLAGS) -c $<
|
$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
dump1090: dump1090.o anet.o
|
$(PROGNAME): dump1090.o anet.o
|
||||||
$(CC) -g -o dump1090 dump1090.o anet.o $(LDFLAGS) $(LDLIBS)
|
$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o dump1090
|
@$(RM) -v *.o $(PROGNAME)
|
||||||
|
4
anet.c
4
anet.c
@ -188,7 +188,7 @@ int anetTcpNonBlockConnect(char *err, char *addr, int port)
|
|||||||
return anetTcpGenericConnect(err,addr,port,ANET_CONNECT_NONBLOCK);
|
return anetTcpGenericConnect(err,addr,port,ANET_CONNECT_NONBLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
int anetUnixGenericConnect(char *err, char *path, int flags)
|
static int anetUnixGenericConnect(char *err, char *path, int flags)
|
||||||
{
|
{
|
||||||
int s;
|
int s;
|
||||||
struct sockaddr_un sa;
|
struct sockaddr_un sa;
|
||||||
@ -366,7 +366,7 @@ int anetPeerToString(int fd, char *ip, int *port) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int anetSockName(int fd, char *ip, int *port) {
|
static int __attribute__((__unused__)) anetSockName(int fd, char *ip, int *port) {
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
socklen_t salen = sizeof(sa);
|
socklen_t salen = sizeof(sa);
|
||||||
|
|
||||||
|
121
dump1090.c
121
dump1090.c
@ -44,6 +44,9 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include "rtl-sdr.h"
|
#include "rtl-sdr.h"
|
||||||
|
/* roughly from commit 4365e5b2d32798c168a8376fad891c0e5cccb4ec
|
||||||
|
* + some statics and unused attribute
|
||||||
|
*/
|
||||||
#include "anet.h"
|
#include "anet.h"
|
||||||
|
|
||||||
#define MODES_DEFAULT_RATE 2000000
|
#define MODES_DEFAULT_RATE 2000000
|
||||||
@ -239,8 +242,8 @@ void useModesMessage(struct modesMessage *mm);
|
|||||||
int fixSingleBitErrors(unsigned char *msg, int bits);
|
int fixSingleBitErrors(unsigned char *msg, int bits);
|
||||||
int fixTwoBitsErrors(unsigned char *msg, int bits);
|
int fixTwoBitsErrors(unsigned char *msg, int bits);
|
||||||
int modesMessageLenByType(int type);
|
int modesMessageLenByType(int type);
|
||||||
void sigWinchCallback();
|
void sigWinchCallback(int);
|
||||||
int getTermRows();
|
int getTermRows(void);
|
||||||
|
|
||||||
/* ============================= Utility functions ========================== */
|
/* ============================= Utility functions ========================== */
|
||||||
|
|
||||||
@ -256,7 +259,7 @@ static long long mstime(void) {
|
|||||||
|
|
||||||
/* =============================== Initialization =========================== */
|
/* =============================== Initialization =========================== */
|
||||||
|
|
||||||
void modesInitConfig(void) {
|
static void modesInitConfig(void) {
|
||||||
Modes.gain = MODES_MAX_GAIN;
|
Modes.gain = MODES_MAX_GAIN;
|
||||||
Modes.dev_index = 0;
|
Modes.dev_index = 0;
|
||||||
Modes.enable_agc = 0;
|
Modes.enable_agc = 0;
|
||||||
@ -276,7 +279,7 @@ void modesInitConfig(void) {
|
|||||||
Modes.interactive_rows = getTermRows();
|
Modes.interactive_rows = getTermRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
void modesInit(void) {
|
static void modesInit(void) {
|
||||||
int i, q;
|
int i, q;
|
||||||
|
|
||||||
pthread_mutex_init(&Modes.data_mutex,NULL);
|
pthread_mutex_init(&Modes.data_mutex,NULL);
|
||||||
@ -331,7 +334,7 @@ void modesInit(void) {
|
|||||||
|
|
||||||
/* =============================== RTLSDR handling ========================== */
|
/* =============================== RTLSDR handling ========================== */
|
||||||
|
|
||||||
void modesInitRTLSDR(void) {
|
static void modesInitRTLSDR(void) {
|
||||||
int j;
|
int j;
|
||||||
int device_count;
|
int device_count;
|
||||||
int ppm_error = 0;
|
int ppm_error = 0;
|
||||||
@ -389,7 +392,7 @@ void modesInitRTLSDR(void) {
|
|||||||
* The reading thread calls the RTLSDR API to read data asynchronously, and
|
* The reading thread calls the RTLSDR API to read data asynchronously, and
|
||||||
* uses a callback to populate the data buffer.
|
* uses a callback to populate the data buffer.
|
||||||
* A Mutex is used to avoid races with the decoding thread. */
|
* A Mutex is used to avoid races with the decoding thread. */
|
||||||
void rtlsdrCallback(unsigned char *buf, uint32_t len, void *ctx) {
|
static void rtlsdrCallback(unsigned char *buf, uint32_t len, void *ctx) {
|
||||||
MODES_NOTUSED(ctx);
|
MODES_NOTUSED(ctx);
|
||||||
|
|
||||||
pthread_mutex_lock(&Modes.data_mutex);
|
pthread_mutex_lock(&Modes.data_mutex);
|
||||||
@ -407,7 +410,7 @@ void rtlsdrCallback(unsigned char *buf, uint32_t len, void *ctx) {
|
|||||||
|
|
||||||
/* This is used when --ifile is specified in order to read data from file
|
/* This is used when --ifile is specified in order to read data from file
|
||||||
* instead of using an RTLSDR device. */
|
* instead of using an RTLSDR device. */
|
||||||
void readDataFromFile(void) {
|
static void readDataFromFile(void) {
|
||||||
pthread_mutex_lock(&Modes.data_mutex);
|
pthread_mutex_lock(&Modes.data_mutex);
|
||||||
while(1) {
|
while(1) {
|
||||||
ssize_t nread, toread;
|
ssize_t nread, toread;
|
||||||
@ -453,7 +456,7 @@ void readDataFromFile(void) {
|
|||||||
|
|
||||||
/* We read data using a thread, so the main thread only handles decoding
|
/* We read data using a thread, so the main thread only handles decoding
|
||||||
* without caring about data acquisition. */
|
* without caring about data acquisition. */
|
||||||
void *readerThreadEntryPoint(void *arg) {
|
static void *readerThreadEntryPoint(void *arg) {
|
||||||
MODES_NOTUSED(arg);
|
MODES_NOTUSED(arg);
|
||||||
|
|
||||||
if (Modes.filename == NULL) {
|
if (Modes.filename == NULL) {
|
||||||
@ -480,8 +483,8 @@ void *readerThreadEntryPoint(void *arg) {
|
|||||||
* "-" is 2
|
* "-" is 2
|
||||||
* "." is 1
|
* "." is 1
|
||||||
*/
|
*/
|
||||||
void dumpMagnitudeBar(int index, int magnitude) {
|
static void dumpMagnitudeBar(int index, int magnitude) {
|
||||||
char *set = " .-o";
|
const char *set = " .-o";
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int div = magnitude / 256 / 4;
|
int div = magnitude / 256 / 4;
|
||||||
int rem = magnitude / 256 % 4;
|
int rem = magnitude / 256 % 4;
|
||||||
@ -505,7 +508,7 @@ void dumpMagnitudeBar(int index, int magnitude) {
|
|||||||
* If possible a few samples before the start of the messsage are included
|
* If possible a few samples before the start of the messsage are included
|
||||||
* for context. */
|
* for context. */
|
||||||
|
|
||||||
void dumpMagnitudeVector(uint16_t *m, uint32_t offset) {
|
static void dumpMagnitudeVector(uint16_t *m, uint32_t offset) {
|
||||||
uint32_t padding = 5; /* Show a few samples before the actual start. */
|
uint32_t padding = 5; /* Show a few samples before the actual start. */
|
||||||
uint32_t start = (offset < padding) ? 0 : offset-padding;
|
uint32_t start = (offset < padding) ? 0 : offset-padding;
|
||||||
uint32_t end = offset + (MODES_PREAMBLE_US*2)+(MODES_SHORT_MSG_BITS*2) - 1;
|
uint32_t end = offset + (MODES_PREAMBLE_US*2)+(MODES_SHORT_MSG_BITS*2) - 1;
|
||||||
@ -518,7 +521,7 @@ void dumpMagnitudeVector(uint16_t *m, uint32_t offset) {
|
|||||||
|
|
||||||
/* Produce a raw representation of the message as a Javascript file
|
/* Produce a raw representation of the message as a Javascript file
|
||||||
* loadable by debug.html. */
|
* loadable by debug.html. */
|
||||||
void dumpRawMessageJS(char *descr, unsigned char *msg,
|
static void dumpRawMessageJS(const char *descr, unsigned char *msg,
|
||||||
uint16_t *m, uint32_t offset, int fixable)
|
uint16_t *m, uint32_t offset, int fixable)
|
||||||
{
|
{
|
||||||
int padding = 5; /* Show a few samples before the actual start. */
|
int padding = 5; /* Show a few samples before the actual start. */
|
||||||
@ -562,7 +565,7 @@ void dumpRawMessageJS(char *descr, unsigned char *msg,
|
|||||||
* display packets in a graphical format if the Javascript output was
|
* display packets in a graphical format if the Javascript output was
|
||||||
* enabled.
|
* enabled.
|
||||||
*/
|
*/
|
||||||
void dumpRawMessage(char *descr, unsigned char *msg,
|
static void dumpRawMessage(const char *descr, unsigned char *msg,
|
||||||
uint16_t *m, uint32_t offset)
|
uint16_t *m, uint32_t offset)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
@ -629,7 +632,7 @@ uint32_t modes_checksum_table[112] = {
|
|||||||
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
|
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t modesChecksum(unsigned char *msg, int bits) {
|
static uint32_t modesChecksum(unsigned char *msg, int bits) {
|
||||||
uint32_t crc = 0;
|
uint32_t crc = 0;
|
||||||
int offset = (bits == 112) ? 0 : (112-56);
|
int offset = (bits == 112) ? 0 : (112-56);
|
||||||
int j;
|
int j;
|
||||||
@ -732,7 +735,7 @@ int fixTwoBitsErrors(unsigned char *msg, int bits) {
|
|||||||
|
|
||||||
/* Hash the ICAO address to index our cache of MODES_ICAO_CACHE_LEN
|
/* Hash the ICAO address to index our cache of MODES_ICAO_CACHE_LEN
|
||||||
* elements, that is assumed to be a power of two. */
|
* elements, that is assumed to be a power of two. */
|
||||||
uint32_t ICAOCacheHashAddress(uint32_t a) {
|
static uint32_t ICAOCacheHashAddress(uint32_t a) {
|
||||||
/* The following three rounds wil make sure that every bit affects
|
/* The following three rounds wil make sure that every bit affects
|
||||||
* every output bit with ~ 50% of probability. */
|
* every output bit with ~ 50% of probability. */
|
||||||
a = ((a >> 16) ^ a) * 0x45d9f3b;
|
a = ((a >> 16) ^ a) * 0x45d9f3b;
|
||||||
@ -744,7 +747,7 @@ uint32_t ICAOCacheHashAddress(uint32_t a) {
|
|||||||
/* Add the specified entry to the cache of recently seen ICAO addresses.
|
/* Add the specified entry to the cache of recently seen ICAO addresses.
|
||||||
* Note that we also add a timestamp so that we can make sure that the
|
* Note that we also add a timestamp so that we can make sure that the
|
||||||
* entry is only valid for MODES_ICAO_CACHE_TTL seconds. */
|
* entry is only valid for MODES_ICAO_CACHE_TTL seconds. */
|
||||||
void addRecentlySeenICAOAddr(uint32_t addr) {
|
static void addRecentlySeenICAOAddr(uint32_t addr) {
|
||||||
uint32_t h = ICAOCacheHashAddress(addr);
|
uint32_t h = ICAOCacheHashAddress(addr);
|
||||||
Modes.icao_cache[h*2] = addr;
|
Modes.icao_cache[h*2] = addr;
|
||||||
Modes.icao_cache[h*2+1] = (uint32_t) time(NULL);
|
Modes.icao_cache[h*2+1] = (uint32_t) time(NULL);
|
||||||
@ -753,7 +756,7 @@ void addRecentlySeenICAOAddr(uint32_t addr) {
|
|||||||
/* Returns 1 if the specified ICAO address was seen in a DF format with
|
/* Returns 1 if the specified ICAO address was seen in a DF format with
|
||||||
* proper checksum (not xored with address) no more than * MODES_ICAO_CACHE_TTL
|
* proper checksum (not xored with address) no more than * MODES_ICAO_CACHE_TTL
|
||||||
* seconds ago. Otherwise returns 0. */
|
* seconds ago. Otherwise returns 0. */
|
||||||
int ICAOAddressWasRecentlySeen(uint32_t addr) {
|
static int ICAOAddressWasRecentlySeen(uint32_t addr) {
|
||||||
uint32_t h = ICAOCacheHashAddress(addr);
|
uint32_t h = ICAOCacheHashAddress(addr);
|
||||||
uint32_t a = Modes.icao_cache[h*2];
|
uint32_t a = Modes.icao_cache[h*2];
|
||||||
uint32_t t = Modes.icao_cache[h*2+1];
|
uint32_t t = Modes.icao_cache[h*2+1];
|
||||||
@ -776,7 +779,7 @@ int ICAOAddressWasRecentlySeen(uint32_t addr) {
|
|||||||
*
|
*
|
||||||
* If the function successfully recovers a message with a correct checksum
|
* If the function successfully recovers a message with a correct checksum
|
||||||
* it returns 1. Otherwise 0 is returned. */
|
* it returns 1. Otherwise 0 is returned. */
|
||||||
int bruteForceAP(unsigned char *msg, struct modesMessage *mm) {
|
static int bruteForceAP(unsigned char *msg, struct modesMessage *mm) {
|
||||||
unsigned char aux[MODES_LONG_MSG_BYTES];
|
unsigned char aux[MODES_LONG_MSG_BYTES];
|
||||||
int msgtype = mm->msgtype;
|
int msgtype = mm->msgtype;
|
||||||
int msgbits = mm->msgbits;
|
int msgbits = mm->msgbits;
|
||||||
@ -821,7 +824,7 @@ int bruteForceAP(unsigned char *msg, struct modesMessage *mm) {
|
|||||||
/* Decode the 13 bit AC altitude field (in DF 20 and others).
|
/* Decode the 13 bit AC altitude field (in DF 20 and others).
|
||||||
* Returns the altitude, and set 'unit' to either MODES_UNIT_METERS
|
* Returns the altitude, and set 'unit' to either MODES_UNIT_METERS
|
||||||
* or MDOES_UNIT_FEETS. */
|
* or MDOES_UNIT_FEETS. */
|
||||||
int decodeAC13Field(unsigned char *msg, int *unit) {
|
static int decodeAC13Field(unsigned char *msg, int *unit) {
|
||||||
int m_bit = msg[3] & (1<<6);
|
int m_bit = msg[3] & (1<<6);
|
||||||
int q_bit = msg[3] & (1<<4);
|
int q_bit = msg[3] & (1<<4);
|
||||||
|
|
||||||
@ -849,7 +852,7 @@ int decodeAC13Field(unsigned char *msg, int *unit) {
|
|||||||
|
|
||||||
/* Decode the 12 bit AC altitude field (in DF 17 and others).
|
/* Decode the 12 bit AC altitude field (in DF 17 and others).
|
||||||
* Returns the altitude or 0 if it can't be decoded. */
|
* Returns the altitude or 0 if it can't be decoded. */
|
||||||
int decodeAC12Field(unsigned char *msg, int *unit) {
|
static int decodeAC12Field(unsigned char *msg, int *unit) {
|
||||||
int q_bit = msg[5] & 1;
|
int q_bit = msg[5] & 1;
|
||||||
|
|
||||||
if (q_bit) {
|
if (q_bit) {
|
||||||
@ -866,7 +869,7 @@ int decodeAC12Field(unsigned char *msg, int *unit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Capability table. */
|
/* Capability table. */
|
||||||
char *ca_str[8] = {
|
const char *ca_str[8] = {
|
||||||
/* 0 */ "Level 1 (Survillance Only)",
|
/* 0 */ "Level 1 (Survillance Only)",
|
||||||
/* 1 */ "Level 2 (DF0,4,5,11)",
|
/* 1 */ "Level 2 (DF0,4,5,11)",
|
||||||
/* 2 */ "Level 3 (DF0,4,5,11,20,21)",
|
/* 2 */ "Level 3 (DF0,4,5,11,20,21)",
|
||||||
@ -878,7 +881,7 @@ char *ca_str[8] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Flight status table. */
|
/* Flight status table. */
|
||||||
char *fs_str[8] = {
|
const char *fs_str[8] = {
|
||||||
/* 0 */ "Normal, Airborne",
|
/* 0 */ "Normal, Airborne",
|
||||||
/* 1 */ "Normal, On the ground",
|
/* 1 */ "Normal, On the ground",
|
||||||
/* 2 */ "ALERT, Airborne",
|
/* 2 */ "ALERT, Airborne",
|
||||||
@ -889,12 +892,14 @@ char *fs_str[8] = {
|
|||||||
/* 7 */ "Value 7 is not assigned"
|
/* 7 */ "Value 7 is not assigned"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if 0
|
||||||
/* ME message type to description table. */
|
/* ME message type to description table. */
|
||||||
char *me_str[] = {
|
char *me_str[] = {
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
char *getMEDescription(int metype, int mesub) {
|
static const char *getMEDescription(int metype, int mesub) {
|
||||||
char *mename = "Unknown";
|
const char *mename = "Unknown";
|
||||||
|
|
||||||
if (metype >= 1 && metype <= 4)
|
if (metype >= 1 && metype <= 4)
|
||||||
mename = "Aircraft Identification and Category";
|
mename = "Aircraft Identification and Category";
|
||||||
@ -924,9 +929,9 @@ char *getMEDescription(int metype, int mesub) {
|
|||||||
/* Decode a raw Mode S message demodulated as a stream of bytes by
|
/* Decode a raw Mode S message demodulated as a stream of bytes by
|
||||||
* detectModeS(), and split it into fields populating a modesMessage
|
* detectModeS(), and split it into fields populating a modesMessage
|
||||||
* structure. */
|
* structure. */
|
||||||
void decodeModesMessage(struct modesMessage *mm, unsigned char *msg) {
|
static void decodeModesMessage(struct modesMessage *mm, unsigned char *msg) {
|
||||||
uint32_t crc2; /* Computed CRC, used to verify the message CRC. */
|
uint32_t crc2; /* Computed CRC, used to verify the message CRC. */
|
||||||
char *ais_charset = "?ABCDEFGHIJKLMNOPQRSTUVWXYZ????? ???????????????0123456789??????";
|
const char *ais_charset = "?ABCDEFGHIJKLMNOPQRSTUVWXYZ????? ???????????????0123456789??????";
|
||||||
|
|
||||||
/* Work on our local copy */
|
/* Work on our local copy */
|
||||||
memcpy(mm->msg,msg,MODES_LONG_MSG_BYTES);
|
memcpy(mm->msg,msg,MODES_LONG_MSG_BYTES);
|
||||||
@ -1109,7 +1114,7 @@ void decodeModesMessage(struct modesMessage *mm, unsigned char *msg) {
|
|||||||
|
|
||||||
/* This function gets a decoded Mode S Message and prints it on the screen
|
/* This function gets a decoded Mode S Message and prints it on the screen
|
||||||
* in a human readable format. */
|
* in a human readable format. */
|
||||||
void displayModesMessage(struct modesMessage *mm) {
|
static void displayModesMessage(struct modesMessage *mm) {
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
/* Handle only addresses mode first. */
|
/* Handle only addresses mode first. */
|
||||||
@ -1181,7 +1186,7 @@ void displayModesMessage(struct modesMessage *mm) {
|
|||||||
/* Decode the extended squitter message. */
|
/* Decode the extended squitter message. */
|
||||||
if (mm->metype >= 1 && mm->metype <= 4) {
|
if (mm->metype >= 1 && mm->metype <= 4) {
|
||||||
/* Aircraft identification. */
|
/* Aircraft identification. */
|
||||||
char *ac_type_str[4] = {
|
const char *ac_type_str[4] = {
|
||||||
"Aircraft Type D",
|
"Aircraft Type D",
|
||||||
"Aircraft Type C",
|
"Aircraft Type C",
|
||||||
"Aircraft Type B",
|
"Aircraft Type B",
|
||||||
@ -1224,7 +1229,7 @@ void displayModesMessage(struct modesMessage *mm) {
|
|||||||
|
|
||||||
/* Turn I/Q samples pointed by Modes.data into the magnitude vector
|
/* Turn I/Q samples pointed by Modes.data into the magnitude vector
|
||||||
* pointed by Modes.magnitude. */
|
* pointed by Modes.magnitude. */
|
||||||
void computeMagnitudeVector(void) {
|
static void computeMagnitudeVector(void) {
|
||||||
uint16_t *m = Modes.magnitude;
|
uint16_t *m = Modes.magnitude;
|
||||||
unsigned char *p = Modes.data;
|
unsigned char *p = Modes.data;
|
||||||
uint32_t j;
|
uint32_t j;
|
||||||
@ -1247,7 +1252,7 @@ void computeMagnitudeVector(void) {
|
|||||||
*
|
*
|
||||||
* Note: this function will access m[-1], so the caller should make sure to
|
* Note: this function will access m[-1], so the caller should make sure to
|
||||||
* call it only if we are not at the start of the current buffer. */
|
* call it only if we are not at the start of the current buffer. */
|
||||||
int detectOutOfPhase(uint16_t *m) {
|
static int detectOutOfPhase(uint16_t *m) {
|
||||||
if (m[3] > m[2]/3) return 1;
|
if (m[3] > m[2]/3) return 1;
|
||||||
if (m[10] > m[9]/3) return 1;
|
if (m[10] > m[9]/3) return 1;
|
||||||
if (m[6] > m[7]/3) return -1;
|
if (m[6] > m[7]/3) return -1;
|
||||||
@ -1283,7 +1288,7 @@ int detectOutOfPhase(uint16_t *m) {
|
|||||||
* it will be more likely to detect a one because of the transformation.
|
* it will be more likely to detect a one because of the transformation.
|
||||||
* In this way similar levels will be interpreted more likely in the
|
* In this way similar levels will be interpreted more likely in the
|
||||||
* correct way. */
|
* correct way. */
|
||||||
void applyPhaseCorrection(uint16_t *m) {
|
static void applyPhaseCorrection(uint16_t *m) {
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
m += 16; /* Skip preamble. */
|
m += 16; /* Skip preamble. */
|
||||||
@ -1301,7 +1306,7 @@ void applyPhaseCorrection(uint16_t *m) {
|
|||||||
/* Detect a Mode S messages inside the magnitude buffer pointed by 'm' and of
|
/* Detect a Mode S messages inside the magnitude buffer pointed by 'm' and of
|
||||||
* size 'mlen' bytes. Every detected Mode S message is convert it into a
|
* size 'mlen' bytes. Every detected Mode S message is convert it into a
|
||||||
* stream of bits and passed to the function to display it. */
|
* stream of bits and passed to the function to display it. */
|
||||||
void detectModeS(uint16_t *m, uint32_t mlen) {
|
static void detectModeS(uint16_t *m, uint32_t mlen) {
|
||||||
unsigned char bits[MODES_LONG_MSG_BITS];
|
unsigned char bits[MODES_LONG_MSG_BITS];
|
||||||
unsigned char msg[MODES_LONG_MSG_BITS/2];
|
unsigned char msg[MODES_LONG_MSG_BITS/2];
|
||||||
uint16_t aux[MODES_LONG_MSG_BITS*2];
|
uint16_t aux[MODES_LONG_MSG_BITS*2];
|
||||||
@ -1563,7 +1568,7 @@ void useModesMessage(struct modesMessage *mm) {
|
|||||||
|
|
||||||
/* Return a new aircraft structure for the interactive mode linked list
|
/* Return a new aircraft structure for the interactive mode linked list
|
||||||
* of aircrafts. */
|
* of aircrafts. */
|
||||||
struct aircraft *interactiveCreateAircraft(uint32_t addr) {
|
static struct aircraft *interactiveCreateAircraft(uint32_t addr) {
|
||||||
struct aircraft *a = malloc(sizeof(*a));
|
struct aircraft *a = malloc(sizeof(*a));
|
||||||
|
|
||||||
a->addr = addr;
|
a->addr = addr;
|
||||||
@ -1588,7 +1593,7 @@ struct aircraft *interactiveCreateAircraft(uint32_t addr) {
|
|||||||
|
|
||||||
/* Return the aircraft with the specified address, or NULL if no aircraft
|
/* Return the aircraft with the specified address, or NULL if no aircraft
|
||||||
* exists with this address. */
|
* exists with this address. */
|
||||||
struct aircraft *interactiveFindAircraft(uint32_t addr) {
|
static struct aircraft *interactiveFindAircraft(uint32_t addr) {
|
||||||
struct aircraft *a = Modes.aircrafts;
|
struct aircraft *a = Modes.aircrafts;
|
||||||
|
|
||||||
while(a) {
|
while(a) {
|
||||||
@ -1599,14 +1604,14 @@ struct aircraft *interactiveFindAircraft(uint32_t addr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Always positive MOD operation, used for CPR decoding. */
|
/* Always positive MOD operation, used for CPR decoding. */
|
||||||
int cprModFunction(int a, int b) {
|
static int cprModFunction(int a, int b) {
|
||||||
int res = a % b;
|
int res = a % b;
|
||||||
if (res < 0) res += b;
|
if (res < 0) res += b;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The NL function uses the precomputed table from 1090-WP-9-14 */
|
/* The NL function uses the precomputed table from 1090-WP-9-14 */
|
||||||
int cprNLFunction(double lat) {
|
static int cprNLFunction(double lat) {
|
||||||
if (lat < 0) lat = -lat; /* Table is simmetric about the equator. */
|
if (lat < 0) lat = -lat; /* Table is simmetric about the equator. */
|
||||||
if (lat < 10.47047130) return 59;
|
if (lat < 10.47047130) return 59;
|
||||||
if (lat < 14.82817437) return 58;
|
if (lat < 14.82817437) return 58;
|
||||||
@ -1669,13 +1674,13 @@ int cprNLFunction(double lat) {
|
|||||||
else return 1;
|
else return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cprNFunction(double lat, int isodd) {
|
static int cprNFunction(double lat, int isodd) {
|
||||||
int nl = cprNLFunction(lat) - isodd;
|
int nl = cprNLFunction(lat) - isodd;
|
||||||
if (nl < 1) nl = 1;
|
if (nl < 1) nl = 1;
|
||||||
return nl;
|
return nl;
|
||||||
}
|
}
|
||||||
|
|
||||||
double cprDlonFunction(double lat, int isodd) {
|
static double cprDlonFunction(double lat, int isodd) {
|
||||||
return 360.0 / cprNFunction(lat, isodd);
|
return 360.0 / cprNFunction(lat, isodd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1689,7 +1694,7 @@ double cprDlonFunction(double lat, int isodd) {
|
|||||||
* simplicity. This may provide a position that is less fresh of a few
|
* simplicity. This may provide a position that is less fresh of a few
|
||||||
* seconds.
|
* seconds.
|
||||||
*/
|
*/
|
||||||
void decodeCPR(struct aircraft *a) {
|
static void decodeCPR(struct aircraft *a) {
|
||||||
const double AirDlat0 = 360.0 / 60;
|
const double AirDlat0 = 360.0 / 60;
|
||||||
const double AirDlat1 = 360.0 / 59;
|
const double AirDlat1 = 360.0 / 59;
|
||||||
double lat0 = a->even_cprlat;
|
double lat0 = a->even_cprlat;
|
||||||
@ -1781,7 +1786,7 @@ struct aircraft *interactiveReceiveData(struct modesMessage *mm) {
|
|||||||
}
|
}
|
||||||
/* If the two data is less than 10 seconds apart, compute
|
/* If the two data is less than 10 seconds apart, compute
|
||||||
* the position. */
|
* the position. */
|
||||||
if (abs(a->even_cprtime - a->odd_cprtime) <= 10000) {
|
if (llabs(a->even_cprtime - a->odd_cprtime) <= 10000) {
|
||||||
decodeCPR(a);
|
decodeCPR(a);
|
||||||
}
|
}
|
||||||
} else if (mm->metype == 19) {
|
} else if (mm->metype == 19) {
|
||||||
@ -1831,7 +1836,7 @@ void interactiveShowData(void) {
|
|||||||
|
|
||||||
/* When in interactive mode If we don't receive new nessages within
|
/* When in interactive mode If we don't receive new nessages within
|
||||||
* MODES_INTERACTIVE_TTL seconds we remove the aircraft from the list. */
|
* MODES_INTERACTIVE_TTL seconds we remove the aircraft from the list. */
|
||||||
void interactiveRemoveStaleAircrafts(void) {
|
static void interactiveRemoveStaleAircrafts(void) {
|
||||||
struct aircraft *a = Modes.aircrafts;
|
struct aircraft *a = Modes.aircrafts;
|
||||||
struct aircraft *prev = NULL;
|
struct aircraft *prev = NULL;
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
@ -1858,7 +1863,7 @@ void interactiveRemoveStaleAircrafts(void) {
|
|||||||
|
|
||||||
/* Get raw IQ samples and filter everything is < than the specified level
|
/* Get raw IQ samples and filter everything is < than the specified level
|
||||||
* for more than 256 samples in order to reduce example file size. */
|
* for more than 256 samples in order to reduce example file size. */
|
||||||
void snipMode(int level) {
|
static void snipMode(int level) {
|
||||||
int i, q;
|
int i, q;
|
||||||
long long c = 0;
|
long long c = 0;
|
||||||
|
|
||||||
@ -1892,7 +1897,7 @@ void snipMode(int level) {
|
|||||||
#define MODES_NET_SERVICE_SBS 3
|
#define MODES_NET_SERVICE_SBS 3
|
||||||
#define MODES_NET_SERVICES_NUM 4
|
#define MODES_NET_SERVICES_NUM 4
|
||||||
struct {
|
struct {
|
||||||
char *descr;
|
const char *descr;
|
||||||
int *socket;
|
int *socket;
|
||||||
int port;
|
int port;
|
||||||
} modesNetServices[MODES_NET_SERVICES_NUM] = {
|
} modesNetServices[MODES_NET_SERVICES_NUM] = {
|
||||||
@ -1903,7 +1908,7 @@ struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Networking "stack" initialization. */
|
/* Networking "stack" initialization. */
|
||||||
void modesInitNet(void) {
|
static void modesInitNet(void) {
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
memset(Modes.clients,0,sizeof(Modes.clients));
|
memset(Modes.clients,0,sizeof(Modes.clients));
|
||||||
@ -1928,7 +1933,7 @@ void modesInitNet(void) {
|
|||||||
/* This function gets called from time to time when the decoding thread is
|
/* This function gets called from time to time when the decoding thread is
|
||||||
* awakened by new data arriving. This usually happens a few times every
|
* awakened by new data arriving. This usually happens a few times every
|
||||||
* second. */
|
* second. */
|
||||||
void modesAcceptClients(void) {
|
static void modesAcceptClients(void) {
|
||||||
int fd, port;
|
int fd, port;
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
@ -1968,7 +1973,7 @@ void modesAcceptClients(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* On error free the client, collect the structure, adjust maxfd if needed. */
|
/* On error free the client, collect the structure, adjust maxfd if needed. */
|
||||||
void modesFreeClient(int fd) {
|
static void modesFreeClient(int fd) {
|
||||||
close(fd);
|
close(fd);
|
||||||
free(Modes.clients[fd]);
|
free(Modes.clients[fd]);
|
||||||
Modes.clients[fd] = NULL;
|
Modes.clients[fd] = NULL;
|
||||||
@ -1993,7 +1998,7 @@ void modesFreeClient(int fd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Send the specified message to all clients listening for a given service. */
|
/* Send the specified message to all clients listening for a given service. */
|
||||||
void modesSendAllClients(int service, void *msg, int len) {
|
static void modesSendAllClients(int service, void *msg, int len) {
|
||||||
int j;
|
int j;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
|
|
||||||
@ -2080,7 +2085,7 @@ void modesSendSBSOutput(struct modesMessage *mm, struct aircraft *a) {
|
|||||||
|
|
||||||
/* Turn an hex digit into its 4 bit decimal value.
|
/* Turn an hex digit into its 4 bit decimal value.
|
||||||
* Returns -1 if the digit is not in the 0-F range. */
|
* Returns -1 if the digit is not in the 0-F range. */
|
||||||
int hexDigitVal(int c) {
|
static int hexDigitVal(int c) {
|
||||||
c = tolower(c);
|
c = tolower(c);
|
||||||
if (c >= '0' && c <= '9') return c-'0';
|
if (c >= '0' && c <= '9') return c-'0';
|
||||||
else if (c >= 'a' && c <= 'f') return c-'a'+10;
|
else if (c >= 'a' && c <= 'f') return c-'a'+10;
|
||||||
@ -2100,7 +2105,7 @@ int hexDigitVal(int c) {
|
|||||||
* The function always returns 0 (success) to the caller as there is
|
* The function always returns 0 (success) to the caller as there is
|
||||||
* no case where we want broken messages here to close the client
|
* no case where we want broken messages here to close the client
|
||||||
* connection. */
|
* connection. */
|
||||||
int decodeHexMessage(struct client *c) {
|
static int decodeHexMessage(struct client *c) {
|
||||||
char *hex = c->buf;
|
char *hex = c->buf;
|
||||||
int l = strlen(hex), j;
|
int l = strlen(hex), j;
|
||||||
unsigned char msg[MODES_LONG_MSG_BYTES];
|
unsigned char msg[MODES_LONG_MSG_BYTES];
|
||||||
@ -2133,7 +2138,7 @@ int decodeHexMessage(struct client *c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Return a description of planes in json. */
|
/* Return a description of planes in json. */
|
||||||
char *aircraftsToJson(int *len) {
|
static char *aircraftsToJson(int *len) {
|
||||||
struct aircraft *a = Modes.aircrafts;
|
struct aircraft *a = Modes.aircrafts;
|
||||||
int buflen = 1024; /* The initial buffer is incremented as needed. */
|
int buflen = 1024; /* The initial buffer is incremented as needed. */
|
||||||
char *buf = malloc(buflen), *p = buf;
|
char *buf = malloc(buflen), *p = buf;
|
||||||
@ -2190,12 +2195,12 @@ char *aircraftsToJson(int *len) {
|
|||||||
*
|
*
|
||||||
* Returns 1 on error to signal the caller the client connection should
|
* Returns 1 on error to signal the caller the client connection should
|
||||||
* be closed. */
|
* be closed. */
|
||||||
int handleHTTPRequest(struct client *c) {
|
static int handleHTTPRequest(struct client *c) {
|
||||||
char hdr[512];
|
char hdr[512];
|
||||||
int clen, hdrlen;
|
int clen, hdrlen;
|
||||||
int httpver, keepalive;
|
int httpver, keepalive;
|
||||||
char *p, *url, *content;
|
char *p, *url, *content;
|
||||||
char *ctype;
|
const char *ctype;
|
||||||
|
|
||||||
if (Modes.debug & MODES_DEBUG_NET)
|
if (Modes.debug & MODES_DEBUG_NET)
|
||||||
printf("\nHTTP request: %s\n", c->buf);
|
printf("\nHTTP request: %s\n", c->buf);
|
||||||
@ -2293,7 +2298,7 @@ int handleHTTPRequest(struct client *c) {
|
|||||||
* The handelr returns 0 on success, or 1 to signal this function we
|
* The handelr returns 0 on success, or 1 to signal this function we
|
||||||
* should close the connection with the client in case of non-recoverable
|
* should close the connection with the client in case of non-recoverable
|
||||||
* errors. */
|
* errors. */
|
||||||
void modesReadFromClient(struct client *c, char *sep,
|
static void modesReadFromClient(struct client *c, const char *sep,
|
||||||
int(*handler)(struct client *))
|
int(*handler)(struct client *))
|
||||||
{
|
{
|
||||||
while(1) {
|
while(1) {
|
||||||
@ -2351,7 +2356,7 @@ void modesReadFromClient(struct client *c, char *sep,
|
|||||||
|
|
||||||
/* Read data from clients. This function actually delegates a lower-level
|
/* Read data from clients. This function actually delegates a lower-level
|
||||||
* function that depends on the kind of service (raw, http, ...). */
|
* function that depends on the kind of service (raw, http, ...). */
|
||||||
void modesReadFromClients(void) {
|
static void modesReadFromClients(void) {
|
||||||
int j;
|
int j;
|
||||||
struct client *c;
|
struct client *c;
|
||||||
|
|
||||||
@ -2371,7 +2376,7 @@ void modesReadFromClients(void) {
|
|||||||
* function here returns as long as there is a single client ready, or
|
* function here returns as long as there is a single client ready, or
|
||||||
* when the specified timeout in milliesconds elapsed, without specifying to
|
* when the specified timeout in milliesconds elapsed, without specifying to
|
||||||
* the caller what client requires to be served. */
|
* the caller what client requires to be served. */
|
||||||
void modesWaitReadableClients(int timeout_ms) {
|
static void modesWaitReadableClients(int timeout_ms) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
fd_set fds;
|
fd_set fds;
|
||||||
int j, maxfd = Modes.maxfd;
|
int j, maxfd = Modes.maxfd;
|
||||||
@ -2400,7 +2405,7 @@ void modesWaitReadableClients(int timeout_ms) {
|
|||||||
/* ============================ Terminal handling ========================== */
|
/* ============================ Terminal handling ========================== */
|
||||||
|
|
||||||
/* Handle resizing terminal. */
|
/* Handle resizing terminal. */
|
||||||
void sigWinchCallback() {
|
void sigWinchCallback(int __attribute__ ((unused))a) {
|
||||||
signal(SIGWINCH, SIG_IGN);
|
signal(SIGWINCH, SIG_IGN);
|
||||||
Modes.interactive_rows = getTermRows();
|
Modes.interactive_rows = getTermRows();
|
||||||
interactiveShowData();
|
interactiveShowData();
|
||||||
@ -2416,7 +2421,7 @@ int getTermRows() {
|
|||||||
|
|
||||||
/* ================================ Main ==================================== */
|
/* ================================ Main ==================================== */
|
||||||
|
|
||||||
void showHelp(void) {
|
static void showHelp(void) {
|
||||||
printf(
|
printf(
|
||||||
"--device-index <index> Select RTL device (default: 0).\n"
|
"--device-index <index> Select RTL device (default: 0).\n"
|
||||||
"--gain <db> Set gain (default: max gain. Use -100 for auto-gain).\n"
|
"--gain <db> Set gain (default: max gain. Use -100 for auto-gain).\n"
|
||||||
@ -2456,7 +2461,7 @@ void showHelp(void) {
|
|||||||
/* This function is called a few times every second by main in order to
|
/* This function is called a few times every second by main in order to
|
||||||
* perform tasks we need to do continuously, like accepting new clients
|
* perform tasks we need to do continuously, like accepting new clients
|
||||||
* from the net, refreshing the screen in interactive mode, and so forth. */
|
* from the net, refreshing the screen in interactive mode, and so forth. */
|
||||||
void backgroundTasks(void) {
|
static void backgroundTasks(void) {
|
||||||
if (Modes.net) {
|
if (Modes.net) {
|
||||||
modesAcceptClients();
|
modesAcceptClients();
|
||||||
modesReadFromClients();
|
modesReadFromClients();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user