Skip to content

Commit

Permalink
add label filter
Browse files Browse the repository at this point in the history
  • Loading branch information
TLeconte committed Dec 8, 2018
1 parent de0c5ae commit bec294b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ It allows the user to directly monitor to up to 8 different frequencies simultan

-i station id: id use in acarsdec network format.

-b filter: filter output by label (ex: -b "H1:Q0" : only output messages with label H1 or Q0"

for the RTLSDR device

-r rtldevice f1 [f2] ... [fN] : decode from rtl dongle number or S/N "rtldevice" receiving at VHF frequencies "f1" and optionally "f2" to "fN" in Mhz (ie : -r 0 131.525 131.725 131.825 ). Frequencies must be within the same 2MHz.
Expand Down
10 changes: 9 additions & 1 deletion acarsdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <libacars/version.h>
#endif
#include "acarsdec.h"
extern void build_label_filter(char *arg);

channel_t channel[MAXNBCHANNELS];
unsigned int nbch;
Expand Down Expand Up @@ -147,11 +148,13 @@ int main(int argc, char **argv)
int res, n;
struct sigaction sigact;
char sys_hostname[8];
char *lblf=NULL;

gethostname(sys_hostname, sizeof(sys_hostname));
idstation = strndup(sys_hostname, 8);

res = 0;
while ((c = getopt(argc, argv, "varfsRo:t:g:Ap:n:N:j:l:c:i:L:G:")) != EOF) {
while ((c = getopt(argc, argv, "varfsRo:t:g:Ap:n:N:j:l:c:i:L:G:b:")) != EOF) {

switch (c) {
case 'v':
Expand All @@ -163,6 +166,9 @@ int main(int argc, char **argv)
case 't':
mdly = atoi(optarg);
break;
case 'b':
lblf=optarg;
break;
#ifdef WITH_ALSA
case 'a':
res = initAlsa(argv, optind);
Expand Down Expand Up @@ -248,6 +254,8 @@ int main(int argc, char **argv)
exit(res);
}

build_label_filter(lblf);

res = initOutput(logfilename, Rawaddr);
if (res) {
fprintf(stderr, "Unable to init output\n");
Expand Down
31 changes: 31 additions & 0 deletions label.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,38 @@
#include <string.h>
#include "acarsdec.h"

static char *lblfilter[1024];

void build_label_filter(char *arg)
{
int i=0;
char *aptr;

lblfilter[0]=NULL;
if(arg==NULL) return;

aptr=strtok(strdup(arg),":");
while(aptr) {
lblfilter[i]=aptr; i++;
aptr=strtok(NULL,":");
}
lblfilter[i]=NULL;
}

int label_filter(char *lbl)
{
int i;

if(lblfilter[0]==NULL) return 1;

i=0;
while(lblfilter[i]) {
if(strcmp(lbl,lblfilter[i])==0) return 1;
i++;
}

return 0;
}

static int label_q1(char *txt,oooi_t *oooi)
{
Expand Down
4 changes: 4 additions & 0 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#endif
#include "acarsdec.h"
#include "cJSON.h"
extern int label_filter(char *lbl);

extern int inmode;
extern char *idstation;
Expand Down Expand Up @@ -558,6 +559,9 @@ void outputmsg(const msgblk_t * blk)
/* txt end */
msg.be = blk->txt[blk->len - 1];


if(label_filter(msg.label)==0) return;

if(outflg)
fl=addFlight(&msg,blk->chn,blk->tv);

Expand Down

0 comments on commit bec294b

Please sign in to comment.