--- AnyEvent-GPSD/GPSD.pm 2008/07/02 05:17:37 1.2 +++ AnyEvent-GPSD/GPSD.pm 2008/07/18 01:31:12 1.4 @@ -90,9 +90,11 @@ minimum value for a good fix). C contains either C<1> to indicate that this satellite was used for -the last position fix, C<0> otherwise. EGNOS/WAAS etc. satellites will +the last position fix, C<0> otherwise. EGNOS/WAAS etc. satellites will always show as C<0>, even if their correction info was used. +The passed hash references are read-only. + =item on_fix => $cb->({point}) Called regularly (usually about once/second), even when there is no @@ -153,6 +155,7 @@ my ($self) = @_; delete $self->{fh}; + delete $self->{command}; Scalar::Util::weaken $self; $self->{retry_w} = AnyEvent->timer (after => 1, cb => sub { @@ -206,6 +209,7 @@ on_eof => sub { $! = &Errno::EPIPE; $self->event ("error"); + $self->log ("disconnect"); $self->retry; }, on_read => sub { @@ -222,6 +226,7 @@ $self->send ("c"); $self->event ("connect"); + $self->log ("connect"); } else { $self->event ("error"); } @@ -251,6 +256,9 @@ $self->{now} = AnyEvent->now; + $self->log (raw => $line) + if $self->{logfh}; + unless ($line =~ /^GPSD,(.)=(.*)$/) { $! = &Errno::EBADMSG; $self->event ("error"); @@ -259,6 +267,8 @@ my ($type, $data) = ($1, $2); + #warn "$type=$data\n";#d# + $self->{state}{$type} = [$data => $self->{now}]; if ($type eq "O") { @@ -318,15 +328,16 @@ want more frequent updates, but not very useful to store, as the next fix might well be totally off. -If the fix is older then C<$max_seconds> (default: C<1.9>) or if no fix is -available, returns the empty list. +If the fix is older then C<$max_seconds> (default: C<1.9> times the update +interval, i.e. usually C<1.9> seconds) or if no fix is available, returns +the empty list. =cut sub estimate { my ($self, $max) = @_; - $max ||= 1.9 unless defined $max; + $max ||= 1.9 * $self->{interval} unless defined $max; my $geo = $self->{geo_forward} ||= new Geo::Forward; @@ -347,6 +358,24 @@ } } +sub log { + my ($self, @arg) = @_; + + syswrite $self->{logfh}, JSON::encode_json ([AnyEvent->time, @arg]) . "\n" + if $self->{logfh}; +} + +sub record_log { + my ($self, $path) = @_, + + require JSON; + + open $self->{logfh}, ">", $path + or Carp::croak "$path: $!"; + + $self->log (start => $VERSION); +} + =back =head1 SEE ALSO