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

New feature: -k flag (keep streaming new data to TCP connections) #34

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
44 changes: 18 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,30 @@ LDFLAGS+=-lpthread -lm
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif

UNAME := $(shell uname)
ifeq ($(UNAME),Linux)
#Conditional for Linux
CFLAGS+= $(shell pkg-config --cflags librtlsdr)
LDFLAGS+=$(shell pkg-config --libs librtlsdr)

CFLAGS += $(shell pkg-config --cflags librtlsdr libusb-1.0)
LDFLAGS +=$(shell pkg-config --libs librtlsdr libusb-1.0)
else ifeq ($(UNAME),Darwin)
CFLAGS += $(shell pkg-config --cflags librtlsdr libusb-1.0)
LDFLAGS += $(shell pkg-config --libs librtlsdr libusb-1.0)
else
#
#ADD THE CORRECT PATH FOR LIBUSB AND RTLSDR
#TODO:
# CMAKE will be much better or create a conditional pkg-config


# RTLSDR
RTLSDR_INCLUDE=/tmp/rtl-sdr/include
RTLSDR_LIB=/tmp/rtl-sdr/build/src
#ADD THE CORRECT PATH FOR LIBUSB AND RTLSDR
#TODO:
# CMAKE will be much better or create a conditional pkg-config

# LIBUSB
LIBUSB_INCLUDE=/tmp/libusb/include/libusb-1.0
LIBUSB_LIB=/tmp/libusb/lib

ifeq ($(UNAME),Darwin)
#Conditional for OSX
CFLAGS+= -I/usr/local/include/ -I$(LIBUSB_INCLUDE) -I$(RTLSDR_INCLUDE)
LDFLAGS+= -L/usr/local/lib -L$(LIBUSB_LIB) -L$(RTLSDR_LIB) -lrtlsdr -lusb-1.0
else
#Conditional for Windows
CFLAGS+=-I $(LIBUSB_INCLUDE) -I $(RTLSDR_INCLUDE)
LDFLAGS+=-L$(LIBUSB_INCLUDE) -L$(RTLSDR_LIB) -L/usr/lib -lusb-1.0 -lrtlsdr -lWs2_32
endif
# RTLSDR
RTLSDR_INCLUDE=/tmp/rtl-sdr/include
RTLSDR_LIB=/tmp/rtl-sdr/build/src

# LIBUSB
LIBUSB_INCLUDE=/opt/homebrew/Cellar/libusb/1.0.24/include
LIBUSB_LIB=/opt/homebrew/Cellar/libusb/1.0.24/lib

#Conditional for Windows
CFLAGS+=-I $(LIBUSB_INCLUDE) -I $(RTLSDR_INCLUDE)
LDFLAGS+=-L$(LIBUSB_INCLUDE) -L$(RTLSDR_LIB) -L/usr/lib -lusb-1.0 -lrtlsdr -lWs2_32
endif

CC?=gcc
Expand Down
4 changes: 2 additions & 2 deletions aisdecoder/aisdecoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ int send_nmea( const char *sentence, unsigned int length) {
return 0;
}

