|
| 1 | +declare module "embedded:io/bluetoothle/peripheral" { |
| 2 | + import type { Buffer } from "embedded:io/_common"; |
| 3 | + import type { GATTSecurityOptions, GATTSecurityState } from "embedded:io/bluetoothle/_common"; |
| 4 | + |
| 5 | + interface GATTServerOptions { |
| 6 | + mtu?: number; |
| 7 | + services: GATTServerService[]; |
| 8 | + security?: GATTSecurityOptions; |
| 9 | + onReady?(this: GATTServer): void; |
| 10 | + onConnect?(this: GATTServer, connection: GATTServerConnection): void; |
| 11 | + onDisconnect?(this: GATTServer, connection: GATTServerConnection): void; |
| 12 | + onPasskey?(this: GATTServer, connection: GATTServerConnection, action: "input" | "display" | "compareNumber" | "outOfBand", data?: number | ArrayBuffer): void; |
| 13 | + onSecured?(this: GATTServer, connection: GATTServerConnection, state: GATTSecurityState): void; |
| 14 | + onWarning?(this: GATTServer, message: string): void; |
| 15 | + } |
| 16 | + |
| 17 | + interface GATTServerConnection { |
| 18 | + close(): void; |
| 19 | + notify(characteristic: GATTServerCharacteristic, value: ArrayBuffer, callback?: (error?: Error) => void): void; |
| 20 | + replyToPasskey(action: "input" | "compareNumber" | "outOfBand", value: number | boolean | ArrayBuffer): void; |
| 21 | + get maxinumWrite(): number; |
| 22 | + } |
| 23 | + |
| 24 | + interface GATTServerService { |
| 25 | + uuid: string; |
| 26 | + characteristics?: GATTServerCharacteristic[]; |
| 27 | + } |
| 28 | + |
| 29 | + interface GATTServerCharacteristic { |
| 30 | + uuid: string; |
| 31 | + properties?: number; |
| 32 | + value?: Buffer; |
| 33 | + descriptors?: GATTServerDescriptor[]; |
| 34 | + |
| 35 | + onRead?(this: GATTServerCharacteristic, connection: GATTServerConnection): Buffer; |
| 36 | + onWrite?(this: GATTServerCharacteristic, value: ArrayBuffer, connection: GATTServerConnection): void; |
| 37 | + onSubscribe?(this: GATTServerCharacteristic, connection: GATTServerConnection): void; |
| 38 | + onUnsubscribe?(cthis: GATTServerCharacteristic, onnection: GATTServerConnection): void; |
| 39 | + } |
| 40 | + |
| 41 | + interface GATTServerDescriptor { |
| 42 | + uuid: string; |
| 43 | + value?: Buffer; |
| 44 | + |
| 45 | + onRead?(connection: GATTServerConnection): Buffer; |
| 46 | + onWrite?(value: ArrayBuffer, connection: GATTServerConnection): void; |
| 47 | + } |
| 48 | + |
| 49 | + interface GATTServerAdvertisingRecords { |
| 50 | + name?: string; |
| 51 | + services?: string[]; |
| 52 | + manufacturerData?: { manufacturer: number, data: Buffer }; |
| 53 | + flags?: number; |
| 54 | + [ADType: number]: Buffer; |
| 55 | + } |
| 56 | + |
| 57 | + class GATTServer { |
| 58 | + constructor(options: GATTServerOptions); |
| 59 | + |
| 60 | + close?(): void; |
| 61 | + addService(service: GATTServerService): void; |
| 62 | + deleteService(service: GATTServerService): void; |
| 63 | + startAdvertising(scan: GATTServerAdvertisingRecords, response?: GATTServerAdvertisingRecords): void; |
| 64 | + stopAdvertising(): void; |
| 65 | + |
| 66 | + static readonly properties: { |
| 67 | + authenticatedSignedWrites: 64; |
| 68 | + broadcast: 1; |
| 69 | + indicate: 32; |
| 70 | + notify: 16; |
| 71 | + read: 2; |
| 72 | + readAuthenticated: 1026; |
| 73 | + readEncrypted: 514; |
| 74 | + reliableWrite: 128; |
| 75 | + subscribeAuthenticated: 65552; |
| 76 | + subscribeEncrypted: 32784; |
| 77 | + write: 8; |
| 78 | + writeAuthenticated: 8200; |
| 79 | + writeEncrypted: 4104; |
| 80 | + writeWithOutResponse: 4; |
| 81 | + }; |
| 82 | + static readonly advertise: { |
| 83 | + limitedDiscoverable: 1; |
| 84 | + generalDiscoverable: 2; |
| 85 | + bleOnly: 4; |
| 86 | + dualModeController: 8; |
| 87 | + dualModeHost: 16; |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + export { GATTServer }; |
| 92 | +} |
0 commit comments