Spaces:
Paused
Paused
Download lib/summaryHelper/tools/mavTlogReader.js from Adhyasta/gcs-backend-server: direct link, hf CLI and curl.
- Browser
- Download file 3.69 kB
-
https://huggingface.co/spaces/Adhyasta/gcs-backend-server/resolve/main/lib/summaryHelper/tools/mavTlogReader.js
- Command line
-
hf download hf://spaces/Adhyasta/gcs-backend-server/lib/summaryHelper/tools/mavTlogReader.js
-
curl -L -o mavTlogReader.js https://huggingface.co/spaces/Adhyasta/gcs-backend-server/resolve/main/lib/summaryHelper/tools/mavTlogReader.js
3.69 kB
| /* | |
| Used fields benchmark: https://plot.ardupilot.org/ | |
| */ | |
| const { MavLinkTLogPacketSplitter, MavLinkPacketParser, common, minimal, ardupilotmega } = require('node-mavlink') | |
| const { toPlotter, filterFields } = require('./plotter.js') | |
| const { toCategorical } = require('./parseToCategories.js') | |
| const { toTabularForm } = require('./tabular.js') | |
| const createMavReaderStream = (file) => { | |
| const splitter = new MavLinkTLogPacketSplitter() | |
| const parser = new MavLinkPacketParser() | |
| const reader = file.pipe(splitter).pipe(parser) | |
| return { reader, splitter } | |
| } | |
| const readMavTlog = (file) => { | |
| const { reader, splitter } = createMavReaderStream(file) | |
| const REGISTRY = { | |
| ...common.REGISTRY, | |
| ...minimal.REGISTRY, | |
| ...ardupilotmega.REGISTRY | |
| } | |
| const readPackets = new Array() | |
| return new Promise((resolve, reject) => { | |
| reader.on('data', packet => { | |
| const cls = REGISTRY[packet.header.msgid] | |
| if (cls) { | |
| const data = packet.protocol.data(packet.payload, cls) | |
| if (packet.header.timestamp) { | |
| if (data instanceof minimal.Heartbeat) { | |
| readPackets.push({ | |
| timestamp: new Date(Number(packet.header.timestamp)), | |
| data | |
| }) | |
| } | |
| if (data instanceof common.Attitude) { | |
| readPackets.push({ | |
| timestamp: new Date(Number(packet.header.timestamp)), | |
| data | |
| }) | |
| } | |
| if (data instanceof common.GlobalPositionInt) { | |
| readPackets.push({ | |
| timestamp: new Date(Number(packet.header.timestamp)), | |
| data | |
| }) | |
| } | |
| if (data instanceof common.GpsRawInt) { | |
| readPackets.push({ | |
| timestamp: new Date(Number(packet.header.timestamp)), | |
| data | |
| }) | |
| } | |
| if (data instanceof common.NavControllerOutput) { | |
| readPackets.push({ | |
| timestamp: new Date(Number(packet.header.timestamp)), | |
| data | |
| }) | |
| } | |
| if (data instanceof common.RcChannels) { | |
| readPackets.push({ | |
| timestamp: new Date(Number(packet.header.timestamp)), | |
| data | |
| }) | |
| } | |
| if (data instanceof common.ServoOutputRaw) { | |
| readPackets.push({ | |
| timestamp: new Date(Number(packet.header.timestamp)), | |
| data | |
| }) | |
| } | |
| if (data instanceof common.VfrHud) { | |
| readPackets.push({ | |
| timestamp: new Date(Number(packet.header.timestamp)), | |
| data | |
| }) | |
| } | |
| } else { | |
| console.log(data) | |
| } | |
| } | |
| }) | |
| file.on('close', () => { | |
| resolve({ readPackets }) | |
| console.log('Number of invalid packages:', splitter.invalidPackages) | |
| console.log('Number of unknown packages:', splitter.unknownPackagesCount) | |
| console.log('Total number of consumed packets:', splitter.validPackages) | |
| }) | |
| }) | |
| } | |
| const parseMavTlog = async (file, cb) => { | |
| try { | |
| const mav = await readMavTlog(file) | |
| const catData = toCategorical(mav) | |
| const tableView = toTabularForm(catData) | |
| const plotInterface = toPlotter(catData) | |
| const tabularFields = tableView.map((type, index) => { | |
| return { | |
| index, | |
| categoryName: type.category, | |
| headerNames: type.header | |
| } | |
| }) | |
| cb({ | |
| meta: { | |
| planeStateKeys: tabularFields, | |
| graphFilterKeys: filterFields | |
| }, | |
| categories: tableView, | |
| plotInterface | |
| }) | |
| } catch (err) { | |
| console.error(err) | |
| } | |
| } | |
| module.exports = { | |
| readMavTlog, | |
| createMavReaderStream, | |
| parseMavTlog | |
| } | |