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

filter: Statementstmt 84.7% 61 / 72 Branchbran 58.3% 7 / 12 Conditioncond 46.1% 6 / 13 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 5 totaltotal 70.5% 84 / 119 CC 12 SCAR 15.8
CC
12
Cov
76%
decode_params
8.6
decode_raw
6.0
decode_timing
5.0
CRAP 4.8
« bin/ir-tasmota2wig ↑ Summary blib/lib/Protocol/IR/Converter.pm »
1 package Protocol::IR::Proto::Pioneer;
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 55 ▶use Math::BigInt;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 55 ▶use Protocol::IR::Proto::NEC;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub new { bless {}, shift }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
12  
13 4 ▶sub _nec_encode {
Subroutine _nec_encode: called CC=1 SCAR=0.0
14 4 my ($addr, $cmd) = @_;
15 # NEC address byte, subaddress default ~addr, command, ~command
16 4 my $sub = (~$addr) & 0xff;
17 4 return (($addr & 0xff) << 24) | ($sub << 16) | (($cmd & 0xff) << 8) | ((~$cmd) & 0xff);
18 }
19  
20 0 ▶sub decode_raw {
Subroutine decode_raw: not called CC=2 SCAR=17.9
Pod undocumented
21 0 my ($class, $raw) = @_;
22 0 my $val;
23 0 ▶ if ($raw =~ /^0x/i) { $val = Math::BigInt->from_hex($raw); }
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /^0x/i) { } 0 0 0
24 0 else { $val = Math::BigInt->new($raw); }
25 0 my $first = ($val >> 32) & 0xffffffff;
26 0 my $second = $val & 0xffffffff;
27 0 my $address = ($first >> 8) & 0xff;
28 0 my $command = ($second >> 8) & 0xff;
29 0 return Protocol::IR::Code->new(
30 protocol => 'Pioneer',
31 bits => 64,
32 address => $address,
33 subaddress => -1,
34 command => $command,
35 data => $val,
36 );
37 }
38  
39 2 ▶sub decode_params {
Subroutine decode_params: called CC=7 SCAR=21.5
Pod undocumented
40 2 my ($class, %args) = @_;
41 2 ▶ my $address = $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
42 2 ▶ $address = hex($address) if $address =~ /^0x/i;
Branch: 1 branch
BranchTrueFalseTotal
if $address =~ /^0x/i 0 2 2
43 2 ▶ my $command = $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
44 2 ▶ $command = hex($command) if $command =~ /^0x/i;
Branch: 1 branch
BranchTrueFalseTotal
if $command =~ /^0x/i 0 2 2
45 2 $address &= 0xff;
46 2 $command &= 0xff;
47 2 my $first = _nec_encode(0, $address);
48 2 my $second = _nec_encode(0, $command);
49 2 my $data = (Math::BigInt->new($first) << 32) | Math::BigInt->new($second);
50 2 return Protocol::IR::Code->new(
51 protocol => 'Pioneer',
52 bits => 64,
53 address => $address,
54 subaddress => -1,
55 command => $command,
56 data => $data,
57 );
58 }
59  
60 939 ▶sub decode_timing {
Subroutine decode_timing: called CC=5 SCAR=16.1
Pod undocumented
61 939 my ($class, $pairs) = @_;
62 939 ▶ return undef unless ref $pairs eq 'ARRAY' && @$pairs >= 68;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pairs eq "ARRAY" and @$pairs >= 68 872 67 939
Condition66%2/3
ref $pairs eq "ARRAY" and @$pairs >= 68
!ll&&!rl&&r
087267
MC/DC50%1/2
ref $pairs eq "ARRAY" and @$pairs >= 68
ref $pairs eq "ARRAY" @$pairs >= 68
Truth table66%2/3
A and B
A= ref $pairs eq "ARRAY"B= @$pairs >= 68
ABresult
0X0
100
111
63 67 my $first = Protocol::IR::Proto::NEC->decode_timing([ @{$pairs}[0 .. 33] ]);
64 67 ▶ return undef unless defined $first;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $first 63 4 67
65 4 my $second = Protocol::IR::Proto::NEC->decode_timing([ @{$pairs}[34 .. 67] ]);
66 4 ▶ return undef unless defined $second;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $second 0 4 4
67 4 my $address = ($first->{data} >> 8) & 0xff;
68 4 my $command = ($second->{data} >> 8) & 0xff;
69 4 my $data = (Math::BigInt->new($first->{data}) << 32) | Math::BigInt->new($second->{data});
70 4 return Protocol::IR::Code->new(
71 protocol => 'Pioneer',
72 bits => 64,
73 address => $address,
74 subaddress => -1,
75 command => $command,
76 data => $data,
77 );
78 }
79  
80 2 ▶sub to_pronto {
Subroutine to_pronto: called CC=1 SCAR=0.0
Pod undocumented
81 2 my ($class, $code) = @_;
82 2 my $data = $code->{data};
83 2 my $first = ($data >> 32) & 0xffffffff;
84 2 my $second = $data & 0xffffffff;
85 2 my $first_code = Protocol::IR::Proto::NEC->decode_raw($first);
86 2 my $second_code = Protocol::IR::Proto::NEC->decode_raw($second);
87 2 my $p1 = Protocol::IR::Proto::NEC->to_pronto($first_code);
88 2 my $p2 = Protocol::IR::Proto::NEC->to_pronto($second_code);
89  
90 2 my @t1 = split(/\s+/, $p1);
91 2 my @t2 = split(/\s+/, $p2);
92 2 my $freq_word = $t1[1];
93 2 my $pairs1 = hex($t1[2]);
94 2 my $pairs2 = hex($t2[2]);
95 2 my $total = $pairs1 + $pairs2;
96 2 my $header = sprintf('0000 %s %04X 0000', $freq_word, $total);
97 2 my $payload1 = join(' ', @t1[4 .. $#t1]);
98 2 my $payload2 = join(' ', @t2[4 .. $#t2]);
99 2 return "$header $payload1 $payload2";
100 }
101  
102 55 1;
103  
104 =head1 NAME
105  
106 Protocol::IR::Proto::Pioneer - IR protocol handler
107  
108 =head1 VERSION
109  
110 version 1.5
111  
112 =cut
« bin/ir-tasmota2wig ↑ Summary blib/lib/Protocol/IR/Converter.pm »