Options
All
  • Public
  • Public/Protected
  • All
Menu

Jacdac TypeScript - v1.28.7

Index

JDOM

Clients

Servers

Trace

Data Packing

Firmware

Other

Roles

Runtime

Specification

JDOM

EventHandler: ((...args: any[]) => void)

Type declaration

    • (...args: any[]): void
    • Parameters

      • Rest ...args: any[]

      Returns void

Servers

Trace

  • parsePacketFilter(bus: JDBus, text: string): PacketFilter
  • parseTrace(contents: string): Trace

Data Packing

PackedSimpleValue: number | boolean | string | Uint8Array
PackedValues: any[]
  • jdpack<T>(fmt: string, data: T): Uint8Array
  • Format strings are space-separated sequences of type descriptions. All numbers are understood to be little endian. The following type descriptions are supported:

    • u8, u16, u32 - unsigned, 1, 2, and 4 bytes long respectively
    • i8, i16, i32 - similar, but signed
    • b - buffer until the end of input (has to be last)
    • s - similar, but utf-8 encoded string
    • z - NUL-terminated utf-8 string
    • b[10] - 10 byte buffer (10 is just an example, here and below)
    • s[10] - 10 byte utf-8 string; trailing NUL bytes (if any) are removed
    • x[10] - 10 bytes of padding

    There is one more token, r:. The type descriptions following it are repeated in order until the input buffer is exhausted. When unpacking, fields after r: are repeated as an array of tuples.

    In case there's only a single field repeating, it's also possible to append [] to its type, to get an array of values.

    Type Parameters

    • T extends any[]

    Parameters

    • fmt: string
    • data: T

    Returns Uint8Array

  • jdpackEqual<T>(fmt: string, left: T, right: T): boolean
  • Checks if two packed values serialize to the same buffer

    Type Parameters

    • T extends any[]

    Parameters

    • fmt: string

      packing format string

    • left: T

      left data

    • right: T

      right data

    Returns boolean

    true if both data serialize to the same buffer

  • jdunpack<T>(buf: Uint8Array, fmt: string): T
  • Unpacks a byte buffer into structured data as specified in the format string. See jdpack for format string reference.

    Type Parameters

    • T extends any[]

    Parameters

    • buf: Uint8Array
    • fmt: string

    Returns T

  • lightEncode(format: string, args: (number | number[])[]): Uint8Array
  • Encodes a light command into a buffer

    Parameters

    • format: string
    • args: (number | number[])[]

    Returns Uint8Array

  • tonePayload(frequency: number, ms: number, volume: number): Uint8Array
  • Encodes a buzzer tone information into a data payload

    Parameters

    • frequency: number

      sound frequency in Hz

    • ms: number

      sound duration in milliseconds

    • volume: number

      volume from [0..1]

    Returns Uint8Array

    data payload

Firmware

  • parseFirmwareFile(blob: Blob, store?: string): Promise<FirmwareBlob[]>
  • Parse a UF2 firmware file and extracts firmware blobs

    Parameters

    • blob: Blob
    • Optional store: string

    Returns Promise<FirmwareBlob[]>

  • parseUF2Firmware(uf2: Uint8Array, store: string): FirmwareBlob[]
  • Parses a UF2 firmware binary into firmware blobs

    Parameters

    • uf2: Uint8Array
    • store: string

    Returns FirmwareBlob[]

  • sendStayInBootloaderCommand(bus: JDBus): Promise<void>
  • This command can be sent every 50ms to keep devices in bootloader mode

    Parameters

    Returns Promise<void>

  • updateApplicable(dev: FirmwareInfo, blob: FirmwareBlob): boolean
  • Indicates if a firmware blob is applicated to the device information

    Parameters

    • dev: FirmwareInfo
    • blob: FirmwareBlob

    Returns boolean

Other

BusBroadcastMessageType: "visibilitychange" | "disconnect" | "connectionstate"
JDFrameBuffer: Uint8Array & { _jacdac_meta?: any; _jacdac_replay?: boolean; _jacdac_sender?: string; _jacdac_timestamp?: number }

