| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
$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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | $addr = hex($addr) if $addr =~ /^0x/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | $cmd = hex($cmd) if $cmd =~ /^0x/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
ref $pairs eq "ARRAY" and @$pairs
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
@expanded and $expanded[-1] < 0
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
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 163 | ▶ | return undef unless @expanded >= 8 + 2 + 2 * 20; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 63 | ▶ | for my $i (0 .. 5) { return undef unless $expanded[$i] > 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 27 | ▶ | return undef unless $expanded[6] < 0 && $expanded[7] < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$expanded[6] < 0 and $expanded[7] < 0
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
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | my $idx = 8; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 6 | ▶ | return undef unless $idx + 1 < @expanded && $expanded[$idx] > 0 && $expanded[$idx + 1] < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$idx + 1 < @expanded and $expanded[$idx] > 0 and $expanded[$idx + 1] < 0
$idx + 1 < @expanded and $expanded[$idx] > 0
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 120 | ▶ | return undef if $idx + 2 * $w > @expanded; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 120 | ▶ | my $levelA = $expanded[$idx] > 0 ? 1 : -1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 120 | for my $k (0 .. $w - 1) { | |||||||||||||||||||||||||||||||||||||||||
| 73 | 126 | ▶ | return undef unless ($expanded[$idx + $k] > 0 ? 1 : -1) == $levelA; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 120 | $idx += $w; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 120 | ▶ | my $levelB = $expanded[$idx] > 0 ? 1 : -1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 120 | for my $k (0 .. $w - 1) { | |||||||||||||||||||||||||||||||||||||||||
| 78 | 126 | ▶ | return undef unless ($expanded[$idx + $k] > 0 ? 1 : -1) == $levelB; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 120 | $idx += $w; | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 120 | ▶ | if ($levelA == 1 && $levelB == -1) { $data = ($data << 1) | 1; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$levelA == 1 and $levelB == -1
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
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 107 | ▶ | elsif ($levelA == -1 && $levelB == 1) { $data = $data << 1; } | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$levelA == -1 and $levelB == 1
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 40 | my $bit = ($data >> (19 - $i)) & 1; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 40 | ▶ | if ($bit == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||