#!/usr/bin/perl -w
use strict;
use lib q{../lib};
use GPS::gpsd;
my ($host,$port)=split(q{:}, shift()||'');
$host||=q{localhost};
$port||=q{2947};

my $gps=GPS::gpsd->new(host=>$host, port=>$port) || die("Error: Cannot connect to the gpsd server");

print join("|", qw{status datetime . lat lon alt speed heading}), "\n";
while (1) {
  my $p=$gps->get();
  if ($p->fix) {
    print join("|", map {defined $_?$_:''}
                     $p->status,
                     $p->datetime,
                     $p->lat,
                     $p->lon,
                     $p->alt,
                     $p->speed,
                     $p->heading),
                     "\n";
    print join(":", map {defined $_?$_:''} @{$p->{'O'}}),"\n";
  }
  sleep 1;
}
