Skip to content

Commit 6581a8f

Browse files
committedOct 23, 2014
Print receiver range statistics in the log every N seconds, if requested.
This feature makes it easier to quickly see if the receiver is performing as expected, when running gnuais on a remote site on a little Raspberry Pi or some other computer with no GUI, or remotely over ssh.
1 parent c4997f9 commit 6581a8f

File tree

6 files changed

+44
-3
lines changed

6 files changed

+44
-3
lines changed
 

‎gnuais.conf-example

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ SoundChannels both
3737
# to disable level logging below distortion levels.
3838
SoundLevelLog 1
3939

40+
# Print receiver range statistics in the log every N seconds.
41+
# StatsInterval defines the logging interval. Latitude and Longitude of the
42+
# receiver are given in decimal degrees (not degrees and minutes, or seconds).
43+
# Positive values for northern latitude and eastern longitude, negative
44+
# values for southern latitude and western longitude.
45+
#StatsInterval 10
46+
#Latitude 35.2512
47+
#Longitude 110.8175
48+
4049
# AIS data uplink configuration - received APRS data will be posted here
4150
# periodically. Can be used for exporting data to aprs.fi. You need to get a
4251
# key for your receiving site to submit data, please read the instructions

‎src/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
if(HAVE_PULSEAUDIO)
2-
add_executable(gnuais ais.c ais.c cfg.c crc32.c hlog.c input.c out_mysql.c receiver.c splay.c cache.c cfgfile.c filter.c hmalloc.c out_json.c protodec.c rwlock.c serial.c spsymbol.c ipc.c pulseaudio.c)
2+
add_executable(gnuais ais.c ais.c cfg.c crc32.c hlog.c input.c out_mysql.c receiver.c splay.c cache.c range.c cfgfile.c filter.c hmalloc.c out_json.c protodec.c rwlock.c serial.c spsymbol.c ipc.c pulseaudio.c)
33
else()
4-
add_executable(gnuais ais.c ais.c cfg.c crc32.c hlog.c input.c out_mysql.c receiver.c splay.c cache.c cfgfile.c filter.c hmalloc.c out_json.c protodec.c rwlock.c serial.c spsymbol.c ipc.c)
4+
add_executable(gnuais ais.c ais.c cfg.c crc32.c hlog.c input.c out_mysql.c receiver.c splay.c cache.c range.c cfgfile.c filter.c hmalloc.c out_json.c protodec.c rwlock.c serial.c spsymbol.c ipc.c)
55
endif()
66

7-
target_link_libraries(gnuais pthread asound)
7+
target_link_libraries(gnuais pthread asound m)
88

99
if(HAVE_MYSQL)
1010
target_link_libraries(gnuais mysqlclient)

‎src/ais.c

+13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "out_mysql.h"
3939
#include "out_json.h"
4040
#include "cache.h"
41+
#include "range.h"
4142
#include "ipc.h"
4243
#ifdef HAVE_PULSEAUDIO
4344
#include "pulseaudio.h"
@@ -77,6 +78,7 @@ int main(int argc, char *argv[])
7778
#ifdef HAVE_PULSEAUDIO
7879
pa_simple *pa_dev = NULL;
7980
#endif
81+
time_t last_stats = time(NULL);
8082

8183
/* command line */
8284
parse_cmdline(argc, argv);
@@ -244,6 +246,17 @@ int main(int argc, char *argv[])
244246
/* ch b/1/left */
245247
receiver_run(rx_b, buffer, buffer_read);
246248
}
249+
250+
if (stats_interval) {
251+
time_t now = time(NULL);
252+
if (last_stats > now) {
253+
// clock jumped backwards
254+
last_stats = now;
255+
} else if (now - last_stats >= stats_interval) {
256+
last_stats = now;
257+
log_range();
258+
}
259+
}
247260
}
248261

249262
hlog(LOG_NOTICE, "Closing down...");

‎src/cfg.c

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "hmalloc.h"
3636
#include "hlog.h"
3737
#include "cfgfile.h"
38+
#include "range.h"
3839

3940
#ifdef DMALLOC
4041
#include <dmalloc.h>
@@ -58,6 +59,7 @@ char *myemail;
5859

5960
float mylat = -200.0;
6061
float mylng = -200.0;
62+
int have_my_loc;
6163

6264
char *sound_device;
6365
char *sound_in_file;
@@ -359,6 +361,12 @@ int read_config(void)
359361
sound_device = NULL;
360362
}
361363

364+
have_my_loc = (mylat > -90 && mylat < 90 && mylng > -180 && mylng < 180);
365+
if (have_my_loc) {
366+
mylat = lat2rad(mylat);
367+
mylng = lon2rad(mylng);
368+
}
369+
362370
/* put in the new uplink config */
363371
free_uplink_config(&uplink_config);
364372
uplink_config = new_uplink_config;

‎src/cfg.h

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ extern char *mycall;
5454
extern char *myemail;
5555

5656
extern float mylat, mylng;
57+
extern int have_my_loc;
5758

5859
extern char *sound_device;
5960
extern char *sound_in_file;

‎src/protodec.c

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "cfg.h"
3636
#include "hlog.h"
3737
#include "cache.h"
38+
#include "range.h"
3839
#include "ipc.h"
3940

4041
#ifdef DMALLOC
@@ -394,6 +395,9 @@ void protodec_pos(struct demod_state_t *d, int bufferlen, time_t received_t, uns
394395
(float) course / 10.0,
395396
rateofturn,
396397
(float) sog / 10.0);
398+
399+
if (have_my_loc)
400+
update_range((float) latitude / 600000.0, (float) longitude / 600000.0);
397401
}
398402

399403
void protodec_4(struct demod_state_t *d, int bufferlen, time_t received_t, unsigned long mmsi)
@@ -433,6 +437,9 @@ void protodec_4(struct demod_state_t *d, int bufferlen, time_t received_t, unsig
433437
(float) latitude / 600000.0,
434438
(float) longitude / 600000.0,
435439
0, 0.0, 0, 0.0);
440+
441+
if (have_my_loc)
442+
update_range((float) latitude / 600000.0, (float) longitude / 600000.0);
436443
}
437444

438445
void protodec_5(struct demod_state_t *d, int bufferlen, time_t received_t, unsigned long mmsi)
@@ -617,6 +624,9 @@ void protodec_18(struct demod_state_t *d, int bufferlen, time_t received_t, unsi
617624
(float) course / 10.0,
618625
rateofturn,
619626
(float) sog / 10.0);
627+
628+
if (have_my_loc)
629+
update_range((float) latitude / 600000.0, (float) longitude / 600000.0);
620630
}
621631

622632
void protodec_19(struct demod_state_t *d, int bufferlen, time_t received_t, unsigned long mmsi)

0 commit comments

Comments
 (0)
Please sign in to comment.