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

Matlab AX3_readFile - last packet has incorrect data read due to off-by-one packet count #15

Closed Woodz closed 8 years ago

Woodz commented 9 years ago

When using AX3_readFile, the last packet read is incorrect. With my test file it returns LIGHT values of 887, 885 and 21044, TEMP values of 23.15, 23.15, 0 and ACC values of 0. Stepping into the packet reading code at https://github.com/digitalinteraction/openmovement/blob/master/Software/Analysis/Matlab/AX3_readFile.m#L243 shows that the offset calculation is off-by-one, as the vector validIds contains the base-1 index of the packet (e.g. 3, 4, 5). However, in the read operation of fseek(fid,validIds(i)*512+18,-1), packet 3 (which starts at 1024 (packet 1 = offset 0, packet 2 = offset 512, packet 3 = offset 1024)) is actually read from position 1536 (3 * 512). Therefore all data reading code should be corrected to (validIds(i) - 1) * 512 +... to correctly compensate for the base-1 index.

danielgjackson commented 8 years ago

Fixed as per commit above.