int init_ais_decoder(char * host, char * port ,int show_levels,int _debug_nmea,int buf_len,int time_print_stats, int use_tcp_listener, int tcp_keep_ais_time, int add_sample_num){
int init_ais_decoder(char * host, char * port ,int show_levels,int _debug_nmea,int buf_len,int time_print_stats, int use_tcp_listener, int tcp_keep_ais_time, int tcp_stream_forever, int add_sample_num){
debug_nmea=_debug_nmea;
use_tcp = use_tcp_listener;
pthread_mutex_init(&message_mutex, NULL);
Expand All @@ -165,7 +165,7 @@ int init_ais_decoder(char * host, char * port ,int show_levels,int _debug_nmea,i
}
}
else {
if (!initTcpSocket(port, debug_nmea, tcp_keep_ais_time)) {
if (!initTcpSocket(port, debug_nmea, tcp_keep_ais_time, tcp_stream_forever)) {
return EXIT_FAILURE;
}
}
Expand Down
2 changes: 1 addition & 1 deletion aisdecoder/aisdecoder.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef __AIS_RL_AIS_INC_
#define __AIS_RL_AIS_INC_
int init_ais_decoder(char * host, char * port,int show_levels,int _debug_nmea,int buf_len,int time_print_stats, int use_tcp_listener, int tcp_keep_ais_time, int add_sample_num);
int init_ais_decoder(char * host, char * port,int show_levels,int _debug_nmea,int buf_len,int time_print_stats, int use_tcp_listener, int tcp_keep_ais_time, int tcp_stream_forever, int add_sample_num);
void run_rtlais_decoder(short * buff, int len);
const char *aisdecoder_next_message();
int free_ais_decoder(void);
Expand Down
2 changes: 1 addition & 1 deletion aisdecoder/lib/protodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void protodec_generate_nmea(struct demod_state_t *d, int bufferlen, int fillbits
int inc;

unsigned char sentences, sentencenum, nmeachk, letter;
received_t=received_t; // not used here, avoid compiling warnings
(void)(received_t); // not used here, avoid compiling warnings
//6bits to nmea-ascii. One sentence len max 82char
//inc. head + tail.This makes inside datamax 62char multipart, 62 single
senlen = 56; //this is normally not needed.For testing only. May be fixed number
Expand Down
20 changes: 12 additions & 8 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void usage(void)
"\t[-P port (default: 10110)]\n"
"\t[-T use TCP communication, rtl-ais is tcp server ( -h is ignored)\n"
"\t[-t time to keep ais messages in sec, using tcp listener (default: 15)\n"
"\t[-k keep TCP socket open and write new messages to it as they arrive\n"
"\t[-n log NMEA sentences to console (stderr) (default off)]\n"
"\t[-I add sample index to NMEA messages (default off)]\n"
"\t[-L log sound levels to console (stderr) (default off)]\n\n"
Expand All @@ -76,7 +77,7 @@ void usage(void)
static volatile int do_exit = 0;
static void sighandler(int signum)
{
signum = signum;
(void)(signum); // unused argument
fprintf(stderr, "Signal caught, exiting!\n");
do_exit = 1;
}
Expand Down Expand Up @@ -105,7 +106,7 @@ int main(int argc, char **argv)
config.host = strdup("127.0.0.1");
config.port = strdup("10110");

while ((opt = getopt(argc, argv, "l:r:s:o:EODd:g:p:RATIt:P:h:nLS:?")) != -1)
while ((opt = getopt(argc, argv, "l:r:s:o:EODd:g:p:RATIkt:P:h:nLS:?")) != -1)
{
switch (opt) {
case 'l':
Expand Down Expand Up @@ -152,12 +153,15 @@ int main(int argc, char **argv)
case 'P':
config.port=strdup(optarg);
break;
case 'T':
config.use_tcp_listener=1;
break;
case 't':
config.tcp_keep_ais_time = atoi(optarg);
break;
case 'T':
config.use_tcp_listener=1;
break;
case 't':
config.tcp_keep_ais_time = atoi(optarg);
break;
case 'k':
config.tcp_stream_forever = 1;
break;
case 'h':
config.host=strdup(optarg);
break;
Expand Down
5 changes: 3 additions & 2 deletions rtl_ais.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ void rtl_ais_default_config(struct rtl_ais_config *config)
config->dc_filter=1;
config->edge = 0;
config->use_tcp_listener = 0, config->tcp_keep_ais_time = 15;
config->tcp_stream_forever = 0;
config->use_internal_aisdecoder=1;
config->seconds_for_decoder_stats=0;
/* Aisdecoder */
Expand Down Expand Up @@ -589,7 +590,7 @@ struct rtl_ais_context *rtl_ais_start(struct rtl_ais_config *config)
}
}
else{ // Internal AIS decoder
int ret=init_ais_decoder(config->host,config->port,config->show_levels,config->debug_nmea,ctx->stereo.bl_len,config->seconds_for_decoder_stats, config->use_tcp_listener, config->tcp_keep_ais_time, config->add_sample_num);
int ret=init_ais_decoder(config->host,config->port,config->show_levels,config->debug_nmea,ctx->stereo.bl_len,config->seconds_for_decoder_stats, config->use_tcp_listener, config->tcp_keep_ais_time, config->tcp_stream_forever, config->add_sample_num);
if(ret != 0){
fprintf(stderr,"Error initializing built-in AIS decoder\n");
rtlsdr_cancel_async(ctx->dev);
Expand Down Expand Up @@ -648,7 +649,7 @@ int rtl_ais_isactive(struct rtl_ais_context *ctx)

const char *rtl_ais_next_message(struct rtl_ais_context *ctx)
{
ctx = ctx; //unused for now
(void)(ctx); //unused for now
return aisdecoder_next_message();
}

Expand Down
2 changes: 1 addition & 1 deletion rtl_ais.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct rtl_ais_config

int oversample, dc_filter, use_internal_aisdecoder;
int seconds_for_decoder_stats;
int use_tcp_listener, tcp_keep_ais_time;
int use_tcp_listener, tcp_keep_ais_time, tcp_stream_forever;
/* Aisdecoder */
int show_levels, debug_nmea;
char *port, *host, *filename;
Expand Down
Loading