Represent serialized Packet, or several packets.

SatNavReadingType: [number, number, number, number, number, number]
CLOUD_COMMAND: "cloudCommand" = "cloudCommand"
DEVICE_IMAGE_HEIGHT: 768 = 768
DEVICE_IMAGE_WIDTH: 1024 = 1024
TYPESCRIPT_STATIC_NAMESPACE: "jacdac" = "jacdac"
UPLOAD: "upload" = "upload"
UPLOAD_BIN: "uploadBin" = "uploadBin"
deviceCatalog: DeviceCatalog = ...

The device catalog

encodings: jdspec.SMap<jdspec.Encoding> = ...
secondaryUnitConverters: jdspec.SMap<{ name: string; offset: number; scale: number; unit: senml.Unit | "#" }> = ...
unitDescription: jdspec.SMap<string> = ...
  • anyRandomUint32(length: number): Uint32Array
  • camelize(name: string): string
  • Parameters

    • name: string

    Returns string

  • capitalize(name: string): string
  • Parameters

    • name: string

    Returns string

  • converters(): jdspec.SMap<((s: jdspec.ServiceSpec) => string)>
  • Returns jdspec.SMap<((s: jdspec.ServiceSpec) => string)>

  • createIFrameBridge(parentOrigin?: string): JDBridge
  • createProxyBridge(sendPacket: ((pkt: Uint8Array, sender: string) => void)): ProxyBridge
  • Parameters

    • sendPacket: ((pkt: Uint8Array, sender: string) => void)
        • (pkt: Uint8Array, sender: string): void
        • Parameters

          • pkt: Uint8Array
          • sender: string

          Returns void

    Returns ProxyBridge

  • cryptoRandomUint32(length: number): Uint32Array
  • dashify(name: string): string
  • Parameters

    • name: string

    Returns string

  • dualDeviceId(id: string): string
  • escapeDeviceIdentifier(text: string): string
  • Parameters

    • text: string

    Returns string

  • escapeDeviceNameIdentifier(text: string): string
  • Parameters

    • text: string

    Returns string

  • generateDeviceSpecificationId(dev: DeviceSpec): string
  • Parameters

    • dev: DeviceSpec

    Returns string

  • humanify(name: string): string
  • Parameters

    • name: string

    Returns string

  • injectDevTools(bus: JDBus, options?: { dashboardUrl?: string }): (() => void)
  • Starts an external or in-page hosted developer tool window for jacdac

    Parameters

    • bus: JDBus
    • Optional options: { dashboardUrl?: string }
      • Optional dashboardUrl?: string

    Returns (() => void)

    function to remove the devtools

      • (): void
      • Starts an external or in-page hosted developer tool window for jacdac

        Returns void

        function to remove the devtools

  • isAckError(e: Error): boolean
  • isCancelError(e: Error): boolean
  • isDualDeviceId(left: string, right: string): boolean
  • Check if the left device identifier is a bootloader dual of the right identifier

    Parameters

    • left: string
    • right: string

    Returns boolean

  • isNumericType(field: PacketMember): boolean
  • Parameters

    • field: PacketMember

    Returns boolean

  • isReadOnlyRegister(pkt: PacketInfo): boolean
  • Indicates if the packet info is not rw

    Parameters

    • pkt: PacketInfo

    Returns boolean

  • localStorageSetting(key: string): Setting
  • normalizeDeviceSpecification(dev: DeviceSpec): DeviceSpec
  • Parameters

    • dev: DeviceSpec

    Returns DeviceSpec

  • packFormat(sinfo: ServiceSpec, pkt: PacketInfo, useBooleans?: boolean): string
  • Generates the format to pack/unpack a data payload for this packet

    Parameters

    • sinfo: ServiceSpec
    • pkt: PacketInfo

      TODO fix this

    • Optional useBooleans: boolean

    Returns string

  • packInfo(info: ServiceSpec, pkt: PacketInfo, options?: { isStatic?: boolean; useBooleans?: boolean; useJDOM?: boolean }): { buffers: string; csTypes: string[]; names: string[]; pyTypes: string[]; types: string[] }
  • Parameters

    • info: ServiceSpec
    • pkt: PacketInfo
    • Optional options: { isStatic?: boolean; useBooleans?: boolean; useJDOM?: boolean }
      • Optional isStatic?: boolean
      • Optional useBooleans?: boolean
      • Optional useJDOM?: boolean

    Returns { buffers: string; csTypes: string[]; names: string[]; pyTypes: string[]; types: string[] }

    • buffers: string
    • csTypes: string[]
    • names: string[]
    • pyTypes: string[]
    • types: string[]
  • parseDualDeviceId(id: string): Uint8Array
  • parseServiceSpecificationMarkdownToJSON(filecontent: string, includes?: SMap<ServiceSpec>, filename?: string): jdspec.ServiceSpec
  • Parameters

    • filecontent: string
    • Optional includes: SMap<ServiceSpec>
    • filename: string = ""

    Returns jdspec.ServiceSpec

  • randomBytes(n: number): Uint8Array
  • randomDeviceId(): string
  • randomUInt(max: number): number
  • resolveUnit(unit: string): { name: string; offset: number; scale: number; unit: undefined } | { name: string; offset: number; scale: number; unit: string }
  • Parameters

    • unit: string

    Returns { name: string; offset: number; scale: number; unit: undefined } | { name: string; offset: number; scale: number; unit: string }

  • sensorSpecifications(): ServiceSpec[]
  • sevenSegmentDigitEncode(value: number, digitCount: number): Uint8Array
  • snakify(name: string): string
  • Parameters

    • name: string

    Returns string

  • snapshotSensors(bus: JDBus, sparse?: boolean): Record<string, number[] | Record<string, number>[]>
  • Collects and flattens all sensor data into a serializable object

    Parameters

    • bus: JDBus
    • Optional sparse: boolean

    Returns Record<string, number[] | Record<string, number>[]>

  • startDevTools(): void
  • units(): { description: string; name: string }[]
  • Returns { description: string; name: string }[]

  • watchLocation(server: SatNavServer, options?: PositionOptions): (() => void)

