import { JDFrameBuffer, Packet } from "./packet"; import { JDDevice } from "./device"; import { JDNode } from "./node"; import { FirmwareBlob } from "./flashing"; import { JDService } from "./service"; import { LoggerPriority } from "../../src/jdom/constants"; import { JDServiceProvider } from "./servers/serviceprovider"; import { Transport } from "./transport/transport"; import { BusStatsMonitor } from "./busstats"; import { RoleManagerClient } from "./clients/rolemanagerclient"; import { JDBridge } from "./bridge"; import { Scheduler } from "./scheduler"; import { ServiceFilter } from "./filters/servicefilter"; import { DeviceFilter } from "./filters/devicefilter"; import { DeviceCatalog } from "./catalog"; export type BusBroadcastMessageType = "visibilitychange" | "disconnect" | "connectionstate"; export interface BusBroadcastMessage { id: string; event: BusBroadcastMessageType; } export interface BusBroadcastVisibilityChangeMessage extends BusBroadcastMessage { event: "visibilitychange"; visibilityState?: "hidden" | "visible"; transports: { type: string; connectionState: string; }[]; } export interface BusBroadcastConnectionStateMessage extends BusBroadcastMessage { event: "connectionstate"; transports: { type: string; connectionState: string; }[]; } export declare const enum BusInteractionMode { /** * The bus mounts a self device and actively interacts with devices, including polling registers * automatically */ Active = 0, /** * The bus mounts a self device and does not poll registers automatically */ Observer = 1, /** * The bus does not emit any package */ Passive = 2 } /** * Creation options for a bus * @category JDOM */ export interface BusOptions { /** * The self-device device id */ deviceId?: string; /** * A custom scheduler to control time */ scheduler?: Scheduler; /** * Parent domain origin to handle iframe messages. Defaults to "*". */ parentOrigin?: string; /** * enable bus acting as a client */ client?: boolean; /** * Ignore role managers detected on the bus */ disableRoleManager?: boolean; /** * This bus is a dashboard */ dashboard?: boolean; /** * This bus is a proxy */ proxy?: boolean; /** * Stable identifier used to generate unique simulator identifier accross multiple hosted bus environment */ serviceProviderIdSalt?: string; /** * Broadcast reset packet */ resetIn?: boolean; /** * Additional serial connection vendor ids */ serialVendorIds?: number[]; /** * Custom services */ services?: jdspec.ServiceSpec[]; } /** * A Jacdac bus manager. This instance maintains the list of devices on the bus. * @category JDOM */ export declare class JDBus extends JDNode { /** * @internal */ readonly selfDeviceId: string; /** * A timer and interval schedular to orchestrate bus timestamps * @category Scheduling */ readonly scheduler: Scheduler; /** * @internal */ readonly parentOrigin: string; /** * @internal */ readonly serviceProviderIdSalt: string; private readonly _transports; private _bridges; private _devices; private _gcInterval; private _announceInterval; private _safeBootInterval; private _refreshRegistersInterval; private _lastPingLoggerTime; private _lastResetInTime; private _restartCounter; private _roleManager; private _minLoggerPriority; private _firmwareBlobs; private _gcDevicesFrozen; private _serviceProviders; private _unsubscribeBroadcastChannel; private _postBroadcastMessage; private _streaming; private _interactionMode; private _autoConnect; private _resetIn; private _client; private _dashboard; private _proxy; /** * the device catalog * @category JDOM */ readonly deviceCatalog: DeviceCatalog; /** * Gets an instance that tracks packet statistics * @category Diagnostics **/ readonly stats: BusStatsMonitor; /** * Creates the bus with the given transport * @param sendPacket * @category Lifecycle */ constructor(transports?: (Transport | undefined)[], options?: BusOptions); private configureBroadcastChannel; /** * Broadcast a request to disconnect to all other javadac buses. */ broadcastDisconnectRequest(): void; /** * Indicates that this bus acts as a client device * @category Lifecycle */ get client(): boolean; /** * Sets the client state * @category Lifecycle */ set client(value: boolean); /** * Indicates if the bus is a dashboard * @category Lifecycle */ get dashboard(): boolean; /** * Gets the list of transports registers with the bus * @category Transports and Bridges */ get transports(): Transport[]; /** * Adds a transport to the bus. Returns unregistration handler * @category Transports and Bridges */ addTransport(transport: Transport | undefined): () => Promise; /** * Automatically try to connect to detected devices */ get autoConnect(): boolean; /** * Sets the auto-connected mode */ set autoConnect(value: boolean); /** * Gets the list of bridges registered with the bus * @category Transports and Bridges */ get bridges(): JDBridge[]; /** * Add a bridge to the bus and returns a callback to remove it. * @param bridge * @returns callback to remove bridge * @category Transports and Bridges * @internal */ addBridge(bridge: JDBridge): () => void; private removeBridge; /** * Do not send any packet on the bus * @category Lifecycle */ get passive(): boolean; /** * Sets the passive state. A passive bus does not send any packets. * @category Lifecycle * @deprecated */ set passive(value: boolean); /** * Determines how the bus interacts with services, including automatic polling of registers */ get interactionMode(): BusInteractionMode; /** * Sets how the bus interacts with services, including automatic polling of registers */ set interactionMode(mode: BusInteractionMode); /** * Indicates if reset in broadcast packets should be sent */ get resetIn(): boolean; /** * Turns on or off reset in broadcast packets */ set resetIn(value: boolean); private preConnect; /** * Connects the bus going through the transports chronologically. Does nothing if already connected. * @param background connection was triggered automatically * @category Lifecycle */ connect(background?: boolean): Promise; /** * Disconnects the bus and any connected transport. * @category Lifecycle */ disconnect(): Promise; /** * Starts to process packets and updates the JDOM nodes * @category Lifecycle */ start(): void; /** * Indicates if the bus is announcing and managing packets */ get running(): boolean; /** * Stops processing packets * @category Lifecycle */ stop(): Promise; /** * Stops the bus and all transport connections. * @category Lifecycle */ dispose(): Promise; /** * Indicates that the bus is sending commands keep devices in bootloader mode. * This property is signaled by CHANGE. * @category Lifecycle */ get safeBoot(): boolean; /** * Turn on or off the safe boot mode where the bus keeps devices in bootloader mode. * Triggers a CHANGE event. * @category Lifecycle */ set safeBoot(enabled: boolean); /** * Indicates if any of the transports is connected. * Some transports might be in the process of connecting or disconnecting. * @category Lifecycle */ get connected(): boolean; /** * Indicates if any of the transports is disconnected. * Some transports might be in the process of connecting or disconnecting. * @category Lifecycle */ get disconnected(): boolean; /** * Clears known devices and service providers (simulators). Optionally reset bus timestamp. * @param timestamp * @category Services */ clear(timestamp?: number): void; /** * Clears current device list and let's them repopulate */ private clearDevices; /** * Gets a unique identifier for this node in the Jacdac DOM. * @category JDOM */ get id(): string; /** * Gets the bus name * @category JDOM */ get name(): string; /** * Gets the bus name * @category JDOM */ get friendlyName(): string; /** * Gets the bus name * @category JDOM */ get qualifiedName(): string; /** * Returns the ``BUS_NODE_NAME`` * @category JDOM */ get nodeKind(): string; /** * Gets the default role manager service client, if any * @category Services */ get roleManager(): RoleManagerClient; /** * Specifies the current role manager */ setRoleManagerService(service: JDService): void; /** * @internal */ toString(): string; /** * Gets a detailled description of the devices and services connected to the bus * @returns * @internal */ describe(options?: DeviceFilter): string; /** * Resolves a JDOM node from an identifier * @param id node identifier * @returns node if found, undefined otherwise * @category JDOM */ node(id: string): JDNode; private resetTime; /** * Gets the current bus-relavite time in milliseconds * @category Scheduling */ get timestamp(): number; /** * Indicates if the bus should force all sensors to stream * @category Lifecycle */ get streaming(): boolean; /** * Sets automatic streaming on and off * @category Lifecycle */ set streaming(value: boolean); /** * Creates a promise that awaits for the given duration using the bus scheduler * @category Scheduling */ delay(millis: number, value?: T): Promise; /** * Gets the current desired minimum logger verbosity on the bus * @category Diagnostics */ get minLoggerPriority(): LoggerPriority; /** * Sets the current desired minimum logger verbosity on the bus * @category Diagnostics */ set minLoggerPriority(priority: LoggerPriority); /** * Returns undefined * @category JDOM */ get parent(): JDNode; private handleRealTimeClockSync; private handleRoleManager; sendFrameAsync(frame: JDFrameBuffer): Promise; /** * Sends a packet to the bus * @param packet packet to send * @internal */ sendPacketAsync(packet: Packet): Promise; /** * Gets the list of known firmware blobs * @category Firmware */ get firmwareBlobs(): FirmwareBlob[]; /** * Sets the list of known firmware blobs * @category Firmware */ set firmwareBlobs(blobs: FirmwareBlob[]); /** * Gets the current list of known devices on the bus * @category Services */ devices(options?: DeviceFilter): JDDevice[]; /** * Gets the current list of service providers on the bus * @category Services */ serviceProviders(): JDServiceProvider[]; /** * Get a service providers for a given device * @param deviceId * @category Services */ findServiceProvider(deviceId: string): JDServiceProvider; /** * Adds the service provider to the bus and returns the associated devoce * @param provider instance to add * @category Services */ addServiceProvider(provider: JDServiceProvider): JDDevice; /** * Removes the service provider from the bus * @param provider instance to remove * @category Services */ removeServiceProvider(provider: JDServiceProvider): void; /** * Removes all service providers from the bus * @category Services */ clearServiceProviders(): void; /** * Remove a device client by identifier * @param deviceId * @category Devices */ removeDevice(deviceId: string): void; /** * Gets the list of devices * @category JDOM */ get children(): JDNode[]; /** * Gets the current list of services from all the known devices on the bus * @category Services */ services(options?: ServiceFilter & DeviceFilter): JDService[]; /** * Gets a device on the bus * @param id device identifier to query * @param skipCreate do not create new device if missing * @param pkt packet that generated this device query * @category Services */ device(id: string, skipCreate?: boolean, pkt?: Packet): JDDevice | undefined; /** * Push a context to disable cleaning device that haven't issued packets recently. * @category Lifecycle */ pushDeviceFrozen(): void; /** * Pop a context to disable cleaning device that haven't issued packets recently. * @category Lifecycle */ popDeviceFrozen(): void; /** * Indicates if the device list if currently frozen. * @category Lifecycle */ get devicesFrozen(): boolean; private gcDevices; /** * Ingests and process a packet received from the bus. * @param pkt a jacdac packet * @internal */ private processPacket; processFrame(frame: JDFrameBuffer, sender: string, skipCrc?: boolean): void; private processLargeFrame; private processPacketCore; /** * Gets the current list of service specifications */ get serviceSpecifications(): jdspec.ServiceSpec[]; /** * Updates the current list of device and clears the bus * @param services */ setCustomServiceSpecifications(services: jdspec.ServiceSpec[]): { added: jdspec.ServiceSpec[]; errors: { message: string; spec: jdspec.ServiceSpec; }[]; changed: boolean; }; /** * Gets the virtual device created by this bus to handle pipes. * @category Services */ get selfDevice(): JDDevice; private handleSelfAnnounce; private sendAnnounce; get lastResetInTime(): number; private sendResetIn; sendStopStreaming(): Promise; private sendPingLoggers; /** * Indicates if registers are automatically refreshed in the background. * @category Services */ get backgroundRefreshRegisters(): boolean; /** * Enables or disables automatically refreshing registers in the background. * @param enabled true to automatically refresh registers * @category Services */ set backgroundRefreshRegisters(enabled: boolean); /** * Cycles through all known registers and refreshes the once that have REPORT_UPDATE registered */ private handleRefreshRegisters; /** * Runs a promise with a timeout. Returns undefined if timeout happens before of disconnection. * @param timeout duration to wait before declaring timeout * @param promise promise to wrap * @category Lifecycle */ withTimeout(timeout: number, promise: Promise): Promise; } //# sourceMappingURL=bus.d.ts.map