File Coverage

blib/lib/BT368i/NMEA/GP/RMC.pm
Criterion Covered Total %
statement 9 71 12.6
branch 0 16 0.0
condition n/a
subroutine 3 6 50.0
pod 2 3 66.6
total 14 96 14.5


line stmt bran cond sub pod time code
1             #
2             # Written by Travis Kent Beste
3             # Fri Aug 6 22:13:22 CDT 2010
4              
5             package BT368i::NMEA::GP::RMC;
6              
7 1     1   6 use strict;
  1         2  
  1         31  
8 1     1   5 use vars qw( );
  1         2  
  1         13  
9              
10 1     1   4 use Data::Dumper;
  1         1  
  1         672  
11              
12             our @ISA = qw( );
13              
14             our $VERSION = sprintf("%d.%02d", q$Revision: 1.00 $ =~ /(\d+)\.(\d+)/);
15              
16             #----------------------------------------#
17             #
18             #----------------------------------------#
19             sub new {
20 0     0 0   my $class = shift;
21 0           my %args = shift;
22              
23 0           my %fields = (
24             log_fh => '',
25             log_filename => '',
26              
27             utc_time => '',
28             status => '',
29             latitude => '',
30             latitude_hemisphere => '',
31             longitude => '',
32             longitude_hemisphere => '',
33             speed => '',
34             course => '',
35             utc_date => '',
36             magnetic_variation => '',
37             magnetic_variation_direction => '',
38             );
39              
40 0           my $self = {
41             %fields,
42             };
43 0           bless $self, $class;
44              
45 0           return $self;
46             }
47              
48             #----------------------------------------#
49             #
50             #----------------------------------------#
51             sub print {
52 0     0 1   my $self = shift;
53              
54 0           print "utc_time : " . $self->{utc_time} . "\n";
55 0 0         if ($self->{status} eq 'A') {
    0          
56 0           print "status : valid position\n";
57             } elsif ($self->{status} eq 'V') {
58 0           print "status : NAV receiver warning\n";
59             }
60 0           print "latitude : " . $self->{latitude} . "\n";
61 0 0         if ($self->{latitude_hemisphere} eq 'N') {
    0          
62 0           print "latitude hemisphere : NORTH\n";
63             } elsif ($self->{latitude_hemisphere} eq 'N') {
64 0           print "latitude hemisphere : SOUTH\n";
65             }
66 0           print "longitude : " . $self->{longitude} . "\n";
67 0 0         if ($self->{longitude_hemisphere} eq 'E') {
    0          
68 0           print "hemisphere : EAST\n";
69             } elsif ($self->{longitude_hemisphere} eq 'W') {
70 0           print "hemisphere : WEST\n";
71             }
72 0           print "course : " . $self->{course} . " degrees\n";
73 0           print "speed : " . $self->{speed} . " knots\n";
74 0           print "utc date : " . $self->{utc_date} . "\n";
75 0           print "magnetic variation : ";
76 0 0         if ($self->{magnetic_variation} ne '') {
77 0           print $self->{magnetic_variation} . " degrees\n";
78             } else {
79 0           print "\n";
80             }
81 0           print "magnetic variation direction : " . $self->{magnetic_variation_direction} . "\n";
82             }
83              
84             #----------------------------------------#
85             #
86             #----------------------------------------#
87             sub parse {
88 0     0 1   my $self = shift;
89 0           my $data = shift;
90              
91             # if we're logging, save data to filehandle
92 0 0         if ($self->{log_fh}) {
93 0           print { $self->{log_fh} } $data . "\n";
  0            
94             }
95              
96 0           $data =~ s/\*..$//; # remove the last three bytes
97 0           my @args = split(/,/, $data);
98              
99             # 1) UTC time of position fix, hhmmss format
100 0           my @utc_time = split(//, $args[1]);
101 0           my $hh = $utc_time[0]; $hh .= $utc_time[1];
  0            
102 0           my $mm = $utc_time[2]; $mm .= $utc_time[3];
  0            
103 0           my $ss = $utc_time[4]; $ss .= $utc_time[5];
  0            
104 0           my $ms = $utc_time[7]; $ms .= $utc_time[8]; $ms .= $utc_time[9];
  0            
  0            
105             #print "utc_time : $hh, $mm, $ss $ms - $args[1]\n";
106 0           $self->{utc_time} = $hh . ':' . $mm . ':' . $ss . '.' . $ms;
107              
108             # 2) Status, A=Valid position, V=NAV receiver warning
109 0           $self->{status} = $args[2];
110              
111             # 3) Latitude, ddmm.mmmm format (leading zeros sent)
112 0           $self->{latitude} = $args[3];
113              
114             # 4) Latitude hemisphere, N or S
115 0           $self->{latitude_hemisphere} = $args[4];
116              
117             # 5) Longitude, dddmm.mmmm format (leading zeros sent)
118 0           $self->{longitude} = $args[5];
119              
120             # 6) Longitude hemisphere, E or W
121 0           $self->{longitude_hemisphere} = $args[6];
122              
123             # 7) Speed over ground, 0.0 to 999.9 knots
124 0           $self->{speed} = $args[7];
125              
126             # 8) Course over ground, 000.0 to 359.9 degrees, true (leading zeros sent)
127 0           $self->{course} = $args[8];
128              
129             # 9) UTC date of position fix, ddmmyy format
130 0           my @utc_date = split(//, $args[9]);
131 0           my $dd = $utc_date[0]; $dd .= $utc_date[1];
  0            
132 0           my $mm = $utc_date[2]; $mm .= $utc_date[3];
  0            
133 0           my $yy = $utc_date[4]; $yy .= $utc_date[5];
  0            
134 0           $self->{utc_date} = $yy . '-' . $mm . '-' . $dd;
135              
136             # 10) Magnetic variation, 000.0 to 180.0 degrees (leading zeros sent)
137 0           $self->{magnetic_variation} = $args[10];
138              
139             # 11) Magnetic variation direction, E or W (westerly variation adds to true course)
140 0           $self->{magnetic_variation_direction} = $args[11];
141             }
142              
143             1;
144              
145             __END__