I am trying to use python to parse data from a .bin file that is stored in hexadecimal format. Unfortunately it's not as simple as converting the hex to decimal to get the data out.
The file contains 'pages' of 300 measures where a 'measure' is a 6 byte block of hex data containing the values of 6 variables: X axis, Y axis, Z axis, light meter, button status and a reserved space (i.e. empty).
Each axis covers 12 bits (i.e. 1.5 bytes), the light covers 10 bits, and the button status/spare are 1 bit each.
For example:
Raw data (6 bytes):
F4 1F 9E 08 20 00
(repeated 300x per 'page')X axis (12bits) =
F4 1
Y axis (12bits) =
F 9E
Z axis (12bits) =
08 2
light (10bits) =
0 0
(and first two bits of final0
)button (1bit) = 2nd to last bit of final
0
reserved (1bit) = last bit of final
0
How would I go about parsing the file, splitting up the blocks into their variables and converting the hex to decimal? Aiming to have a data frame of the decimal values, with the variables as columns and each measure (i.e. 6 byte blocks) as a row.
Past the usual open/read code below I am not sure how best to approach this.
with open(<PATH>, 'r') as f:
data = f.read()