| 1 | package Protocol::IR::Proto::Aiwa; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 55 | my $PRE_DATA = 0x1D8113F; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 55 | my $PRE_BITS = 26; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 55 | my $DATA_BITS = 15; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 55 | my $POST_BITS = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 55 | my $TOTAL_BITS = $PRE_BITS + $DATA_BITS + $POST_BITS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub new { bless {}, shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub _reverse_bits { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reverse_bits: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my ($v, $bits) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my $out = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | for my $i (0 .. $bits - 1) { $out |= (($v >> $i) & 1) << ($bits - 1 - $i); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub decode_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_raw: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my ($class, $raw) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my $val = $raw =~ /^0x/i ? Math::BigInt->from_hex($raw) : Math::BigInt->new($raw); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | return Protocol::IR::Code->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | protocol => 'Aiwa', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | bits => $DATA_BITS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | address => ($val >> 8) & 0x7f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | subaddress => -1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | command => $val & 0xff, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | data => $val, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | sub decode_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_params: called CC=7 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | $addr = hex($addr) if $addr =~ /^0x/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | $cmd = hex($cmd) if $cmd =~ /^0x/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | $addr &= 0x7f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | $cmd &= 0xff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | my $data = (Math::BigInt->new($addr) << 8) | Math::BigInt->new($cmd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | return Protocol::IR::Code->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | protocol => 'Aiwa', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | bits => $DATA_BITS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | address => $addr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | subaddress => -1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | command => $cmd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | data => $data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 145 | ▶ | sub decode_timing { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_timing: called CC=11 SCAR=25.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 145 | my ($class, $pairs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 145 | ▶ | return undef unless ref $pairs eq 'ARRAY' && @$pairs >= $TOTAL_BITS + 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $pairs eq "ARRAY" and @$pairs >= $TOTAL_BITS + 1
MC/DC50%1/2
ref $pairs eq "ARRAY" and @$pairs >= $TOTAL_BITS + 1
ref $pairs eq "ARRAY"
@$pairs >= $TOTAL_BITS + 1
Truth table66%2/3
A and B
A= ref $pairs eq "ARRAY"B= @$pairs >= $TOTAL_BITS + 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 5 | my ($hdr_mark, $hdr_space) = @{$pairs->[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 5 | ▶ | return undef unless $hdr_mark >= 7500 && $hdr_mark <= 10500 && $hdr_space >= 3500 && $hdr_space <= 5500; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$hdr_mark >= 7500 and $hdr_mark <= 10500 and $hdr_space >= 3500 and $hdr_space <= 5500
$hdr_mark >= 7500 and $hdr_mark <= 10500 and $hdr_space >= 3500
$hdr_mark >= 7500 and $hdr_mark <= 10500
MC/DC0%0/4
$hdr_mark >= 7500 and $hdr_mark <= 10500 and $hdr_space >= 3500 and $hdr_space <= 5500
$hdr_mark >= 7500
$hdr_mark <= 10500
$hdr_space >= 3500
$hdr_space <= 5500
Truth table20%1/5
A and B and C and D
A= $hdr_mark >= 7500B= $hdr_mark <= 10500C= $hdr_space >= 3500D= $hdr_space <= 5500
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 5 | my $data = Math::BigInt->bzero(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | for my $i (0 .. $TOTAL_BITS - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 210 | my $space = $pairs->[$i + 1][1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 210 | ▶ | my $bit = $space > 1100 ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 210 | $data = ($data << 1) | $bit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | my $prefix = ($data >> ($DATA_BITS + $POST_BITS)) & ((1 << $PRE_BITS) - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | my $postfix = $data & 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 5 | ▶ | return undef unless $prefix == $PRE_DATA && $postfix == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$prefix == $PRE_DATA and $postfix == 1
MC/DC50%1/2
$prefix == $PRE_DATA and $postfix == 1
$prefix == $PRE_DATA
$postfix == 1
Truth table66%2/3
A and B
A= $prefix == $PRE_DATAB= $postfix == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 4 | my $var = ($data >> $POST_BITS) & Math::BigInt->new((1 << $DATA_BITS) - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 4 | return Protocol::IR::Code->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | protocol => 'Aiwa', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | bits => $DATA_BITS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | address => ($var >> 8) & 0x7f, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | subaddress => -1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | command => $var & 0xff, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | data => $var, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | ▶ | sub to_pronto { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_pronto: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | my ($class, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | my $var = $code->{data} & Math::BigInt->new('0x7fff'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | my $full = (Math::BigInt->new($PRE_DATA) << ($DATA_BITS + $POST_BITS)) | ($var << $POST_BITS) | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | my $carrier_hz = 38000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | my $freq_word = int(1000000.0 / ($carrier_hz * 0.241246) + 0.5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | my $period_us = $freq_word * 0.241246; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | my $us_to_pulses = sub { int($_[0] / $period_us + 0.5) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | my @bits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | for my $i (reverse 0 .. $TOTAL_BITS - 1) { push @bits, ($full >> $i) & 1; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | my @pairs = ( [ $us_to_pulses->(9024), $us_to_pulses->(4512) ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | for my $bit (@bits) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 84 | ▶ | push @pairs, [ $us_to_pulses->(562.5), $us_to_pulses->($bit ? 1687.5 : 562.5) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | push @pairs, [ $us_to_pulses->(564), $us_to_pulses->(43992) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | my $seq1 = scalar(@pairs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | my $header = sprintf('0000 %04X %04X 0000', $freq_word, $seq1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | my $payload = join(' ', map { sprintf('%04X %04X', $_->[0], $_->[1]) } @pairs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | return "$header $payload"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 55 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | Protocol::IR::Proto::Aiwa - IR protocol handler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | version 1.5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||