View Source BlueHeron.HCI.Event.LEMeta.AdvertisingReport.Device (blue_heron v0.5.1)

A struct representing a single device within a LE Advertising Report.

The LE Advertising Report event indicates that one or more Bluetooth devices have responded to an active scan or have broadcast advertisements that were received during a passive scan. The Controller may queue these advertising reports and send information from multiple devices in one LE Advertising Report event.

This event shall only be generated if scanning was enabled using the LE Set Scan Enable command. It only reports advertising events that used legacy advertising PDUs.

Reference: Version 5.0, Vol 2, Part E, 7.7.65.2

The :data field of an BlueHeron.HCI.Event.LEMeta.AdvertisingReport.Device struct represents AD Structures.

The significant part contains a sequence of AD structures. Each AD structure shall have a Length field of one octet, which contains the Length value, and a Data field of Length octets.

Reference: Version 5.0, Vol 3, Part C, 11

Summary

Functions

Deserializes a LE Advertising Report Event.

Deserializes AD Structures.

Deserializes AD Structures into basic Bluetooth data types.

Serializes a list of BlueHeron.HCI.Event.LEMeta.AdvertisingReport structs into a LE Advertising Report Event.

Serializes basic Bluetooth data types into AD Structures.

Serializes a BlueHeron.HCI.Event.LEMeta.AdvertisingData.Device structs' :data field into AD Structures.

Types

t()

@type t() :: %BlueHeron.HCI.Event.LEMeta.AdvertisingReport.Device{
  address: term(),
  address_type: term(),
  data: term(),
  event_type: term(),
  rss: term()
}

Functions

deserialize(bin)

Deserializes a LE Advertising Report Event.

iex> Device.deserialize(
...>   <<2, 0, 1, 1, 2, 2, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 7, 6, 32, 1, 0, 0, 0, 2, 4,
...>     7>>
...> )
{:ok, [
  %Device{
    event_type: 0,
    address_type: 1,
    address: 2,
    data: [],
    rss: 4
  },
  %Device{
    event_type: 1,
    address_type: 2,
    address: 5,
    data: [{"Service Data - 32-bit UUID", %{uuid: 1, data: <<2>>}}],
    rss: 7
  }
]}

deserialize_ads(bin)

Deserializes AD Structures.

iex> deserialize_ads(<<0xFF, 76, 2, 0x15, 1::size(168)>>)
{:ok,
 {"Manufacturer Specific Data",
  {"Apple, Inc.", {"iBeacon", %{major: 0, minor: 0, tx_power: 1, uuid: 0}}}}}

iex> deserialize_ads(<<0x20, 1::size(40)>>)
{:ok, {"Service Data - 32-bit UUID", %{uuid: 0, data: <<1>>}}}

iex> deserialize_ads(<<0xFF>>)
{:error, {"Manufacturer Specific Data", <<>>}}

deserialize_advertising_data(data, acc \\ {:ok, []})

Deserializes AD Structures into basic Bluetooth data types.

iex> deserialize_advertising_data(<<25, 255, 76, 2, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
...>   0, 0, 0, 1, 0, 1, 0, 2, 3, 6, 32, 1, 0, 0, 0, 2>>)
{:ok, [
  {"Manufacturer Specific Data", {"Apple, Inc.", {"iBeacon", %{
    major: 1,
    minor: 2,
    tx_power: 3,
    uuid: 1
  }}}},
  {"Service Data - 32-bit UUID", %{uuid: 1, data: <<2>>}}]
}

serialize(devices)

Serializes a list of BlueHeron.HCI.Event.LEMeta.AdvertisingReport structs into a LE Advertising Report Event.

iex> Device.serialize([
...>   %Device{
...>     event_type: 0,
...>     address_type: 1,
...>     address: 2,
...>     data: [],
...>     rss: 4
...>   },
...>   %Device{
...>     event_type: 1,
...>     address_type: 2,
...>     address: 5,
...>     data: [{"Service Data - 32-bit UUID", %{uuid: 1, data: <<2>>}}],
...>     rss: 7
...>   }
...> ])
{:ok,
 <<2, 0, 1, 1, 2, 2, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 7, 6, 32, 1, 0, 0, 0, 2, 4, 7>>}

serialize_advertising_data(ads, bin \\ <<>>)

Serializes basic Bluetooth data types into AD Structures.

iex> serialize_advertising_data([
...>   {"Manufacturer Specific Data",
...>     {"Apple, Inc.",
...>       {"iBeacon",
...>         %{
...>           major: 1,
...>           minor: 2,
...>           tx_power: 3,
...>           uuid: 1
...>         }}}},
...>   {"Service Data - 32-bit UUID", %{uuid: 1, data: <<2>>}}
...> ])
{:ok,
 <<25, 255, 76, 2, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 2, 3, 6, 32,
   1, 0, 0, 0, 2>>}

serialize_device_data(device)

Serializes a BlueHeron.HCI.Event.LEMeta.AdvertisingData.Device structs' :data field into AD Structures.

iex> serialize_device_data(
...>   %Device{
...>     address: 1,
...>     address_type: 2,
...>     data: [
...>       {"Manufacturer Specific Data",
...>        {"Apple, Inc.",
...>         {"iBeacon",
...>          %{
...>            major: 4,
...>            minor: 5,
...>            tx_power: 6,
...>            uuid: 7
...>          }}}},
...>       {"Service Data - 32-bit UUID", %{uuid: 8, data: <<9>>}}
...>     ],
...>     event_type: 1,
...>     rss: 2
...>   }
...> )
%Device{
  address: 1,
  address_type: 2,
  data: <<25, 255, 76, 2, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 4, 0, 5,
          6, 6, 32, 8, 0, 0, 0, 9>>,
  event_type: 1,
  rss: 2
}