Skip to content

Commit 0b5f0bd

Browse files
authored
Merge pull request #33 from ntoll/master
Add an AdafruitRadio Advertisement class.
2 parents 94f3528 + 7f05c51 commit 0b5f0bd

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

adafruit_ble/advertising/adafruit.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
_MANUFACTURING_DATA_ADT = const(0xff)
4444
_ADAFRUIT_COMPANY_ID = const(0x0822)
4545
_COLOR_DATA_ID = const(0x0000)
46+
_RADIO_DATA_ID = const(0x0001) # TODO: check this isn't already taken.
47+
4648

4749
class AdafruitColor(Advertisement):
4850
"""Broadcast a single RGB color."""
@@ -61,12 +63,17 @@ class AdafruitColor(Advertisement):
6163
color = ManufacturerDataField(_COLOR_DATA_ID, "<I")
6264
"""Color to broadcast as RGB integer."""
6365

64-
# TODO: Add radio packets.
65-
#
66-
# class AdafruitRadio(Advertisement):
67-
# prefix = b"\x06\xff\xff\xff\x00\x01"
68-
#
69-
# channel = Struct()
70-
# address =
71-
# group =
72-
# data =
66+
67+
class AdafruitRadio(Advertisement):
68+
"""Broadcast arbitrary bytes as a radio message."""
69+
prefix = struct.pack("<BBHH",
70+
0x6,
71+
_MANUFACTURING_DATA_ADT,
72+
_ADAFRUIT_COMPANY_ID,
73+
_RADIO_DATA_ID)
74+
manufacturer_data = LazyField(ManufacturerData,
75+
"manufacturer_data",
76+
advertising_data_type=_MANUFACTURING_DATA_ADT,
77+
company_id=_ADAFRUIT_COMPANY_ID,
78+
key_encoding="<H")
79+
msg = ManufacturerDataField(_RADIO_DATA_ID, "<248s") # 255 byte ads

0 commit comments

Comments
 (0)