ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/GPS/GPS.pm
Revision: 1.1
Committed: Fri Apr 26 18:37:25 2002 UTC (22 years ago) by stefan
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

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