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

Diff of /lib/NMEA.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 26 by dpavlin, Fri Dec 7 03:03:42 2007 UTC revision 27 by dpavlin, Fri Dec 7 03:44:12 2007 UTC
# Line 18  sub hhmm { Line 18  sub hhmm {
18  my $got_it;  my $got_it;
19  my $stats;  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 {  sub line {
32          my $self = shift;          my $self = shift;
33          my $l = shift || return;          my $l = shift || return;
# Line 26  sub line { Line 36  sub line {
36                  chomp;                  chomp;
37                  my @a = split(/,/,$_);                  my @a = split(/,/,$_);
38    
39                  return unless $#a == 12;                  if ( $#a != 12 ) {
40                            $self->error( 'invalid line length' => $_ );
41                            return;
42                    }
43    
44  #               warn "## [$#a] ", join(' ', map { "$_:$a[$_]" } ( 0 .. $#a )), " from $_\n";  #               warn "## [$#a] ", join(' ', map { "$_:$a[$_]" } ( 0 .. $#a )), " from $_\n";
45    
46                  # is valid?                  # is valid?
47                  return unless $a[2] eq 'A';                  if ( $a[2] ne 'A' ) {
48                            $self->error( 'not valid' => $_ );
49                            return;
50                    }
51    
52                  my $hash;                  my $hash;
53                  my $i = 1; # skip GPRMC;                  my $i = 1; # skip GPRMC;
# Line 42  sub line { Line 58  sub line {
58                  $hash->{lat} = hhmm( ( $hash->{lat_ns} eq 'S' ? -1 : 1 ) * $hash->{lat_hhmm} ) || return;                  $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;                  $hash->{lon} = hhmm( ( $hash->{lon_ew} eq 'W' ? -1 : 1 ) * $hash->{lon_hhmm} ) || return;
60    
61                  return if ( $got_it->{ $hash->{lat} . ' ' . $hash->{lon} }++ );                  if ( $got_it->{ $hash->{lat} . ' ' . $hash->{lon} }++ ) {
62                            $self->error( 'duplicate line' => $_ );
63                            return;
64                    }
65    
66                    $stats->{ 'min_'.$_ } = $hash->{ $_ } < $stats->{ 'min_'.$_ } foreach ( qw/lat lon/ );
67                    $stats->{ 'max_'.$_ } = $hash->{ $_ } > $stats->{ 'max_'.$_ } foreach ( qw/lat lon/ );
68    
69                    $hash->{number} = $stats->{total}++;
70    
71  #               warn "##>>>> ",dump( $hash );  #               warn "##>>>> ",dump( $hash );
72                  return $hash;                  return $hash;

Legend:
Removed from v.26  
changed lines
  Added in v.27

  ViewVC Help
Powered by ViewVC 1.1.26