Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_eddystone_url(self):
pckt = aioblescan.HCI_Event()
pckt.decode(
b'\x04>)\x02\x01\x03\x01\xdc)e\x90U\xf1\x1d\x02\x01\x06\x03\x03\xaa\xfe\x15\x16\xaa\xfe\x10\xf6\x03makecode\x00#about\xb5')
result = EddyStone().decode(pckt)
self.assertDictEqual(result, {'mac address': 'f1:55:90:65:29:dc',
'tx_power': -10,
'url': 'https://makecode.com/#about',
'rssi': -75})
def test_eddystone_uid(self):
pckt = aioblescan.HCI_Event()
pckt.decode(
b'\x04>)\x02\x01\x03\x01\xdc)e\x90U\xf1\x1d\x02\x01\x06\x03\x03\xaa\xfe\x15\x16\xaa\xfe\x00\xf6\x00\x00\x00\x00\x00\x00\x00\x00\x00c\x00\x00\x00\x00\x00X\xb6')
result = EddyStone().decode(pckt)
self.assertDictEqual(result, {'tx_power': -10,
'rssi': -74,
'name space': (0x63).to_bytes(10,byteorder="big"),
'instance': (0x58).to_bytes(6,byteorder="big"),
'mac address': 'f1:55:90:65:29:dc'})
def processBLEBeacon(data):
# While I'm not a fan of globals, not sure how else we can store state here easily
global verbose
global reload_objects_at
global tilts
ev = aiobs.HCI_Event()
xx = ev.decode(data)
# To make things easier, let's convert the byte string to a hex string first
if ev.raw_data is None:
if verbose:
LOG.error("Event has no raw data")
return False
raw_data_hex = ev.raw_data.hex()
if len(raw_data_hex) < 80: # Very quick filter to determine if this is a valid Tilt device
# if verbose:
# LOG.info("Small raw_data_hex: {}".format(raw_data_hex))
return False
if "1370f02d74de" not in raw_data_hex: # Another very quick filter (honestly, might not be faster than just looking at uuid below)
# if verbose:
def my_process(data):
global opts
ev=aiobs.HCI_Event()
xx=ev.decode(data)
if opts.mac:
goon = False
mac= ev.retrieve("peer")
for x in mac:
if x.val in opts.mac:
goon=True
break
if not goon:
return
if opts.raw:
print("Raw data: {}".format(ev.raw_data))
if opts.eddy:
xx=EddyStone().decode(ev)
if xx:
def _process_packet(data):
"""
Filter BLE packets to only show Eddystone data
before calling packet_callback
:param data: BLE Packet data
:return: None
"""
logging.debug('Packet found')
ev = aioblescan.HCI_Event()
ev.decode(data)
logging.debug('Using the following callback %s', packet_callback)
if packet_callback is not None:
eddystone_data = EddyStone().decode(ev)
if eddystone_data:
packet_callback(eddystone_data)