Skip to content

Commit

Permalink
wip read local
Browse files Browse the repository at this point in the history
  • Loading branch information
danielspofford committed Jun 21, 2019
1 parent 7d16e5a commit f7f26fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/harald.ex
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions lib/harald/hci/controller_and_baseband.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
defmodule Harald.HCI.ControllerAndBaseband do
alias Harald.HCI

@moduledoc """
HCI commands for working with the controller and baseband.
Expand All @@ -12,6 +10,8 @@ defmodule Harald.HCI.ControllerAndBaseband do
Bluetooth Spec v5
"""

alias Harald.HCI

@ogf 0x03

@doc """
Expand Down
28 changes: 25 additions & 3 deletions lib/harald/le.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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}}},
Expand All @@ -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

Expand Down

0 comments on commit f7f26fe

Please sign in to comment.