Documentation:
On basic packets: https://www.nmra.org/sites/default/files/s-92-2004-07.pdf
On extended packets: https://www.nmra.org/sites/default/files/s-9.2.1_2012_07.pdf
Example of extended accessory packet addressing: https://github.com/JMRI/JMRI/blob/master/java/src/jmri/NmraPacket.java#L652
Preamble is 12 "1" bits. DCC++ uses 22 bits. Preamble is followed by "0" bit
PPP - preamble
EEEE-EEEE - Error Detection Data Byte = XOR of all previous bytes
PPP 0 0AAA-AAAA 0 01DC-SSSS 0 EEEE-EEEE 1 Speed and Direction Packet For Locomotive Decoders (7-bit). S-9.2#36
D dir (1=FWD)
SSSS 14-steps speed
C lowest bit of 28-steps speed or F0, see S-9.2#48
PPP 0 11AA-AAAA 0 AAAA-AAAA 0 CCCD DDDD () 0 EEEE-EEEE 1 - Extended Locomotive packet (14-bit address), S-9.2.1#60
() - may be 0, 1 or 2 bytes, depending on CCC
01DC SSSS - 14/28 speed and dir (as in Basic packet)
0011 1111 0 CDDD-DDDD 0 E..E - 128 steps speed
C - dir (1=FWD)
DDD-DDDD - 128 steps speed, normal bit order
100D DDDD - F0,F4,F3,F2,F1
1011 DDDD - F8,F7,F6,F5
1010 DDDD - F12,F11,F10,F9
1101 1110 0 DDDD-DDDD 0 E..E - F20..F13
1101 1111 0 DDDD-DDDD 0 E..E - F28..F21
PPP 0 10AA-AAAA 0 1AAA-CDDD 0 EEEE-EEEE 1 - Basic Accessory Decoder Packet Format (9/11-bit address) S-9.2.1#420
AAA - high bits of address, in 1's complement
C - activate or deactivate
DD - output pair or 2 lowest bits of 11-bit address
D - thrown/closed
PPP 0 10AA-AAAA 0 0AAA-0AA1 0 000X-XXXX 0 EEEE-EEEE 1 - Extended Accessory Decoder Control Packet S-9.2.1#436
AA-AAAA AAA AA - 11-bit address
AAA - 1's complement, highest 3 bits of address
AA - lowest 2 bits of address
X-XXXX - aspect to be shown. 0=stop aspect
PPP 0 1011-1111 0 1000-CDDD 0 EEEE-EEEE 1 - broadcast for basic accessory decoders S-9.2.1#447
PPP 0 1011-1111 0 0000-0111 0 000X-XXXX 0 EEEE-EEEE 1 - broadcast for extended accessory decoders S-9.2.1#456
PPP 0 0000-0000 0 0000-0000 0 0000-0000 1 - Digital Decoder Reset Packet For All Decoders S-9.2#74
PPP 0 1111-1111 0 0000-0000 0 1111-1111 1 - Digital Decoder Idle Packet For All Decoders S-9.2#89
PPP 0 0000-0000 0 01DC-000S 0 EEEE-EEEE 1 - Digital Decoder Broadcast Stop Packets For All Decoders S-9.2#99
S - 0=stop, 1=coast (stop delivering energy to motors)
D - dir
C - 2= D(dir) may be ignored