@commaai/log_reader
Read in comma.ai capnp logfiles whilst retaining sanity
Last updated 7 months ago by commabot .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @commaai/log_reader 
SYNC missed versions from official npm registry.

@commaai/log_reader

Read in Comma AI rlog files using JavaScript. Supports, and encourages, streaming of the data.

Under the hood this is using capnp-ts, capnp-split, and capnp-json to do most of the heavy lifting.

Installation

npm i --save @commaai/log_reader
or
yarn add @commaai/log_reader

Usage

const Reader = require('@commaai/log_reader');
const fs = require('fs');


var readStream = fs.createReadStream('/path/to/rlog');
var reader = Reader(readStream);

reader(function (obj) {
  console.log('This is an Event message object', obj);
});

API

Reader(inputStream) => Event(function (message)) => unlisten

Creates a new stream reader which buffers and splits all messages coming in to it and sends all completed parsed messages over the returned Event interface.

The Event object returned is a function. This function takes in a function which will be called each time a new message is available with exactly 1 parameter, the JSONified message. This function returns an unlisten function which can be used to stop calling the handler. Note that unlistening to the stream of messages does not stop the stream from flowing, you will miss messages. To pause the stream you need to pause the stream feeding in the data.

Reader.Event(buf) => EventWrapper

Reader.Event is a class designed to wrap the raw buffers of individual messages. It returns a very simple wrapper.

  • buf: (required Buffer) The buffer containing the full unpacked message you're trying to read.

EventWrapper.toJSON

Returns a normal JavaScript object where all data available in the event is exposed as defineProperty values which call the underlying struct's getter method and caches the result. Read more here.

EventWrapper.toStruct

Return the raw capnp-ts struct. This is not recommended as using the raw struct in incorrect ways can result in massive performance drops. Since the JSON objects fetch all their data lazily, changes made to the underlying struct will be reflected in JSON objects who have not yet tried to look up the value.

Command Line Tools

This package ships with a CLI tool. Check the --help command to see all of the options.

log-to-json [source]

The most simple and obvious use case for this library. This tool takes in the path to a source log file and converts the entire thing into JSON. If source is is not specified then stdin will be used. The -o flag can be used to write the output to a file instead of stdout

Examples:

# Convert an entire log file into a JSON feed
$ log-to-json rlog -o rlog.json

# Write the JSON as 1 giant array instead of newline deliminated objects
$ log-to-json rlog --array -o rlog.json
# read from stdin and write to stdout
$ cat rlog | log-to-json

License

MIT @ comma.ai

Read more about how to get started hacking your car with panda here.

Current Tags

  • 0.5.5                                ...           latest (7 months ago)

18 Versions

  • 0.5.5                                ...           7 months ago
  • 0.5.4                                ...           7 months ago
  • 0.5.3                                ...           9 months ago
  • 0.5.2                                ...           10 months ago
  • 0.5.1                                ...           a year ago
  • 0.4.5                                ...           a year ago
  • 0.4.4                                ...           a year ago
  • 0.4.3                                ...           a year ago
  • 0.4.2                                ...           a year ago
  • 0.4.1                                ...           a year ago
  • 0.4.0                                ...           2 years ago
  • 0.3.1                                ...           2 years ago
  • 0.3.0                                ...           2 years ago
  • 0.2.2                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 18
Last Day 0
Last Week 18
Last Month 1
Dependencies (10)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |