Created
July 8, 2015 12:47
-
-
Save creaktive/bbdcad83b8d1f94b9cfd to your computer and use it in GitHub Desktop.
gpsd-wrapper.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings qw(all); | |
use Data::Dumper; | |
use IPC::Run qw(start pump); | |
use JSON::XS; | |
use Net::GPSD3; | |
my $gpsd_host = '127.0.0.1'; | |
my $gpsd_port = 2947; | |
my ($lat, $lon, $alt) = (47, 8, 0); | |
my @command = ('./flarm_decode', $lat, $lon, $alt); | |
my ($in, $out, $err); | |
my $h = start \@command, \$in, \$out, \$err; | |
my $json = JSON::XS->new; | |
my $gpsd = Net::GPSD3->new(host => $gpsd_host, port => $gpsd_port); | |
while (my $packet = <>) { | |
my $poll = $gpsd->poll; | |
if ($poll->class eq 'TPV') { | |
$lat = $poll->lat; | |
$lon = $poll->lon; | |
$alt = $poll->alt; | |
} | |
$in = "# $lat $lon $alt\n"; | |
pump $h while length $in; | |
$in = $packet; | |
$out = $err = ''; | |
pump $h while length $in; | |
pump $h until $out =~ /\n$/mx || $err =~ /\n$/mx; | |
if ($err) { | |
print STDERR $err; | |
} else { | |
my $data = eval { $json->decode($out) } || next; | |
# do something with the data here | |
print Dumper($data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment