Options
All
  • Public
  • Public/Protected
  • All
Menu

iotile-common

Common utilities for IoTile Packages and Applications

Index

Type aliases

MutexReleaser

MutexReleaser: function

Type declaration

    • (): void
    • Returns void

QueuedRunnable

QueuedRunnable: function

Type declaration

QueuedWaiter

QueuedWaiter: function

Type declaration

    • (): void
    • Returns void

Functions

base64ToArrayBuffer

  • base64ToArrayBuffer(encodedString: string): ArrayBuffer
  • ngdoc

    object

    name

    Utilities.object:base64ToArrayBuffer

    description

    Decode a Base 64 encoded string into an ArrayBuffer

    Parameters

    • encodedString: string

      The base 64 encoded string

    Returns ArrayBuffer

    The decoded ArrayBuffer

copyArrayBuffer

  • copyArrayBuffer(dest: ArrayBuffer, src: ArrayBuffer, srcOffset: number, destOffset: number, length: number): void
  • ngdoc

    object

    name

    Utilities.function:copyArrayBuffer

    description

    Copy an ArrayBuffer into another one like memcpy

    This function is a javascript translation of memcpy. It takes a source and destination ArrayBuffer, an offset into both and a length of bytes to copy. In slicing syntax, this function does the following:

    dest[destOffset:destOffset+length] = src[srcOffset:srcOffset+length]

    • Exceptions

    • {@link type:InsufficientSpaceError InsufficentSpaceError}: If there is not space in the destination buffer to hold the copied data. This function will not expand the size of the destination buffer, so it must already be allocated with enough space for the copied data.
    throws

    {InsufficientSpaceError} If there is not space in the destination buffer to hold the copied data.

    Parameters

    • dest: ArrayBuffer

      The destination buffer that we should copy into. There must be enough space in dest to hold what you are copying. This function will not allocate more space for you.

    • src: ArrayBuffer

      The source buffer to copy from

    • srcOffset: number

      The offset in src to start copying from, 0 would mean copy from the beginning

    • destOffset: number

      The offset in dest to start copying into, 0 would mean to copy to the beginning of dest.

    • length: number

      The number of bytes to copy from src into dest.

    Returns void

createStreamerSlug

  • createStreamerSlug(deviceID: number, streamer: number): string
  • ngdoc

    object

    name

    Utilities.function:createStreamerSlug

    description

    Convert a numeric deviceID and streamer index to an IOTile cloud streamer slug

    This function converts a device id like 0x20 and streamer 0 to a string slug of the form: t--XXXX-XXXX-XXXX-XXXX--YYYY

    The slug always has the hex string in lowercase. The device id is converted into the XXXX portion and the streamer is converted to the YYYY portion.

    Parameters

    • deviceID: number

      The device ID to convert into a slug

    • streamer: number

      The streamer index to convert into a slug

    Returns string

    The corresponding streamer slug

delay

  • delay(delayMS: number): Promise<void>
  • ngdoc

    object

    name

    Utilities.function:delay

    description

    Delay for a fixed number of milliseconds

    This function wraps setTimeout in a promise API that can be used with async/await.

    Parameters

    • delayMS: number

      The number of milliseconds to wait

    Returns Promise<void>

    A promise that is fullfilled after delayMS milliseconds

deviceIDToSlug

  • deviceIDToSlug(deviceID: number): string
  • ngdoc

    object

    name

    Utilities.function:deviceIDToSlug

    description

    Convert a numeric deviceID to an IOTile cloud device slug

    This function converts a device id like 0x20 to a string slug of the form: d--XXXX-XXXX-XXXX-XXXX

    The slug always has the hex string in lowercase.

    Parameters

    • deviceID: number

      The device ID to convert into a slug

    Returns string

    The corresponding device slug

endsWith

  • endsWith(str: string, suffix: string): boolean
  • ngdoc

    object

    name

    Utilities.function:endsWith

    description

    Check if a string ends with another string

    Parameters

    • str: string

      The input string

    • suffix: string

      The suffix to check

    Returns boolean

    Whether the string ends with the suffix

expectedBufferSize

  • expectedBufferSize(fmt: string): number
  • ngdoc

    object

    name

    Utilities.function:expectedBufferSize

    description

    Determine how large a buffer is given its binary format string

    This function takes a string describing how fixed width integers are packed into a binary ArrayBuffer and calculates how large the buffer would need to be to contain that many integers of those sizes. It also support packing fixed length strings that must be prefixed with a number like 18s for an exactly 18 character string.

    Alignment is not taken into account, so if you are trying to match the alignment of a structure on, e.g. a 32 bit platform, you will need to insert alignment gaps as needed.

    See Also

    {@link Utilities.function:packArrayBuffer Utilities.packArrayBuffer}

    {@link Utilities.function:unpackArrayBuffer Utilities.unpackArrayBuffer}

    Parameters

    • fmt: string

      The format we are trying to determine the size of

    Returns number

    The number of bytes required to store fmt

