Net::GPSD3(3pm)
๐ Net::GPSD3 ๐
okay so bestie, this is the manual page for Net::GPSD3 โ that's the Perl module, in section 3pm of the User Contributed Perl Documentation. pull up a chair, grab a boba, and let's get into it ๐งโจ
โจ NAME โจ
Net::GPSD3 โ Interface to the gpsd server daemon protocol versions 3 (JSON).
like, it's the little Perl buddy that talks to gpsd and speaks JSON protocol v3. that's the whole vibe ๐
๐ฐ๏ธ SYNOPSIS ๐ฐ๏ธ
๐ Watch Interface ๐
use Net::GPSD3;
my $gpsd=Net::GPSD3->new;
$gpsd->watch;
One Liner โ yes she can do it in one line, she's an icon:
perl -MNet::GPSD3 -e 'Net::GPSD3->new->watch'
๐ก Poll Interface ๐ก
use Net::GPSD3;
use Data::Dumper qw{Dumper};
my $gpsd=Net::GPSD3->new;
my $poll=$gpsd->poll;
print Dumper($poll);
One Liner โ look at her go:
perl -MNet::GPSD3 -e 'printf "Protocol: %s\n", Net::GPSD3->new->poll->parent->cache->VERSION->protocol;'
and she prints, no cap:
Protocol: 3.4
๐ธ POE Interface ๐ธ
go look at Net::GPSD3::POE, she lives over there ๐ซถ
๐ซ DESCRIPTION ๐ซ
so Net::GPSD3 gives you an object client interface to the gpsd server daemon, and it's using the version 3 protocol. gpsd is an open source GPS daemon from http://www.catb.org/gpsd/ ๐
Version 3 of the protocol (that's the JSON one) got added to the daemon back in version 2.90. so if your daemon is from before 2.90 (aka protocol 2.X territory, ancient history, grandma era ๐ญ), you need to use the Net::GPSD package instead. wrong module for your daemon = no data, and we don't do that here ๐
๐ CONSTRUCTOR ๐
โจ new โจ
Returns a new Net::GPSD3 object. fresh out the box, ready to slay ๐
my $gpsd=Net::GPSD3->new;
my $gpsd=Net::GPSD3->new(host=>"127.0.0.1", port=>2947); #defaults
those are literally the defaults btw, host of "127.0.0.1" and port of 2947, so you're getting them whether you ask or not ๐
๐ ๏ธ METHODS ๐ ๏ธ
๐ host ๐
Sets or returns the current gpsd host. get it, set it, whatever you need bestie.
my $host=$obj->host;
๐ช port ๐ช
Sets or returns the current gpsd TCP port.
my $port=$obj->port;
๐ฌ poll ๐ฌ
Sends a Poll request to the gpsd server and returns a Net::GPSD3::Return::POLL object. and not only that, this method also populates the cache object with the Net::GPSD3::Return::VERISON and Net::GPSD3::Return::DEVICES objects. multi-tasking queen ๐
my $poll=$gpsd->poll; #isa Net::GPSD3::Return::POLL object
Note: In order to use the poll method consistently you should run the GPSD daemon as a service. You may also need to run the daemon with the -n option. fr fr, do this or poll will be flaky and you'll be sad ๐ญ
๐๏ธ watch ๐๏ธ
Calls all handlers that are registered in the handler method.
$gpsd->watch; #will not return unless something goes wrong.
like she will NOT come back. she stays out there. only if something goes wrong does she return, and at that point, we're not okay ๐
โ addHandler โ
Adds handlers to the handler list. stack 'em up.
$gpsd->addHandler(\&myHandler);
$gpsd->addHandler(\&myHandler1, \&myHandler2);
A handler is a sub reference where the first argument is a Net::GPSD3::Return::* object. so your sub gets fed the good stuff ๐
๐ handlers ๐
List of handlers that are called in order to process objects from the gpsd wathcer stream.
my @handler=$gpsd->handlers; #()
my $handler=$gpsd->handlers; #[]
list context โ list, scalar context โ arrayref. she's flexible like that ๐
๐๏ธ cache ๐๏ธ
Returns the Net::GPSD3::Cache caching object. that's where the good stuff gets stashed โจ
๐ METHODS Internal ๐
๐งฉ default_handler ๐งฉ
(no description here, she's just chillin' in the internal section, keeping it mysterious ๐)
๐ socket ๐
Returns the cached IO::Socket::INET6 object.
my $socket=$gpsd->socket; #try to reconnect on failure
she'll try to reconnect on failure. resilient icon ๐ซถ
๐งพ json ๐งพ
Returns the cached JSON::XS object.
๐ decode ๐
Returns a perl data structure given a JSON formated string.
my %data=$gpsd->decode($string); #()
my $data=$gpsd->decode($string); #{}
hash in list context, hashref in scalar context, she read the room ๐
๐ encode ๐
Returns a JSON string from a perl data structure. the reverse girly ๐
๐๏ธ constructor ๐๏ธ
Constructs a class object by lazy loading the classes. lazy but make it efficient, we love her for it ๐
my $obj=$gpsd->constructor(%$data);
my $obj=$gpsd->constructor(class=>"DEVICE",
string=>'{...}',
...);
Returns and object in the Net::GPSD3::Return::* namespace. (that's "an object", the original said "and object", we're just quoting the vibe here bestie, no notes ๐)
๐ BUGS ๐
Log on RT and Send to gpsd-dev email list. that's the protocol, literally ๐ฎ
There are no two GPS devices that are alike. Each GPS device has a different GPSD signature as well. If your GPS device does not work out of the box with this package, please send me a log of your devices JSON sentences. every device is a unique little main character and sometimes they need a vibe check ๐
echo '?POLL;' | nc 127.0.0.1 2947
echo '?WATCH={"enable":true,"json":true};' | socat -t10 stdin stdout | nc 127.0.0.1 2947
run those, capture the tea, send it over โ
๐ซถ SUPPORT ๐ซถ
DavisNetworks.com supports all Perl applications including this package. shoutout ๐
Try gpsd-dev email list.
๐ AUTHOR ๐
Michael R. Davis
CPAN ID: MRDVT
STOP, LLC
domain=>michaelrdavis,tld=>com,account=>perl
http://www.stopllc.com/
๐ COPYRIGHT ๐
This program is free software licensed under the...
The BSD License
The full text of the license can be found in the LICENSE file included with this module. read it, it's giving legal but make it slay โ๏ธโจ
๐ญ SEE ALSO ๐ญ
- Net::GPSD
- Net::GPSD3::POE
- GPS::Point
- JSON::XS
- IO::Socket::INET6
- DateTime
go read those too, they're all part of the friend group ๐ฆ
okay that's the whole page bestie, you're officially a Net::GPSD3 girlie now ๐
this masterpiece was brought to you by perl v5.34.0 on 2022-06-16 โ and yes, the manual name really is Net::GPSD3(3pm), remember it for the exam ๐ ๐๐ธ
๐ฆ where this page comes from
- debian bookworm: libnet-gpsd3-perl 0.19-2 ยท BSD-3
- debian trixie: libnet-gpsd3-perl 0.19-2 ยท BSD-3
- ubuntu noble: libnet-gpsd3-perl 0.19-2 ยท BSD-3
- ubuntu resolute: libnet-gpsd3-perl 0.19-2 ยท BSD-3
- ubuntu stonking: libnet-gpsd3-perl 0.19-2 ยท BSD-3
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms