xref: /btstack/platform/daemon/binding/python/test.py (revision a43b5e871707c65eb7c38af653dad20372668fbd)
10c4cc577SMatthias Ringwald#!/usr/bin/env python3
20c4cc577SMatthias Ringwald
3b1f6df3bSMatthias Ringwaldfrom btstack import btstack_server, btstack_client, event_factory
40c4cc577SMatthias Ringwald
50c4cc577SMatthias Ringwalddef packet_handler(packet):
6b1f6df3bSMatthias Ringwald	global btstack_client
7b1f6df3bSMatthias Ringwald	if isinstance(packet, event_factory.BTstackEventState):
8b1f6df3bSMatthias Ringwald		print("BTstack state: %u" % packet.get_state())
9b1f6df3bSMatthias Ringwald		if packet.get_state() == 2:
10b1f6df3bSMatthias Ringwald			print('BTstack up and running, starting scan')
11b1f6df3bSMatthias Ringwald			btstack_client.gap_le_scan_start()
12b1f6df3bSMatthias Ringwald	if isinstance(packet, event_factory.GAPEventAdvertisingReport):
130c4cc577SMatthias Ringwald		print(packet)
140c4cc577SMatthias Ringwald
150c4cc577SMatthias Ringwald# Conrtrol for BTstack Server
160c4cc577SMatthias Ringwaldbtstack_server = btstack_server.BTstackServer()
170c4cc577SMatthias Ringwald
180c4cc577SMatthias Ringwald# start BTstack Server from .dll
190c4cc577SMatthias Ringwaldbtstack_server.load()
200c4cc577SMatthias Ringwald# btstack_server.set_storage_path("/tmp")
210c4cc577SMatthias Ringwaldbtstack_server.run_tcp()
220c4cc577SMatthias Ringwald
230c4cc577SMatthias Ringwald# Client for BTstack Server
240c4cc577SMatthias Ringwaldbtstack_client = btstack_client.BTstackClient()
250c4cc577SMatthias Ringwald
260c4cc577SMatthias Ringwald# connect to slient, register for HCI packets and power up
27*a43b5e87SMatthias Ringwaldok = btstack_client.connect()
28*a43b5e87SMatthias Ringwaldif ok:
290c4cc577SMatthias Ringwald	btstack_client.register_packet_handler(packet_handler)
309fb9416bSMatthias Ringwald	btstack_client.btstack_set_power_mode(1)
310c4cc577SMatthias Ringwald	btstack_client.run()
32