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

filter: Statementstmt 92.8% 52 / 56 Branchbran 75.0% 12 / 16 Conditioncond 50.0% 8 / 16 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 5 totaltotal 73.6% 81 / 110 CC 18 SCAR 18.3
CC
18
Cov
82%
decode_params
9.1
decode_timing
8.0
decode_raw
6.0
CRAP 6.2
« blib/lib/Protocol/IR/Proto/Denon.pm ↑ Summary bin/ir-convert »
1 package Protocol::IR::Proto::Mitsubishi;
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 => 'Mitsubishi',
16 bits => 16,
17 address => ($val >> 8) & 0xff,
18 subaddress => -1,
19 command => $val & 0xff,
20 data => $val & 0xffff,
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 => 'Mitsubishi',
35 bits => 16,
36 address => $addr,
37 subaddress => -1,
38 command => $cmd,
39 data => $data,
40 );
41 }
42  
43 158 ▶sub decode_timing {
Subroutine decode_timing: called CC=8 SCAR=20.8
Pod undocumented
44 158 my ($class, $pairs) = @_;
45 158 ▶ return undef unless ref $pairs eq 'ARRAY' && @$pairs >= 16;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pairs eq "ARRAY" and @$pairs >= 16 73 85 158
Condition66%2/3
ref $pairs eq "ARRAY" and @$pairs >= 16
!ll&&!rl&&r
07385
MC/DC50%1/2
ref $pairs eq "ARRAY" and @$pairs >= 16
ref $pairs eq "ARRAY" @$pairs >= 16
Truth table66%2/3
A and B
A= ref $pairs eq "ARRAY"B= @$pairs >= 16
ABresult
0X0
100
111
46 85 my $data = 0;
47 85 for my $i (0 .. 15) {
48 154 my ($mark, $space) = @{$pairs->[$i]};
49 154 ▶ return undef unless $mark >= 250 && $mark <= 350;
Branch: 1 branch
BranchTrueFalseTotal
unless $mark >= 250 and $mark <= 350 72 82 154
Condition66%2/3
$mark >= 250 and $mark <= 350
!ll&&!rl&&r
07282
MC/DC50%1/2
$mark >= 250 and $mark <= 350
$mark >= 250 $mark <= 350
Truth table66%2/3
A and B
A= $mark >= 250B= $mark <= 350
ABresult
0X0
100
111
50 82 my $bit;
51 82 ▶ if (abs($space - 2100) < 200) { $bit = 1; }
Branch: 2 branches
BranchTrueFalseTotal
if (abs $space - 2100 < 200) { } 26 56 82
elsif (abs $space - 900 < 200) { } 47 9 56
52 47 elsif (abs($space - 900) < 200) { $bit = 0; }
53 9 else { return undef; }
54 73 $data = ($data << 1) | $bit;
55 }
56 4 return Protocol::IR::Code->new(
57 protocol => 'Mitsubishi',
58 bits => 16,
59 address => ($data >> 8) & 0xff,
60 subaddress => -1,
61 command => $data & 0xff,
62 data => $data,
63 );
64 }
65  
66 2 ▶sub to_pronto {
Subroutine to_pronto: called CC=4 SCAR=13.9
Pod undocumented
67 2 my ($class, $code) = @_;
68 2 my $data = $code->{data} & 0xffff;
69 2 my $carrier_hz = 33000;
70 2 my $freq_word = int(1000000.0 / ($carrier_hz * 0.241246) + 0.5);
71 2 my $period_us = $freq_word * 0.241246;
72 2 ▶ my $us_to_pulses = sub { int($_[0] / $period_us + 0.5) };
Subroutine __ANON__: called CC=1 SCAR=0.0
73  
74 2 my @bits;
75 2 for my $i (reverse 0 .. 15) { push @bits, ($data >> $i) & 1; }
76  
77 2 my @pairs;
78 2 for my $bit (@bits) {
79 32 ▶ push @pairs, [ $us_to_pulses->(300), $us_to_pulses->($bit ? 2100 : 900) ];
Branch: 1 branch
BranchTrueFalseTotal
$bit ? : 14 18 32
80 }
81  
82 2 my $seq1 = scalar(@pairs);
83 2 my $header = sprintf('0000 %04X %04X 0000', $freq_word, $seq1);
84 2 my $payload = join(' ', map { sprintf('%04X %04X', $_->[0], $_->[1]) } @pairs);
85 2 return "$header $payload";
86 }
87  
88 55 1;
89  
90 =head1 NAME
91  
92 Protocol::IR::Proto::Mitsubishi - IR protocol handler
93  
94 =head1 VERSION
95  
96 version 1.5
97  
98 =cut
« blib/lib/Protocol/IR/Proto/Denon.pm ↑ Summary bin/ir-convert »