smerckel / dbdreader

A reader for binary data files created by Slocum ocean gliders (AUVs)
GNU General Public License v3.0
17 stars 14 forks source link

Support parsing byte-order from *bd files #7

Closed erinaceous closed 2 years ago

erinaceous commented 2 years ago

Addressing #6!

Was expecting to have to deal with lots of segfaults but refreshing my C less painful than anticipated :)

In read_sensor_value the bit-shifting stuff where floats and doubles were being read into one byte at a time, I replaced with calls to fread - that appears to work fine with all the .[ts]bd files I've thrown at it on our dockserver (mostly G2s, with 3 G3s). If the magic number 0x1234 isn't read from the third field in the "known bytes binary cycle" (a int16), the values read are byte-swapped before they're cast to doubles.

Have added an example tbd/sbd pair from unit_887 which is a G3 with the different byte-order.

Also I've never seen them used before, but apparently the format also supports sending back shorts, so added that in.

smerckel commented 2 years ago

Hi erinaceous,

Thank you for providing this patch. It seems to work fine and I included your contribution into the master branch. Also, now I know what those 17 bytes that follow the ascii header, are meant for :-)

Thanks a lot!