line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package GPS::Magellan::Message; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
6
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
100
|
|
6
|
1
|
|
|
1
|
|
4
|
use vars qw($AUTOLOAD); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
862
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
10
|
|
|
10
|
1
|
11
|
my $proto = shift; |
10
|
10
|
|
|
|
|
11
|
my $raw_msg = shift; |
11
|
|
|
|
|
|
|
|
12
|
10
|
|
33
|
|
|
33
|
my $class = ref($proto) || $proto; |
13
|
|
|
|
|
|
|
|
14
|
10
|
|
|
|
|
38
|
my $self = bless { |
15
|
|
|
|
|
|
|
fields => [ qw/RAW COMMAND DATA CHECKSUM/ ], |
16
|
|
|
|
|
|
|
}, $class; |
17
|
|
|
|
|
|
|
|
18
|
10
|
|
|
|
|
21
|
$self->_init(); |
19
|
|
|
|
|
|
|
|
20
|
10
|
50
|
|
|
|
35
|
return $self unless $raw_msg; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
0
|
$self->RAW($raw_msg); |
23
|
0
|
|
|
|
|
0
|
$self->_parse_message($raw_msg); |
24
|
0
|
|
|
|
|
0
|
$self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _init { |
29
|
10
|
|
|
10
|
|
12
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
10
|
|
|
|
|
10
|
foreach my $field (@{$self->fields}){ |
|
10
|
|
|
|
|
211
|
|
32
|
40
|
|
|
|
|
63
|
$self->_set($field, ""); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub verify_checksum { |
37
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
38
|
0
|
|
|
|
|
0
|
$self->CHECKSUM eq $self->_checksum($self->RAW); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub get { |
42
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
43
|
0
|
|
|
|
|
0
|
$self->RAW(sprintf('PMGN%s,%s', $self->COMMAND, $self->DATA)); |
44
|
0
|
|
|
|
|
0
|
sprintf('$%s*%s', $self->RAW, $self->_checksum($self->RAW)); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _checksum { |
49
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
50
|
0
|
|
|
|
|
0
|
my $msg = shift; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
my $chksum = 0; |
53
|
0
|
|
|
|
|
0
|
for (split //, $msg){ |
54
|
0
|
|
|
|
|
0
|
$chksum ^= ord($_); |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
0
|
sprintf('%02X', $chksum); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _parse_message { |
61
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
0
|
my @msg = $self->RAW =~ / |
64
|
|
|
|
|
|
|
^\$( |
65
|
|
|
|
|
|
|
PMGN |
66
|
|
|
|
|
|
|
([A-Z]{3}), |
67
|
|
|
|
|
|
|
(.*) |
68
|
|
|
|
|
|
|
) |
69
|
|
|
|
|
|
|
\* |
70
|
|
|
|
|
|
|
([A-Z0-9]{2}) |
71
|
|
|
|
|
|
|
$ |
72
|
|
|
|
|
|
|
/x or die sprintf("Cannot parse message: %s\n", $self->RAW); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
foreach my $field (@{$self->fields}){ |
|
0
|
|
|
|
|
0
|
|
75
|
0
|
|
|
|
|
0
|
$self->_set($field, shift @msg); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _dump { |
80
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
81
|
0
|
|
|
|
|
0
|
Dumper($self); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Accessors |
85
|
|
|
|
|
|
|
sub _get { |
86
|
110
|
|
|
110
|
|
140
|
my $self = shift; |
87
|
110
|
|
|
|
|
133
|
my $attr = shift; |
88
|
110
|
|
|
|
|
278
|
return $self->{$attr}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _set { |
92
|
50
|
|
|
50
|
|
223
|
my $self = shift; |
93
|
50
|
|
|
|
|
59
|
my $attr = shift; |
94
|
50
|
|
100
|
|
|
134
|
my $value = shift || ''; |
95
|
|
|
|
|
|
|
|
96
|
50
|
50
|
|
|
|
109
|
return unless $attr; |
97
|
|
|
|
|
|
|
|
98
|
50
|
|
|
|
|
63
|
$self->{$attr} = $value; |
99
|
50
|
|
|
|
|
89
|
return $self->_get($attr); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _debug_autoload { |
103
|
30
|
|
|
30
|
|
36
|
my $self = shift; |
104
|
30
|
50
|
|
|
|
56
|
$self->_set('_debug_autoload', shift) if @_; |
105
|
30
|
|
|
|
|
54
|
$self->_get('_debug_autoload'); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub AUTOLOAD { |
110
|
30
|
|
|
30
|
|
39
|
my $self = shift; |
111
|
30
|
|
|
|
|
37
|
my $attr = $AUTOLOAD; |
112
|
|
|
|
|
|
|
|
113
|
30
|
|
|
|
|
100
|
$attr =~ s/.*:://; |
114
|
|
|
|
|
|
|
|
115
|
30
|
50
|
|
|
|
68
|
return if $attr =~ /^_/; |
116
|
|
|
|
|
|
|
|
117
|
30
|
50
|
|
|
|
54
|
warn "AUTOLOAD: $attr\n" if $self->_debug_autoload; |
118
|
|
|
|
|
|
|
|
119
|
30
|
100
|
|
|
|
59
|
if(@_){ |
120
|
10
|
|
|
|
|
22
|
$self->_set($attr, shift); |
121
|
|
|
|
|
|
|
} |
122
|
30
|
|
|
|
|
49
|
return $self->_get($attr); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
0
|
|
|
sub DESTROY { |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |