I've got a raw binary file (1 KB↓) that is a serial data dump of a GPS stream (along with some associated metadata). I'm specifically trying to pull a value out of the binary file that represents the GPS time; I know its offset and width in the file (10 and 8 bytes respectively, with a total frame width of 28 bytes) but it's encoded in a very weird way as described in the quote below.
What's the most Pythonic way to read this data (into a list or array)?
GPS TIME - GPS Sensor time (time of week in seconds, starting at Saturday 2400 hours/ Sunday 0000 hours) if GPS Time Valid Message 3500 is set to 1, otherwise SDN500 system time since power up is reported. Data words are in the order 2, 1 (MSW), 4 (LSW), 3.
A message word length is 16 bits on the SDN500–HV interface. However, the SDN500–HV protocol, which uses a standard Universal Asynchronous Receiver Transmitter (UART), transmits data in 8-bit groups (bytes). This means that two bytes are required in order to make up one message word.
A byte of information is transmitted as a sequence of 11 bits: one start bit, 8 bits of data (least significant bit (LSB) first), one parity bit (odd), and one stop bit. For each 16-bit data word, the least significant byte is transmitted first, followed by the most significant byte. Integer and floating point data types consisting of more than one word are transmitted from the lowest numbered word to the highest numbered word. The one exception to this rule is the time tag, which is output in words 6-9 of each HV output message. The four 16-bit data words are in the following order: 2,1,4,3, where 1 represents the most significant word and 4 the least significant word. Each word is separately byte-reversed.