| 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
| |||||||||||||||||||||||||||||
| 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
$args{"address"} // $args{"device"}
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"}
| |||||||||||||||||||||||||||||
| 34 | 3 | ▶ | $addr = hex($addr) if $addr =~ /^0x/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 3 | ▶ | my $cmd = $args{command} // $args{function} // 0; | ||||||||||||||||||||||||||
|
Condition40%2/5
($args{"command"} // $args{"function"}) // 0
$args{"command"} // $args{"function"}
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"}
| |||||||||||||||||||||||||||||
| 36 | 3 | ▶ | $cmd = hex($cmd) if $cmd =~ /^0x/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
ref $pairs eq "ARRAY" and @$pairs >= 15
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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$mark >= 130 and $mark <= 390
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
| |||||||||||||||||||||||||||||
| 57 | 135 | my $bit; | |||||||||||||||||||||||||||
| 58 | 135 | my $mid = (1820 + 780) / 2; | |||||||||||||||||||||||||||
| 59 | 135 | ▶ | if ($space > $mid) { $bit = 1; } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 60 | 90 | ▶ | elsif ($space < $mid && $space > 390) { $bit = 0; } | ||||||||||||||||||||||||||
|
Condition33%1/3
$space < $mid and $space > 390
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||