Net::GPSD3(3pm)

๐Ÿ“ฆ
version 0.19 ยท 2 versions
  • 0.19 ยท debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.19 ยท ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

๐Ÿ’– 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/

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