blib/lib/Protocol/IR/Proto/RC6.pm

filter: Statementstmt 93.9% 78 / 83 Branchbran 78.5% 33 / 42 Conditioncond 51.6% 16 / 31 MC/DCmcdc 29.4% 5 / 17 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 5 totaltotal 74.3% 139 / 187 CC 41 SCAR 32.0
CC
41
Cov
81%
decode_timing
35.4
decode_params
9.1
decode_raw
6.0
CRAP 24.4
« blib/lib/Protocol/IR/Proto/Sharp.pm ↑ Summary blib/lib/Protocol/IR/Format/CSV.pm »
1 package Protocol::IR::Proto::RC6;
2 55 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 55 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 55 our $VERSION = '1.5';
6  
7 55 ▶use Protocol::IR::Code;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶sub new { bless {}, shift }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
10  
11 0 ▶sub decode_raw {
Subroutine decode_raw: not called CC=2 SCAR=17.9
Pod undocumented
12 0 my ($class, $raw) = @_;
13 0 ▶ my $val = $raw =~ /^0x/i ? hex($raw) : $raw + 0;
Branch: 1 branch
BranchTrueFalseTotal
$raw =~ /^0x/i ? : 0 0 0
14 0 return Protocol::IR::Code->new(
15 protocol => 'RC6',
16 bits => 20,
17 address => ($val >> 8) & 0xff,
18 subaddress => -1,
19 command => $val & 0xff,
20 data => $val,
21 );
22 }
23  
24 2 ▶sub decode_params {
Subroutine decode_params: called CC=7 SCAR=22.0
Pod undocumented
25 2 my ($class, %args) = @_;
26 2 ▶ my $addr = $args{address} // $args{device} // 0;
Condition40%2/5
($args{"address"} // $args{"device"}) // 0
l!l
20
$args{"address"} // $args{"device"}
l!l&&r!l&&!r
200
MC/DC0%0/2
($args{"address"} // $args{"device"}) // 0
$args{"address"} $args{"device"}
Truth table33%1/3
A // B
A= $args{"address"}B= $args{"device"}
ABresult
1X1
011
000
27 2 ▶ $addr = hex($addr) if $addr =~ /^0x/i;
Branch: 1 branch
BranchTrueFalseTotal
if $addr =~ /^0x/i 0 2 2
28 2 ▶ my $cmd = $args{command} // $args{function} // 0;
Condition40%2/5
($args{"command"} // $args{"function"}) // 0
l!l
20
$args{"command"} // $args{"function"}
l!l&&r!l&&!r
200
MC/DC0%0/2
($args{"command"} // $args{"function"}) // 0
$args{"command"} $args{"function"}
Truth table33%1/3
A // B
A= $args{"command"}B= $args{"function"}
ABresult
1X1
011
000
29 2 ▶ $cmd = hex($cmd) if $cmd =~ /^0x/i;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd =~ /^0x/i 0 2 2
30 2 $addr &= 0xff;
31 2 $cmd &= 0xff;
32 2 my $data = ($addr << 8) | $cmd;
33 2 return Protocol::IR::Code->new(
34 protocol => 'RC6',
35 bits => 20,
36 address => $addr,
37 subaddress => -1,
38 command => $cmd,
39 data => $data,
40 );
41 }
42  
43 164 ▶sub decode_timing {
Subroutine decode_timing: called CC=31 SCAR=35.7
Pod undocumented
44 164 my ($class, $pairs) = @_;
45 164 ▶ return undef unless ref $pairs eq 'ARRAY' && @$pairs;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pairs eq "ARRAY" and @$pairs 1 163 164
Condition66%2/3
ref $pairs eq "ARRAY" and @$pairs
!ll&&!rl&&r
01163
MC/DC50%1/2
ref $pairs eq "ARRAY" and @$pairs
ref $pairs eq "ARRAY" @$pairs
Truth table66%2/3
A and B
A= ref $pairs eq "ARRAY"B= @$pairs
ABresult
0X0
100
111
46  
47 # Expand pairs into tick units.
48 163 my @expanded;
49 163 for my $p (@$pairs) {
50 2352 my ($m, $s) = @$p;
51 2352 my $mn = int(($m + 222) / 444);
52 2352 for (1 .. $mn) { push @expanded, 444; }
53 2352 my $sn = int(($s + 222) / 444);
54 2352 for (1 .. $sn) { push @expanded, -444; }
55 }
56 # strip trailing spaces
57 163 ▶ while (@expanded && $expanded[-1] < 0) { pop @expanded; }
Branch: 1 branch
BranchTrueFalseTotal
if (@expanded and $expanded[-1] < 0) 76016 163 76179
Condition100%3/3
@expanded and $expanded[-1] < 0
!ll&&!rl&&r
216176016
MC/DC100%2/2
@expanded and $expanded[-1] < 0
@expanded $expanded[-1] < 0
Truth table100%3/3
A and B
A= @expandedB= $expanded[-1] < 0
ABresult
0X0
100
111
58  
59 163 ▶ return undef unless @expanded >= 8 + 2 + 2 * 20;
Branch: 1 branch
BranchTrueFalseTotal
unless @expanded >= 50 100 63 163
60 63 ▶ for my $i (0 .. 5) { return undef unless $expanded[$i] > 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless $expanded[$i] > 0 36 198 234
61 27 ▶ return undef unless $expanded[6] < 0 && $expanded[7] < 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $expanded[6] < 0 and $expanded[7] < 0 21 6 27
Condition66%2/3
$expanded[6] < 0 and $expanded[7] < 0
!ll&&!rl&&r
2106
MC/DC50%1/2
$expanded[6] < 0 and $expanded[7] < 0
$expanded[6] < 0 $expanded[7] < 0
Truth table66%2/3
A and B
A= $expanded[6] < 0B= $expanded[7] < 0
ABresult
0X0
100
111
62  
63 6 my $idx = 8;
64 6 ▶ return undef unless $idx + 1 < @expanded && $expanded[$idx] > 0 && $expanded[$idx + 1] < 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $idx + 1 < @expanded and $expanded[$idx] > 0 and $expanded[$idx + 1] < 0 0 6 6
Condition33%2/6
$idx + 1 < @expanded and $expanded[$idx] > 0 and $expanded[$idx + 1] < 0
!ll&&!rl&&r
006
$idx + 1 < @expanded and $expanded[$idx] > 0
!ll&&!rl&&r
006
MC/DC0%0/3
$idx + 1 < @expanded and $expanded[$idx] > 0 and $expanded[$idx + 1] < 0
$idx + 1 < @expanded $expanded[$idx] > 0 $expanded[$idx + 1] < 0
Truth table25%1/4
A and B and C
A= $idx + 1 < @expandedB= $expanded[$idx] > 0C= $expanded[$idx + 1] < 0
ABCresult
0XX0
10X0
1100
1111
65 6 $idx += 2;
66  
67 6 my $data = 0;
68 6 for my $bitIndex (0 .. 19) {
69 120 ▶ my $w = ($bitIndex == 3) ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$bitIndex == 3 ? : 6 114 120
70 120 ▶ return undef if $idx + 2 * $w > @expanded;
Branch: 1 branch
BranchTrueFalseTotal
if $idx + 2 * $w > @expanded 0 120 120
71 120 ▶ my $levelA = $expanded[$idx] > 0 ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$expanded[$idx] > 0 ? : 13 107 120
72 120 for my $k (0 .. $w - 1) {
73 126 ▶ return undef unless ($expanded[$idx + $k] > 0 ? 1 : -1) == $levelA;
Branch: 2 branches
BranchTrueFalseTotal
unless ($expanded[$idx + $k] > 0 ? 1 : -1) == $levelA 0 126 126
$expanded[$idx + $k] > 0 ? : 17 109 126
74 }
75 120 $idx += $w;
76 120 ▶ my $levelB = $expanded[$idx] > 0 ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$expanded[$idx] > 0 ? : 107 13 120
77 120 for my $k (0 .. $w - 1) {
78 126 ▶ return undef unless ($expanded[$idx + $k] > 0 ? 1 : -1) == $levelB;
Branch: 2 branches
BranchTrueFalseTotal
unless ($expanded[$idx + $k] > 0 ? 1 : -1) == $levelB 0 126 126
$expanded[$idx + $k] > 0 ? : 109 17 126
79 }
80 120 $idx += $w;
81  
82 120 ▶ if ($levelA == 1 && $levelB == -1) { $data = ($data << 1) | 1; }
Branch: 2 branches
BranchTrueFalseTotal
if ($levelA == 1 and $levelB == -1) { } 13 107 120
elsif ($levelA == -1 and $levelB == 1) { } 107 0 107
Condition66%2/3
$levelA == 1 and $levelB == -1
!ll&&!rl&&r
107013
MC/DC50%1/2
$levelA == 1 and $levelB == -1
$levelA == 1 $levelB == -1
Truth table66%2/3
A and B
A= $levelA == 1B= $levelB == -1
ABresult
0X0
100
111
83 107 ▶ elsif ($levelA == -1 && $levelB == 1) { $data = $data << 1; }
Condition33%1/3
$levelA == -1 and $levelB == 1
!ll&&!rl&&r
00107
MC/DC0%0/2
$levelA == -1 and $levelB == 1
$levelA == -1 $levelB == 1
Truth table33%1/3
A and B
A= $levelA == -1B= $levelB == 1
ABresult
0X0
100
111
84 0 else { return undef; }
85 }
86  
87 6 return Protocol::IR::Code->new(
88 protocol => 'RC6',
89 bits => 20,
90 address => ($data >> 8) & 0xff,
91 subaddress => -1,
92 command => $data & 0xff,
93 data => $data,
94 );
95 }
96  
97 2 ▶sub to_pronto {
Subroutine to_pronto: called CC=4 SCAR=13.9
Pod undocumented
98 2 my ($class, $code) = @_;
99 2 my $data = $code->{data} & 0xfffff;
100 2 my $carrier_hz = 36000;
101 2 my $freq_word = int(1000000.0 / ($carrier_hz * 0.241246) + 0.5);
102 2 my $period_us = $freq_word * 0.241246;
103 2 ▶ my $us_to_pulses = sub { int($_[0] / $period_us + 0.5) };
Subroutine __ANON__: called CC=1 SCAR=0.0
104  
105 2 my @pronto_pairs;
106 # header
107 2 push @pronto_pairs, [ $us_to_pulses->(6 * 444), $us_to_pulses->(2 * 444) ];
108 # start bit
109 2 push @pronto_pairs, [ $us_to_pulses->(444), $us_to_pulses->(444) ];
110 2 for my $i (0 .. 19) {
111 40 ▶ my $w = ($i == 3) ? 2 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$i == 3 ? : 2 38 40
112 40 my $bit = ($data >> (19 - $i)) & 1;
113 40 ▶ if ($bit == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bit == 1) { } 5 35 40
114 5 push @pronto_pairs, [ $w * $us_to_pulses->(444), $w * $us_to_pulses->(444) ];
115 } else {
116 35 push @pronto_pairs, [ 0, $w * $us_to_pulses->(444) ];
117 35 push @pronto_pairs, [ $w * $us_to_pulses->(444), 0 ];
118 }
119 }
120  
121 2 my $seq1 = scalar(@pronto_pairs);
122 2 my $header = sprintf('0000 %04X %04X 0000', $freq_word, $seq1);
123 2 my $payload = join(' ', map { sprintf('%04X %04X', $_->[0], $_->[1]) } @pronto_pairs);
124 2 return "$header $payload";
125 }
126  
127 55 1;
128  
129 =head1 NAME
130  
131 Protocol::IR::Proto::RC6 - IR protocol handler
132  
133 =head1 VERSION
134  
135 version 1.5
136  
137 =cut
« blib/lib/Protocol/IR/Proto/Sharp.pm ↑ Summary blib/lib/Protocol/IR/Format/CSV.pm »