harald v0.1.1 Harald.HCI.Event.LEMeta.AdvertisingReport.Device View Source
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 Harald.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
Link to this section Summary
Functions
Deserializes a LE Advertising Report Event into Harald.HCI.Event.LEMeta.AdvertisingReport
structs
Deserializes AD Structures
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>>}}]
}
Serializes a list of Harald.HCI.Event.LEMeta.AdvertisingReport
structs into a LE Advertising
Report Event
Serializes a Harald.HCI.Event.LEMeta.AdvertisingReport
struct's :data
field into AD
Structures
Given a list of Harald.HCI.Event.LEMeta.AdvertisingReport.Device
structs', serializes their
:data
fields into AD Structures
Link to this section Types
Link to this section Functions
deserialize(bin) View Source
Deserializes a LE Advertising Report Event into Harald.HCI.Event.LEMeta.AdvertisingReport
structs.
iex> AdvertisingReport.deserialize(
...> <<2, 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, [
%AdvertisingReport{
event_type: 0,
address_type: 1,
address: 2,
data: [],
rss: 4
},
%AdvertisingReport{
event_type: 1,
address_type: 2,
address: 5,
data: [{"Service Data - 32-bit UUID", %{uuid: 1, data: <<2>>}}],
rss: 7
}
]}
deserialize_ads(arg) View Source
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", {:error, {:unhandled_company_id, <<>>}}}}
iex> deserialize_ads(<<0x44, 1, 2, 3>>)
{:error, {:unknown_type, {0x44, <<1, 2, 3>>}}}
deserialize_advertising_data(data, acc \\ {:ok, []}) View Source
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) View Source
Serializes a list of Harald.HCI.Event.LEMeta.AdvertisingReport
structs into a LE Advertising
Report Event.
iex> AdvertisingReport.serialize([
...> %AdvertisingReport{
...> event_type: 0,
...> address_type: 1,
...> address: 2,
...> data: [],
...> rss: 4
...> },
...> %AdvertisingReport{
...> event_type: 1,
...> address_type: 2,
...> address: 5,
...> data: [{"Service Data - 32-bit UUID", %{uuid: 1, data: <<2>>}}],
...> rss: 7
...> }
...> ])
{:ok,
<<2, 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 \\ <<>>) View Source
Serializes a Harald.HCI.Event.LEMeta.AdvertisingReport
struct's :data
field 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) View Source
Given a list of Harald.HCI.Event.LEMeta.AdvertisingReport.Device
structs', serializes their
:data
fields into AD Structures.
iex> serialize_device_data(
...> %AdvertisingReport.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
...> }
...> )
[
%Harald.HCI.Event.LEMeta.AdvertisingReport.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
}
]