blib/lib/GPS/Magellan.pm

filter: Statementstmt 71.4% 60 / 84 Branchbran 31.2% 10 / 32 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 80.0% 12 / 15 Podpod n/a totaltotal 58.6% 85 / 145 CC 22 SCAR 20.6
CC
22
Cov
58%
_command
30.0
_set
12.0
DESTROY
6.0
CRAP 7.9
↑ Summary blib/lib/GPS/Magellan/File.pm »
1 package GPS::Magellan;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use GPS::Magellan::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use GPS::Magellan::Coord;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use vars qw($AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 our $VERSION = '0.61';
12  
13 1 ▶sub new {
Subroutine new: called CC=5 SCAR=17.3
14 1 my $proto = shift;
15  
16 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
17  
18 1 my %args = @_;
19  
20 1 ▶ my $port = $args{port} || '/dev/ttyS0';
Condition50%1/2
$args{'port'} || '/dev/ttyS0'
l!l
10
MC/DC0%0/1
$args{'port'} || '/dev/ttyS0'
$args{'port'}
Truth table50%1/2
A
A= $args{'port'}
Aresult
11
00
21  
22 my $self = bless {
23 1 ▶ RUN_OFFLINE => $args{RUN_OFFLINE} || 0,
Condition50%1/2
$args{'RUN_OFFLINE'} || 0
l!l
10
MC/DC0%0/1
$args{'RUN_OFFLINE'} || 0
$args{'RUN_OFFLINE'}
Truth table50%1/2
A
A= $args{'RUN_OFFLINE'}
Aresult
11
00
24 port => $port,
25 raw_file => 'magellan.log',
26 debug => 1,
27 }, $class;
28  
29 1 warn "calling init\n";
30 1 ▶ magellan_init() unless $self->RUN_OFFLINE;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->RUN_OFFLINE 0 1 1
31 1 $self;
32 }
33  
34 1 ▶sub connect {
Subroutine connect: called CC=2 SCAR=7.2
35 1 my $self = shift;
36 1 ▶ return if $self->RUN_OFFLINE;
Branch: 1 branch
BranchTrueFalseTotal
if $self->RUN_OFFLINE 1 0 1
37 # die sprintf("GPS::Magellan::new(): port not specified") unless $self->{port};
38 # OpenPort($self->{port});
39 }
40  
41 1 ▶sub getPoints {
Subroutine getPoints: called CC=3 SCAR=11.0
42 1 my $self = shift;
43 1 ▶ my $cmd = shift or die "getPoint( WAYPOINT | TRACKLOG )\n";
Branch: 1 branch
BranchTrueFalseTotal
my $cmd = shift() or die "getPoint( WAYPOINT | TRACKLOG )\n" 1 0 1
44  
45 1 my @messages = $self->command($cmd);
46 1 my @coords = ();
47 1 foreach my $msg (@messages){
48 10 my $wpt = GPS::Magellan::Coord->new($msg->DATA);
49 10 push @coords, $wpt;
50 }
51 1 return @coords;
52 }
53  
54 1 ▶sub command {
Subroutine command: called CC=4 SCAR=14.0
55 1 my $self = shift;
56 1 my $cmd = shift;
57  
58 1 ▶ die "command() needs cmd" unless $cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd 0 1 1
59  
60 1 ▶ return $self->_command($cmd) unless $self->RUN_OFFLINE;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->RUN_OFFLINE 0 1 1
61  
62 1 my $data_file = "test-data/$cmd";
63  
64 1 ▶ open(DATA, "$data_file") or die "cannot open $data_file\n";
Branch: 1 branch
BranchTrueFalseTotal
open DATA, "$data_file" or die "cannot open $data_file\n" 1 0 1
65 1 my @result = <DATA>;
66 1 close(DATA);
67  
68 map {
69 1 chomp;
70 10 my $data = $_;
71 10 $_ = GPS::Magellan::Message->new;
72 10 $_->DATA($data);
73 } @result;
74
75 1 return @result;
76  
77 }
78  
79 0 ▶sub _command {
Subroutine _command: not called CC=5 SCAR=34.0
80 0 my $self = shift;
81 0 my $cmd = shift;
82  
83 0 ▶ die "_command() needs cmd" unless $cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd 0 0 0
84  
85 0 magellan_handon();
86  
87 0 MagWriteMessageSum("PMGNCMD,$cmd");
88  
89 0 my @messages = ();
90  
91 0 while(1){
92 0 ▶ my $raw_msg = magellan_findmessage('$PMGN') or next;
Branch: 1 branch
BranchTrueFalseTotal
my $raw_msg = magellan_findmessage("\$PMGN") or next 0 0 0
93  
94 0 my $msg = GPS::Magellan::Message->new($raw_msg);
95
96 0 ▶ if($msg->COMMAND eq 'CMD'){
Branch: 1 branch
BranchTrueFalseTotal
if ($msg->COMMAND eq "CMD") 0 0 0
97 0 ▶ last if $msg->DATA eq 'END';
Branch: 1 branch
BranchTrueFalseTotal
if $msg->DATA eq "END" 0 0 0
98 }
99  
100 0 my $chksum = $msg->CHECKSUM;
101  
102 0 my $ack = sprintf("PMGNCSM,%s", $chksum);
103  
104 0 MagWriteMessageNoAck($ack);
105
106 0 push @messages, $msg;
107 }
108 0 return @messages;
109 }
110  
111  
112 # Accessors
113 6 ▶sub _get {
Subroutine _get: called CC=1 SCAR=0.0
114 6 my $self = shift;
115 6 my $attr = shift;
116 6 return $self->{$attr};
117 }
118  
119 0 ▶sub _set {
Subroutine _set: not called CC=3 SCAR=24.8
120 0 my $self = shift;
121 0 my $attr = shift;
122 0 ▶ my $value = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
123  
124 0 ▶ return unless $attr;
Branch: 1 branch
BranchTrueFalseTotal
unless $attr 0 0 0
125  
126 0 $self->{$attr} = $value;
127 0 return $self->_get($attr);
128 }
129  
130 3 ▶sub _debug_autoload {
Subroutine _debug_autoload: called CC=2 SCAR=7.1
131 3 my $self = shift;
132 3 ▶ $self->_set('_debug_autoload', shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 3 3
133 3 $self->_get('_debug_autoload');
134 }
135  
136
137 3 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=14.8
138 3 my $self = shift;
139 3 my $attr = $AUTOLOAD;
140  
141 3 $attr =~ s/.*:://;
142  
143 3 ▶ return if $attr =~ /^_/;
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^_/ 0 3 3
144  
145 3 ▶ warn "AUTOLOAD: $attr\n" if $self->_debug_autoload;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_debug_autoload 0 3 3
146  
147 3 ▶ if(@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 3 3
148 0 $self->_set($attr, shift);
149 }
150 3 return $self->_get($attr);
151 }
152  
153 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=2 SCAR=17.9
154 0 ▶ ClosePort() unless shift->RUN_OFFLINE;
Branch: 1 branch
BranchTrueFalseTotal
unless (shift())->RUN_OFFLINE 0 0 0
155 }
156  
157 require XSLoader;
158 XSLoader::load('GPS::Magellan', $VERSION);
159  
160 1;
161  
162 __END__
↑ Summary blib/lib/GPS/Magellan/File.pm »