Options
All
  • Public
  • Public/Protected
  • All
Menu
ngdoc

object

name

iotile.device.object:ReportParser

description

A stream based report parser that knows how to construct IOTileReport objects from data streamed from an IOTile Device. The ReportParser has only 2 public methods (and several getters). You can call pushData to send additional data received from an IOTileDevice to the ReportParser.

The ReportParser will automatically try to see how many reports it can build using all of the data it currently has and return a list of those reports to you.

If any error occurs during parsing, the ReportParser enters a broken state and will not process any further data until you call the reset() function.

ReportParser is built on top of a fixed size RingBuffer that it uses for efficiently handling report data.

See {@link Utilities.type:RingBuffer Utilities.RingBuffer}

Hierarchy

  • ReportParser

Index

Constructors

constructor

  • new ReportParser(ringBufferSize: number, expand?: boolean): ReportParser

Properties

Private _inProgressReceived

_inProgressReceived: number

Private _inProgressTotal

_inProgressTotal: number

Private _lastEvent

_lastEvent: ReportParserEvent | null

Private _lastProgressReport

_lastProgressReport: number

Private _lastUpdateTime

_lastUpdateTime: Date | null

Private _progressReportInterval

_progressReportInterval: number

Private _receiveState

_receiveState: ReceiveStatus

Private _receivedTime

_receivedTime: Date | null

Private _reportsReceived

_reportsReceived: number

Private broken

broken: boolean

Private ringBuffer

ringBuffer: RingBuffer

Accessors

inProgressReceived

inProgressReceived:

inProgressTotal

inProgressTotal:

state

state:

Methods

popLastEvent

  • ngdoc

    method

    name

    iotile.device.object:ReportParser#popLastEvent

    methodof

    iotile.device.object:ReportParser

    description

    If there has been a change in reportParser's progress getting a report since the last time we called popLastEvent(), return that event, otherwise return null;

    This function can be used to get progress information while receiving long reports. There are three kinds of events you can get:

    • ReportStartedEvent: when a new report header has been received;
    • ReportProgressEvent: sent every time X percent (currently 5%) of the report has been received.
    • ReportFinishedEvent: sent whenever a long report is fully receiving.

    Returns null | ReportParserEvent

    The last event that happened or null if nothing has happened since the last call to this function.

pushData

  • pushData(chunk: ArrayBuffer | SharedArrayBuffer): any[]
  • ngdoc

    method

    name

    iotile.device.object:ReportParser#pushData

    methodof

    iotile.device.object:ReportParser

    description

    Add new data received from a device to the RingBuffer and try to parse reports out of it

    throws

    {Errors.ReportParsingError} If there is an unrecoverable error processing reports.

    throws

    {Errors.ReportParsingStoppedError} If there was a previous report parsing error and processing is therefore stopped.

    throws

    {Errors.InsufficientSpaceError} If there is not enough space in the internal ring buffer to hold the data for processing.

    Parameters

    • chunk: ArrayBuffer | SharedArrayBuffer

    Returns any[]

    A list of all of the reports that could be parsed out of the currently received data. If no reports could be parsed, returns an empty list.

reset

  • reset(): void
  • ngdoc

    method

    name

    iotile.device.object:ReportParser#reset

    methodof

    iotile.device.object:ReportParser

    description

    Reset the internal state of the report parser back to a clean slate. Should be called every time we connect to a new device.

    Returns void

stop

  • stop(): void

Private tryParseIndividualReport

Private tryParseListReport

  • List reports have a variable size with a fixed size header that contains the size of the total report.

    This function will also update the reportParser object's current report progress status so that people who care can be informed about progress receiving this report.

    NB We need to keep track of the time when we first start receiving information from a report because that the time the report was sent. So we keep an internal state variable _receivedTime that we set to the current time when we start receiving a report and to null when we're done processing a report.

    Returns null | IOTileReport

Private tryParseReport

  • Try to parse a single report from the report ring buffer. We get one single byte to figure out the type and then, optionally read the header and finally read the entire report.

    Returns null | IOTileReport

Private tryParseReports

  • tryParseReports(): any[]
  • ngdoc

    method

    name

    iotile.device.object:ReportParser#tryParseReports

    methodof

    iotile.device.object:ReportParser

    description

    Attempt to process as many reports as possible from the current ring buffer contents

    throws

    {Errors.ReportParsingError} If there is an unrecoverable error processing reports.

    throws

    {Errors.ReportParsingStoppedError} If there was a previous report parsing error and processing is therefore stopped.

    Returns any[]

    A list of all of the reports that could be parsed out of the currently received data. If no reports could be parsed, returns an empty list.

Private updateStatus

  • updateStatus(inProgress: boolean, totalSize: number, receivedSize: number, streamer?: undefined | number): void
  • Update our internal status information so that we can inform the user about progress receiving long reports. We only send events when a report is not received in a single shot. So if we are just dumped a complete report in a single pushData() call, then no progress will be reported.

    Parameters

    • inProgress: boolean
    • totalSize: number
    • receivedSize: number
    • Optional streamer: undefined | number

    Returns void

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc