Skip to content

266. The biphase reader required a favour from its caller, and 411 records went unread

The Harmony 300's set top box was the one device group of section 265 that could not be identified in Logitech's catalogue, because none of its 44 records decoded into a number. That was read there as the family being one this decoder refuses, and it is not: the family's rhythm has been in packages/codec/src/protocols.ts since section 162, measured, and its codes read perfectly well. What refused them was a precondition nothing had written down.

The mechanism, which is four lines of one function

halfCells in packages/codec/src/irframe.ts walks a pulse train collecting intervals until it meets one too long to be a half cell, and that interval is the gap before the next copy of the code. The loop broke on such an interval wherever it sat, so a block that opens with a gap collected nothing at all, fell under the minimum bit count and returned undefined, and biphaseFrames returned an empty list. Not a wrong frame: no frame.

A block opening with a gap is the ordinary case rather than the odd one. Of 5232 infrared records across this project's configurations and the five arch 16 ones, 3871 open with one.

Every caller inside bin/protocols.ts passes its train through fromFirstMark first, all three of them, so none ever met this and the generated rhythm table never noticed. That is what let the requirement survive in a function this module exports: the reader's own docstring never states it, and the only callers were the ones that happened to satisfy it. make protocols prints byte for byte the same report before and after the fix.

What it cost

reads as a pulse distance frame reads as biphase read by nothing
before 3838 112 1282
after 3838 523 871

411 records moved from unreadable to read, and the pulse distance count does not move at all, since the change is inside a function only the biphase path uses.

Every infrared record of the as found Harmony 350 is in that 411. Section 261 measured all 130 of them as unreadable and drew a real conclusion from it, that the archive of names inside the container is the only route to a command name on that remote where the catalogue is the route everywhere else. All 130 read now.

Believing it needed an answer from outside, and the method is section 162's

A decoder that starts returning frames is easy to believe and hard to check, since the frames could be arithmetic on the right durations and still not be what the appliance answers to. So the check is Logitech's own codeset for the very set top box these configurations drive, across four remotes and three architectures.

The method is not new and this section first claimed it was. Section 162 established all three unknowns a biphase reader cannot get from the durations, where the payload starts, which half means a set bit and how wide the frame is, and settled all three against the catalogue: it measured this family's width as 22 and its polarity as mark first, and matched 56 of 56 of its records to the numbers Logitech states for those commands. So what follows is that measurement repeated on a different population, four real remotes rather than a compiled sample, and it is a confirmation rather than a first. Section 162 never met the defect above because it worked on trains that had been trimmed.

configuration the family's records named in the catalogue
Harmony 300, programmed 44 44
Harmony 350, programmed 46 46
Harmony 600 51 51
Harmony One 58 55

The 35 distinct commands are a set top box's keypad: the ten digits, the four colour keys, the direction pad, ChannelUp, ChannelPrev, Guide, Info, Menu, Home, Radio, Teletext, DVR, Record, Pause, Stop, Rewind, FastForward, Select and PowerToggle. There is no volume command and that is correct, since a set top box does not carry one and the television's group was identified separately in section 265. The first version of the test demanded one on the strength of what a remote usually has, which is a guess, and the measurement disagreed with it.

Three of the Harmony One's 58 do not match and that is unexplained.

The width is Logitech's to state, not the name's

biphaseFrames returns 23 bits where this family carries 22, and its own docstring predicts exactly that: where the payload starts cannot be read off the train, since part of a biphase lead in is not transmitted at all, so the reader hands back the longest self consistent alignment and a caller trims to the width it is looking for. Trimming to 22 is what turns 0 matches into 44 of 44.

So a caller needs the width from somewhere, and there are two somewheres. Section 162 measured it, 22, and the archive states it, NumberOfBits inside the segment's Payload, which keycodeFields exposes. The two agree. Either way it is not taken from the string "Kreatel IP 22 Bit", and section 231 is why that is not pedantry: a width read off a family name was wrong on the one family whose name was checked against its own definition.

The measured width is not in the code, and that is the finding here. BiphaseTimings in packages/codec/src/protocols.ts carries the half cell, the lead in and the polarity and no width, so section 162's three widths live in that section's table in this document and nowhere executable. A number in prose with no field behind it is the state this project's four places rule exists to prevent, and it is why a caller has to reach for the archive for something already measured.

What is deliberately not built

The catalogue naming pass is still blind to biphase families, and this section does not change that. numbersOf in packages/codec/bin/catalogue.ts uses irFrame, the pulse distance reader, so make catalogue cannot identify a biphase device group at all.

And its own headline number hides that, which this section got wrong before measuring it. It was written here that "36 of 38 device groups are identified today and the two that are not are biphase". Both halves are false. The accounting population holds 51 occupied device groups; the pulse distance reader yields numbers for 38 of them, of which 36 are identified, and the other 13 are omitted from the total altogether rather than counted as failures, because the pass skips a group before counting it when it has no numbers. So the honest figure is 36 of 51. The two that are counted and unidentified are groups the reader does read and no codeset matches, which is a different thing entirely.

Of those 13 invisible groups, 5 read as biphase now, 199 records, and 8 read as nothing at all. So the prize is 5 groups and the first step is smaller than a design decision: put the width into BiphaseTimings beside the polarity, where section 162's measurement belongs, and give the pass a denominator that counts every occupied group.

The lesson, which is about the shape of the callers rather than the bug

A precondition satisfied by every existing caller is invisible. Three call sites all trimmed first, so the requirement read as the natural way to use the function rather than as a constraint, and nothing in the module said otherwise. What found it was a fourth kind of caller, one holding raw block words out of a container, which is also the kind of caller framesOfPulses exists for: its docstring records that FreeHarmony turned up holding durations and not a file.

So the regression test is an equivalence and not a count: biphaseFrames must return the same frames whether or not its caller trimmed. A count would pass again the moment somebody reintroduced the break and updated the number.

Reproduced by

packages/codec/test/irframe.test.ts, the equivalence per record over 5232 records plus the control that the two readers stay disjoint, and packages/codec/test/catalogue.test.ts, the four configurations against Logitech's codeset with the width taken from their definition.


Section 265 | the archive | section 267. Section 266 of the findings archive, which is frozen; the reference holds the current answer. The archive on GitHub.