我在C ++程序中做到这一点没有问题,但是我坚持用JS写ulong。
如果我使用32位process.hrtime()值,FB不会有问题。
但是,如何为64位创建createLong()?
参见:[https://nodejs.org/api/process.html#process_process_hrtime_bigint]
# commented line does not work
# let timeStamp = process.hrtime.bigint()
let timeStamp = process.hrtime()
let ts = builder.createLong(0, timeStamp)
PNT.Telemetry.startTelemetry(builder)
PNT.Telemetry.addSystemTime(builder, ts)
FB模板文件
// Simple Telemetry data from/to Sim and Sensor
namespace PNT;
enum DeviceType:byte { IMU, VAN, GPS, MAGNAV, SOOP }
struct PosVector {
lat:double;
lon:double;
alt:double;
}
table Telemetry {
source: string;
systemTime:ulong = 0;
systemTimeString: string;
description: string;
position: PosVector;
}
root_type Telemetry;
最佳答案
您可以使用此功能,它可以很好地用于时间戳记
var flatBufferTimeStamp = function(value) {
var bin = (value).toString(2);
var pad = new Array(64 - bin.length + 1 ).join('0');
bin = pad + bin;
return {
low: parseInt(bin.substring(32), 2),
high: parseInt(bin.substring(0, 32), 2)
};
}
var timeStamp = flatBufferTimeStamp(process.hrtime())
let ts = builder.createLong(timeStamp.low, timeStamp.high);
PNT.Telemetry.startTelemetry(builder)
PNT.Telemetry.addSystemTime(builder, ts)
资料来源:https://groups.google.com/forum/#!topic/flatbuffers/ieXNEsB_2wc