diff --git a/lib/harald.ex b/lib/harald.ex index a977b24..1f7ba2f 100644 --- a/lib/harald.ex +++ b/lib/harald.ex @@ -1,5 +1,5 @@ defmodule Harald do @moduledoc """ - Elixir library for working directly with Bluetooth via the HCI. + Facade for executing high level Bluetooth functionality. """ end diff --git a/lib/harald/hci/controller_and_baseband.ex b/lib/harald/hci/controller_and_baseband.ex index 99280df..aab61f5 100644 --- a/lib/harald/hci/controller_and_baseband.ex +++ b/lib/harald/hci/controller_and_baseband.ex @@ -1,6 +1,4 @@ defmodule Harald.HCI.ControllerAndBaseband do - alias Harald.HCI - @moduledoc """ HCI commands for working with the controller and baseband. @@ -12,6 +10,8 @@ defmodule Harald.HCI.ControllerAndBaseband do Bluetooth Spec v5 """ + alias Harald.HCI + @ogf 0x03 @doc """ diff --git a/lib/harald/le.ex b/lib/harald/le.ex index feba3ae..d03170c 100644 --- a/lib/harald/le.ex +++ b/lib/harald/le.ex @@ -5,7 +5,7 @@ defmodule Harald.LE do use GenServer alias Harald.HCI.Event.{LEMeta, LEMeta.AdvertisingReport} - alias Harald.HCI.LEController + alias Harald.HCI.{ControllerAndBaseband, LEController} alias Harald.Transport alias Harald.Transport.Handler require Logger @@ -14,7 +14,18 @@ defmodule Harald.LE do defmodule State do @moduledoc false - defstruct devices: %{} + defstruct from: nil, devices: %{} + end + + @doc """ + HCI_Read_Local_Name + + - `OGF` - `0x03` + - `OCF` - `0x0014` + """ + @spec read_local_name(atom()) :: {:ok, String.t()} + def read_local_name(namespace) do + GenServer.call(name(namespace), {:read_local_name, namespace}) end def scan(namespace, opts \\ []) do @@ -46,6 +57,15 @@ defmodule Harald.LE do end end + def handle_call({:read_local_name, ns}, from, state) do + try do + :ok = Transport.call(ns, ControllerAndBaseband.read_local_name()) + {:noreply, %{state | from: from}} + catch + :exit, {:timeout, _} -> {:reply, {:error, :timeout}, state} + end + end + @impl GenServer def handle_info( {:bluetooth_event, %LEMeta{subevent: %AdvertisingReport{devices: devices}}}, @@ -60,7 +80,9 @@ defmodule Harald.LE do end # Let other bluetooth events fall through. - def handle_info({:bluetooth_event, _}, state) do + def handle_info({:bluetooth_event, event}, state) do + require Logger + Logger.warn(event) {:noreply, state} end