diff --git a/iroha-drip-general-master/bluetooth/beacon.py b/iroha-drip-general-master/bluetooth/beacon.py index 589d281198e3e1ba00be2ca860e3fa93c74cadbd..6d315f6382839434d23e8d63cff38b5ac92d2c19 100644 --- a/iroha-drip-general-master/bluetooth/beacon.py +++ b/iroha-drip-general-master/bluetooth/beacon.py @@ -104,10 +104,27 @@ def location_update(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id): executor.submit( iroha.set_account_details, "location", iroha_msg ) + + # Set (Extended) Advertising command if is_bt5: + """ + OGF: 0x08 (LE controller commands) + OCF: 0x0037 (LE Set Extended Advertising Data command) + Advertising handle: 0x00 (Advertising set number) + Operation: 0x03 (Complete extended advertising data) + Fragment_Preference: 0x01 (The Controller should not fragment or should minimize fragmentation of Host advertising data) + Advertising_Data_Length: 0x1f + Advertising_Data: 1e 16 fa ff 0d 00 10 + payload + """ subprocess.run( - "hcitool -i hci0 cmd 0x08 0x0037 1f 1e 16 fa ff 0d 00 10 {payload}".format(payload=payload), shell=True) # TODO + "hcitool -i hci0 cmd 0x08 0x0037 00 03 01 1f 1e 16 fa ff 0d 00 10 {payload}".format(payload=payload), shell=True) else: + """ + OGF: 0x08 (LE controller commands) + OCF: 0x0008 (LE Set Advertising Data command) + Advertising_Data_Length: 0x1f + Advertising_Data: 1e 16 fa ff 0d 00 10 + payload + """ subprocess.run( "hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d 00 10 {payload}".format(payload=payload), shell=True) @@ -115,17 +132,61 @@ def location_update(gpsd: GpsPoller, iroha: DripIrohaAccount, flight_id): def basic_id_update(hhit): # ASTM F3-411 Basic ID message 0x0 with HHIT. print("basic_id_update") - subprocess.run( - "hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d 00 00 §x42 {} 00 00 00 00 00 00 00".format(hhit), shell=True) + # Set (Extended) Advertising Command + if is_bt5: + """ + OGF: 0x08 (LE controller commands) + OCF: 0x0037 (LE Set Extended Advertising Data command) + Advertising handle: 0x00 (Advertising set number) + Operation: 0x03 (Complete extended advertising data) + Fragment_Preference: 0x01 (The Controller should not fragment or should minimize fragmentation of Host advertising data) + Advertising_Data_Length: 0x1f + Advertising_Data: 1e 16 fa ff 0d 00 10 + hhit + """ + subprocess.run( + "hcitool -i hci0 cmd 0x08 0x0037 00 03 01 1f 1e 16 fa ff 0d 00 00 42 {} 00 00 00 00 00 00 00".format(hhit), shell=True) + else: + """ + OGF: 0x08 (LE controller commands) + OCF: 0x0008 (LE Set Advertising Data command) + Advertising_Data_Length: 0x1f + Advertising_Data: 1e 16 fa ff 0d 00 00 42 + hhit + """ + subprocess.run( + "hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d 00 00 42 {} 00 00 00 00 00 00 00".format(hhit), shell=True) time.sleep(0.5) -def auth_update(auth_pages): +def auth_update(auth_pages, msg_number): print("auth_update") for page in auth_pages: msg = separate_bytes(hexlify(page).decode("utf-8")) - subprocess.run( - "hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d {} 20 {}".format("00", msg), shell=True) + # Set (Extended) Advertising Command + if is_bt5: + """ + OGF: 0x08 (LE controller commands) + OCF: 0x0037 (LE Set Extended Advertising Data command) + Advertising handle: 0x00 (Advertising set number) + Operation: 0x03 (Complete extended advertising data) + Fragment_Preference: 0x01 (The Controller should not fragment or should minimize fragmentation of Host advertising data) + Advertising_Data_Length: 0x1f + Advertising_Data: 1e 16 fa ff 0d 00 20 + msg + """ + if msg_number == 1: + subprocess.run( + "hcitool -i hci0 cmd 0x08 0x0037 00 01 01 1f 1e 16 fa ff 0d {} 20 {}".format("00", msg), shell=True) + elif msg_number == 2: + subprocess.run( + "hcitool -i hci0 cmd 0x08 0x0037 00 02 01 1f 1e 16 fa ff 0d {} 20 {}".format("00", msg), shell=True) + else: + """ + OGF: 0x08 (LE controller commands) + OCF: 0x0008 (LE Set Advertising Data command) + Advertising_Data_Length: 0x1f + Advertising_Data: 1e 16 fa ff 0d 00 20 + msg + """ + subprocess.run( + "hcitool -i hci0 cmd 0x08 0x0008 1f 1e 16 fa ff 0d {} 20 {}".format("00", msg), shell=True) time.sleep(0.2) @@ -245,8 +306,8 @@ def main(): OCF: 0x0036 (LE Set Extended Advertising Parameters command) Advertising handle: 0x00 (Advertising set number) Advertising_Event_Properties: 0x0000 (Non-connectable, non-scannable undirected and not legacy PDU) - Primary_Advertising_Interval_Min: 0x0800 (1.28 s) - Primary_Advertising_Interval_Max: 0x0800 (1.28 s) + Primary_Advertising_Interval_Min: 0x0001e0 (480 ms) + Primary_Advertising_Interval_Max: 0x0001e0 (480 ms) Primary_Advertising_Channel_Map: 0x07 (All three channels enabled) Own_Address_Type: 0x00 (Public device address) Peer_Address_Type: 0x00 (Public Device Address or Public Identity Address) @@ -260,7 +321,7 @@ def main(): Scan_Request_Notification_Enable: 0x00 (Scan request notifications disabled) """ subprocess.run( - "hcitool -i hci0 cmd 0x08 0x0036 00 00 00 08 00 08 00 07 00 00 00 00 00 00 00 00 02 7f 03 00 03 00 00", shell=True) # TODO + "hcitool -i hci0 cmd 0x08 0x0036 00 00 07 00 01 e0 00 01 e0 07 00 00 00 00 00 00 00 00 02 7f 03 00 03 00 00", shell=True) else: """ OGF: 0x08 (LE controller commands) @@ -314,10 +375,10 @@ def main(): basic_id_update(hhit) # Send first half of auth pages second second elif i % 3 == 1: - auth_update(auth_pages[:2]) + auth_update(auth_pages[:2], 1) # Send last half of auth pages last second elif i % 3 == 2: - auth_update(auth_pages[2:]) + auth_update(auth_pages[2:], 2) # Location updates at least once every second. location_update(gpsd, iroha, flight_id)