Skip to content

152. A stored code's frame is redundant: five durations and the bits rebuild it exactly, 3502 of 3502

An infrared command is a lamp blinking in a precise rhythm, and a record stores that rhythm as a list of on and off times. Section 133 read the bits back out of one: a code carries a number, and comparing that number to a number written down elsewhere is what let a scan code be given a button name. This is the other direction, and it was believed impossible here. irframe.ts said so in its own docstring: "this is a decoder and not an encoder", because the timings, the header, the repeat and the trailing gap are protocol facts the bits do not carry.

Half of that is wrong, and it is the half that matters. A record states its own timings. Take five numbers off it, the leading mark and the space after it, the length of the half of every pair that carries no bit, and the two lengths the carrying half takes, and the frame comes back byte for byte from those five plus the bits. On 3502 of 3502 records in the corpus that read as a frame at all, across seventeen containers and three of the four architectures. Nothing in the codec knows what a Panasonic or an NEC frame looks like, and it does not need to.

Why this is not tidiness. Logitech's surviving service states a command as a protocol family and a frame value with the durations field null, on all 419 commands ever fetched, docs/host-client.md. That made "an infrared encoder per protocol family" "a work item nobody had priced", and it is the wrong shape of the problem: the durations do not have to come from a protocol table at all, they can come from any record of the same appliance that a configuration already holds. 52 of 58 device groups in the corpus use exactly one set of timings for every code they carry, six carry two, so the timings are a property of the appliance and not of the command. That is what makes importing a named command from the catalogue a possibility rather than a research project.

The correction that took the count from 3347 to 3547, which is 3502 today

The first measurement said 3347, and the 200 that refused were the instructive part. All of them were in the two configurations Logitech compiled to our own specification, all pulse width, 112 of twelve bits and 88 of fifteen. Their supposedly constant half had two values, which is what the splitter refuses.

The second value was always the last one. A pulse width frame's last space is a trailing gap and not a bit cell: the bit is in the mark, so the frame ends on a space no bit occupies, and section 133's decoder already knew this from the other side, where TRAILING_GAP_US is tested after the push rather than before it. So it is one number more for that convention rather than a defect in the reading, and the shape of the mistake is the familiar one: a rule read off the architectures that dominate the corpus, refused by the population that has an independent answer.

What the frame does not determine, stated so it is not read as more

pulsesOfFrame returns the frame and stops. A record's block holds that frame over and over, and what separates and follows the copies does not follow from the bits:

copies of the frame per block 1 in 2188 records, 3 in 1305, 7 in 4, 11 in 1, 30 in 4
the gap between consecutive copies byte identical every time, in all 3502
what follows the last copy 140 distinct shapes

The tail is a closing mark, a long gap, sometimes the protocol's own short repeat frame, and a silence built out of 32767 microsecond spaces, which is the cap on one duration. A constant total block duration explains it in only 31 of 41 classes, so no rule is claimed. An editor that changes how fast a held key repeats edits that gap, section 127.

"A writer copies the tail from a record that already has one" is what this said, and it is too simple. Danny asked on 23 August 2026 whether a command made of several presses plays into any of this, since a Harmony can be taught one. It does, and not in the way the question expected: 226 records in the corpus hold more than one distinct code in a single block. Splitting a block on silences longer than ten milliseconds, so that each burst is one press, and reading each burst on its own: 117 records are six bursts carrying two codes, 58 are two bursts carrying two, 47 are three bursts carrying two, and 4 are thirty six bursts carrying four. They are in arch 8, arch 12 and arch 14 containers and in one Logitech compiled to our own specification, so this is not one architecture's habit.

Copying such a tail from a sibling would emit the sibling's second code, which is a different command. The byte comparison behind the 2942 of 3546 above already refused those pairs, since it demanded equality, so the measurement was right and the sentence was not.

What the second code is turns out to be systematic rather than authored, which is the part worth carrying. Three shapes, each consistent within its group: a code and its exact complement, on a Harmony One's 14 bit codes, where the pair's exclusive or is 0x3ff in every one of them; a code and a near variant differing in two to six bits, on a Harmony 700, with the difference always of the form 0x101, 0x303 or 0x707; and a constant lead in followed by the command, in 88 records of one arch 8 config where the first burst is the same code every time. So these are protocol structure, and a writer that needs to emit one has to know which shape it is in.

Where a command of several presses actually lives is the button, and we already read it: an action list sends several codes in order, 12 such bindings in one Harmony 600 config, 26 in a Harmony 700's and 6 sending three codes in a config Logitech compiled for us, with keyCodes returning them in order. Nothing inside a record is a user authored macro.

An earlier version of this measurement reported 1951 of 2085 whole blocks rebuilt, and that number was an artefact of its own classifier. It trimmed trailing terminators and trailing maximum length spaces before comparing gaps, and the trimming was doing the work: with the heuristics removed the count is zero, because every tail carries a mark the frame does not account for. Two lessons already in this repository, met again. A remainder with an explanation attached is a remainder nobody counts again, section 139. And the population matters: the first run used a hand written list of thirteen containers where the frame tests use seventeen, so the totals were computed over four containers fewer than the claim beside them, which is exactly the pair of diverging population lists section 143 is about.

The tests

packages/codec/test/irframe.test.ts. Five, and the two that carry the weight are not the rebuild:

  • the per container counts, deep equal rather than totalled, because a total hides one architecture sitting at zero, which is the defect section 148 found in the renderer's own completeness claim
  • the sensitivity control: each of the five durations moved by one microsecond and each bit of the value flipped, on one real record per container, all 599 of which have to stop matching. One microsecond is the smallest change the format can express, so it is the sharpest control available
  • the pulse width population, asserted as a biconditional: every mark carrier has a closing space, every space carrier has none, and the closing space differs from the flat half in all 200
  • the boundary above, so nobody reads the rebuild as a whole block
  • the timings per device group, 52 of 58, which is the half the application needs

Section 151 | the archive | section 153. Section 152 of the findings archive, which is frozen; the reference holds the current answer. The archive on GitHub.