Default Infrared Protocol

By Rob Evans1/15/2026

0

Description

This protocol script tells the IR encoder/decoder how to send and receive data by converting to and from individual IR pulses to bits.

Tags

infraredprotocol

Script Content

include "./battlecore/infrared.bst";

program {
	type "protocol";
	name "Infrared";
	author "Irrelon Software Limited";
	version "1.0.0";
}

// Uses a pulse width protocol, not pulse distance and we are
// using a 250us tolerance.
// battlecore::infrared.setEncodingStyle(IrEncodingStyle::PULSE_DISTANCE);
battlecore::infrared.setEncodingStyle(IrEncodingStyle::PULSE_WIDTH);
battlecore::infrared.setTolerance(250);

// Sets the mark duration to 500us for a zero, 1000us for a one
battlecore::infrared.setMarkDuration(500, 1000);

// Fixed duration space, 500us regardless of the value
battlecore::infrared.setSpaceDuration(500, 500);

// This is a lead-in MARK and SPACE. If we don't see this first,
// it's not our protocol. This is a native-level check before the
// data even gets to the protocol decoder. It helps to reduce processing
// of obviously invalid signal data.
battlecore::infrared.setLeadIn(2500, 500);

// This installs the RMT driver with the configuration values we set above
battlecore::infrared.install();

protocol "default-ir" for "ir" {
	step decode {
		// The system pre-fills the bitLength field with the length of the data before our protocol is executed
		// Our protocol uses 22 bits so if we don't have that, exit
		// This is not 23 because the lead-in is not included in the bitLength
		require terminate "bitLength" == 22;
	}

	parity {
		// Move the bit cursor to the beginning of the bit stream
        offset 0;

		// Read 19 bits from the bit stream and xor them
		xor bits<19> "parityBit";
		rule uint<3> "parityValue" = "parityBit" == 0 ? 5 : 2;

		// Move the bit cursor to the beginning of the bit stream
        offset 0;
	}

	define uint<4> "bulletTypeId";
	define uint<4> "playerId";
	define uint<2> "teamId";
	define uint<8> "hitValue";
	define uint<1> "isCritical"; // 19 bits total in data payload
}