| 1 | package Protocol::IR::Proto::NEC; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 55 | ▶ | use Protocol::IR::Code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # Protocol::IR::Proto::NEC is the base class for the whole NEC protocol family. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # The single-frame formats differ only along two independent axes, both | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # taken from the MakeHex IRP files IRDB builds on (nec1.irp, nec2.irp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # NECx1.irp, NECx2.irp): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # header NEC1/NEC2 use the full 9024/4512 µs preamble | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # (Prefix=16,-8); NECx1/NECx2 use the half header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # 4512/4512 µs (Prefix=8,-8, see _half_header). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # subaddress NEC1/NEC2 expect the subaddress byte to be the one's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # complement of the address (Default S=~D); NECx1/NECx2 use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # it as the low byte of a real 16-bit address (Default S=D), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # so it is never normalized to -1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # NEC2 and NECx2 are timing-identical to NEC1 and NECx1 respectively for a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # single frame; the "2" variants only repeat the *entire* 32-bit frame | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # instead of a short header+gap ditto frame, which is invisible to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # single-frame decoders here. Their protocol name is preserved so repeat | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # behavior survives conversion (see the individual subclass PODs). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # The protocol name this class decodes into / encodes as. Subclasses | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # override this (NEC2, NECX1, NECX2). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 578 | ▶ | sub _protocol_name { 'NEC' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_protocol_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # True for the half-header (4512/4512 µs) NECx1/NECx2 framing; false for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # the full-header (9024/4512 µs) NEC1/NEC2 framing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1238 | ▶ | sub _half_header { 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_half_header: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # True when an omitted subaddress means the one's complement of the address | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # (Default S=~D, stored as -1); false when it means "copy the address" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # (Default S=D, stored as a real byte). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 212 | ▶ | sub _inverted_subaddress_default { 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inverted_subaddress_default: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # True when a raw subaddress byte equal to ~address is normalized to -1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # NEC1/NEC2 treat that byte as redundant; NECx1/NECx2 keep it as part of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # 16-bit address. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 438 | ▶ | sub _normalize_subaddress { 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_normalize_subaddress: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1122 | ▶ | sub _parse_int { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_int: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1122 | my ($val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1122 | ▶ | return 0 unless defined $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1122 | $val =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1122 | ▶ | return hex($val) if $val =~ /^0x/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1103 | return $val + 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 252 | ▶ | sub decode_raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_raw: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 252 | my ($class, $raw_val) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 252 | my $val = _parse_int($raw_val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 252 | my $addr = ($val >> 24) & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 252 | my $subaddr = ($val >> 16) & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 252 | my $cmd = ($val >> 8) & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 252 | ▶ | if ($class->_normalize_subaddress && $subaddr == ((~$addr) & 0xFF)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$class->_normalize_subaddress and $subaddr == (~$addr & 255)
MC/DC100%2/2
$class->_normalize_subaddress and $subaddr == (~$addr & 255)
$class->_normalize_subaddress
$subaddr == (~$addr & 255)
Truth table100%3/3
A and B
A= $class->_normalize_subaddressB= $subaddr == (~$addr & 255)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 248 | $subaddr = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 252 | return Protocol::IR::Code->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | protocol => $class->_protocol_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | bits => 32, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | address => $addr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | subaddress => $subaddr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | command => $cmd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | data => $val, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # True when the value decode_raw reads (Tasmota DataLSB) is the accumulated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # per-byte LSB-first wire form; the display form (Tasmota Data) is its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # per-byte bit reversal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 5 | ▶ | sub lsb_is_accumulated { 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lsb_is_accumulated: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # Reverse the bits within each byte of a $bits-bit value, keeping the byte | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # order. Each frame byte is sent LSB-first, so this maps between the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # accumulated value a receiver collects (Tasmota DataLSB, the "LSB" form the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # LIRC pre_data/post_data composition lands on) and the display form decode_raw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # reads. Arithmetic shifts rather than the 32-bit bitwise ops, so wide words | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # survive whole. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 227 | ▶ | sub _bit_reverse_bytes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bit_reverse_bytes: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 227 | my ($val, $bits) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 227 | my $out = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 227 | for my $i (0 .. $bits - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 7264 | my $byte = int($i / 8); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 7264 | my $bit = $i % 8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 7264 | my $src = 8 * $byte + (7 - $bit); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 7264 | $out |= (($val >> $src) & 1) << $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 227 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # lsb=true is the form decode_raw reads (Tasmota DataLSB, the display hex); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # lsb=false is the accumulated wire form (Tasmota Data), reached from the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # display form by reversing the bits within each byte. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 228 | ▶ | sub decode_byte_order { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_byte_order: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 228 | my ($class, $raw_val, $lsb) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 228 | my $val = _parse_int($raw_val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 228 | ▶ | return $class->decode_raw($lsb ? $val : _bit_reverse_bytes($val, 32)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 214 | ▶ | sub decode_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_params: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 214 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 214 | ▶ | my $addr = _parse_int($args{address} // $args{device} // 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
($args{"address"} // $args{"device"}) // 0
$args{"address"} // $args{"device"}
MC/DC0%0/2
($args{"address"} // $args{"device"}) // 0
$args{"address"}
$args{"device"}
Truth table66%2/3
A // B
A= $args{"address"}B= $args{"device"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 214 | ▶ | my $subaddr = _parse_int($args{subaddress} // $args{subdevice} // -1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
($args{"subaddress"} // $args{"subdevice"}) // -1
$args{"subaddress"} // $args{"subdevice"}
MC/DC100%2/2
($args{"subaddress"} // $args{"subdevice"}) // -1
$args{"subaddress"}
$args{"subdevice"}
Truth table100%3/3
A // B
A= $args{"subaddress"}B= $args{"subdevice"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 214 | ▶ | my $cmd = _parse_int($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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 214 | my ($real_subaddr, $stored_subaddr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 214 | ▶ | if ($subaddr == -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # Omitted subaddress: derive it from the address per the IRP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # "Default S=..." rule of this variant. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 142 | ▶ | if ($class->_inverted_subaddress_default) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 140 | $real_subaddr = (~$addr) & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 140 | $stored_subaddr = -1; # redundant byte, normalized away | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | $real_subaddr = $addr & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2 | $stored_subaddr = $addr & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 72 | $real_subaddr = $subaddr & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 72 | $stored_subaddr = $subaddr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 214 | my $inv_cmd = (~$cmd) & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 214 | my $data = (($addr & 0xFF) << 24) | | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | (($real_subaddr) << 16) | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | (($cmd & 0xFF) << 8) | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | ($inv_cmd); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 214 | return Protocol::IR::Code->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | protocol => $class->_protocol_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | bits => 32, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | address => $addr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | subaddress => $stored_subaddr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | command => $cmd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | data => $data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # Decode microsecond timing pairs into Protocol::IR::Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2287 | ▶ | sub decode_timing { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode_timing: called CC=18 SCAR=29.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2287 | my ($class, $burst_pairs) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 2287 | ▶ | return undef unless scalar(@$burst_pairs) >= 34; # Header + 32 bits + Stop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1289 | my ($hdr_mark, $hdr_space) = @{$burst_pairs->[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1289 | ▶ | if ($class->_half_header) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # NECx1/NECx2 Header Check: ~4500 µs mark, ~4500 µs space | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 135 | ▶ | return undef unless ($hdr_mark >= 3800 && $hdr_mark <= 5200) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$hdr_mark >= 3800 and $hdr_mark <= 5200 and ($hdr_space >= 3800 and $hdr_space <= 5200)
$hdr_mark >= 3800 and $hdr_mark <= 5200
$hdr_space >= 3800 and $hdr_space <= 5200
MC/DC50%2/4
$hdr_mark >= 3800 and $hdr_mark <= 5200 and ($hdr_space >= 3800 and $hdr_space <= 5200)
$hdr_mark >= 3800
$hdr_mark <= 5200
$hdr_space >= 3800
$hdr_space <= 5200
Truth table60%3/5
A and B and C and D
A= $hdr_mark >= 3800B= $hdr_mark <= 5200C= $hdr_space >= 3800D= $hdr_space <= 5200
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | ($hdr_space >= 3800 && $hdr_space <= 5200); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # NEC1/NEC2 Header Check: ~9000 µs mark, ~4500 µs space | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1154 | ▶ | return undef unless ($hdr_mark >= 7500 && $hdr_mark <= 10500) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
$hdr_mark >= 7500 and $hdr_mark <= 10500 and ($hdr_space >= 3500 and $hdr_space <= 5500)
$hdr_mark >= 7500 and $hdr_mark <= 10500
$hdr_space >= 3500 and $hdr_space <= 5500
MC/DC25%1/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 table40%2/5
A and B and C and D
A= $hdr_mark >= 7500B= $hdr_mark <= 10500C= $hdr_space >= 3500D= $hdr_space <= 5500
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | ($hdr_space >= 3500 && $hdr_space <= 5500); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 410 | my @bytes = (0, 0, 0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 410 | for my $i (0 .. 31) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 13120 | my $pair = $burst_pairs->[$i + 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 13120 | my $space = $pair->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # Space ~1687 µs = 1, ~562 µs = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 13120 | ▶ | my $bit = ($space > 1100) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 13120 | my $byte_idx = int($i / 8); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 13120 | my $bit_idx = $i % 8; # LSB-first | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 13120 | $bytes[$byte_idx] |= ($bit << $bit_idx); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 410 | my ($addr, $subaddr_raw, $cmd, $inv_cmd) = @bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # Stop bit: a short mark (~562 µs) followed by the long inter-message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # space (~40000 µs, or the shorter repeat gap). This distinguishes NEC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # frames from multi-frame captures of other protocols whose header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # overlaps NEC's (e.g. JVC). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 410 | my ($stop_mark, $stop_space) = @{$burst_pairs->[33]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 410 | ▶ | return undef unless ($stop_mark >= 400 && $stop_mark <= 900) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$stop_mark >= 400 and $stop_mark <= 900 and $stop_space >= 3000
$stop_mark >= 400 and $stop_mark <= 900
MC/DC66%2/3
$stop_mark >= 400 and $stop_mark <= 900 and $stop_space >= 3000
$stop_mark >= 400
$stop_mark <= 900
$stop_space >= 3000
Truth table75%3/4
A and B and C
A= $stop_mark >= 400B= $stop_mark <= 900C= $stop_space >= 3000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ($stop_space >= 3000); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 190 | ▶ | my $subaddr = ($class->_normalize_subaddress && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$class->_normalize_subaddress and $subaddr_raw == (~$addr & 255)
MC/DC100%2/2
$class->_normalize_subaddress and $subaddr_raw == (~$addr & 255)
$class->_normalize_subaddress
$subaddr_raw == (~$addr & 255)
Truth table100%3/3
A and B
A= $class->_normalize_subaddressB= $subaddr_raw == (~$addr & 255)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | $subaddr_raw == ((~$addr) & 0xFF)) ? -1 : $subaddr_raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 190 | my $data = ($addr << 24) | ($subaddr_raw << 16) | ($cmd << 8) | $inv_cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 190 | return Protocol::IR::Code->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | protocol => $class->_protocol_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | bits => 32, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | address => $addr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | subaddress => $subaddr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | command => $cmd, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | data => $data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 121 | ▶ | sub to_pronto { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_pronto: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 121 | my ($class, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 121 | my $carrier_hz = 38000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # The Pronto frequency word is the carrier period in 0.241246 µs units, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # rounded to an integer. Pronto parsers decode pulses using that rounded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # word (freq_word * 0.241246), and MakeHex converts IRP timings to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # pulses the same way, so build the pulse conversion period from it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # Using the exact 38 kHz period instead would make every pulse count | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # drift by +/-1 from the reference. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 121 | my $freq_word = int(sprintf("%.0f", 1000000.0 / ($carrier_hz * 0.241246))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 121 | my $period_us = $freq_word * 0.241246; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 121 | ▶ | my $us_to_pulses = sub { int(sprintf("%.0f", $_[0] / $period_us)) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 121 | my $addr = $code->address & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # A code that reached to_pronto normally carries a real subaddress for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # the NECx variants, but fall back to the IRP "Default S=..." rule if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # it is still the -1 sentinel. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 121 | ▶ | my $subaddr = ($code->subaddress != -1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | ? ($code->subaddress & 0xFF) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | : ($class->_inverted_subaddress_default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | ? ((~$addr) & 0xFF) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | : ($addr & 0xFF)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 121 | my $cmd = $code->command & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 121 | my $inv_cmd = (~$cmd) & 0xFF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 121 | my @bytes = ($addr, $subaddr, $cmd, $inv_cmd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 121 | my @bits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 121 | for my $b (@bytes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 484 | for my $i (0..7) { push @bits, ($b >> $i) & 1; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 121 | ▶ | my ($hdr_mark_us, $hdr_space_us) = $class->_half_header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | ? (4512, 4512) # NECx1/NECx2: Prefix=8,-8 (8*564, 8*564) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | : (9024, 4512); # NEC1/NEC2: Prefix=16,-8 (16*564, 8*564) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 121 | my @burst_pairs = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | [$us_to_pulses->($hdr_mark_us), $us_to_pulses->($hdr_space_us)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 121 | for my $bit (@bits) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 3872 | ▶ | push @burst_pairs, [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | $us_to_pulses->(562.5), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | $us_to_pulses->($bit ? 1687.5 : 562.5) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # Suffix=1,-78: a 564 µs stop mark and the inter-message space | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # (78*564 = ~44 ms), matching the MakeHex reference output. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 121 | push @burst_pairs, [$us_to_pulses->(564), $us_to_pulses->(43992)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 121 | my $seq1_pairs = scalar @burst_pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 121 | my $header = sprintf("0000 %04X %04X 0000", $freq_word, $seq1_pairs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 121 | my @payload = map { sprintf("%04X %04X", $_->[0], $_->[1]) } @burst_pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 121 | return join(" ", $header, @payload); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 55 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | Protocol::IR::Proto::NEC - NEC protocol handler (32-bit) and NEC-family base class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | version 1.5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | use Protocol::IR::Converter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | my $converter = Protocol::IR::Converter->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # From a raw 32-bit value or from parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | my $code = $converter->import_code('NEC', '0x10EF00FF'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | my $code = $converter->import_code('NEC', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | { address => 16, command => 0 }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | The NEC protocol family transmits 32-bit frames at 38 kHz. Each frame is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | four bytes -- B<address> (device), B<subaddress>, B<command>, and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | command's one's complement -- sent LSB-first, preceded by a header and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | followed by a stop mark. The C<data> value matches Tasmota's C<Data> field: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | B<address> in bits 24-31, B<subaddress> in bits 16-23, B<command> in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | bits 8-15, and the inverted command in bits 0-7. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | IRDB (via the MakeHex IRP files) distinguishes four single-frame formats: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | =item * C<NEC1> (this class) -- full 9000/4500 µs header, subaddress is the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | one's complement of the address (Default S=~D), short header+gap repeat. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | =item * C<NEC2> (L<Protocol::IR::Proto::NEC2>) -- identical single-frame timing to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | NEC1; only the repeat differs (it re-transmits the whole frame). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | =item * C<NECx1> (L<Protocol::IR::Proto::NECX1>) -- half 4500/4500 µs header, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | subaddress is the low byte of a real 16-bit address (Default S=D), short | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | repeat. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | =item * C<NECx2> (L<Protocol::IR::Proto::NECX2>) -- identical single-frame timing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | to NECx1; whole-frame repeat. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | C<Protocol::IR::Proto::NEC> implements the shared machinery and doubles as the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | base class; the variants only override the header, the subaddress rule, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | their protocol name. For a single frame NEC1 and NEC2 are timing-identical | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | and so are NECx1 and NECx2, so a timing decode cannot tell the "1" and "2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | forms apart -- the repeat structure is a property of the code's protocol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | name, not of any single frame. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | When the subaddress equals the one's complement of the address (the normal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | case for standard NEC frames), C<subaddress> is normalized to C<-1> on the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | resulting L<Protocol::IR::Code>. NECx1/NECx2 never normalize: their subaddress byte | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | is a real part of the 16-bit address. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | Frame timing: header mark/space of B<9024/4512 µs> (NEC1/NEC2, the IRP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | B<Prefix=16,-8> at a 564 µs time base) or B<4512/4512 µs> (NECx1/NECx2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | B<Prefix=8,-8>); each bit is a B<562.5 µs> mark followed by a space of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | B<562.5 µs> for 0 or B<1687.5 µs> for 1. A B<564 µs> stop mark and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | inter-message space of B<~44 ms> (IRP B<Suffix=1,-78>) end the frame, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | matching the MakeHex reference output for these IRPs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | The C<decode_timing> decoder validates both the header and the stop bit, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | a capture from an overlapping protocol (e.g. JVC, whose frame structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | starts with a similar header) is rejected rather than misidentified. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | =head2 decode_raw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | my $code = $class->decode_raw('0x10EF00FF'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | Builds an L<Protocol::IR::Code> from the raw 32-bit value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | =head2 decode_byte_order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | my $code = $class->decode_byte_order($raw, $lsb); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | Decodes from either byte order: C<$lsb> true reads the accumulated (DataLSB) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | form directly; false reads the display (Data) form, the per-byte bit reversal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | of the accumulated word (the Tasmota C<Data> field and the IRDB C<Code> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | column). NEC sends each byte LSB-first, so the accumulated word is the one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | carried on the wire and by Tasmota's C<DataLSB>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | =head2 lsb_is_accumulated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | my $flag = $class->lsb_is_accumulated; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | True (always, for NEC) when the accumulated byte order is what | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | C<decode_raw> reads, informing the Tasmota structured importer which of its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | C<Data>/C<DataLSB> fields to prefer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | =head2 decode_params | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | my $code = $class->decode_params(address => 16, command => 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | Builds an L<Protocol::IR::Code> from discrete parameters. Accepts C<address> or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | C<device>, C<subaddress> or C<subdevice>, and C<command> or C<function>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | =head2 decode_timing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | my $code = $class->decode_timing(\@burst_pairs_us); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | Decodes an arrayref of microsecond C<[mark_us, space_us]> pairs. Returns an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | L<Protocol::IR::Code> when the header, 32 data bits, and stop bit match the NEC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | timing signature, otherwise C<undef>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | =head2 to_pronto | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | my $pronto = $class->to_pronto($ir_code); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | Encodes an L<Protocol::IR::Code> object as a Pronto Hex string at 38 kHz. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | Source code: L<https://github.com/bwarden/perl-protocol-ir> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | Bug reports and feature requests: L<https://github.com/bwarden/perl-protocol-ir/issues> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | Brett T. Warden <bwarden@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | Copyright (c) 2026 Brett T. Warden | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | This library is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | under the terms of the GNU General Public License as published by the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | Free Software Foundation; either version 2 of the License, or (at your | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | option) any later version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||