/[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 14 - (show annotations)
Mon Dec 3 14:25:40 2007 UTC (16 years, 4 months ago) by dpavlin
File size: 1002 byte(s)
- refactored NMEA parsing into own package from web interface
- script which converts NMEA dump to KML for GoogleMaps
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 # next unless $#a == 12;
29
30 warn "## [$#a] ", join(' ',
31 map { "$_:$a[$_]" }
32 ( 0 .. $#a )
33 ), " from $_\n";
34
35 # is valid?
36 return unless $a[2] eq 'A';
37
38 my $hash;
39 my $i = 1; # skip GPRMC;
40 $hash->{$_} = $a[$i++] foreach ( qw/
41 time validity lat_hhmm lat_ns lon_hhmm lon_ew speed course date var var_ew
42 / );
43
44 $hash->{lat} = hhmm( ( $hash->{lat_ns} eq 'S' ? -1 : 1 ) * $hash->{lat_hhmm} ) || return;
45 $hash->{lon} = hhmm( ( $hash->{lon_ns} eq 'W' ? -1 : 1 ) * $hash->{lon_hhmm} ) || return;
46
47 return if ( $got_it->{ $hash->{lat} . ' ' . $hash->{lon} }++ );
48
49 warn "##>>>> ",dump( $hash );
50 return $hash;
51 }
52
53 return;
54 }
55
56 1;

  ViewVC Help
Powered by ViewVC 1.1.26