Skip to content

Commit

Permalink
Cleaned up use of module, did some more linting
Browse files Browse the repository at this point in the history
  • Loading branch information
khaytsus committed Aug 4, 2016
1 parent 49d5e94 commit fc65349
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 70 deletions.
96 changes: 52 additions & 44 deletions aprs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use strict;
use warnings;
use FindBin;
use lib $FindBin::Bin;

our $VERSION = '1.2';

Expand All @@ -17,24 +19,25 @@
use aprsobjects;

# Get default settings from our aprsobjects module
my ( $debug, $moduleversion, $icalurl, $startinterval, $delayinterval,
@outputs )
= get_defaults();
my $debug = $aprsobjects::debug;
my $moduleversion = $aprsobjects::moduleversion;
my $icalurl = $aprsobjects::icalurl;
my $startinterval = $aprsobjects::startinterval;
my $delayinterval = $aprsobjects::delayinterval;
my @outputs = @aprsobjects::outputs;
my @objects = @aprsobjects::objects;

# Test to make sure our versions match so we know our fields are going to be correct
if ( $VERSION ne $moduleversion ) {
die 'Our program version number '
. $VERSION
. ' does not match our module version '
. $moduleversion . "\n";
. $VERSION
. ' does not match our module version '
. $moduleversion . "\n";
}

# Get our initial delay for advertisements which will be incremented for each additional object
my $delay = $startinterval;

# Create our empty objects variable to populate from our module or ical
my @objects;

# See if we're using iCal and if so, make sure iCal::Parser and LWP::Simple are available
my $ical;

Expand All @@ -50,7 +53,8 @@
}

