-
Notifications
You must be signed in to change notification settings - Fork 1
/
ansrvr-grp-cap.pl
143 lines (109 loc) · 3.72 KB
/
ansrvr-grp-cap.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/perl
#
# ansrvr-grp-cap.pl
# v0.2
#
# Mike Cleckner, KD2FDX
#
# GitHub Repo "cgeek5467/NoAgendaHAMs-APRS-tools" short URL http://itm.im/4gsjq
#
# Perl script using Ham::APRS::FAP to grab APRS packets.
# You need to get it from CPAN and maybe other dependencies.
# This will grab only messages sent to ANSRVR which are CQ command and for a specific group.
#
# Takes one command line argument for the ANSRVR Group to monitor.
#
# Wake up fellow human resource and tune into The No Agenda Show Sundays and Thursdays.
# http://noagendashow.com
#
use strict;
use warnings;
use Ham::APRS::IS;
use Ham::APRS::FAP qw(parseaprs);
use Date::Manip;
my $debugON = 0;
# APRS-IS config
my $IShost = "noam.aprs2.net:14580";
my $ISmycall = "N0CALL";
my $ISfilter = "g/ANSRVR"; # other tries "t/poimqstunw" "t/m g/ANSRVR"
my $ISclient = "ansrvr-grp-cap.pl v0.2";
my ($GMTTime,$Time);
# ANSRVR Command to watch for
my $targetCMD = "CQ";
my $targetGRP = ""; # Get from command line
print "\n";
print "ansrvr-grp-cap.pl\n";
my $num_args = $#ARGV + 1;
if ($num_args != 1)
{
print "\nUsage: ansrvr-grp-cap.pl ansrvr_group_name\n\n";
exit;
}
$targetGRP = uc($ARGV[0]);
my $packetFile = "/var/www/APRS/ANSRVR-${targetGRP}-packets.txt";
my $is = new Ham::APRS::IS($IShost, $ISmycall, 'filter' => $ISfilter, 'appid' => $ISclient);
$is->connect('retryuntil' => 3) || die "Failed to connect: $is->{error}";
$GMTTime = gmtime(time); $Time = &UnixDate($GMTTime, '%Y-%m-%d %H:%M:%S');
print "Connected $IShost at $Time UTC\n";
print "Monitoring '$targetGRP' on 'ANSRVR' ...\n";
print "Ctrl-C to stop\n";
# Be a spinner ... and just spin and spin grabbing packets
for (;;)
{
my $l = $is->getline_noncomment();
next if (!defined $l);
debug("\n--- new packet ---\n$l\n");
my %packetdata;
my $retval = parseaprs($l, \%packetdata);
if ($retval == 1)
{
# For ANSRVR messages, format "command group blah"
my @msgpcs = split(' ', $packetdata{message});
my $msglst = scalar @msgpcs;
my $msgcmd = $msgpcs[0];
my $msggrp = $msgpcs[1];
# check that command+group is the one we are looking
# Watch out for one word and no word messages.
# Don't show no word messages!
if ( (uc($targetCMD) eq uc($msgcmd))
&& (uc($targetGRP) eq uc($msggrp))
&& ($msglst > 2)
)
{
# These are the droids you are looking for ...
debug("MATCH! CMD = $msgcmd\t GRP = $msggrp\n");
my $msgslc = "";
if ($msglst > 3)
{
$msgslc = join(' ',@msgpcs[2..$msglst-1]);
}
else
{
$msgslc = $msgpcs[2];
}
print "\n---\n";
# What time is it!?!?
$GMTTime = gmtime(time);
$Time = &UnixDate($GMTTime, '%Y-%m-%d %H:%M:%S');
my $rssTime = &UnixDate($GMTTime, '%a, %d %b %Y %H:%M:%S UT');
# Print something out. Your choices for packetdata appear to be:
# destination, dstcallsign, digipeaters, messageid, message, body,
# origpacket, type, srccallsign, header
# Format it like other APRS clients do
print "$Time UTC ";
print "$packetdata{srccallsign}\n";
print "N:" . uc($msggrp) ." $msgslc\n";
debug("$packetdata{origpacket}\n");
open (PACKETFILE, ">> $packetFile") || die "problem opening $packetFile\n";
print PACKETFILE "$rssTime#$packetdata{origpacket}\n";
close (PACKETFILE);
}
if ($debugON) { print "---\n"; while (my ($key, $value) = each (%packetdata)) { print "\t$key: $value\n"; } print "---\n"; }
}
}
$is->disconnect() || die "Failed to disconnect: $is->{error}";
sub debug {
my $dtxt = $_[0];
if ($debugON) { print $dtxt; }
return;
}