Skip to content

Commit e21fe83

Browse files
mavlink: use tlog timestamp header for timing information
1 parent eb63dc2 commit e21fe83

3 files changed

Lines changed: 19 additions & 27 deletions

File tree

mavlink_common_v1.0/mavlink.js

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Generated from: ardupilotmega.xml,common.xml,uAvionix.xml,icarous.xml
66
Note: this file has been auto-generated. DO NOT EDIT
77
*/
88

9+
const Uint64BE = require("int64-buffer").Uint64BE;
910
const jspack = require('jspack').jspack
1011
const _ = require('underscore')
1112
const 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)

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"epic-spinners": "^1.1.0",
2323
"fast-xml-parser": "^3.16.0",
2424
"git-revision-webpack-plugin": "^3.0.4",
25+
"int64-buffer": "^0.99.1007",
2526
"jquery": "^3.4.1",
2627
"jspack": "0.0.4",
2728
"mavlink_common_v1.0": "file:mavlink_common_v1.0",

0 commit comments

Comments
 (0)