Add command line option to output packet timing information

pull/13/head
Bertold Van den Bergh 2019-02-16 03:14:51 +01:00
rodzic 252f33b128
commit efd05adf88
11 zmienionych plików z 40 dodań i 20 usunięć

Wyświetl plik

@ -151,7 +151,7 @@ int send_nmea( const char *sentence, unsigned int length) {
return 0; 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 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){
debug_nmea=_debug_nmea; debug_nmea=_debug_nmea;
use_tcp = use_tcp_listener; use_tcp = use_tcp_listener;
pthread_mutex_init(&message_mutex, NULL); pthread_mutex_init(&message_mutex, NULL);
@ -171,7 +171,7 @@ int init_ais_decoder(char * host, char * port ,int show_levels,int _debug_nmea,i
} }
if (show_levels) on_sound_level_changed=sound_level_changed; if (show_levels) on_sound_level_changed=sound_level_changed;
on_nmea_sentence_received=nmea_sentence_received; on_nmea_sentence_received=nmea_sentence_received;
initSoundDecoder(buf_len,time_print_stats); initSoundDecoder(buf_len,time_print_stats,add_sample_num);
return 0; return 0;
} }

Wyświetl plik

@ -1,6 +1,6 @@
#ifndef __AIS_RL_AIS_INC_ #ifndef __AIS_RL_AIS_INC_
#define __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 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);
void run_rtlais_decoder(short * buff, int len); void run_rtlais_decoder(short * buff, int len);
const char *aisdecoder_next_message(); const char *aisdecoder_next_message();
int free_ais_decoder(void); int free_ais_decoder(void);

Wyświetl plik

