openmovementproject / openmovement

Open Movement devices are miniature, embeddable, open source sensors developed at Newcastle University, UK. The source code for the firmware and software is available under a BSD 2-clause license, and the hardware (PCB designs, layouts and schematics), enclosure designs and documentation are available under a Creative Commons 3.0 BY Attribution License.
https://openmovement.dev
146 stars 76 forks source link

cwa-convert Java - CwaBlock incorrectly deserialises accelerometer packets with BPS of 4 #9

Closed Woodz closed 9 years ago

Woodz commented 9 years ago

The logic for reading packets with a BPS of 4 is incorrect as the statement byteBuffer.getInt(30 + 4 * i) is upcast to a long. When the result of getInt is negative then the resulting upcasting is negative as well, which pads the exponent with 1's. This means that the exponent is read out as a negative instead of a positive so the values are right shifted further than they should.

danielgjackson commented 9 years ago

Thanks for the bug report -- the 4 bytes-per-sample conversion has now been fixed (thanks again Java for the lack of unsigned types!). I'm quite surprised this issue had gone unnoticed!