Roles

  • startRoles<TRoles>(bus: JDBus, bindings: TRoles, onUpdate: ((roles: Record<keyof TRoles, JDService>) => void), options?: { incomplete?: boolean }): (() => void)
  • Tracks a set of roles

    Type Parameters

    • TRoles extends Record<string, { preferredDeviceId?: string; preferredServiceIndex?: number; serviceClass: number }>

    Parameters

    • bus: JDBus

      bus hosting the devices

    • bindings: TRoles

      map of role names to device service pairs

    • onUpdate: ((roles: Record<keyof TRoles, JDService>) => void)

      callback to run whenver role assignments change

        • (roles: Record<keyof TRoles, JDService>): void
        • Parameters

          Returns void

    • Optional options: { incomplete?: boolean }

      Additional options

      • Optional incomplete?: boolean

        Calls update even if not all role around bound

    Returns (() => void)

    A unsubscribe callback to cleanup handlers

      • (): void
      • Subscribes to an event and returns the unsubscription handler

        category

        JDOM

        Returns void

Runtime

  • errorCode(e: Error): string
  • Extract the Jacdac error code if any

    Parameters

    • e: Error

    Returns string

Specification

  • addCustomServiceSpecification(service: ServiceSpec): void
  • Adds a custom service specification

    Parameters

    • service: ServiceSpec

    Returns void

  • clearCustomServiceSpecifications(): void
  • isActuator(spec: ServiceSpec): boolean
  • Indicates if the specified service is an actuator

    Parameters

    • spec: ServiceSpec

    Returns boolean

  • isCommand(pkt: PacketInfo): boolean
  • Indicates if the packet info represents a command

    Parameters

    • pkt: PacketInfo

    Returns boolean

  • isConstRegister(pkt: PacketInfo): boolean
  • Indicates if the packet info represents an const register

    Parameters

    • pkt: PacketInfo

    Returns boolean

  • isEvent(pkt: PacketInfo): boolean
  • Indicates if the packet info represents an event

    Parameters

    • pkt: PacketInfo

    Returns boolean

  • isHighLevelEvent(pkt: PacketInfo): boolean
  • Indicates if the event is usable from a high-level programming environment.

    Parameters

    • pkt: PacketInfo

    Returns boolean

  • isHighLevelRegister(pkt: PacketInfo): boolean
  • Indicates if the register is usable from a high-level programming environment.

    Parameters

    • pkt: PacketInfo

    Returns boolean

  • isInfrastructure(spec: ServiceSpec): boolean
  • Checks if the service supports the Jacdac infrastructure

    Parameters

    • spec: ServiceSpec

    Returns boolean

  • isInstanceOf(classIdentifier: number, requiredClassIdentifier: number): boolean
  • Checks if classIdentifier is compatible with requiredClassIdentifier

    Parameters

    • classIdentifier: number
    • requiredClassIdentifier: number

    Returns boolean

  • isIntensity(pkt: PacketInfo): boolean
  • Indicates if the packet info represents an intensity register

    Parameters

    • pkt: PacketInfo

    Returns boolean

  • isOptionalReadingRegisterCode(code: number): boolean
  • Indicate if the register code is an auxilliary register to support streaming.

    Parameters

    • code: number

    Returns boolean

  • isPipeReport(pkt: PacketInfo): boolean
  • Indicates if the packet info represents a pipe_report

    Parameters

    • pkt: PacketInfo

    Returns boolean

  • isPipeReportOf(cmd: PacketInfo, pipeReport: PacketInfo): boolean
  • Indicates if the report packet is the pipe report specication of the cmd command.

    Parameters

    • cmd: PacketInfo
    • pipeReport: PacketInfo

    Returns boolean

  • isReading(pkt: PacketInfo): boolean
  • Indicates if the packet information is a reading register

    Parameters

    • pkt: PacketInfo

    Returns boolean

  • isRegister(pkt: PacketInfo): boolean
  • Indicates if the packet information is a register

    Parameters

    • pkt: PacketInfo

    Returns boolean

  • isReportOf(cmd: PacketInfo, report: PacketInfo): boolean
  • Indicates if the report packet is the report specication of the cmd command.

    Parameters

    • cmd: PacketInfo
    • report: PacketInfo

    Returns boolean

  • isSensor(spec: ServiceSpec): boolean
  • Indicates if the specified service is a sensor

    Parameters

    • spec: ServiceSpec

    Returns boolean

  • isValue(pkt: PacketInfo): boolean
  • Indicates if the packet info represents a value register

    Parameters

    • pkt: PacketInfo

    Returns boolean

  • isValueOrIntensity(pkt: PacketInfo): boolean
  • Indicates if the packet info represents a intensity or a value register

    Parameters

    • pkt: PacketInfo

    Returns boolean

  • loadServiceSpecifications(specs: ServiceSpec[]): void
  • Override built-in service specifications

    Parameters

    • specs: ServiceSpec[]

    Returns void

  • parseDeviceId(id: string): Uint8Array
  • Parses a device identifier into a buffer, returns undefined if invalid

    Parameters

    • id: string

    Returns Uint8Array

  • serviceMap(): Record<string, jdspec.ServiceSpec>
  • Returns a map from service short ids to service specifications

    Returns Record<string, jdspec.ServiceSpec>

  • serviceSpecificationFromClassIdentifier(classIdentifier: number): jdspec.ServiceSpec
  • Looks up a service specification by class

    Parameters

    • classIdentifier: number

    Returns jdspec.ServiceSpec

  • serviceSpecificationFromName(shortId: string): jdspec.ServiceSpec
  • Looks up a service specification by name

    Parameters

    • shortId: string

    Returns jdspec.ServiceSpec

  • serviceSpecifications(): ServiceSpec[]
  • Returns the list of service specifications

    Returns ServiceSpec[]

Generated using TypeDoc