/[maps]/NMEA.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /NMEA.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (show annotations)
Mon Dec 3 14:57:31 2007 UTC (16 years, 4 months ago) by dpavlin
File size: 996 byte(s)
- remove debugging
- skip invalid lines
1 package NMEA;
2
3 use strict;
4 use warnings;
5
6 use Data::Dump qw/dump/;
7
8 sub hhmm {
9 my $a = shift;
10 if ( $a =~ m/^(\d+)(\d\d\.\d\d+)$/ ) {
11 return sprintf("%1.6f", $1 + ( $2 / 60 ));
12 } else {
13 warn "## skipped $a\n";
14 return;
15 }
16 }
17
18 my $got_it;
19
20 sub line {
21 my $self = shift;
22 my $l = shift || return;
23
24 if ( m/\$GPRMC/ ) {
25 chomp;
26 my @a = split(/,/,$_);
27
28 return unless $#a == 12;
29
30 # warn "## [$#a] ", join(' ', map { "$_:$a[$_]" } ( 0 .. $#a )), " from $_\n";
31
32 # is valid?
33 return unless $a[2] eq 'A';
34
35 my $hash;
36 my $i = 1; # skip GPRMC;
37 $hash->{$_} = $a[$i++] foreach ( qw/
38 time validity lat_hhmm lat_ns lon_hhmm lon_ew speed course date var var_ew
39 / );
40
41 $hash->{lat} = hhmm( ( $hash->{lat_ns} eq 'S' ? -1 : 1 ) * $hash->{lat_hhmm} ) || return;
42 $hash->{lon} = hhmm( ( $hash->{lon_ew} eq 'W' ? -1 : 1 ) * $hash->{lon_hhmm} ) || return;
43
44 return if ( $got_it->{ $hash->{lat} . ' ' . $hash->{lon} }++ );
45
46 # warn "##>>>> ",dump( $hash );
47 return $hash;
48 }
49
50 return;
51 }
52
53 1;

  ViewVC Help
Powered by ViewVC 1.1.26