Skip to content
Snippets Groups Projects

Show COVID-19 exposure notification statistics

Merged schneider requested to merge schneider/covid-tracing into master
Files
2
@@ -8,11 +8,12 @@ import color
DM_ADV_TYPE_FLAGS = 0x01
DM_ADV_TYPE_16_UUID = 0x03
DM_ADV_TYPE_SERVICE_DATA = 0x16
UUID = b'\x6f\xfd'
UUID = b"\x6f\xfd"
TIMEOUT = 100
seen = {}
def parse_advertisement_data(data):
ads = {}
@@ -23,24 +24,27 @@ def parse_advertisement_data(data):
p += 1
if ad_len > 0:
ad_type = data[p]
ad_data = b''
ad_data = b""
p += 1
if ad_len > 1:
ad_data = data[p:p+ad_len - 1]
ad_data = data[p : p + ad_len - 1]
p += ad_len - 1
ads[ad_type] = ad_data
return ads
def bytes2hex(bin, sep=''):
def bytes2hex(bin, sep=""):
return sep.join(["%02x" % x for x in bin])
def process_covid_dada(mac, service_data, rssi, flags):
vibra.vibrate(10)
print(bytes2hex(mac, ':'), rssi, bytes2hex(service_data), flags)
print(bytes2hex(mac, ":"), rssi, bytes2hex(service_data), flags)
# try to produce a small int
seen[mac] = [int(time.time() - t0), flags]
def prune():
global seen
seen_pruned = {}
@@ -52,13 +56,14 @@ def prune():
seen = seen_pruned
def process_scan_report(scan_report):
ads = parse_advertisement_data(scan_report[0])
mac = scan_report[4]
mac = bytes([mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]])
rssi = scan_report[1]
#print(bytes2hex(mac, ':'), rssi, bytes2hex(scan_report[0]), ads)
# print(bytes2hex(mac, ':'), rssi, bytes2hex(scan_report[0]), ads)
# According to spec there is no other service announced and the
# service is always listed in the complete list of 16 bit services
if DM_ADV_TYPE_16_UUID in ads:
@@ -70,6 +75,7 @@ def process_scan_report(scan_report):
# service data contains another copy of the service UUID
process_covid_dada(mac, ads[DM_ADV_TYPE_SERVICE_DATA][2:], rssi, flags)
def ble_callback(_):
event = sys_ble.get_event()
prune()
@@ -79,6 +85,7 @@ def ble_callback(_):
return
process_scan_report(scan_report)
t0 = time.time()
disp = display.open()
@@ -110,6 +117,6 @@ while True:
disp.print("Apple: %d" % seen_apple, posy=40, fg=color.BLUE)
disp.print("Total: %d" % seen_total, posy=60, fg=color.WHITE)
disp.update()
#print(seen)
# print(seen)
time.sleep(1)
Loading