# Get the current time and set up variables to use later
my ($lt_sec, $lt_min, $lt_hour, $lt_mday, $lt_mon,
my (
$lt_sec, $lt_min, $lt_hour, $lt_mday, $lt_mon,
$lt_year, $lt_wday, $lt_yday, $lt_isdst
) = localtime();
$lt_year += 1900;
Expand All @@ -65,12 +69,12 @@
else {
# Get our objects from our aprsobjects module
print "\n### Objects generated using module data\n";
(@objects) = get_objects();
}

# Iterate through each entry in the @objects array
foreach my $entry (@objects) {
my ($DOW, $ENABLED, $MONTH, $DAY, $YEAR,
my (
$DOW, $ENABLED, $MONTH, $DAY, $YEAR,
$STARTTIME, $ENDTIME, $TIMEBEFORE, $OBJNAME, $MHZ,
$LAT, $LON, $FREQ, $OFFSET, $TONE,
$HEIGHT, $POWER, $SYMBOL, $COMMENT
Expand Down Expand Up @@ -104,10 +108,13 @@
# Determine if this object matches the day, is an every-day object, or is dated with todays date
# If the object is enabled make sure that dated events are only matched on their proper date regardless
# of DOW settings, so make sure daily vs single day vs dated events are tested separately.
if ($ENABLED
if (
$ENABLED

# This object matches a single-day event, not a dated event
&& (( ( $DOW eq $lt_wday && $DAY !~ /\d+/x )
&& (
(
( $DOW eq $lt_wday && $DAY !~ /\d+/x )

# This object matches a daily event, not a dated event
|| ( $DOW eq "-1" && $DAY !~ /\d+/x )
Expand All @@ -116,7 +123,7 @@
# If it's not a single or daily event, test to see if this object matches todays date
|| ( $MONTH eq $lt_mon && $DAY eq $lt_mday && $YEAR eq $lt_year )
)
)
)
{

# Determine if the object should be advertised based on comparing our adjusted start time or always if start/end are 0
Expand Down Expand Up @@ -160,39 +167,38 @@

# If we're a dated event
if ( $DAY =~ /\d+/x ) {
$datestring
= ' ('
. $MONTH . '/'
. $DAY . '/'
. $YEAR . ') ('
. $STARTTIME . ' - '
. $ENDTIME . ') ';
$datestring = ' ('
. $MONTH . '/'
. $DAY . '/'
. $YEAR . ') ('
. $STARTTIME . ' - '
. $ENDTIME . ') ';

}

print "\n# " . $OBJNAME . $datestring . "\n";

foreach my $output (@outputs) {
print 'OBEACON '
. $output
. ' DELAY='
. $delay
. ' EVERY='
. $FREQ
. ' OBJNAME='
. $OBJNAME . ' LAT='
. $LAT
. ' LONG='
. $LON
. ' SYMBOL='
. $SYMBOL
. ' FREQ='
. $MHZ
. $offset_string
. $tone_string
. $height_string
. $power_string
. $comment_string . "\n";
. $output
. ' DELAY='
. $delay
. ' EVERY='
. $FREQ
. ' OBJNAME='
. $OBJNAME . ' LAT='
. $LAT
. ' LONG='
. $LON
. ' SYMBOL='
. $SYMBOL
. ' FREQ='
. $MHZ
. $offset_string
. $tone_string
. $height_string
. $power_string
. $comment_string . "\n";

# Update the delay value so each object advertises $delayinterval seconds after the previous one
$delay = update_delay( $delay, $delayinterval );
Expand Down Expand Up @@ -225,7 +231,7 @@ sub ical_parse {
my $parser = iCal::Parser->new(%defaults);
my $hash = $parser->parse_strings($file);

# Get the events for today (specifically; ignore the rest of the iCal data)
# Get the events for today (specifically; ignore the rest of the iCal data)
my $todayhash = $hash->{events}->{$lt_year}->{$lt_mon}->{$lt_mday};
my @todayarray = $todayhash;

Expand Down Expand Up @@ -282,7 +288,8 @@ sub ical_parse {

# Build a string of this objects fields
sub build_object {
my ($start, $end, $allday, $dow, $month,
my (
$start, $end, $allday, $dow, $month,
$day, $year, $TRANSP, $DESCRIPTION
) = @_;

Expand Down Expand Up @@ -314,7 +321,8 @@ sub split_description {
# We literally get the string \n for carriage returns here. Yuck?
my (@description) = split( /\\n/xs, $description );

my ($timebefore, $objname, $mhz, $lat, $lon, $freq,
my (
$timebefore, $objname, $mhz, $lat, $lon, $freq,
$offset, $tone, $height, $power, $symbol, $comment
);

Expand Down
45 changes: 19 additions & 26 deletions aprsobjects.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,26 @@ package aprsobjects;

require Exporter;
@ISA = ("Exporter");
@EXPORT = ( "get_objects", "get_defaults" );

# Set default options
sub get_defaults {

# Debug mode
my $debug = 0;
# Debug mode
our $debug = 0;

# Version control our module to make sure our field expections are correct
my $moduleversion = '1.2';
# Version control our module to make sure our field expections are correct
our $moduleversion = '1.2';

# If using iCal for our source, put the URL here
my $ical = "https://calendar.google.com/calendar/ical/vmk180ahs4stmati3go5dek4c8%40group.calendar.google.com/private-dbfa0949d58f94bf76f763f75bc8b107/basic.ics";
# If using iCal for our source, put the URL here
our $icalurl = "https://calendar.google.com/calendar/ical/vmk180ahs4stmati3go5dek4c8%40group.calendar.google.com/private-dbfa0949d58f94bf76f763f75bc8b107/basic.ics";

# How long to delay our initial beacon advertisement, in direwolf format (min:sec)
my $startinterval = '0:30';
# How long to delay our initial beacon advertisement, in direwolf format (min:sec)
our $startinterval = '0:30';

# How many more seconds of delay to add between each additional beacon so advertisements are spaced out
my $delayinterval = '15';
# How many more seconds of delay to add between each additional beacon so advertisements are spaced out
our $delayinterval = '15';

# Define our output paths for every object
my @outputs = ( 'sendto=IG', 'via="WIDE1-1,WIDE2-1"' );

return ( $debug, $moduleversion, $ical, $startinterval, $delayinterval, @outputs );
}
# Define our output paths for every object
our @outputs = ( 'sendto=IG', 'via="WIDE1-1,WIDE2-1"' );

# Objects array is a pipe (|) separated list of fields
## Leave empty for unused field, ie: |data|data||data|data
Expand All @@ -51,14 +46,12 @@ sub get_defaults {
# SYMBOL - APRS Symbol to use for object
# COMMENT (OPTIONAL) - Description of object

sub get_objects {
my @objects = (
# DOW ENABLED MONTH DAY YEAR STARTTIME ENDTIME TIMEBEFORE OBJNAME MHZ LAT LON FREQ OFFSET TONE HEIGHT POWER SYMBOL COMMENT
'0|1||||21:00|22:00|15|NETATVCOM|146.760|38^02.380N|84^24.170W|5:00|-0.600||750|50|/N|9pm R30m AVT and Specialized Communications Net Sun',
'-1|1|9|24|2016|8:00|14:00|60|CK-HAMFST|146.865|37^43.778N|84^19.012W|5:00|-0.600|192.8|200|50|/E|8am to 2pm Today Central Kentucky Hamfest',
'-1|1||||0|0|15|146.940/R|146.940|38^02.856N|84^29.943W|10:00|-0.600|88.5|500|50|/r|R45m KY4K IRLP node 4945 in Lexington, KY',
);
return (@objects);
}
our @objects = (

# DOW ENABLED MONTH DAY YEAR STARTTIME ENDTIME TIMEBEFORE OBJNAME MHZ LAT LON FREQ OFFSET TONE HEIGHT POWER SYMBOL COMMENT
'0|1||||21:00|22:00|15|NETATVCOM|146.760|38^02.380N|84^24.170W|5:00|-0.600||750|50|/N|9pm R30m AVT and Specialized Communications Net Sun',
'-1|1|9|24|2016|8:00|14:00|60|CK-HAMFST|146.865|37^43.778N|84^19.012W|5:00|-0.600|192.8|200|50|/E|8am to 2pm Today Central Kentucky Hamfest',
'-1|1||||0|0|15|146.940/R|146.940|38^02.856N|84^29.943W|10:00|-0.600|88.5|500|50|/r|R45m KY4K IRLP node 4945 in Lexington, KY',
);

1;

0 comments on commit fc65349

Please sign in to comment.