Appearance
Recorded data processing
The resol-vbus-core
provides classes to encoded and decode VBus data primitives from and to their storable recording representation as specified by the VBus Recording File Format Specification.
See VBus Recording File Format for details.
Encoding
Encoding VBus data primitives
The three VBus data primitives Packet
, Datagram
and Telegram
can be encoded using their respective function:
They each encode their VBus data primitive into an Uint8Array
containing the bytes in recording representation.
Encode Start-Of-Header-Set
To mark the beginning of a group of VBus data primitives that are stored together at a certain point in time, the encodeStartOfHeaderSetRecord
can be used to generate a S-O-H-S record.
See encodeStartOfHeaderSetRecord
function API for details.
Encode VBus channel
Some VBus products support more than one channel. The "VBus channel marker" is used announce that all subsequent records originate from the provided VBus channel. The function encodeChannelRecord
can be used to generate that record.
See encodeChannelRecord
function API for details.
Encode a complete HeaderSet
The encodeHeaderSetRecords
combines the five previously mentioned functions by generating an array of Uint8Array
buffers of encodeStartOfHeaderSetRecord
followed by the encode___Record
and optional encodeChannelRecord
for every VBus data primitive in the provided HeaderSet
argument.
See encodeHeaderSetRecords
function API for details.
Decoding
The RecordingDecoder
class decodes incoming Uint8Array
data and tries to decode records from it. Whenever a record was decoded, the respective callback is called to inform the consumer of the decoded data.
typescript
import { RecordingDecoder } from 'resol-vbus-core';
const decoder = new RecordingDecoder({
onStartOfHeaderSet(timestamp) {
// ...
},
onPacket(packet) {
// ...
},
onEndOfHeaderSet(timestamp) {
// NOTE: called before the next S-O-H record generates a `onStartOfHeaderSet` or when the stream of data end with `end()`
},
});
const bytesToDecode = new Uint8Array(... /* TODO: insert data here */);
decoder.decode(bytesToDecode);
// TODO: optionally decode more chunks of data here
// signal to the decoder that no addional data is expected, forcing it to process the data from its internal buffer
decoder.end();
See RecordingDecoder
class API for details.