Skip to content

recording-writer

Collects received packets and periodically writes them to the filesystem.

Description

Importing this script creates a recording writer that periodically writes a binary representation of the current VBus values to a file that conforms to the VBus Recording File Format.

This recording writer is initially configured to write once every 10 seconds to a file named logs/recording/%Y%m%d.vbus where %Y%m%d are placeholders for the current year, month and day of the current date.

The UTC date is used for the formatting of the file's path. That means that data recorded at "2025-04-01 01:30:00 CEST (Central European Summertime)" will still be stored in a file under logs/recording/20250331.vbus, because its still before midnight in UTC time.

The shared recording writer can be accessed using the service.getSharedRecordingWriter() function. In addition to this shared recording writer scripts can create custom recording writers using the service.createRecordingWriter() function.

All recording writers start logging after all scripts have called their respective $.connect function.

Service

API Docs

typescript
createRecordingWriter(options: RecordingWriterConstructorOptions): RecordingWriter;
getSharedRecordingWriter(): RecordingWriter;

Example

Config:

typescript
export default defineConfig({
  connections: [{
    kind: 'serialPort',
    path: '/dev/tty.usbmodem',
  }],
  scripts: [
    import('../scripts/recording-writer'),

    defineScript(async ($) => {
      const rwScript = await import('../scripts/recording-writer');
      const rwService = await rwScript.default.requireService();

      rwService.getSharedRecordingWriter().setInterval(1000); // = 1 second

      await $.connect();

      // NOTE: recordingWriter.setInterval() is not allowed after $.connect()
    }),
  ],
});