import type { RestMessageOptions } from "../../types/communication-between-apps/wrapper-communication"; import { ConnectableRaftType, ConnectionAttemptResults, RaftConnectionMethod, RaftTypeE } from "../../types/raft"; import { RaftInfoEvents } from "../../types/events/raft-info"; import { FOUND_RAFT_ON_DISCOVERY_RESPONSE } from "../../types/phone-app-communicator"; import RICInterface from "./RAFTInterface"; import { RaftObserver } from "./RaftObserver"; import { RaftConnEvent, RaftUpdateEvent, RaftPublishEvent, RaftOKFail, RaftSystemInfo } from "@robdobsn/raftjs"; import { RICLedLcdColours, RICStateInfo } from "@robotical/roboticaljs"; import { SimplifiedCogStateInfo } from "@robotical/roboticaljs/dist/SystemTypeCog/CogTypes"; export default class RAFT implements RICInterface { id: string; type: RaftTypeE; _ledLcdColours: RICLedLcdColours; protected _observers: { [key: string]: Array; }; isSerialNoRegisteredInWarranty: boolean | null; systemInfo: RaftSystemInfo | null; raftStateInfo: RICStateInfo | SimplifiedCogStateInfo | null; isVerified: boolean; /** * Transport metadata belongs to the host RAFT entity so every embedded * platform sees the same connection, regardless of how it was established. */ connectionMethod: RaftConnectionMethod | null; connectionLocator: string; private _verificationDecision; hasVerifiedConnection(): boolean; /** * Method to get ledLcdColours, to be implemented in child classes. */ get ledLcdColours(): RICLedLcdColours; constructor(id: string); /** * Check if RAFT is connected * Sends a message to the Wrapper RICConnector and waits for a response */ getIsConnectedFresh(): Promise; /** * Connect to a RAFT * We first connect, then we discover the raft type, and then we create the appopriate raft instance */ static connect(method: RaftConnectionMethod, uuids: string[], locator?: string, expectedRaftType?: ConnectableRaftType): Promise; /** * Disconnect from a RAFT */ disconnect(): Promise; /** * Get RAFT name */ getRaftName(): Promise; /** * Verify correct RAFT is selected for phone app */ verifyRaftPhoneApp(discoveredDevice: FOUND_RAFT_ON_DISCOVERY_RESPONSE['foundRIC']): Promise; /** * Verify correct RAFT is selected */ verifyRaft(): Promise; /** * Stops the verification process */ stopVerifyingRaft(isCorrectRIC: boolean): Promise; /** * Receiveds events from the RICConnector */ receivedRICEvent(eventType: string, eventEnum: RaftConnEvent | RaftUpdateEvent | RaftPublishEvent | RaftInfoEvents, eventName: string, eventData: any): void; /** * Send a REST message to the RAFT */ sendRestMessage(msg: string, params?: object, options?: RestMessageOptions): Promise; /** * Highlights the raft */ highlight(): Promise; /** * Publishing events to observers * It could be either events we get from RAFT, or custom events related to the app */ publish(eventType: string, eventEnum: RaftConnEvent | RaftUpdateEvent | RaftPublishEvent | RaftInfoEvents, eventName: string, eventData: any): void; subscribe(observer: RaftObserver, topics: Array): void; unsubscribe(observer: RaftObserver): void; /** * Gets the RSSI of the RAFT */ getRSSI(): number; /** * Gets the battery strength of the RAFT */ getBatteryStrength(): number; /** * Gets the version of the RAFT */ getRaftVersion(): string; /** * Gets the Serial Number of the RAFT */ getSerialNumber(): string; /** * Gets the Friendly name of the RAFT */ getFriendlyName(): string | undefined; setRaftName(newName: string): Promise; /** * Stream audio to the RAFT */ streamAudio(streamContents: Uint8Array, clearExisting: boolean, duration: number): Promise; /** * Handles RAFT events * (to be implemented in child classes) */ handleRaftEvent(eventType: string, eventEnum: RaftConnEvent | RaftUpdateEvent | RaftPublishEvent | RaftInfoEvents, eventName: string, eventData: any): void; /** * Connection Event Handler */ _connectionEventHandler(eventEnum: RaftConnEvent, eventName: string, data: any): Promise; /** * Pub Event Handler */ _pubEventHandler(eventEnum: RaftPublishEvent, eventName: string, data: any): Promise; /** * Raft Info Event Handler */ _raftInfoEventHandler(eventEnum: RaftInfoEvents, eventName: string, data: any): Promise; }