/[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

Contents of /lib/NMEA.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (show annotations)
Fri Dec 7 04:05:07 2007 UTC (16 years, 4 months ago) by dpavlin
File size: 1633 byte(s)
fix NMEA stats, report on web
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 my $stats;
20
21 sub error {
22 my ( $self, $message, $line ) = @_;
23 push @{ $stats->{errors}->{$message} }, $line;
24 }
25
26 sub stats {
27 my $self = shift;
28 return $stats;
29 }
30
31 sub line {
32 my $self = shift;
33 my $l = shift || return;
34
35 if ( m/\$GPRMC/ ) {
36 chomp;
37 my @a = split(/,/,$_);
38
39 if ( $#a != 12 ) {
40 $self->error( 'invalid line length' => $_ );
41 return;
42 }
43
44 # warn "## [$#a] ", join(' ', map { "$_:$a[$_]" } ( 0 .. $#a )), " from $_\n";
45
46 # is valid?
47 if ( $a[2] ne 'A' ) {
48 $self->error( 'not valid' => $_ );
49 return;
50 }
51
52 my $hash;
53 my $i = 1; # skip GPRMC;
54 $hash->{$_} = $a[$i++] foreach ( qw/
55 time validity lat_hhmm lat_ns lon_hhmm lon_ew speed course date var var_ew
56 / );
57
58 $hash->{lat} = hhmm( ( $hash->{lat_ns} eq 'S' ? -1 : 1 ) * $hash->{lat_hhmm} ) || return;
59 $hash->{lon} = hhmm( ( $hash->{lon_ew} eq 'W' ? -1 : 1 ) * $hash->{lon_hhmm} ) || return;
60
61 if ( $got_it->{ $hash->{lat} . ' ' . $hash->{lon} }++ ) {
62 $self->error( 'duplicate line' => $_ );
63 return;
64 }
65
66 foreach my $n ( qw/lat lon time speed/ ) {
67 $stats->{'min_'.$n} ||= $hash->{$n};
68 $stats->{'max_'.$n} ||= $hash->{$n};
69 $stats->{'min_'.$n} = $hash->{$n} if $hash->{$n} < $stats->{'min_'.$n};
70 $stats->{'max_'.$n} = $hash->{$n} if $hash->{$n} > $stats->{'max_'.$n};
71 }
72
73 $hash->{number} = $stats->{total}++;
74
75 # warn "##>>>> ",dump( $hash );
76 return $hash;
77 }
78
79 return;
80 }
81
82 1;

  ViewVC Help
Powered by ViewVC 1.1.26