-
Notifications
You must be signed in to change notification settings - Fork 58
Description
Hello! I’m not really sure where to put this, but I wanted to write it down somewhere in case anyone else comes across this looking for an answer.
The Mod-T scripts include several lines like the following:
# Some commands are human readable some are maybe checksums
dev.write(2, bytearray.fromhex('246a0095ff'))
dev.write(2, '{"transport":{"attrs":["request","twoway"],"id":3},"data":{"command":{"idx":0,"name":"bio_get_version"}}};')The mystery packet seems to consist of the fixed bit pattern 0x241, followed by the 2-byte, little-endian length of the message, and then that same 2-byte length inverted (bitwise not).
Here is my implementation in Rust, which matches for every sample in the scripts.
fn compute_prefix_packet(message: &str) -> [u8; 5] {
const FIXED_PREFIX: u8 = 0b_0010_0100;
let length: [u8; 2] = { message.len() as u16 }.to_le_bytes();
return [FIXED_PREFIX, length[0], length[1], !length[0], !length[1]];
}Footnotes
-
It is, of course, possible that this value actually contains meaning. However, unlike the probably little-endian 0x00 and 0xFF bytes, I think this is most likely just a bit pattern intended to help prevent the beginning of a front-turncated message being misinterpreted as the length. ↩