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

File Contents

# Content
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 warn "$6,$5,$4,$1,$2,$3,0,0\n";
36 $self->{data} = {
37 time => (POSIX::mktime $6,$5,$4,$2,$1-1,$3-1900,0,0),
38 lat => $7,
39 long => $8,
40 v => $9,
41 alt => $10,
42 };
43 $self->{last} = time;
44 }
45 }
46
47 sub data {
48 $_[0]->poll if time - $_[0]{last} >= $_[0]{minpoll};
49 $_[0]{data};
50 }
51
52 1;
53