Skip to content

Commit

Permalink
Merge pull request #8 from dhalbert/match_prefixes
Browse files Browse the repository at this point in the history
prefix -> match_prefixes
  • Loading branch information
evaherrada authored Jun 18, 2020
2 parents 2a49010 + e568999 commit 7d9f502
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
11 changes: 2 additions & 9 deletions adafruit_ble_eddystone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __set__(self, obj, value):
class EddystoneAdvertisement(Advertisement):
"""Top level Eddystone advertisement that manages frame type. For library use only."""

# Subclasses must provide `prefix`.
# Subclasses must provide `match_prefixes`.
services = ServiceList(standard_services=[0x03], vendor_services=[0x07])
eddystone_frame = _EddystoneFrame()

Expand All @@ -116,17 +116,10 @@ def __init__(self, *, minimum_size=None):
self.connectable = False
self.flags.general_discovery = True
self.flags.le_only = True
self.frame_type = bytearray(1)
# Frame type is in the prefix.
self.frame_type[0] = self.prefix[-1]
# self.frame_type is defined by the subclass.
if not self.eddystone_frame:
self.eddystone_frame = bytearray(minimum_size)

@classmethod
def matches(cls, entry):
"""True if the entry matches all of the prefixes. This is stricter than the scan."""
return entry.matches(cls.prefix, all=True)

def __str__(self):
parts = []
for attr in dir(self.__class__):
Expand Down
3 changes: 2 additions & 1 deletion adafruit_ble_eddystone/uid.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class EddystoneUID(EddystoneAdvertisement):
:param int tx_power: TX power at the beacon
"""

prefix = b"\x03\x03\xaa\xfe\x04\x16\xaa\xfe\x00"
match_prefixes = (b"\x03\xaa\xfe", b"\x16\xaa\xfe\x00")
frame_type = b"\x00"

tx_power = EddystoneFrameStruct("<B", offset=0)
"""TX power at the beacon in dBm"""
Expand Down
3 changes: 2 additions & 1 deletion adafruit_ble_eddystone/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ class EddystoneURL(EddystoneAdvertisement):
:param str url: Target url
:param int tx_power: TX power in dBm"""

prefix = b"\x03\x03\xaa\xfe\x04\x16\xaa\xfe\x10"
match_prefixes = (b"\x03\xaa\xfe", b"\x16\xaa\xfe\x10")
frame_type = b"\x10"
tx_power = EddystoneFrameStruct("<B", offset=0)
"""TX power in dBm"""

Expand Down

0 comments on commit 7d9f502

Please sign in to comment.