Skip to content

Commit

Permalink
Remove Unneeded logging features
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorRigby committed Dec 20, 2024
1 parent 889ecd8 commit 6a99a28
Show file tree
Hide file tree
Showing 12 changed files with 2 additions and 2,186 deletions.
31 changes: 0 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,37 +68,6 @@ and
[BlueHeronTransportUSB](https://github.com/blue-heron/blue_heron_transport_usb)
for examples.

## HCI Logging

This project includes a Logger backend to dump PKTLOG format. This is the same format
that Android, IOS, btstack, hcidump, and bluez use.

Add the backend to debug all data to/from the HCI transport:

```elixir
iex> Logger.add_backend(BlueHeron.HCIDump.Logger)
BlueHeron.HCIDump.Logger
```

This will produce a file `/tmp/hcidump.pklg` that can be loaded into Wireshark.

**NOTE** This project configures logger so it is always enabled by default.
However, this can be disabled by setting `config :blue_heron, log_hci_dump_file:
false`

The `BlueHeron.HCIDump.Logger` module implements a superset of Elixir's builtin logger and
all non-HCI data is forwarded directly to Elixir's Logger.

```elixir
iex> require BlueHeron.HCIDump.Logger, as: Logger
BlueHeron.HCIDump.Logger
iex> Logger.debug("sample data")

16:43:46.496 [debug] sample data

iex>
```

## Helpful docs

* [Bluetooth Core Specification v5.2](https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=478726)
Expand Down
12 changes: 2 additions & 10 deletions lib/blue_heron/hci/transport.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ defmodule BlueHeron.HCI.Transport do
a physical link that implements the callbacks in this module
"""

require Logger

alias BlueHeron.HCI.Command.{
ControllerAndBaseband,
InformationalParameters,
Expand Down Expand Up @@ -59,8 +61,6 @@ defmodule BlueHeron.HCI.Transport do
handlers: [],
max_error_count: @default_max_error_count

require BlueHeron.HCIDump.Logger, as: Logger

@type config :: map()
@type recv_fun :: (binary -> any())
@callback start_link(config, recv_fun) :: GenServer.on_start()
Expand Down Expand Up @@ -155,8 +155,6 @@ defmodule BlueHeron.HCI.Transport do
end

def prepare(:info, {:transport_data, <<0x4, hci::binary>>}, data) do
Logger.hci_packet(:HCI_EVENT_PACKET, :in, hci)

case handle_hci_packet(hci, data) do
{:ok, %CommandComplete{}, data} ->
actions = [{:next_event, :internal, :init}]
Expand Down Expand Up @@ -193,7 +191,6 @@ defmodule BlueHeron.HCI.Transport do

case module.send_command(pid, command) do
true ->
Logger.hci_packet(:HCI_COMMAND_DATA_PACKET, :out, command)
prepare(:internal, :init, %{data | init_commands: rest})

false ->
Expand All @@ -217,7 +214,6 @@ defmodule BlueHeron.HCI.Transport do

case module.send_command(pid, bin) do
true ->
Logger.hci_packet(:HCI_COMMAND_DATA_PACKET, :out, bin)
{:keep_state, add_call(data, {from, opcode})}

false ->
Expand All @@ -243,7 +239,6 @@ defmodule BlueHeron.HCI.Transport do

case module.send_acl(pid, acl) do
true ->
Logger.hci_packet(:HCI_ACL_DATA_PACKET, :out, acl)
{:keep_state, data, [{:reply, from, :ok}]}

false ->
Expand All @@ -261,8 +256,6 @@ defmodule BlueHeron.HCI.Transport do
end

def ready(:info, {:transport_data, <<0x4, hci::binary>>}, data) do
Logger.hci_packet(:HCI_EVENT_PACKET, :in, hci)

case handle_hci_packet(hci, data) do
{:ok, %CommandComplete{} = reply, data} ->
{actions, data} = maybe_reply(data, reply)
Expand Down Expand Up @@ -290,7 +283,6 @@ defmodule BlueHeron.HCI.Transport do
end

def ready(:info, {:transport_data, <<0x2, acl::binary>>}, data) do
Logger.hci_packet(:HCI_ACL_DATA_PACKET, :in, acl)
acl = BlueHeron.ACL.deserialize(acl)
for pid <- data.handlers, do: send(pid, {:HCI_ACL_DATA_PACKET, acl})
:keep_state_and_data
Expand Down
58 changes: 0 additions & 58 deletions lib/blue_heron/hci_dump.ex

This file was deleted.

229 changes: 0 additions & 229 deletions lib/blue_heron/hci_dump/logger.ex

This file was deleted.

Loading

0 comments on commit 6a99a28

Please sign in to comment.