mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:37:08 +00:00
Add toJSON() function to binary decoder
This commit is contained in:
@@ -103,7 +103,30 @@ function unpack (data, index=0, endianness = platformEndianness) {
|
||||
return bundles;
|
||||
}
|
||||
|
||||
function toJSON (data, index=0, endianness = platformEndianness) {
|
||||
const items = [];
|
||||
const chunks = unpack(data, index, endianness);
|
||||
for (const chunk of chunks) {
|
||||
const type = chunk.type;
|
||||
const sequence = chunk.seq;
|
||||
let point = chunk.sp0;
|
||||
let timestamp = Number(chunk.ts0);
|
||||
for (let i=0; i < chunk.count; i++) {
|
||||
const longitude = chunk.positions[i*2 + 0];
|
||||
const latitude = chunk.positions[i*2 + 1];
|
||||
timestamp += chunk.Δts[i];
|
||||
const Δi = chunk.Δij[i*2 + 0];
|
||||
const Δj = chunk.Δij[i*2 + 1];
|
||||
|
||||
items.push({ type, sequence, point, timestamp, longitude, latitude, Δi, Δj });
|
||||
point += chunk.Δsp;
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
unbundle,
|
||||
unpack
|
||||
unpack,
|
||||
toJSON
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user