Background
I have a device connected to my machine on a serial port that is message oriented, where each incoming command message is exactly eight 16-bit words. The most significant byte of each word is received first and the least significant byte received second. Each header word is a command identifier (ranging from 0 - 255). The format is defined like so:
XXXX Header Word (Placeholder for 16-bit Hexadecimal value)
XXXX Data Word
XXXX Data Word
XXXX Data Word
XXXX Data Word
XXXX Data Word
XXXX Data Word
XXXX Checksum Word (Result of Exclusive OR on header word and all six data words)
The format for the command I need to send, header 0x5D, is defined like so:
Word 1: Header = 005Dh
Word 2: Mode (values can be 2, 3, 6, 8, 9)
Words 3-7: Not significant
Word 8: 16 bit checksum
Questions (all related)
I have this example from other source code that apparently sends this message correctly, but I'm not sure what is going on, even after reading perldoc on pack.
pack("v"x8, 0x00, 0x5D, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x5D);
- "v" means little endian, but I cannot find any reference on the x8 following it.
- And according to the format of the message, shouldn't the 0x5D value be right after the "v"x8, not after the 0x00?
- The message is supposed to have eight 16-bit words, so why are there 16 and not 8? Some are 0x00, and not 0x0? Does that make a difference?