@@ -6,6 +6,7 @@ Generated from: ardupilotmega.xml,common.xml,uAvionix.xml,icarous.xml
66Note: this file has been auto-generated. DO NOT EDIT
77*/
88
9+ const Uint64BE = require("int64-buffer").Uint64BE;
910const jspack = require('jspack').jspack
1011const _ = require('underscore')
1112const events = require('events')
@@ -18250,7 +18251,7 @@ MAVLink = function (logger, srcSystem, srcComponent) {
1825018251 this.buf = Buffer.alloc(0)
1825118252 this.bufInError = Buffer.alloc(0)
1825218253 this.bufmap = {}
18253- this.timemap = {}
18254+ this.startTime = null
1825418255
1825518256 this.srcSystem = typeof srcSystem === 'undefined' ? 0 : srcSystem
1825618257 this.srcComponent = typeof srcComponent === 'undefined' ? 0 : srcComponent
@@ -18678,32 +18679,17 @@ MAVLink.prototype.parseType = function (type) {
1867818679 console.log('could not find message: ' + type)
1867918680 return
1868018681 }
18681- for (let i of this.bufmap[mavlink.nameMap[type]]) {
18682- let m = this.decode(this.buf.slice(i[0], i[1]))
18683-
18684- // TODO: Fix this somehow. this is a hack to add time information to messages without it.
18685- // It populates a "timemap", which is dict of timestamp at each offset, and whenever a message has no
18686- // time information, it goes back in time until it finds an time information
18687- let start = i[0]
18688- // If there is a timestamp, save to the map
18689- if ('time_boot_ms' in m) {
18690- this.timemap[start] = m.time_boot_ms
18691- } else {
18692- // if there is not, seek back until we find a valid timestamp, and use that
18693- m.time_boot_ms = 0
18694- let index = start
18695- while (index > 0) {
18696- if (index in this.timemap) {
18697- m.time_boot_ms = this.timemap[index]
18698- break
18699- }
18700- index -= 1
18701- }
18702- }
18703- // This filters out the first messages, which have no time_boot_ms information
18704- if (m.time_boot_ms !== 0) {
18705- messages.push(m)
18682+ for (let offsets of this.bufmap[mavlink.nameMap[type]]) {
18683+ let m = this.decode(this.buf.slice(offsets[0], offsets[1]))
18684+ // The 8 bytes preceding the mavlink message are actually a very useful timestamp saved by the GCS!
18685+ let slice = this.buf.slice(offsets[0]-8, offsets[0])
18686+ let timestamp = new Uint64BE(slice)
18687+ if (this.startTime === null)
18688+ {
18689+ this.startTime = timestamp/1000
1870618690 }
18691+ m.time_boot_ms = timestamp/1000 - this.startTime
18692+ messages.push(m)
1870718693 }
1870818694 if (messages.length > 0) {
1870918695 this.emit('message', messages)
0 commit comments