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

filter: Statementstmt 90.9% 70 / 77 Branchbran 72.2% 13 / 18 Conditioncond 47.3% 9 / 19 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 73.3% 11 / 15 Podpod 0.0% 0 / 5 totaltotal 72.9% 105 / 144 CC 22 SCAR 18.3
CC
22
Cov
81%
decode_timing
9.5
decode_params
9.1
to_pronto
7.0
CRAP 6.2
« blib/lib/Protocol/IR/Proto/SAMSUNG.pm ↑ Summary blib/lib/Protocol/IR/Proto/Mitsubishi.pm »
1 package Protocol::IR::Proto::Denon;
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 3 ▶sub _pack {
Subroutine _pack: called CC=1 SCAR=0.0
12 3 my ($class, $addr, $cmd) = @_;
13 3 return (($addr & 0x1f) << 10) | (($cmd & 0xff) << 2);
14 }
15  
16 12 ▶sub _protocol_name { 'DENON' }
Subroutine _protocol_name: called CC=1 SCAR=0.0
17  
18 0 ▶sub decode_raw {
Subroutine decode_raw: not called CC=2 SCAR=17.9
Pod undocumented
19 0 my ($class, $raw) = @_;
20 0 ▶ my $val = $raw =~ /^0x/i ? hex($raw) : $raw + 0;
Branch: 1 branch
BranchTrueFalseTotal
$raw =~ /^0x/i ? : 0 0 0
21 0 return Protocol::IR::Code->new(
22 protocol => $class->_protocol_name,
23 bits => 15,
24 address => ($val >> 10) & 0x1f,
25 subaddress => -1,
26 command => ($val >> 2) & 0xff,
27 data => $val,
28 );
29 }
30  
31 3 ▶sub decode_params {
Subroutine decode_params: called CC=7 SCAR=22.0
Pod undocumented
32 3 my ($class, %args) = @_;
33 3 ▶ my $addr = $args{address} // $args{device} // 0;
Condition40%2/5
($args{"address"} // $args{"device"}) // 0
l!l
30
$args{"address"} // $args{"device"}
l!l&&r!l&&!r
300
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
34 3 ▶ $addr = hex($addr) if $addr =~ /^0x/i;
Branch: 1 branch
BranchTrueFalseTotal
if $addr =~ /^0x/i 0 3 3
35 3 ▶ my $cmd = $args{command} // $args{function} // 0;
Condition40%2/5
($args{"command"} // $args{"function"}) // 0
l!l
30
$args{"command"} // $args{"function"}
l!l&&r!l&&!r
300
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
36 3 ▶ $cmd = hex($cmd) if $cmd =~ /^0x/i;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd =~ /^0x/i 0 3 3
37 3 $addr &= 0x1f;
38 3 $cmd &= 0xff;
39 3 my $data = $class->_pack($addr, $cmd);
40 3 return Protocol::IR::Code->new(
41 protocol => $class->_protocol_name,
42 bits => 15,
43 address => $addr,
44 subaddress => -1,
45 command => $cmd,
46 data => $data,
47 );
48 }
49  
50 414 ▶sub decode_timing {
Subroutine decode_timing: called CC=9 SCAR=22.5
Pod undocumented
51 414 my ($class, $pairs) = @_;
52 414 ▶ return undef unless ref $pairs eq 'ARRAY' && @$pairs >= 15;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pairs eq "ARRAY" and @$pairs >= 15 219 195 414
Condition66%2/3
ref $pairs eq "ARRAY" and @$pairs >= 15
!ll&&!rl&&r
0219195
MC/DC50%1/2
ref $pairs eq "ARRAY" and @$pairs >= 15
ref $pairs eq "ARRAY" @$pairs >= 15
Truth table66%2/3
A and B
A= ref $pairs eq "ARRAY"B= @$pairs >= 15
ABresult
0X0
100
111
53 195 my $data = 0;
54 195 for my $i (0 .. 14) {
55 321 my ($mark, $space) = @{$pairs->[$i]};
56 321 ▶ return undef unless $mark >= 130 && $mark <= 390;
Branch: 1 branch
BranchTrueFalseTotal
unless $mark >= 130 and $mark <= 390 186 135 321
Condition66%2/3
$mark >= 130 and $mark <= 390
!ll&&!rl&&r
0186135
MC/DC50%1/2
$mark >= 130 and $mark <= 390
$mark >= 130 $mark <= 390
Truth table66%2/3
A and B
A= $mark >= 130B= $mark <= 390
ABresult
0X0
100
111
57 135 my $bit;
58 135 my $mid = (1820 + 780) / 2;
59 135 ▶ if ($space > $mid) { $bit = 1; }
Branch: 2 branches
BranchTrueFalseTotal
if ($space > $mid) { } 45 90 135
elsif ($space < $mid and $space > 390) { } 90 0 90
60 90 ▶ elsif ($space < $mid && $space > 390) { $bit = 0; }
Condition33%1/3
$space < $mid and $space > 390
!ll&&!rl&&r
0090
MC/DC0%0/2
$space < $mid and $space > 390
$space < $mid $space > 390
Truth table33%1/3
A and B
A= $space < $midB= $space > 390
ABresult
0X0
100
111
61 0 else { return undef; }
62 135 $data = ($data << 1) | $bit;
63 }
64 9 return Protocol::IR::Code->new(
65 protocol => $class->_protocol_name,
66 bits => 15,
67 address => ($data >> 10) & 0x1f,
68 subaddress => -1,
69 command => ($data >> 2) & 0xff,
70 data => $data,
71 );
72 }
73  
74 3 ▶sub to_pronto {
Subroutine to_pronto: called CC=7 SCAR=19.5
Pod undocumented
75 3 my ($class, $code) = @_;
76 3 my $data = $code->{data};
77 3 my $carrier_hz = 38000;
78 3 my $freq_word = int(1000000.0 / ($carrier_hz * 0.241246) + 0.5);
79 3 my $period_us = $freq_word * 0.241246;
80 3 ▶ my $us_to_pulses = sub { int($_[0] / $period_us + 0.5) };
Subroutine __ANON__: called CC=1 SCAR=0.0
81  
82 3 my @bits;
83 3 for my $i (reverse 0 .. 14) { push @bits, ($data >> $i) & 1; }
84  
85 3 my @pairs;
86 3 for my $bit (@bits) {
87 45 ▶ push @pairs, [ $us_to_pulses->(260), $us_to_pulses->($bit ? 1820 : 780) ];
Branch: 1 branch
BranchTrueFalseTotal
$bit ? : 15 30 45
88 }
89 # inverted frame
90 3 my $addr = ($data >> 10) & 0x1f;
91 3 my $rest = $data & 0x3ff;
92 3 my $inverted = ($addr << 10) | (~$rest & 0x3ff);
93 3 my @invbits;
94 3 for my $i (reverse 0 .. 14) { push @invbits, ($inverted >> $i) & 1; }
95 3 for my $bit (@invbits) {
96 45 ▶ push @pairs, [ $us_to_pulses->(260), $us_to_pulses->($bit ? 1820 : 780) ];
Branch: 1 branch
BranchTrueFalseTotal
$bit ? : 27 18 45
97 }
98  
99 3 my $seq1 = scalar(@pairs);
100 3 my $header = sprintf('0000 %04X %04X 0000', $freq_word, $seq1);
101 3 my $payload = join(' ', map { sprintf('%04X %04X', $_->[0], $_->[1]) } @pairs);
102 3 return "$header $payload";
103 }
104  
105 55 1;
106  
107 package Protocol::IR::Proto::DenonK;
108 55 ▶use base 'Protocol::IR::Proto::Denon';
Subroutine BEGIN: called CC=1 SCAR=0.0
109 0 ▶sub _protocol_name { 'DENON-K' }
Subroutine _protocol_name: not called CC=1 SCAR=6.9
110  
111 package Protocol::IR::Proto::Denon1;
112 55 ▶use base 'Protocol::IR::Proto::Denon';
Subroutine BEGIN: called CC=1 SCAR=0.0
113 0 ▶sub _protocol_name { 'DENON{1}' }
Subroutine _protocol_name: not called CC=1 SCAR=6.9
114  
115 55 1;
116  
117 =head1 NAME
118  
119 Protocol::IR::Proto::Denon - IR protocol handler
120  
121 =head1 VERSION
122  
123 version 1.5
124  
125 =cut
« blib/lib/Protocol/IR/Proto/SAMSUNG.pm ↑ Summary blib/lib/Protocol/IR/Proto/Mitsubishi.pm »