Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
danielspofford committed Jun 7, 2019
1 parent 18fb449 commit 7d16e5a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
5 changes: 4 additions & 1 deletion dialyzer_ignore.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[
~r/test\/support\/generators.*return/
~r/test\/support\/generators.*return/,
{"lib/harald/hci/controller_and_baseband.ex:24:contract_supertype Type specification for read_local_name is a supertype of the success typing."},
{"lib/harald/hci/le_controller.ex:39:contract_supertype Type specification for set_enable_scan is a supertype of the success typing."},
{"lib/harald/hci/le_controller.ex:75:contract_supertype Type specification for set_scan_parameters is a supertype of the success typing."}
]
22 changes: 4 additions & 18 deletions lib/harald/chip/ti/bts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,30 @@ defmodule Harald.Chip.TI.BTS do
>>,
actions
) do
debug(:send, data)
reduce_actions(rest, [data | actions])
end

defp reduce_actions(
<<
@action_wait_event::little-size(16),
size::little-size(16),
data::binary-size(size),
_data::binary-size(size),
rest::binary
>>,
actions
) do
debug(:wait, data)
reduce_actions(rest, actions)
end

defp reduce_actions(
<<
@action_serial::little-size(16),
size::little-size(16),
data::binary-size(size),
_data::binary-size(size),
rest::binary
>>,
actions
) do
debug(:serial, data)
reduce_actions(rest, actions)
end

Expand All @@ -87,41 +84,30 @@ defmodule Harald.Chip.TI.BTS do
>>,
actions
) do
debug(:delay, data)
reduce_actions(rest, [data | actions])
end

defp reduce_actions(
<<
@action_run_script::little-size(16),
size::little-size(16),
data::binary-size(size),
_data::binary-size(size),
rest::binary
>>,
actions
) do
debug(:run_script, data)
reduce_actions(rest, actions)
end

defp reduce_actions(
<<
@action_remarks::little-size(16),
size::little-size(16),
data::binary-size(size),
_data::binary-size(size),
rest::binary
>>,
actions
) do
debug(:remarks, data)
reduce_actions(rest, actions)
end

defp debug(:remarks, bin) do
:ok = Logger.debug("remarks " <> String.replace(bin, <<0>>, <<>>))
end

defp debug(label, bin) do
:ok = Logger.debug(String.pad_trailing("#{label}", 10, " ") <> inspect(bin))
end
end
9 changes: 6 additions & 3 deletions lib/harald/transport.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ defmodule Harald.Transport do
alias Harald.HCI

@type adapter_state :: map

@type event :: struct() | binary()
@type namespace :: atom
@type handler_msg :: {:bluetooth_event, event()}

defmodule State do
@moduledoc false
Expand Down Expand Up @@ -84,6 +85,8 @@ defmodule Harald.Transport do

@doc """
Adds `pid` to the `namespace` transport's handlers.
`pid` will receive messages like `t:handler_msg/0`.
"""
def add_handler(namespace, pid) do
namespace
Expand Down Expand Up @@ -116,6 +119,8 @@ defmodule Harald.Transport do
{:reply, :ok, %State{state | handlers: [pid | state.handlers]}}
end

defp name(namespace), do: String.to_atom("#{namespace}.#{__MODULE__}")

defp notify_handlers({:ok, events}, handlers) when is_list(events) do
for e <- events do
for h <- handlers do
Expand All @@ -124,8 +129,6 @@ defmodule Harald.Transport do
end
end

defp name(namespace), do: String.to_atom("#{namespace}.#{__MODULE__}")

defp notify_handlers({:ok, event}, handlers), do: notify_handlers({:ok, [event]}, handlers)

defp notify_handlers({:error, _} = error, handlers) do
Expand Down

0 comments on commit 7d16e5a

Please sign in to comment.