| 1 | |||||||||||||||||||||
| 2 | package GPS::Magellan::Message; | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use vars qw($AUTOLOAD); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 10 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=13.1
Pod
documented
| |||||||||||||||||||||
| 9 | 10 | my $proto = shift; | |||||||||||||||||||
| 10 | 10 | my $raw_msg = shift; | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 10 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 10 | my $self = bless { | |||||||||||||||||||
| 15 | fields => [ qw/RAW COMMAND DATA CHECKSUM/ ], | ||||||||||||||||||||
| 16 | }, $class; | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 10 | $self->_init(); | |||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 10 | ▶ | return $self unless $raw_msg; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 0 | $self->RAW($raw_msg); | |||||||||||||||||||
| 23 | 0 | $self->_parse_message($raw_msg); | |||||||||||||||||||
| 24 | 0 | $self; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 10 | ▶ | sub _init { | ||||||||||||||||||
|
Subroutine
_init: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 29 | 10 | my $self = shift; | |||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 10 | foreach my $field (@{$self->fields}){ | |||||||||||||||||||
| 32 | 40 | $self->_set($field, ""); | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 0 | ▶ | sub verify_checksum { | ||||||||||||||||||
|
Subroutine
verify_checksum: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||||||||
| 38 | 0 | $self->CHECKSUM eq $self->_checksum($self->RAW); | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | ▶ | sub get { | ||||||||||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 42 | 0 | my $self = shift; | |||||||||||||||||||
| 43 | 0 | $self->RAW(sprintf('PMGN%s,%s', $self->COMMAND, $self->DATA)); | |||||||||||||||||||
| 44 | 0 | sprintf('$%s*%s', $self->RAW, $self->_checksum($self->RAW)); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | ▶ | sub _checksum { | ||||||||||||||||||
|
Subroutine
_checksum: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 49 | 0 | my $self = shift; | |||||||||||||||||||
| 50 | 0 | my $msg = shift; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | my $chksum = 0; | |||||||||||||||||||
| 53 | 0 | for (split //, $msg){ | |||||||||||||||||||
| 54 | 0 | $chksum ^= ord($_); | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | 0 | sprintf('%02X', $chksum); | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | ▶ | sub _parse_message { | ||||||||||||||||||
|
Subroutine
_parse_message: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | ▶ | my @msg = $self->RAW =~ / | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | foreach my $field (@{$self->fields}){ | |||||||||||||||||||
| 75 | 0 | $self->_set($field, shift @msg); | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | ▶ | sub _dump { | ||||||||||||||||||
|
Subroutine
_dump: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||||||||||
| 81 | 0 | Dumper($self); | |||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | # Accessors | ||||||||||||||||||||
| 85 | 110 | ▶ | sub _get { | ||||||||||||||||||
|
Subroutine
_get: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 86 | 110 | my $self = shift; | |||||||||||||||||||
| 87 | 110 | my $attr = shift; | |||||||||||||||||||
| 88 | 110 | return $self->{$attr}; | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 50 | ▶ | sub _set { | ||||||||||||||||||
|
Subroutine
_set: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 92 | 50 | my $self = shift; | |||||||||||||||||||
| 93 | 50 | my $attr = shift; | |||||||||||||||||||
| 94 | 50 | ▶ | my $value = shift || ''; | ||||||||||||||||||
|
Condition100%2/2
shift() || ''
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 50 | ▶ | return unless $attr; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 50 | $self->{$attr} = $value; | |||||||||||||||||||
| 99 | 50 | return $self->_get($attr); | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 30 | ▶ | sub _debug_autoload { | ||||||||||||||||||
|
Subroutine
_debug_autoload: called CC=2 SCAR=7.1
| |||||||||||||||||||||
| 103 | 30 | my $self = shift; | |||||||||||||||||||
| 104 | 30 | ▶ | $self->_set('_debug_autoload', shift) if @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 105 | 30 | $self->_get('_debug_autoload'); | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 30 | ▶ | sub AUTOLOAD { | ||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=14.0
| |||||||||||||||||||||
| 110 | 30 | my $self = shift; | |||||||||||||||||||
| 111 | 30 | my $attr = $AUTOLOAD; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 30 | $attr =~ s/.*:://; | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 30 | ▶ | return if $attr =~ /^_/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 30 | ▶ | warn "AUTOLOAD: $attr\n" if $self->_debug_autoload; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 30 | ▶ | if(@_){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 120 | 10 | $self->_set($attr, shift); | |||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | 30 | return $self->_get($attr); | |||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 1 | 1; | |||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||