3 from __future__ import absolute_import, print_function, unicode_literals
8 def connect_disconnect_by_client(sap):
10 print("[Test] Connect - Disconnect by client \n")
13 if not sap.isConnected():
16 if sap.proc_connect():
17 if sap.proc_disconnectByClient():
24 except BluetoothError as e:
25 print("Error " + str(e))
28 def connect_disconnect_by_server_gracefully(sap, timeout=0):
30 print("[Test] Connect - Disconnect by server with timer \n")
33 if not sap.isConnected():
36 if sap.proc_connect():
37 if sap.proc_disconnectByServer(timeout):
44 except BluetoothError as e:
45 print("Error " + str(e))
48 def connect_txAPDU_disconnect_by_client(sap):
50 print("[Test] Connect - TX APDU - Disconnect by client \n")
53 if not sap.isConnected():
56 if sap.proc_connect():
57 if not sap.proc_transferAPDU():
61 if not sap.proc_transferAPDU():
65 if not sap.proc_transferAPDU():
69 if not sap.proc_transferAPDU():
73 if sap.proc_disconnectByClient():
80 except BluetoothError as e:
81 print("Error " + str(e))
83 def connect_rfcomm_only_and_wait_for_close_by_server(sap):
85 print("[Test] Connect rfcomm only - Disconnect by server timeout \n")
87 if not sap.isConnected():
93 def power_sim_off_on(sap):
95 print("[Test] Powe sim off \n")
98 if not sap.isConnected():
101 if sap.proc_connect():
102 if not sap.proc_resetSim():
106 if not sap.proc_powerSimOff():
110 if not sap.proc_powerSimOn():
114 if sap.proc_disconnectByClient():
121 except BluetoothError as e:
122 print("Error " + str(e))
125 if __name__ == "__main__":
127 host = "00:00:00:00:00:0" # server bd_addr
128 port = 8 # sap server port
131 s = SAPClient(host, port)
132 except BluetoothError as e:
133 print("Error " + str(e))
135 connect_disconnect_by_client(s)
136 connect_disconnect_by_server_gracefully(s)
137 connect_disconnect_by_server_gracefully(s, 40) # wait 40 sec for srv to close rfcomm sock
138 connect_rfcomm_only_and_wait_for_close_by_server(s)
139 connect_txAPDU_disconnect_by_client(s)