NAME

Protocol::IR::Proto::NECX2 - NECx2 protocol handler (extended NEC, whole-frame repeat)

VERSION

version 0.08

SYNOPSIS

use Protocol::IR::Converter;

my $converter = Protocol::IR::Converter->new();

# NECx2 is the framing used by Samsung TVs: half 4500/4500 us header
# and a real 16-bit address (device + subdevice bytes).
my $code = $converter->import_code('NECX2',
    { device => 7, subdevice => 7, command => 2 });

DESCRIPTION

The NECx2 protocol (MakeHex NECx2.irp) transmits the same frame as Protocol::IR::Proto::NECX1 -- half 4500/4500 us header, 16-bit address (Default S=D) -- but repeats the entire frame instead of a short header+gap ditto. For a single frame the two are timing-identical, so this class only changes the protocol name. Samsung TV IRDB files (for example) label their codes NECx2; a Samsung POWER row of device 7, subdevice 7, function 2 packs to 0x070702FD, which matches the output of a reference MakeHex build.

Like NECx1, a single NECx2 frame cannot be told apart from Protocol::IR::Proto::SAMSUNG by timing alone; see Protocol::IR::Proto::NECX1 for how Protocol::IR::Converter resolves that. The name is preserved on the by-name (CSV) import path.

METHODS

All methods are inherited from Protocol::IR::Proto::NEC; only the protocol name, header, and subaddress behavior differ, plus the following additional method:

as_samsung_params

my $params = $class->as_samsung_params($code);

Converts a NECX2 code to its Protocol::IR::Proto::SAMSUNG equivalent parameter hashref. The NECX2 device byte is bit-reversed to produce the Samsung address, and the function byte is bit-reversed to produce the Samsung command.

The returned hashref is suitable for $converter->import_code('SAMSUNG', $params).

Example:

# NECX2 Samsung TV POWER: device=7, function=2
#   -> SAMSUNG address=0xE0, command=0x40
my $sam_params = Protocol::IR::Proto::NECX2->as_samsung_params($code);

This is used by "cross_protocol" in Protocol::IR::Converter and is also available for direct use when matching captures against IRDB entries.

CROSS-PROTOCOL MAPPING

NECX2 shares identical timing with Protocol::IR::Proto::SAMSUNG: both use a 4500/4500 us half header, 560/1680 us bit timing, 32 bits, per-byte LSB-first. They are distinguished only by the byte structure on the wire: Samsung repeats the address byte and follows the command with its one's complement (addr, addr, cmd, ~cmd), while NECX2 carries a real subaddress byte (device, subdevice, function, ~function).

When a Samsung TV code is stored in IRDB as NECX2 (the common convention), the Samsung address is the bit-reversal of the NECX2 device byte, and the Samsung command is the bit-reversal of the function byte. For example, Samsung TV POWER is IRDB entry NECx2,7,7,2: device 7 bit-reverses to address 0xE0, function 2 bit-reverses to command 0x40.

Use "cross_protocol" in Protocol::IR::Converter to convert between the two automatically, or call as_samsung_params directly.

SUPPORT

Source code: https://github.com/bwarden/perl-protocol-ir

Bug reports and feature requests: https://github.com/bwarden/perl-protocol-ir/issues

AUTHOR

Brett T. Warden <bwarden@cpan.org>

COPYRIGHT AND LICENSE

Copyright (c) 2026 Brett T. Warden

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.