Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async readFrames(onFrame) {
const bag = await open(this.bagPath);
let frame = {};
function flushFrame() {
if (frame.keyTopic) {
onFrame(frame);
frame = {};
}
}
await bag.readMessages({topics: this.topics}, result => {
// rosbag.js reuses the data buffer for subsequent messages, so we need to make a copy
if (result.message.data) {
result.message.data = Buffer.from(result.message.data);
}
if (result.topic === this.keyTopic) {
flushFrame();
async readFrameByKeyTopic(start, end) {
const bag = await open(this.bagPath);
let frame = {};
async function flushFrame() {
if (frame.keyTopic) {
// This needs to be address, was used to flush on keyTopic message to sync
// await onFrame(frame);
frame = {};
}
}
const options = {
startTime: TimeUtil.fromDate(new Date(start * 1e3)),
endTime: TimeUtil.fromDate(new Date(end * 1e3))
};
if (this.topics) {
extensionPoint.progressCallback({
fullyLoadedFractionRanges: ranges.map(({ start, end }) => ({
start: Math.max(0, start / approximateSize),
end: Math.min(1, end / approximateSize),
})),
});
}
},
});
await remoteReader.open(); // Important that we call this first, because it might throw an error if the file can't be read.
approximateSize = remoteReader.size() * 0.99; // Chop off the last percentage or so for the indexes.
this._bag = new Bag(new BagReader(remoteReader));
await this._bag.open();
} else {
this._bag = await open(bagPath.file);
extensionPoint.progressCallback({ fullyLoadedFractionRanges: [{ start: 0, end: 1 }] });
}
const { startTime, endTime } = this._bag;
const connections = ((Object.values(this._bag.connections): any): Connection[]);
if (!startTime || !endTime || !connections.length) {
// This will abort video generation:
reportError("Invalid bag", "Bag is empty or corrupt.", "user");
return new Promise(() => {}); // Just never finish initializing.
}
this._connectionsByTopic = keyBy(connections, "topic");
return {
start: startTime,
end: endTime,
topics: bagConnectionsToTopics(connections),
initialize = async (initialize: InitializeMessage): Promise => {
await decompress.isLoaded;
this._bag = await open(initialize.bagPath);
};
async calculateOrigin() {
const bag = await open(this.bagPath);
let origin = {latitude: 0, longitude: 0, altitude: 0};
await bag.readMessages({topics: ['/gps/fix']}, ({message}) => {
origin = _.minBy(ORIGINS, ({longitude, latitude}) => {
return turf.distance(
turf.point([longitude, latitude]),
turf.point([message.longitude, message.latitude])
)
});
});
return origin;
}
async _openBag() {
return await open(this.bagPath);
}
async open() {
this.bag = await open(this.bagPath);
}