line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GPS::Magellan; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
8113
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
55
|
|
4
|
1
|
|
|
1
|
|
11
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
837
|
use GPS::Magellan::Message; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
7
|
1
|
|
|
1
|
|
537
|
use GPS::Magellan::Coord; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use vars qw($AUTOLOAD); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1295
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.61'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
1
|
|
|
1
|
|
2553
|
my $proto = shift; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
33
|
|
|
9
|
my $class = ref($proto) || $proto; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
4
|
my %args = @_; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
50
|
|
|
4
|
my $port = $args{port} || '/dev/ttyS0'; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
50
|
|
|
8
|
my $self = bless { |
23
|
|
|
|
|
|
|
RUN_OFFLINE => $args{RUN_OFFLINE} || 0, |
24
|
|
|
|
|
|
|
port => $port, |
25
|
|
|
|
|
|
|
raw_file => 'magellan.log', |
26
|
|
|
|
|
|
|
debug => 1, |
27
|
|
|
|
|
|
|
}, $class; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
27
|
warn "calling init\n"; |
30
|
1
|
50
|
|
|
|
10
|
magellan_init() unless $self->RUN_OFFLINE; |
31
|
1
|
|
|
|
|
4
|
$self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub connect { |
35
|
1
|
|
|
1
|
|
314
|
my $self = shift; |
36
|
1
|
50
|
|
|
|
5
|
return if $self->RUN_OFFLINE; |
37
|
|
|
|
|
|
|
# die sprintf("GPS::Magellan::new(): port not specified") unless $self->{port}; |
38
|
|
|
|
|
|
|
# OpenPort($self->{port}); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub getPoints { |
42
|
1
|
|
|
1
|
|
678
|
my $self = shift; |
43
|
1
|
50
|
|
|
|
4
|
my $cmd = shift or die "getPoint( WAYPOINT | TRACKLOG )\n"; |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
4
|
my @messages = $self->command($cmd); |
46
|
1
|
|
|
|
|
3
|
my @coords = (); |
47
|
1
|
|
|
|
|
2
|
foreach my $msg (@messages){ |
48
|
10
|
|
|
|
|
45
|
my $wpt = GPS::Magellan::Coord->new($msg->DATA); |
49
|
10
|
|
|
|
|
24
|
push @coords, $wpt; |
50
|
|
|
|
|
|
|
} |
51
|
1
|
|
|
|
|
16
|
return @coords; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub command { |
55
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
56
|
1
|
|
|
|
|
1
|
my $cmd = shift; |
57
|
|
|
|
|
|
|
|
58
|
1
|
50
|
|
|
|
3
|
die "command() needs cmd" unless $cmd; |
59
|
|
|
|
|
|
|
|
60
|
1
|
50
|
|
|
|
5
|
return $self->_command($cmd) unless $self->RUN_OFFLINE; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
3
|
my $data_file = "test-data/$cmd"; |
63
|
|
|
|
|
|
|
|
64
|
1
|
50
|
|
|
|
54
|
open(DATA, "$data_file") or die "cannot open $data_file\n"; |
65
|
1
|
|
|
|
|
45
|
my @result = ; |
66
|
1
|
|
|
|
|
11
|
close(DATA); |
67
|
|
|
|
|
|
|
|
68
|
10
|
|
|
|
|
16
|
map { |
69
|
1
|
|
|
|
|
2
|
chomp; |
70
|
10
|
|
|
|
|
11
|
my $data = $_; |
71
|
10
|
|
|
|
|
27
|
$_ = GPS::Magellan::Message->new; |
72
|
10
|
|
|
|
|
43
|
$_->DATA($data); |
73
|
|
|
|
|
|
|
} @result; |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
9
|
return @result; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _command { |
80
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
81
|
0
|
|
|
|
|
0
|
my $cmd = shift; |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
0
|
die "_command() needs cmd" unless $cmd; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
0
|
magellan_handon(); |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
0
|
MagWriteMessageSum("PMGNCMD,$cmd"); |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
0
|
my @messages = (); |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
0
|
while(1){ |
92
|
0
|
0
|
|
|
|
0
|
my $raw_msg = magellan_findmessage('$PMGN') or next; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
0
|
my $msg = GPS::Magellan::Message->new($raw_msg); |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
0
|
if($msg->COMMAND eq 'CMD'){ |
97
|
0
|
0
|
|
|
|
0
|
last if $msg->DATA eq 'END'; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
0
|
my $chksum = $msg->CHECKSUM; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
my $ack = sprintf("PMGNCSM,%s", $chksum); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
0
|
MagWriteMessageNoAck($ack); |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
0
|
push @messages, $msg; |
107
|
|
|
|
|
|
|
} |
108
|
0
|
|
|
|
|
0
|
return @messages; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Accessors |
113
|
|
|
|
|
|
|
sub _get { |
114
|
6
|
|
|
6
|
|
8
|
my $self = shift; |
115
|
6
|
|
|
|
|
7
|
my $attr = shift; |
116
|
6
|
|
|
|
|
27
|
return $self->{$attr}; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _set { |
120
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
121
|
0
|
|
|
|
|
0
|
my $attr = shift; |
122
|
0
|
|
0
|
|
|
0
|
my $value = shift || ''; |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
0
|
return unless $attr; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
0
|
$self->{$attr} = $value; |
127
|
0
|
|
|
|
|
0
|
return $self->_get($attr); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _debug_autoload { |
131
|
3
|
|
|
3
|
|
4
|
my $self = shift; |
132
|
3
|
50
|
|
|
|
24
|
$self->_set('_debug_autoload', shift) if @_; |
133
|
3
|
|
|
|
|
10
|
$self->_get('_debug_autoload'); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub AUTOLOAD { |
138
|
3
|
|
|
3
|
|
4
|
my $self = shift; |
139
|
3
|
|
|
|
|
6
|
my $attr = $AUTOLOAD; |
140
|
|
|
|
|
|
|
|
141
|
3
|
|
|
|
|
14
|
$attr =~ s/.*:://; |
142
|
|
|
|
|
|
|
|
143
|
3
|
50
|
|
|
|
9
|
return if $attr =~ /^_/; |
144
|
|
|
|
|
|
|
|
145
|
3
|
50
|
|
|
|
7
|
warn "AUTOLOAD: $attr\n" if $self->_debug_autoload; |
146
|
|
|
|
|
|
|
|
147
|
3
|
50
|
|
|
|
8
|
if(@_){ |
148
|
0
|
|
|
|
|
0
|
$self->_set($attr, shift); |
149
|
|
|
|
|
|
|
} |
150
|
3
|
|
|
|
|
5
|
return $self->_get($attr); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub DESTROY { |
154
|
0
|
0
|
|
0
|
|
|
ClosePort() unless shift->RUN_OFFLINE; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
require XSLoader; |
158
|
|
|
|
|
|
|
XSLoader::load('GPS::Magellan', $VERSION); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
__END__ |