Refactor data parsing to use DataView for consistency

Updated data parsing to rely on DataView methods instead of direct array indexing. This ensures a more consistent approach to handling binary data, improving readability and maintainability.
main
Arne Schauf 1 day ago
parent e808036092
commit aab89ae047
  1. 16
      flymaster-client.js

@ -399,12 +399,12 @@ window.FlymasterClient = class FlymasterClient {
const view = new DataView(data.buffer); const view = new DataView(data.buffer);
return { return {
fix: data[16], fix: view.getInt8(0),
latitude: view.getInt32(0, true), // little-endian latitude: view.getInt32(1, true), // little-endian
longitude: view.getInt32(4, true), // little-endian longitude: view.getInt32(5, true), // little-endian
gpsaltitude: view.getInt16(8, true), // little-endian gpsaltitude: view.getInt16(9, true), // little-endian
baro: view.getInt16(10, true), // little-endian baro: view.getInt16(11, true), // little-endian
time: view.getUint32(12, true) // little-endian time: view.getUint32(13, true) // little-endian
}; };
} }
@ -422,12 +422,12 @@ window.FlymasterClient = class FlymasterClient {
for (let i = 0; i + DELTA_SIZE <= data.length; i += DELTA_SIZE) { for (let i = 0; i + DELTA_SIZE <= data.length; i += DELTA_SIZE) {
const delta = { const delta = {
fix: data[i], fix: view.getInt8(i),
latoff: view.getInt8(i + 1), latoff: view.getInt8(i + 1),
lonoff: view.getInt8(i + 2), lonoff: view.getInt8(i + 2),
gpsaltoff: view.getInt8(i + 3), gpsaltoff: view.getInt8(i + 3),
baroff: view.getInt8(i + 4), baroff: view.getInt8(i + 4),
timeoff: data[i + 5] timeoff: view.getUint8(i + 5)
}; };
deltas.push(delta); deltas.push(delta);

Loading…
Cancel
Save