/[maps]/lib/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

Annotation of /lib/NMEA.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 26 - (hide annotations)
Fri Dec 7 03:03:42 2007 UTC (16 years, 4 months ago) by dpavlin
File size: 1007 byte(s)
paths re-org
1 dpavlin 14 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 dpavlin 26 my $stats;
20 dpavlin 14
21     sub line {
22     my $self = shift;
23     my $l = shift || return;
24    
25     if ( m/\$GPRMC/ ) {
26     chomp;
27     my @a = split(/,/,$_);
28    
29 dpavlin 16 return unless $#a == 12;
30 dpavlin 14
31 dpavlin 16 # warn "## [$#a] ", join(' ', map { "$_:$a[$_]" } ( 0 .. $#a )), " from $_\n";
32 dpavlin 14
33     # is valid?
34     return unless $a[2] eq 'A';
35    
36     my $hash;
37     my $i = 1; # skip GPRMC;
38     $hash->{$_} = $a[$i++] foreach ( qw/
39     time validity lat_hhmm lat_ns lon_hhmm lon_ew speed course date var var_ew
40     / );
41    
42     $hash->{lat} = hhmm( ( $hash->{lat_ns} eq 'S' ? -1 : 1 ) * $hash->{lat_hhmm} ) || return;
43 dpavlin 16 $hash->{lon} = hhmm( ( $hash->{lon_ew} eq 'W' ? -1 : 1 ) * $hash->{lon_hhmm} ) || return;
44 dpavlin 14
45     return if ( $got_it->{ $hash->{lat} . ' ' . $hash->{lon} }++ );
46    
47 dpavlin 16 # warn "##>>>> ",dump( $hash );
48 dpavlin 14 return $hash;
49     }
50    
51     return;
52     }
53    
54     1;

  ViewVC Help
Powered by ViewVC 1.1.26