line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- perl -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: Base.pm,v 1.4 2006/09/09 16:57:15 eserte Exp $ |
5
|
|
|
|
|
|
|
# Author: Slaven Rezic |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright (C) 2003 Slaven Rezic. All rights reserved. |
8
|
|
|
|
|
|
|
# This package is free software; you can redistribute it and/or |
9
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Mail: slaven@rezic.de |
12
|
|
|
|
|
|
|
# WWW: http://www.rezic.de/eserte/ |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package GPS::Base; |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
112
|
|
18
|
3
|
|
|
3
|
|
17
|
use vars qw($VERSION); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
2207
|
|
19
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Factory |
22
|
|
|
|
|
|
|
sub new { |
23
|
1
|
|
|
1
|
0
|
335
|
my($class, %param) = @_; |
24
|
1
|
50
|
|
|
|
50
|
if ($param{Protocol} eq 'GRMN') { |
|
|
0
|
|
|
|
|
|
25
|
1
|
|
|
|
|
6
|
require GPS::Garmin; |
26
|
1
|
|
|
|
|
12
|
GPS::Garmin->new(%param); |
27
|
|
|
|
|
|
|
} elsif ($param{Protocol} eq 'NMEA') { |
28
|
0
|
|
|
|
|
0
|
require GPS::NMEA; |
29
|
0
|
|
|
|
|
0
|
GPS::NMEA->new(%param); |
30
|
|
|
|
|
|
|
} else { |
31
|
0
|
|
|
|
|
0
|
die "Unknown or unspecified Protocol: $param{Protocol}"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub common_new { |
36
|
6
|
|
|
6
|
0
|
10
|
my $type = shift; |
37
|
6
|
|
|
|
|
13
|
my %param = @_; |
38
|
6
|
|
66
|
|
|
50
|
my $port = $param{'Port'} || |
39
|
|
|
|
|
|
|
($^O eq 'MSWin32' |
40
|
|
|
|
|
|
|
? 'COM1' |
41
|
|
|
|
|
|
|
: ($^O =~ /^(?:(?:free|net|open)bsd|bsd(?:os|i))$/ |
42
|
|
|
|
|
|
|
? (-e '/dev/cuad0' |
43
|
|
|
|
|
|
|
? '/dev/cuad0' # FreeBSD 6.x and later |
44
|
|
|
|
|
|
|
: '/dev/cuaa0' |
45
|
|
|
|
|
|
|
) |
46
|
|
|
|
|
|
|
: '/dev/ttyS1' |
47
|
|
|
|
|
|
|
) |
48
|
|
|
|
|
|
|
); |
49
|
6
|
|
100
|
|
|
35
|
my $baud = $param{'Baud'} || 9600; |
50
|
6
|
|
50
|
|
|
20
|
my $protocol = $param{'Protocol'} || 'GRMN'; |
51
|
6
|
|
100
|
|
|
25
|
my $timeout = $param{'timeout'} || 10; |
52
|
|
|
|
|
|
|
|
53
|
6
|
50
|
33
|
|
|
53
|
my $self = bless |
54
|
|
|
|
|
|
|
{ 'port' => $port, |
55
|
|
|
|
|
|
|
'baud' => $baud, |
56
|
|
|
|
|
|
|
'protocol' => $protocol, |
57
|
|
|
|
|
|
|
'timeout' => $timeout, |
58
|
|
|
|
|
|
|
'verbose' => $param{verbose}, |
59
|
|
|
|
|
|
|
(exists $param{'Return'} && $param{'Return'} eq 'hash' |
60
|
|
|
|
|
|
|
? (return_as_hash => 1) |
61
|
|
|
|
|
|
|
: () |
62
|
|
|
|
|
|
|
), |
63
|
|
|
|
|
|
|
}, $type; |
64
|
|
|
|
|
|
|
|
65
|
6
|
100
|
|
|
|
32
|
$self->connect unless $param{do_not_init}; |
66
|
|
|
|
|
|
|
|
67
|
5
|
|
|
|
|
61
|
$self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |