BrickOS sets two different protocols on top of the physical layer that are intended for user level communication. If does not matter if an application is running on a PC or a RCX.
The first protocol is called integrity layer. It allows sending data packets with a payload of up to 255 bytes to all receivers within range. Content is protected by a checksum.
The header starts with a magic constant and the length of the packet, followed directly by the payload and the checksum.
len = n c = ( 0xF0 + len + d1 + ... + dn + 0xFF ) and 0xFF
The integrity layer only supports broadcast messages. Many applications need the possibility to address a single station. This functionality is offered by the addressing layer, which describes sender and receiver by 8 bit addresses. These consist of a host address and a port number, by default the upper 4 bits form the host number, the remaining ones are used to describe a specific port on the host, with port 0 being reserved by the system for program downloads. These parameters can be changed as needed.
The image shows the structure of a packet in the addressing layer. Compared to the integrity layer, fields for the addresses of sender and receiver have been added, which decreases the maximum payload size to 253 bytes.
len = n + 2 c = ( 0xF1 + len + dest + src + d1 + ... + dn + 0xFF ) and 0xFF
Applications written for brickOS may define a callback function for every port which is executed upon the reception of a matching packet. An argument of the function contains a pointer to the payload. The host address is fixed for every RCX and may only be changed in the source code or by a parameter of the download software. On the PC side, lnphost allows programs to define callback functions for every address they want to.