MatterEx.Transport.BLE.Adapter behaviour (matter_ex v0.4.0)

Copy Markdown View Source

Behaviour for BLE hardware adapters.

Separates the BTP + GenServer logic from hardware-specific BLE details. Implement this to plug in blue_heron, a raw HCI driver, or a test mock.

The adapter sends events to the owner process (the BLE GenServer):

{:ble_connected, connection_ref}
{:ble_data, connection_ref, binary}
{:ble_disconnected, connection_ref}

Summary

Callbacks

Send data to the connected peer via the TX characteristic indication.

Start the adapter. Returns an opaque handle for subsequent calls.

Begin BLE advertising with the CHIPoBLE service.

Disconnect and clean up.

Stop advertising.

Callbacks

send_data(handle, connection_ref, data)

@callback send_data(handle :: term(), connection_ref :: term(), data :: binary()) ::
  :ok | {:error, term()}

Send data to the connected peer via the TX characteristic indication.

connection_ref is the opaque reference from the {:ble_connected, ref} event.

start(opts)

@callback start(opts :: keyword()) :: {:ok, handle :: term()} | {:error, term()}

Start the adapter. Returns an opaque handle for subsequent calls.

opts contains at minimum:

  • :owner — pid to receive BLE events
  • :discriminator — 12-bit commissioning discriminator
  • :vendor_id — 16-bit vendor ID
  • :product_id — 16-bit product ID

start_advertising(handle, ad_data)

@callback start_advertising(handle :: term(), ad_data :: binary()) ::
  :ok | {:error, term()}

Begin BLE advertising with the CHIPoBLE service.

stop(handle)

@callback stop(handle :: term()) :: :ok

Disconnect and clean up.

stop_advertising(handle)

@callback stop_advertising(handle :: term()) :: :ok

Stop advertising.