guid

  • guid(): string

joinPath

  • joinPath(path1: string, path2: string): string
  • Parameters

    • path1: string
    • path2: string

    Returns string

mapStreamName

  • mapStreamName(streamName: string): number
  • ngdoc

    object

    name

    Utilities.function:mapStreamName

    description

    Convert a string description of an IOTile variable into a number

    This function converts string like 'output 1' into 16 bit integers like 0x5001.

    Parameters

    • streamName: string

      The string name of the variable that you want to convert

    Returns number

    The numerical stream identifier

numberToHexString

  • numberToHexString(inputNumber: number, length: number): string
  • ngdoc

    object

    name

    Utilities.function:numberToHexString

    description

    Convert a number to lowercase hex string

    This function takes a number like 0x16 and returns the string '16'. It would also take 0xAF and return 'af'. It will pad the number out to a fixed length using the second length parameter.

    The slug always has the hex string in lowercase.

    Parameters

    • inputNumber: number

      The number to convert to a hex string

    • length: number

      The number of hex digits to pad out to.

    Returns string

    The correspond lowercase hex string

packArrayBuffer

  • packArrayBuffer(fmt: string, ...args: any[]): ArrayBuffer
  • ngdoc

    object

    name

    Utilities.function:packArrayBuffer

    description

    Pack a series of arguments into an ArrayBuffer using a format string

    This function is a javascript equivalent of the python struct.pack function. It takes a format string consisting of the letters l, L, B and H and a variable list of numeric arguments. There must be exactly as many arguments as letters in the format string. The format string is used to convert each argument into a little endian binary representation of the number which is serialized into an ArrayBuffer. The resulting ArrayBuffer is returned.

    The meaning of each format code is:

    • B: An 8 bit wide unsigned integer
    • H: A 16 bit wide unsigned integer
    • L: A 32 bit wide unsigned integer
    • l: A 32 bit wide signed integer
    • #s: A fixed length string with length given by the number preceding s, e.g. 5s for a 5 character string. If the string argument is shorter than what is specified, it is padded with null characters.

    Exceptions

    • **{@link type:ArgumentError} If there is an unknown format string code or the string does not match the number or type of arguments received.

    Parameters

    • fmt: string

      The format string specifying the size of each argument

    • Rest ...args: any[]

    Returns ArrayBuffer

    The packed resulting binary array buffer

padString

  • padString(input: string, pad: string, length: number): string
  • ngdoc

    object

    name

    Utilities.function:padString

    description

    Pad a string by appended a given character until it reaches a fixed length

    Parameters

    • input: string

      The string we are trying to pad.

    • pad: string

      The padding character to add.

    • length: number

      The length of the final string you want.

    Returns string

    The correctgly padded string.

parseBufferFormatCode

  • parseBufferFormatCode(fmt: string): object[]
  • ngdoc

    object

    name

    Utilities.function:parseBufferFormatCode

    description

    Parse a string format code describing the packing of a binary buffer into an array of entries where each entry has a type code and a count prefix. For example,

    "18sH" would turn into [{count: 18, code: 's'}, {count: 8, code: 'H'}]

    See Also

    {@link Utilities.function:packArrayBuffer Utilities.packArrayBuffer}

    {@link Utilities.function:unpackArrayBuffer Utilities.unpackArrayBuffer}

    Parameters

    • fmt: string

      The format we are trying to determine the size of

    Returns object[]

    A list of the parsed format codes that were extracted from the input format string.

startsWith

  • startsWith(str: string, prefix: string): boolean
  • ngdoc

    object

    name

    Utilities.function:startsWith

    description

    Check if a string ends with another string

    Parameters

    • str: string

      The input string

    • prefix: string

      The prefix to check

    Returns boolean

    Whether the string ends with the suffix

unpackArrayBuffer

  • unpackArrayBuffer(fmt: string, buffer: ArrayBuffer): any[]
  • ngdoc

    object

    name

    Utilities.function:unpackArrayBuffer

    description

    Unpack an ArrayBuffer into a list of numeric values using a format string

    This function is a javascript equivalent of the python struct.unpack function. It takes a format string consisting of the letters l, L, B and H and a single ArrayBuffer. The format string is used to decode the ArrayBuffer into a list of numbers assuming that those numbers are encoded into fixed width integers in little endian format in the ArrayBuffer.

    The meaning of each format code is:

    • B: An 8 bit wide unsigned integer
    • H: A 16 bit wide unsigned integer
    • L: A 32 bit wide unsigned integer
    • l: A 32 bit wide signed integer
    • #s: A fixed length string. # should be a decimal number, e.g. 5s or 18s

    Exceptions

    • **{@link type:ArgumentError} If there is an unknown format string code or the string does not match the data contained inside the ArrayBuffer.

    Parameters

    • fmt: string

      The format string specifying the size of each argument

    • buffer: ArrayBuffer

      The packed ArrayBuffer that should be decoded using fmt

    Returns any[]

    A list of numbers decoded from the buffer using fmt

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