mirror of
https://github.com/undera/pylgbst.git
synced 2020-11-18 19:37:26 -08:00
* Cosmetics * Harmonograph demo * Cleanup * Original * Original * Cosmetics * Original file * Fixes * cosmetics * separate classes * Cosmetics * Cosmetics * fix tests * Remove plotter tests * Add bluegiga * Rename it * Progress * Fix tests * Cosmetics * Found a way for pygatt! * Playing with gatt * Fix hung subscribe * rename class * add test * skeleton for autodetect * safer order * Fix tests * Fix test * Add dbus install * another try * 2 * 3 * 34 * 6 * 7 * Isolate some tests * 8 * back to roots * Try more * 9 * Help * rep * site-packs * Fix? * Py3 come on * dbus * busss * dev null! * Fix test * Cleanup * Fix tests * Fix after review * add package * FIx package paths * Cosmetics * Update * More doc
63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
import logging
|
|
import traceback
|
|
|
|
from pylgbst.comms import DebugServer
|
|
|
|
log = logging.getLogger('pylgbst')
|
|
|
|
|
|
def get_connection_bluegiga(mac):
|
|
from pylgbst.comms_pygatt import BlueGigaConnection
|
|
|
|
return BlueGigaConnection().connect(mac)
|
|
|
|
|
|
def get_connection_gattool(controller='hci0', hub_mac=None):
|
|
from pylgbst.comms_pygatt import GattoolConnection
|
|
|
|
return GattoolConnection(controller).connect(hub_mac)
|
|
|
|
|
|
def get_connection_gatt(controller='hci0', hub_mac=None):
|
|
from pylgbst.comms_gatt import GattConnection
|
|
|
|
return GattConnection(controller).connect(hub_mac)
|
|
|
|
|
|
def get_connection_gattlib(controller='hci0', hub_mac=None):
|
|
from pylgbst.comms_gattlib import GattLibConnection
|
|
|
|
return GattLibConnection(controller).connect(hub_mac)
|
|
|
|
|
|
def get_connection_auto(controller='hci0', hub_mac=None):
|
|
conn = None
|
|
try:
|
|
return get_connection_bluegiga(hub_mac)
|
|
except BaseException:
|
|
logging.debug("Failed: %s", traceback.format_exc())
|
|
try:
|
|
conn = get_connection_gatt(controller, hub_mac)
|
|
except BaseException:
|
|
logging.debug("Failed: %s", traceback.format_exc())
|
|
|
|
try:
|
|
conn = get_connection_gattool(controller, hub_mac)
|
|
except BaseException:
|
|
logging.debug("Failed: %s", traceback.format_exc())
|
|
|
|
try:
|
|
conn = get_connection_gattlib(controller, hub_mac)
|
|
except BaseException:
|
|
logging.debug("Failed: %s", traceback.format_exc())
|
|
|
|
if conn is None:
|
|
raise Exception("Failed to autodetect connection, make sure you have installed prerequisites")
|
|
|
|
return conn
|
|
|
|
|
|
def start_debug_server(iface="hci0", port=9090):
|
|
server = DebugServer(get_connection_auto(iface))
|
|
server.start(port)
|