@ -34,7 +34,7 @@ decoder_on_nmea_sentence_received on_nmea_sentence_received=NULL;
#include <dmalloc.h> #include <dmalloc.h>
#endif #endif
void protodec_initialize(struct demod_state_t *d, struct serial_state_t *serial, char chanid) void protodec_initialize(struct demod_state_t *d, struct serial_state_t *serial, char chanid, int add_sample_num)
{ {
memset(d, 0, sizeof(struct demod_state_t)); memset(d, 0, sizeof(struct demod_state_t));
@ -48,6 +48,7 @@ void protodec_initialize(struct demod_state_t *d, struct serial_state_t *serial,
protodec_reset(d); protodec_reset(d);
d->seqnr = 0; d->seqnr = 0;
d->add_sample_num = add_sample_num;
d->buffer = hmalloc(DEMOD_BUFFER_LEN); d->buffer = hmalloc(DEMOD_BUFFER_LEN);
d->rbuffer = hmalloc(DEMOD_BUFFER_LEN); d->rbuffer = hmalloc(DEMOD_BUFFER_LEN);
@ -210,7 +211,11 @@ void protodec_generate_nmea(struct demod_state_t *d, int bufferlen, int fillbits
nmeachk = d->nmea[m++]; nmeachk = d->nmea[m++];
while (d->nmea[m] != '*') nmeachk ^= d->nmea[m++]; while (d->nmea[m] != '*') nmeachk ^= d->nmea[m++];
sprintf(&d->nmea[k + 3], "%02X\r\n", nmeachk); if (d->add_sample_num){
sprintf(&d->nmea[k + 3], "%02X,%lu\r\n", nmeachk, d->startsample);
}else{
sprintf(&d->nmea[k + 3], "%02X\r\n", nmeachk);
}
if (on_nmea_sentence_received != NULL) if (on_nmea_sentence_received != NULL)
on_nmea_sentence_received(d->nmea, k+7, sentences, sentencenum); on_nmea_sentence_received(d->nmea, k+7, sentences, sentencenum);
} while (sentencenum < sentences); } while (sentencenum < sentences);
@ -245,7 +250,7 @@ void protodec_getdata(int bufferlen, struct demod_state_t *d)
return; // unsupported packet type return; // unsupported packet type
} }
void protodec_decode(char *in, int count, struct demod_state_t *d) void protodec_decode(char *in, int count, struct demod_state_t *d, unsigned long samplenum)
{ {
int i = 0; int i = 0;
int bufferlength, correct; int bufferlength, correct;
@ -330,6 +335,7 @@ void protodec_decode(char *in, int count, struct demod_state_t *d)
if (d->nstartsign >= 7) { if (d->nstartsign >= 7) {
if (in[i] == 0) { if (in[i] == 0) {
d->state = ST_DATA; d->state = ST_DATA;
d->startsample = samplenum;
d->nstartsign = 0; d->nstartsign = 0;
d->antallenner = 0; d->antallenner = 0;
memset(d->buffer, 0, DEMOD_BUFFER_LEN); memset(d->buffer, 0, DEMOD_BUFFER_LEN);

Wyświetl plik

@ -31,7 +31,7 @@
#define DEMOD_BUFFER_LEN 450 #define DEMOD_BUFFER_LEN 450
#define MAX_AIS_PACKET_TYPE 27 #define MAX_AIS_PACKET_TYPE 27
#define NMEABUFFER_LEN 100 #define NMEABUFFER_LEN 128
struct demod_state_t { struct demod_state_t {
char chanid; char chanid;
@ -52,14 +52,17 @@ struct demod_state_t {
int lostframes2; int lostframes2;
unsigned char seqnr; unsigned char seqnr;
unsigned long startsample;
int add_sample_num;
struct serial_state_t *serial; struct serial_state_t *serial;
char *nmea; char *nmea;
}; };
void protodec_initialize(struct demod_state_t *d, struct serial_state_t *serial, char chanid); void protodec_initialize(struct demod_state_t *d, struct serial_state_t *serial, char chanid, int add_sample_num);
void protodec_reset(struct demod_state_t *d); void protodec_reset(struct demod_state_t *d);
void protodec_getdata(int bufferlengde, struct demod_state_t *d); void protodec_getdata(int bufferlengde, struct demod_state_t *d);
void protodec_decode(char *in, int count, struct demod_state_t *d); void protodec_decode(char *in, int count, struct demod_state_t *d, unsigned long samplenum);
#endif #endif

Wyświetl plik

@ -47,7 +47,7 @@ static float coeffs[]={
#define COEFFS_L 36 #define COEFFS_L 36
struct receiver *init_receiver(char name, int num_ch, int ch_ofs) struct receiver *init_receiver(char name, int num_ch, int ch_ofs, int add_sample_num)
{ {
struct receiver *rx; struct receiver *rx;
@ -57,7 +57,7 @@ struct receiver *init_receiver(char name, int num_ch, int ch_ofs)
rx->filter = filter_init(COEFFS_L, coeffs); rx->filter = filter_init(COEFFS_L, coeffs);
rx->decoder = hmalloc(sizeof(struct demod_state_t)); rx->decoder = hmalloc(sizeof(struct demod_state_t));
protodec_initialize(rx->decoder, NULL, name); protodec_initialize(rx->decoder, NULL, name, add_sample_num);
rx->name = name; rx->name = name;
rx->lastbit = 0; rx->lastbit = 0;
@ -105,6 +105,8 @@ void receiver_run(struct receiver *rx, short *buf, int len)
maxval = filter_run_buf(rx->filter, buf, filtered, rx_num_ch, len); maxval = filter_run_buf(rx->filter, buf, filtered, rx_num_ch, len);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
rx->samplenum++;
out = filtered[i]; out = filtered[i];
curr = (out > 0); curr = (out > 0);
@ -125,7 +127,7 @@ void receiver_run(struct receiver *rx, short *buf, int len)
/* nrzi decode */ /* nrzi decode */
b = !(bit ^ rx->lastbit); b = !(bit ^ rx->lastbit);
/* feed to the decoder */ /* feed to the decoder */
protodec_decode(&b, 1, rx->decoder); protodec_decode(&b, 1, rx->decoder, rx->samplenum);
rx->lastbit = bit; rx->lastbit = bit;
rx->pll &= 0xffff; rx->pll &= 0xffff;

Wyświetl plik

@ -46,9 +46,10 @@ struct receiver {
struct demod_state_t *decoder; struct demod_state_t *decoder;
int prev; int prev;
time_t last_levellog; time_t last_levellog;
unsigned long samplenum;
}; };
extern struct receiver *init_receiver(char name, int num_ch, int ch_ofs); extern struct receiver *init_receiver(char name, int num_ch, int ch_ofs, int add_sample_num);
extern void free_receiver(struct receiver *rx); extern void free_receiver(struct receiver *rx);
extern void receiver_run(struct receiver *rx, short *buf, int len); extern void receiver_run(struct receiver *rx, short *buf, int len);

Wyświetl plik

@ -45,15 +45,15 @@ static void readBuffers();
static time_t tprev=0; static time_t tprev=0;
static int time_print_stats=0; static int time_print_stats=0;
int initSoundDecoder(int buf_len,int _time_print_stats) int initSoundDecoder(int buf_len,int _time_print_stats, int add_sample_num)
{ {
sound_channels=SOUND_CHANNELS_STEREO; sound_channels=SOUND_CHANNELS_STEREO;
channels = sound_channels == SOUND_CHANNELS_MONO ? 1 : 2; channels = sound_channels == SOUND_CHANNELS_MONO ? 1 : 2;
time_print_stats=_time_print_stats; time_print_stats=_time_print_stats;
tprev=time(NULL); // for decoder statistics tprev=time(NULL); // for decoder statistics
buffer = (short *) hmalloc(channels*sizeof(short)*buf_len); buffer = (short *) hmalloc(channels*sizeof(short)*buf_len);
rx_a = init_receiver('A', 2, 0); rx_a = init_receiver('A', 2, 0, add_sample_num);
rx_b = init_receiver('B', 2, 1); rx_b = init_receiver('B', 2, 1, add_sample_num);
return 1; return 1;
} }

Wyświetl plik

@ -26,7 +26,7 @@ typedef enum {
} Sound_Driver; } Sound_Driver;
extern char errorSoundDecoder[]; extern char errorSoundDecoder[];
int initSoundDecoder(int buf_len,int _time_print_stats); int initSoundDecoder(int buf_len,int _time_print_stats, int add_sample_num);
void runSoundDecoder(int *stop); void runSoundDecoder(int *stop);
void freeSoundDecoder(void); void freeSoundDecoder(void);
void run_mem_decoder(short * buf, int len,int max_buf_len); void run_mem_decoder(short * buf, int len,int max_buf_len);

6
main.c
Wyświetl plik

@ -55,6 +55,7 @@ void usage(void)
"\t[-T use TCP communication, rtl-ais is tcp server ( -h is ignored)\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[-t time to keep ais messages in sec, using tcp listener (default: 15)\n"
"\t[-n log NMEA sentences to console (stderr) (default off)]\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" "\t[-L log sound levels to console (stderr) (default off)]\n\n"
"\t[-S seconds_for_decoder_stats (default 0=off)]\n\n" "\t[-S seconds_for_decoder_stats (default 0=off)]\n\n"
"\tWhen the built-in AIS decoder is disabled the samples are sent to\n" "\tWhen the built-in AIS decoder is disabled the samples are sent to\n"
@ -103,7 +104,7 @@ int main(int argc, char **argv)
config.host = strdup("127.0.0.1"); config.host = strdup("127.0.0.1");
config.port = strdup("10110"); config.port = strdup("10110");
while ((opt = getopt(argc, argv, "l:r:s:o:EODd:g:p:RATt:P:h:nLS:?")) != -1) while ((opt = getopt(argc, argv, "l:r:s:o:EODd:g:p:RATIt:P:h:nLS:?")) != -1)
{ {
switch (opt) { switch (opt) {
case 'l': case 'l':
@ -144,6 +145,9 @@ int main(int argc, char **argv)
case 'A': case 'A':
config.use_internal_aisdecoder=0; config.use_internal_aisdecoder=0;
break; break;
case 'I':
config.add_sample_num = 1;
break;
case 'P': case 'P':
config.port=strdup(optarg); config.port=strdup(optarg);
break; break;

Wyświetl plik

@ -481,6 +481,8 @@ void rtl_ais_default_config(struct rtl_ais_config *config)
config->port=NULL; config->port=NULL;
config->filename = "-"; config->filename = "-";
config->add_sample_num = 0;
} }
struct rtl_ais_context *rtl_ais_start(struct rtl_ais_config *config) struct rtl_ais_context *rtl_ais_start(struct rtl_ais_config *config)
@ -587,7 +589,7 @@ struct rtl_ais_context *rtl_ais_start(struct rtl_ais_config *config)
} }
} }
else{ // Internal AIS decoder 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); 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);
if(ret != 0){ if(ret != 0){
fprintf(stderr,"Error initializing built-in AIS decoder\n"); fprintf(stderr,"Error initializing built-in AIS decoder\n");
rtlsdr_cancel_async(ctx->dev); rtlsdr_cancel_async(ctx->dev);

Wyświetl plik

@ -31,6 +31,8 @@ struct rtl_ais_config
/* Aisdecoder */ /* Aisdecoder */
int show_levels, debug_nmea; int show_levels, debug_nmea;
char *port, *host, *filename; char *port, *host, *filename;
int add_sample_num;
}; };
struct rtl_ais_context; struct rtl_ais_context;