3 from __future__ import absolute_import, print_function, unicode_literals
5 from sap_client import *
9 def connect_disconnect_by_client(sap):
11 print("[Test] Connect - Disconnect by client \n")
14 if not sap.isConnected():
17 if sap.proc_connect():
18 if sap.proc_disconnectByClient():
25 except BluetoothError as e:
26 print("Error " + str(e))
29 def connect_disconnect_by_server_gracefully(sap, timeout=0):
31 print("[Test] Connect - Disconnect by server with timer \n")
34 if not sap.isConnected():
37 if sap.proc_connect():
38 if sap.proc_disconnectByServer(timeout):
45 except BluetoothError as e:
46 print("Error " + str(e))
49 def connect_txAPDU_disconnect_by_client(sap):
51 print("[Test] Connect - TX APDU - Disconnect by client \n")
54 if not sap.isConnected():
57 if sap.proc_connect():
58 if not sap.proc_transferAPDU():
62 if not sap.proc_transferAPDU():
66 if not sap.proc_transferAPDU():
70 if not sap.proc_transferAPDU():
74 if sap.proc_disconnectByClient():
81 except BluetoothError as e:
82 print("Error " + str(e))
84 def connect_rfcomm_only_and_wait_for_close_by_server(sap):
86 print("[Test] Connect rfcomm only - Disconnect by server timeout \n")
88 if not sap.isConnected():
94 def power_sim_off_on(sap):
96 print("[Test] Powe sim off \n")
99 if not sap.isConnected():
102 if sap.proc_connect():
103 if not sap.proc_resetSim():
107 if not sap.proc_powerSimOff():
111 if not sap.proc_powerSimOn():
115 if sap.proc_disconnectByClient():
122 except BluetoothError as e:
123 print("Error " + str(e))
126 if __name__ == "__main__":
128 host = None # server bd_addr
129 port = 8 # sap server port
131 if (len(sys.argv) < 2):
132 print("Usage: %s <address> [port]" % (sys.argv[0]))
137 if (len(sys.argv) == 3):
141 s = SAPClient(host, port)
142 except BluetoothError as e:
143 print("Error: " + str(e))
146 connect_disconnect_by_client(s)
147 connect_disconnect_by_server_gracefully(s)
148 connect_disconnect_by_server_gracefully(s, 40) # wait 40 sec for srv to close rfcomm sock
149 connect_rfcomm_only_and_wait_for_close_by_server(s)
150 connect_txAPDU_disconnect_by_client(s)