| GPS-Magellan documentation | Contained in the GPS-Magellan distribution. |
GPS::Magellan - Module for communicating with Magellan receivers
GPS::Magellan::OpenPort('/dev/ttyS0');
$gps = GPS::Magellan->new(
port => '/dev/ttyS0'
);
# Download waypoints
@waypoints = $gps->getPoints('WAYPOINT');
foreach $coord (@waypoints){
printf("longitude: %s, latitude: %s\n", $coord->longitude, $coord->latitude);
}
# Download trackpoints
@trackpoints = $gps->getPoints('TRACKLOG');
foreach $coord (@trackpoints){
printf("longitude: %s, latitude: %s\n", $coord->longitude, $coord->latitude);
}
$file = GPS::Magellan::File::Way_Txt->new(
coords => \@waypoints
);
print $file->as_string();
Soming soon, until then see README, examples/magellan.pl and the test suite for example.
Instantiates a new GPS::Magellan object. SERIAL_DEVICE specifies which port if the receiver connected to.
Downloads coordinates of the specified type from the receiver.
Returns: an array of GPS::Magellan::Coord objects.
Send arbitrary command to the receiver.
Returns: the receiver's response as an array of GPS::Magellan::Message objects.
Peter Banik <peter@login-fo.net>
GPS::Magellan::Coord GPS::Magellan::Message GPS::Magellan::File
$Id: Magellan.pm,v 1.2 2004/02/29 21:48:38 peter Exp $
Missing coordinate upload feature. Needs more documentation. Instead of GPS::Magellan::Coord, it should make use of a generic coordinate class.
Please report bugs to the author.
Copyright (c) 2003
| GPS-Magellan documentation | Contained in the GPS-Magellan distribution. |
package GPS::Magellan; use strict; use warnings; use GPS::Magellan::Message; use GPS::Magellan::Coord; use vars qw($AUTOLOAD); our $VERSION = '0.61'; sub new { my $proto = shift; my $class = ref($proto) || $proto; my %args = @_; my $port = $args{port} || '/dev/ttyS0'; my $self = bless { RUN_OFFLINE => $args{RUN_OFFLINE} || 0, port => $port, raw_file => 'magellan.log', debug => 1, }, $class; warn "calling init\n"; magellan_init() unless $self->RUN_OFFLINE; $self; } sub connect { my $self = shift; return if $self->RUN_OFFLINE; # die sprintf("GPS::Magellan::new(): port not specified") unless $self->{port}; # OpenPort($self->{port}); } sub getPoints { my $self = shift; my $cmd = shift or die "getPoint( WAYPOINT | TRACKLOG )\n"; my @messages = $self->command($cmd); my @coords = (); foreach my $msg (@messages){ my $wpt = GPS::Magellan::Coord->new($msg->DATA); push @coords, $wpt; } return @coords; } sub command { my $self = shift; my $cmd = shift; die "command() needs cmd" unless $cmd; return $self->_command($cmd) unless $self->RUN_OFFLINE; my $data_file = "test-data/$cmd"; open(DATA, "$data_file") or die "cannot open $data_file\n"; my @result = <DATA>; close(DATA); map { chomp; my $data = $_; $_ = GPS::Magellan::Message->new; $_->DATA($data); } @result; return @result; } sub _command { my $self = shift; my $cmd = shift; die "_command() needs cmd" unless $cmd; magellan_handon(); MagWriteMessageSum("PMGNCMD,$cmd"); my @messages = (); while(1){ my $raw_msg = magellan_findmessage('$PMGN') or next; my $msg = GPS::Magellan::Message->new($raw_msg); if($msg->COMMAND eq 'CMD'){ last if $msg->DATA eq 'END'; } my $chksum = $msg->CHECKSUM; my $ack = sprintf("PMGNCSM,%s", $chksum); MagWriteMessageNoAck($ack); push @messages, $msg; } return @messages; } # Accessors sub _get { my $self = shift; my $attr = shift; return $self->{$attr}; } sub _set { my $self = shift; my $attr = shift; my $value = shift || ''; return unless $attr; $self->{$attr} = $value; return $self->_get($attr); } sub _debug_autoload { my $self = shift; $self->_set('_debug_autoload', shift) if @_; $self->_get('_debug_autoload'); } sub AUTOLOAD { my $self = shift; my $attr = $AUTOLOAD; $attr =~ s/.*:://; return if $attr =~ /^_/; warn "AUTOLOAD: $attr\n" if $self->_debug_autoload; if(@_){ $self->_set($attr, shift); } return $self->_get($attr); } sub DESTROY { ClosePort() unless shift->RUN_OFFLINE; } require XSLoader; XSLoader::load('GPS::Magellan', $VERSION); 1; __END__