ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/GPS/GPS.pm
Revision: 1.3
Committed: Fri Apr 26 21:53:14 2002 UTC (22 years ago) by root
Branch: MAIN
Changes since 1.2: +0 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 stefan 1.1 package GPS;
2    
3     use strict;
4     use warnings;
5     use POSIX ();
6     use Coro::Socket;
7    
8     our $VERSION = 0.01;
9    
10     sub new {
11     my ($class, %arg) = @_;
12     $arg{port} ||= 2947;
13     $arg{host} ||= 'localhost';
14    
15     my $sock = new Coro::Socket PeerHost => $arg{host}, PeerPort => $arg{port}
16     or die 'GPSD ($arg{host}:$arg{port}): $!';
17     print $sock "HELO\n";
18     <$sock> =~ /GPSD/ or die 'no GPSD';
19    
20     bless {
21     fh => $sock,
22     minpoll => $arg{minpoll} || 1,
23     last => 0,
24     data => {}
25     }, $class;
26     }
27    
28     sub poll {
29     my $self = shift;
30    
31     print {$self->{fh}} "dpva\n";
32    
33     if ($self->{fh}->readline =~ m%GPSD,D=(\d\d)/(\d\d)/(\d\d\d\d) (\d\d):(\d\d):(\d\d),P=([\-0-9.]+) ([\-0-9.]+),V=([0-9.]+),A=([\-0-9.]+)%) {
34     local $ENV{TZ} = "+0000";
35     $self->{data} = {
36     time => (POSIX::mktime $6,$5,$4,$2,$1-1,$3-1900,0,0),
37     lat => $7,
38     long => $8,
39     v => $9,
40     alt => $10,
41     };
42     $self->{last} = time;
43     }
44     }
45    
46     sub data {
47     $_[0]->poll if time - $_[0]{last} >= $_[0]{minpoll};
48     $_[0]{data};
49     }
50    
51     1;
52