Skip to content

Commit

Permalink
Fix tests and mix format
Browse files Browse the repository at this point in the history
Signed-off-by: Connor Rigby <[email protected]>
  • Loading branch information
ConnorRigby committed Sep 21, 2023
1 parent 464eae6 commit 0974e13
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 131 deletions.
5 changes: 4 additions & 1 deletion lib/blue_heron/acl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ defmodule BlueHeron.ACL do

defstruct [:handle, :flags, :data]

def deserialize(<<handle::little-12, pb::2, bc::2, length::little-16,acl_data::binary-size(length)>>) do
def deserialize(
<<handle::little-12, pb::2, bc::2, length::little-16, acl_data::binary-size(length)>>
) do
data = BlueHeron.L2Cap.deserialize(acl_data)

%ACL{
handle: handle,
flags: %{pb: pb, bc: bc},
Expand Down
2 changes: 1 addition & 1 deletion lib/blue_heron/acl_buffer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ defmodule BlueHeron.ACLBuffer do
{:noreply, state}
end

def handle_info({:HCI_EVENT_PACKET, %NumberOfCompletedPackets{} = event}, state) do
def handle_info({:HCI_EVENT_PACKET, %NumberOfCompletedPackets{} = _event}, state) do
send(self(), :out)
{:noreply, state}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/blue_heron/address.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ defmodule BlueHeron.Address do
end

defp format_iodata(iodata) do
to_string(:io_lib.format('~2.16.0B:~2.16.0B:~2.16.0B:~2.16.0B:~2.16.0B:~2.16.0B', iodata))
to_string(:io_lib.format(~c"~2.16.0B:~2.16.0B:~2.16.0B:~2.16.0B:~2.16.0B:~2.16.0B", iodata))
end
end
4 changes: 2 additions & 2 deletions lib/blue_heron/att/responses/read_by_type_response.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ defmodule BlueHeron.ATT.ReadByTypeResponse do
when uuid > 0xFFFF do
<<handle::little-16, characteristic_properties, characteristic_value_handle::little-16,
uuid::little-128>>
end
end

def serialize(%{
handle: handle,
Expand All @@ -51,7 +51,7 @@ defmodule BlueHeron.ATT.ReadByTypeResponse do
uuid: _uuid,
value: value
}) do
<<handle::little-16, value::binary>>
<<handle::little-16, value::binary>>
end
end

Expand Down
5 changes: 4 additions & 1 deletion lib/blue_heron/gatt/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,14 @@ defmodule BlueHeron.GATT.Server do
[characteristic] ->
# TODO: Handle exceptions and long values
value = state.mod.read(characteristic.id)

attr =
%ReadByTypeResponse.AttributeData{
handle: characteristic.handle,
uuid: characteristic.type,
value: value
value: value,
characteristic_properties: characteristic.properties,
characteristic_value_handle: characteristic.value_handle
}

{state, %ReadByTypeResponse{attribute_data: [attr]}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule BlueHeron.HCI.Command.ControllerAndBaseband.SetControllerToHostFlowControl do
use BlueHeron.HCI.Command.ControllerAndBaseband, ocf: 0x0031

defparameters [flow_control_enable: 0]
defparameters flow_control_enable: 0

defimpl BlueHeron.HCI.Serializable do
def serialize(%{opcode: opcode, flow_control_enable: flow_control_enable}) do
Expand Down
2 changes: 1 addition & 1 deletion lib/blue_heron/hci/commands/link_control/disconnect.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule BlueHeron.HCI.Command.LinkControl.Disconnect do
use BlueHeron.HCI.Command.LinkControl, ocf: 0x0006

defparameters [reason: 0x16, connection_handle: 0]
defparameters reason: 0x16, connection_handle: 0

defimpl BlueHeron.HCI.Serializable do
def serialize(%{opcode: opcode, connection_handle: handle, reason: reason}) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ defmodule BlueHeron.HCI.Event.LEMeta.ConnectionUpdateComplete do
:status
]

defimpl BlueHeron.HCI.Serializable do
def serialize(cc) do
raise(RuntimeError, "fixme")
end
end

@impl BlueHeron.HCI.Event
def deserialize(<<@code, _size, @subevent_code, bin::binary>>) do
<<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule BlueHeron.HCI.Event.LEMeta.EnhancedConnectionCompleteV1 do
:connection_interval,
:peripheral_latency,
:supervision_timeout,
:central_clock_accuracy,
:central_clock_accuracy
]

defimpl BlueHeron.HCI.Serializable do
Expand Down Expand Up @@ -72,7 +72,7 @@ defmodule BlueHeron.HCI.Event.LEMeta.EnhancedConnectionCompleteV1 do
supervision_timeout: supervision_timeout,
central_clock_accuracy: central_clock_accuracy,
local_resolvable_private_address: local_resolvable_private_address,
peer_resolvable_private_address: peer_resolvable_private_address,
peer_resolvable_private_address: peer_resolvable_private_address
}
end

Expand Down
4 changes: 2 additions & 2 deletions lib/blue_heron/hci/transport.ex
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ defmodule BlueHeron.HCI.Transport do
:keep_state_and_data
end

def ready(:info, {:transport_data, <<0x01, unknown::binary>>}, data) do
def ready(:info, {:transport_data, <<0x01, unknown::binary>>}, _data) do
Logger.warning(%{unexpected_data: inspect(unknown, base: :hex)})
:keep_state_and_data
end
Expand Down Expand Up @@ -326,7 +326,7 @@ defmodule BlueHeron.HCI.Transport do
for pid <- data.handlers, do: send(pid, {:HCI_EVENT_PACKET, reply})
{:ok, reply, data}

%{opcode: opcode} = reply ->
%{opcode: _opcode} = reply ->
{:error, reply, data}

%{} = reply ->
Expand Down
2 changes: 1 addition & 1 deletion lib/blue_heron/peripheral.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule BlueHeron.Peripheral do
:gatt_server,
:smp_server,
:smp_handler,
:acl_buffer,
:acl_buffer
]

@doc "Start a non-secured peripheral"
Expand Down
2 changes: 1 addition & 1 deletion test/blue_heron/acl_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule BlueHeron.ACLTest do
}
|> ACL.serialize()

assert <<64, 32, 7, 0, 3, 0, 4, 0, 2, 185, 0>> == serialized
assert <<64, 2, 7, 0, 3, 0, 4, 0, 2, 185, 0>> == serialized
end

test "serde is symmetric" do
Expand Down
8 changes: 8 additions & 0 deletions test/blue_heron/gatt/server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,18 @@ defmodule BlueHeron.GATT.ServerTest do
"a-value-longer-than-22-bytes"
end

def read({:custom_service_1, :long_uuid}) do
"a-value-longer-than-22-bytes"
end

def read({:gap, :service_changed}) do
""
end

def read({:gap, :appearance}) do
<<0x008D::little-16>>
end

@impl Server
def write({:custom_service_1, :short_uuid}, value) do
send(self(), value)
Expand Down
Loading

0 comments on commit 0974e13

Please sign in to comment.