Skip to content

Commit

Permalink
Throwaway branch to test with BBBW
Browse files Browse the repository at this point in the history
  • Loading branch information
danielspofford committed Apr 16, 2019
1 parent 6d3206b commit 985ec2b
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/harald.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@ defmodule Harald do
@moduledoc """
Elixir library for working directly with Bluetooth via the HCI.
"""

def get_system_status(namespace) do
Harald.Transport.send_command(namespace, <<1, 0xFE1F::little-size(16), 0>>)
end

def read_bd_addr(namespace) do
Harald.Transport.send_command(namespace, <<1, 9, 16, 0>>)
end
end
2 changes: 1 addition & 1 deletion lib/harald/hci.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ defmodule Harald.HCI do

def command(opcode, opts) do
s = byte_size(opts)
opcode <> <<s::size(8)>> <> opts
<<1>> <> opcode <> <<s::size(8)>> <> opts
end

@doc """
Expand Down
2 changes: 1 addition & 1 deletion lib/harald/transport/uart.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Harald.Transport.UART do

@impl GenServer
def handle_call({:send_command, message}, _from, %{uart_pid: uart_pid} = state) do
{:reply, UART.write(uart_pid, <<1>> <> message), state}
{:reply, UART.write(uart_pid, message), state}
end

@impl GenServer
Expand Down
73 changes: 72 additions & 1 deletion lib/harald/transport/uart/framing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,78 @@ defmodule Harald.Transport.UART.Framing do
def frame_timeout(state), do: {:ok, [state], <<>>}

@impl Framing
def remove_framing(new_data, state), do: process_data(new_data, state)
def remove_framing(new_data, state) do
require Logger

case new_data do
# read bd addr
<<4, 14, 10, 1, 9, 16, status, bd_addr::binary>> ->
Logger.warn("ret read bd addr: #{inspect(%{status: status, bd_addr: bd_addr})}")

# vendor specific - get system status
<<
4,
14,
29,
1,
31,
254,
status,
software_version_x,
software_version_z,
chip_revision,
chip_mode,
fref::little-size(16),
slow_clock_used,
process_type_detected,
odp_process,
deep_sleep_mode,
whitening_mode,
cdc_mode,
self_test,
hopping_mode,
baud_rate::little-size(32),
temperature_index,
temperature_detected,
i2c_status,
fref_tcxo_clock::little-size(16),
reserved1,
reserved2
>> ->
Logger.warn(
"ret get system status: #{
inspect(%{
status: status,
software_version_x: software_version_x,
software_version_z: software_version_z,
chip_revision: chip_revision,
chip_mode: chip_mode,
fref: fref,
slow_clock_used: slow_clock_used,
process_type_detected: process_type_detected,
odp_process: odp_process,
deep_sleep_mode: deep_sleep_mode,
whitening_mode: whitening_mode,
cdc_mode: cdc_mode,
self_test: self_test,
hopping_mode: hopping_mode,
baud_rate: baud_rate,
temperature_index: temperature_index,
temperature_detected: temperature_detected,
i2c_status: i2c_status,
fref_tcxo_clock: fref_tcxo_clock,
reserved1: reserved1,
reserved2: reserved2
})
}"
)

_ ->
Logger.warn("ret: #{inspect(new_data)}")
end

process_data(new_data, state)
end

@doc """
Returns a tuple like `{remaining_desired_length, part_of_bin, rest_of_bin}`.
Expand Down

0 comments on commit 985ec2b

Please sign in to comment.