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

Wrong unpacking in receiveprop-decoder for floats #40

Open
spheenik opened this issue Dec 24, 2013 · 0 comments
Open

Wrong unpacking in receiveprop-decoder for floats #40

spheenik opened this issue Dec 24, 2013 · 0 comments

Comments

@spheenik
Copy link
Member

in skadi/decoder/recv_prop/float.py you can find the following:

    def _decode_normal(self, stream):
        """
        Decode 'normal' float, which appears to be 11 low bits in a float
        multiplied by specific float-encoding-related values.

        Arguments:
        stream -- a Stream (skadi.io.stream)

        Returns a float.

        """
        s = stream.read_numeric_bits(1) # sign
        l = stream.read_numeric_bits(11) # low
        b = bytearray(0, 0, l & 0x0000ff00, l & 0x000000ff)
        v = struct.unpack('f', b)[0]

        # not sure this is ever called. what does bitshifting a float mean?
        if v >> 31:
            v += 4.2949673e9

        v *= 4.885197850512946e-4

        return v * -1 if s else v

which puts the eleven bits read in l into the bytearray b.
However, the third value put in, l & 0x0000ff00 will be zero all the time.

Proposed fix:
put (l & 0x0000ff00) >> 8 into the third byte.

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