{"version":3,"sources":["../src/profiles/nordic-uart.ts"],"names":["NUS_SERVICE","NUS_RX","NUS_TX","NUS_SERVICES","NordicUARTProfile","BaseProfile","callback","data"],"mappings":"qCAGA,IAAMA,EAAc,sCAAA,CAEdC,CAAAA,CAAS,uCAETC,CAAAA,CAAS,sCAAA,CAOFC,EAAkC,CAACH,CAAW,CAAA,CAwC9CI,CAAAA,CAAN,cAAgCC,CAAY,CAA5C,kCAIL,IAAA,CAAmB,OAAA,CAAUL,GAS7B,SAAA,CAAUM,CAAAA,CAAiD,CACzD,OAAO,KAAK,SAAA,CAAUJ,CAAAA,CAAQI,CAAQ,CACxC,CASA,MAAM,IAAA,CAAKC,CAAAA,CAAmC,CAI5C,MAAM,IAAA,CAAK,YAAYN,CAAAA,CAAQM,CAAI,EACrC,CACF,EA9BaH,EAEK,QAAA,CAAWD,CAAAA","file":"chunk-WKLBTKL5.mjs","sourcesContent":["import { BaseProfile } from './base';\n\n/** Nordic UART Service (NUS) UUID. */\nconst NUS_SERVICE = '6e400001-b5a3-f393-e0a9-e50e24dcca9e';\n/** RX characteristic: host -> device. Write (without response). */\nconst NUS_RX = '6e400002-b5a3-f393-e0a9-e50e24dcca9e';\n/** TX characteristic: device -> host. Notify. */\nconst NUS_TX = '6e400003-b5a3-f393-e0a9-e50e24dcca9e';\n\n/**\n * Service UUIDs a Nordic UART device may reach after connection (the single NUS\n * service). Use with `optionalServices` / `Beacio.registerServices`, or via\n * {@link deriveOptionalServices} given {@link NordicUARTProfile}.\n */\nexport const NUS_SERVICES: readonly string[] = [NUS_SERVICE];\n\n/**\n * Nordic UART Service (NUS) profile — a bidirectional serial-over-BLE pipe.\n *\n * The de-facto standard \"UART service\" exposed by Espruino devices\n * (Bangle.js, Puck.js, Pixl.js, MDBT42Q), the BBC micro:bit, and Adafruit\n * Bluefruit modules. Data flows over two characteristics on the NUS service\n * `6e400001-b5a3-f393-e0a9-e50e24dcca9e`:\n *\n * - **TX** `6e400003-…` — device -> host, delivered via notifications.\n *   Enabled through {@link BaseProfile.subscribe} (the native layer owns the\n *   CCCD descriptor; `startNotifications()` covers notify *and* indicate).\n * - **RX** `6e400002-…` — host -> device, sent with write-without-response and\n *   chunked to the negotiated MTU.\n *\n * Strictly W3C `navigator.bluetooth` GATT: this profile never reads or writes\n * a CCCD/SCCD descriptor itself.\n *\n * @example\n * ```ts\n * import { NordicUARTProfile, deriveOptionalServices } from '@beacio/core/profiles';\n *\n * // Declare the service from the profile — no hand-copied UUID:\n * // requestDevice({ filters: [{ namePrefix: 'Puck.js' }],\n * //   optionalServices: deriveOptionalServices(NordicUARTProfile) })\n * const uart = new NordicUARTProfile(device);\n * await uart.connect();\n *\n * const decoder = new TextDecoder();\n * const unsubscribe = uart.onReceive((chunk) => {\n *   process.stdout.write(decoder.decode(chunk));\n * });\n *\n * await uart.send(new TextEncoder().encode('LED1.set()\\n'));\n *\n * unsubscribe();\n * uart.stop();\n * ```\n */\nexport class NordicUARTProfile extends BaseProfile {\n  /** Services this profile's device may reach after connection (the NUS service). Read by {@link deriveOptionalServices}. */\n  static readonly services = NUS_SERVICES;\n\n  protected readonly service = NUS_SERVICE;\n\n  /**\n   * Subscribe to inbound data from the device (TX characteristic, notify).\n   * Each notification is delivered as a raw {@link DataView} chunk.\n   *\n   * @param callback - Invoked with every inbound chunk.\n   * @returns Unsubscribe function. Also cleaned up by {@link BaseProfile.stop}.\n   */\n  onReceive(callback: (chunk: DataView) => void): () => void {\n    return this.subscribe(NUS_TX, callback);\n  }\n\n  /**\n   * Send data to the device (RX characteristic, write-without-response).\n   * Payloads larger than the negotiated write-without-response limit are\n   * split into MTU-sized chunks and written sequentially.\n   *\n   * @param data - Bytes to send. Accepts any {@link BufferSource}.\n   */\n  async send(data: BufferSource): Promise<void> {\n    // Delegate fragmentation to the core write-chunker (via BaseProfile.sendChunked),\n    // which derives a branded, always-positive ChunkSize from the negotiated\n    // write-without-response limit / MTU. No hand-rolled offset loop here.\n    await this.sendChunked(NUS_RX, data);\n  }\n}\n"]}