… | |
… | |
56 | The host to connect to, default is C<locahost>. |
56 | The host to connect to, default is C<locahost>. |
57 | |
57 | |
58 | =item port => $port |
58 | =item port => $port |
59 | |
59 | |
60 | The port to connect to, default is C<2947>. |
60 | The port to connect to, default is C<2947>. |
|
|
61 | |
|
|
62 | =item min_speed => $speed_in_m_per_s |
|
|
63 | |
|
|
64 | Sets the mininum speed (default: 0) that is considered real for the |
|
|
65 | purposes of replay compression or estimate. Speeds below this value will |
|
|
66 | be considered 0. |
61 | |
67 | |
62 | =item on_error => $cb->($gps) |
68 | =item on_error => $cb->($gps) |
63 | |
69 | |
64 | Called on every connection or protocol failure, reason is in C<$!> |
70 | Called on every connection or protocol failure, reason is in C<$!> |
65 | (protocl errors are signalled via EBADMSG). Can be used to bail out if you |
71 | (protocl errors are signalled via EBADMSG). Can be used to bail out if you |
… | |
… | |
342 | } |
348 | } |
343 | |
349 | |
344 | =item ($lat, $lon) = $gps->estimate ([$max_seconds]) |
350 | =item ($lat, $lon) = $gps->estimate ([$max_seconds]) |
345 | |
351 | |
346 | This returns an estimate of the current position based on the last fix and |
352 | This returns an estimate of the current position based on the last fix and |
347 | the time passed since then. Useful for interactive applications where you |
353 | the time passed since then. |
348 | want more frequent updates, but not very useful to store, as the next fix |
354 | |
349 | might well be totally off. |
355 | Useful for interactive applications where you want more frequent updates, |
|
|
356 | but not very useful to store, as the next fix might well be totally |
|
|
357 | off. For example, when displaying a real-time map, you could simply call |
|
|
358 | C<estimate> ten times a second and update the cursor or map position, but |
|
|
359 | you should use C<on_fix> to actually gather data to plot the course itself. |
350 | |
360 | |
351 | If the fix is older then C<$max_seconds> (default: C<1.9> times the update |
361 | If the fix is older then C<$max_seconds> (default: C<1.9> times the update |
352 | interval, i.e. usually C<1.9> seconds) or if no fix is available, returns |
362 | interval, i.e. usually C<1.9> seconds) or if no fix is available, returns |
353 | the empty list. |
363 | the empty list. |
354 | |
364 | |
… | |
… | |
366 | |
376 | |
367 | my $diff = AnyEvent->time - $fix->{time}; |
377 | my $diff = AnyEvent->time - $fix->{time}; |
368 | |
378 | |
369 | $diff <= $max or return; |
379 | $diff <= $max or return; |
370 | |
380 | |
371 | if ($fix->{speed} > $fix->{serr}) { |
381 | if ($fix->{speed} >= $self->{min_speed}) { |
372 | my ($lat, $lon) = $geo->forward ($fix->{lat}, $fix->{lon}, $fix->{bearing}, $fix->{speed} * $diff); |
382 | my ($lat, $lon) = $geo->forward ($fix->{lat}, $fix->{lon}, $fix->{bearing}, $fix->{speed} * $diff); |
373 | ($lat, $lon) |
383 | ($lat, $lon) |
374 | |
384 | |
375 | } else { |
385 | } else { |
376 | # if we likely have zero speed, return the point itself |
386 | # if we likely have zero speed, return the point itself |
… | |
… | |
421 | |
431 | |
422 | Please note that replaying a log will change configuration options that |
432 | Please note that replaying a log will change configuration options that |
423 | will not be restored, so it's best not to reuse a gpsd object after a |
433 | will not be restored, so it's best not to reuse a gpsd object after a |
424 | replay. |
434 | replay. |
425 | |
435 | |
|
|
436 | The C<AnyEvent::GPSD> distribution comes with an example log |
|
|
437 | (F<eg/example.aegps>) that you can replay for testing or enjoyment |
|
|
438 | purposes. |
|
|
439 | |
426 | The options include: |
440 | The options include: |
427 | |
441 | |
428 | =over 4 |
442 | =over 4 |
429 | |
443 | |
430 | =item compress => 1 |
444 | =item compress => 1 |
… | |
… | |
481 | } |
495 | } |
482 | |
496 | |
483 | if ( |
497 | if ( |
484 | $type eq "start" |
498 | $type eq "start" |
485 | or ($self->{compress} |
499 | or ($self->{compress} |
486 | and $self->{fix} && ($self->{fix}{mode} < 2 || $self->{fix}{speed} < 5)) |
500 | and $self->{fix} && ($self->{fix}{mode} < 2 || $self->{fix}{speed} < $self->{min_speed})) |
487 | ) { |
501 | ) { |
488 | $self->{replay_now} = $time; |
502 | $self->{replay_now} = $time; |
489 | } |
503 | } |
490 | |
504 | |
491 | $self->{replay_timer} = AnyEvent->timer (after => $time - $self->{replay_now}, cb => sub { |
505 | $self->{replay_timer} = AnyEvent->timer (after => $time - $self->{replay_now}, cb => sub { |