Skip to content

prefix -> match_prefixes #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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