WPILogWriter

class WPILogWriter @JvmOverloads constructor(output: OutputStream, extraHeader: String = "", timeSource: TimeSource.WithComparableMarks = TimeSource.Monotonic, val origin: ComparableTimeMark = timeSource.markNow()) : Closeable, Flushable(source)

Writes the WPILOG format, version 1.0, to output.

Start an entry with startEntry (or startStructEntry), then append values to the id it returns. Every timestamp is in microseconds since origin, as measured by timeSource. Get one from now or timestampOf, or compute your own on the same basis.

All methods are safe to call from multiple threads. Each call writes one whole record, so records from different threads interleave but never tear. The writer adds a buffer in front of output unless it is already a BufferedOutputStream, so call flush to force pending records out.

Parameters

output

Where the log goes. close closes it.

extraHeader

A string stored in the file header, conventionally JSON. Readers ignore it.

timeSource

The clock that timestamps are measured on. A log created on its own can use the default. To line a log up with a dev.nextftc.telemetry.nt.NT4Server or another writer, give them the same source and the same origin.

origin

The moment timestamp zero refers to, a mark from timeSource. The default is the moment the writer is created. Share one origin between sinks that should agree on every timestamp.

Throws

if origin isn't from timeSource, or is in the future

Constructors

Link copied to clipboard
constructor(output: OutputStream, extraHeader: String = "", timeSource: TimeSource.WithComparableMarks = TimeSource.Monotonic, origin: ComparableTimeMark = timeSource.markNow())

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun appendBoolean(id: Int, value: Boolean, timestampMicros: Long = now())

Like appendBoolean, stamped with at. See timestampOf.

Link copied to clipboard
fun appendBooleanArray(id: Int, value: BooleanArray, timestampMicros: Long = now())

Like appendBooleanArray, stamped with at. See timestampOf.

Link copied to clipboard
fun appendDouble(id: Int, value: Double, timestampMicros: Long = now())

Like appendDouble, stamped with at. See timestampOf.

Link copied to clipboard
fun appendDoubleArray(id: Int, value: DoubleArray, timestampMicros: Long = now())

Like appendDoubleArray, stamped with at. See timestampOf.

Link copied to clipboard
fun appendFloat(id: Int, value: Float, timestampMicros: Long = now())

fun appendFloat(id: Int, value: Float, at: ComparableTimeMark)

Like appendFloat, stamped with at. See timestampOf.

Link copied to clipboard
fun appendFloatArray(id: Int, value: FloatArray, timestampMicros: Long = now())

Like appendFloatArray, stamped with at. See timestampOf.

Link copied to clipboard
fun appendInteger(id: Int, value: Long, timestampMicros: Long = now())

Like appendInteger, stamped with at. See timestampOf.

Link copied to clipboard
fun appendIntegerArray(id: Int, value: LongArray, timestampMicros: Long = now())

Like appendIntegerArray, stamped with at. See timestampOf.

Link copied to clipboard
fun appendRaw(id: Int, value: ByteArray, timestampMicros: Long = now())

Appends value to the entry id as is. Use this for raw entries.

Like appendRaw, stamped with at. See timestampOf.

Link copied to clipboard
fun appendString(id: Int, value: String, timestampMicros: Long = now())

Appends value as UTF-8.

Like appendString, stamped with at. See timestampOf.

Link copied to clipboard
fun appendStringArray(id: Int, value: List<String>, timestampMicros: Long = now())

Like appendStringArray, stamped with at. See timestampOf.

Link copied to clipboard
fun <T> appendStruct(id: Int, schema: StructSchema<T>, value: T, timestampMicros: Long = now())

Appends one packed value to an entry started with startStructEntry.

fun <T> appendStruct(id: Int, schema: StructSchema<T>, value: T, at: ComparableTimeMark)

Like appendStruct, stamped with at. See timestampOf.

Link copied to clipboard
fun <T> appendStructArray(id: Int, schema: StructSchema<T>, values: List<T>, timestampMicros: Long = now())

Appends values packed back to back to an entry started with startStructArrayEntry.

fun <T> appendStructArray(id: Int, schema: StructSchema<T>, values: List<T>, at: ComparableTimeMark)

Like appendStructArray, stamped with at. See timestampOf.

Link copied to clipboard
open override fun close()

Flushes pending records and closes the underlying stream. Does nothing if already closed.

Link copied to clipboard
fun finishEntry(id: Int, timestampMicros: Long = now())

Marks the entry id as finished. No more values should be appended to it.

Like finishEntry, stamped with at. See timestampOf.

Link copied to clipboard
open override fun flush()
Link copied to clipboard
fun now(): Long

Returns the current time as a timestamp in microseconds since origin.

Link copied to clipboard
fun setMetadata(id: Int, metadata: String, timestampMicros: Long = now())

Replaces the metadata of the entry id.

fun setMetadata(id: Int, metadata: String, at: ComparableTimeMark)

Like setMetadata, stamped with at. See timestampOf.

Link copied to clipboard
fun startEntry(name: String, type: WPILogType, timestampMicros: Long = now(), metadata: String = ""): Int

Starts an entry of type. See the overload that takes a type string.

fun startEntry(name: String, type: WPILogType, at: ComparableTimeMark, metadata: String = ""): Int

Like startEntry, for a WPILogType and stamped with at. See timestampOf.

fun startEntry(name: String, type: String, timestampMicros: Long = now(), metadata: String = ""): Int

Starts an entry and returns its id.

fun startEntry(name: String, type: String, at: ComparableTimeMark, metadata: String = ""): Int

Like startEntry, stamped with at. See timestampOf.

Link copied to clipboard
fun startStructArrayEntry(name: String, schema: StructSchema<*>, timestampMicros: Long = now(), metadata: String = ""): Int

Starts an entry that holds arrays of schema values, and returns its id. Otherwise the same as startStructEntry.

fun startStructArrayEntry(name: String, schema: StructSchema<*>, at: ComparableTimeMark, metadata: String = ""): Int

Like startStructArrayEntry, stamped with at. See timestampOf.

Link copied to clipboard
fun startStructEntry(name: String, schema: StructSchema<*>, timestampMicros: Long = now(), metadata: String = ""): Int

Starts an entry that holds single values of schema, and returns its id.

fun startStructEntry(name: String, schema: StructSchema<*>, at: ComparableTimeMark, metadata: String = ""): Int

Like startStructEntry, stamped with at. See timestampOf.

Link copied to clipboard

Returns mark as a timestamp in microseconds since origin.