Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to read vector of floats #2

Open
PatWie opened this issue Jun 12, 2024 · 0 comments
Open

Failed to read vector of floats #2

PatWie opened this issue Jun 12, 2024 · 0 comments

Comments

@PatWie
Copy link

PatWie commented Jun 12, 2024

For the data chunk

data = [217, 135, 153, 12, 0, 0, 0, 0, 
        251, 133, 153, 12, 0, 0, 0, 0, 
        231, 207, 50, 49, 
        64, 131, 213, 36, 
        215, 182, 109, 50, 
        247, 152, 146, 50, 
        0, 0, 192, 127, 
        0, 0, 192, 127, 
        0, 0, 192, 127, 
        0, 0, 192, 127, 
        0, 0, 192, 127, 
        0, 0, 192, 127, 
        0, 0, 192, 127, 
        0, 0, 192, 127, 
        0, 0]

and field description

[('uint64_t', 1, 'timestamp'),
 ('uint64_t', 1, 'timestamp_sample'),
 ('float', 12, 'control'),
 ('uint16_t', 1, 'reversible_flags'),
 ('uint8_t', 6, '_padding0')]

This library only outputs the first two items from the field description in

println!("{} at {}: {:?}", item.name(), item.index(), item.data());

The extracted format from this library is

["uint64_t timestamp", "uint64_t timestamp_sample", "float[12] control", "uint16_t reversible_flags", "uint8_t[6] _padding0", ""]

Here is how I correctly parse them

import struct

timestamp = struct.unpack('<Q', bytes([217, 135, 153, 12, 0, 0, 0, 0]))[0]
timestamp_sample = struct.unpack('<Q', bytes([251, 133, 153, 12, 0, 0, 0, 0]))[0]
control_0 = struct.unpack('<f', bytes([231, 207, 50, 49]))
control_1 = struct.unpack('<f', bytes([64, 131, 213, 36]))
control_2 = struct.unpack('<f', bytes([215, 182, 109, 50]))
control_3 = struct.unpack('<f', bytes([247, 152, 146, 50]))
control_4 = np.nan 
# ...
control_11 = np.nan 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant