From bdeb675bf326233a182a38eaea80a2bfdd1ea209 Mon Sep 17 00:00:00 2001 From: Piotr Dobrowolski Date: Wed, 23 Oct 2019 17:48:30 +0200 Subject: [PATCH] fwupd: fix after py3k migration Sadly bleak link implementation doesn't seem to work good enough to flash yet, but fwupd of ESC and BLE over serial has been confirmed to work fine. --- fwupd.py | 10 ++++++++-- py9b/command/base.py | 2 +- py9b/link/bleak.py | 4 +++- py9b/transport/base.py | 2 +- py9b/transport/packet.py | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/fwupd.py b/fwupd.py index 87ab7f5..9c62a27 100644 --- a/fwupd.py +++ b/fwupd.py @@ -17,7 +17,7 @@ PING_RETRIES = 20 def checksum(s, data): for c in data: - s += ord(c) + s += c return s & 0xFFFFFFFF @@ -99,7 +99,7 @@ parser.add_argument( "--interface", help="communication interface, default: %(default)s", type=str.lower, - choices=("ble", "serial", "tcp", "blefleet"), + choices=("ble", "serial", "tcp", "blefleet", "bleak"), default="ble", ) @@ -149,6 +149,12 @@ elif args.interface == "blefleet": except: exit("BLE is not supported on your system !") link = BLELink() +elif args.interface == "bleak": + try: + from py9b.link.bleak import BleakLink + except: + exit("BLE is not supported on your system !") + link = BleakLink() else: exit("!!! BUG !!! Unknown interface selected: " + args.interface) diff --git a/py9b/command/base.py b/py9b/command/base.py index 3d2af4f..5b468b6 100644 --- a/py9b/command/base.py +++ b/py9b/command/base.py @@ -7,7 +7,7 @@ class InvalidResponse(Exception): class BaseCommand(object): - def __init__(self, src=BT.HOST, dst=0, cmd=0, arg=0, data="", has_response=True): + def __init__(self, src=BT.HOST, dst=0, cmd=0, arg=0, data=bytearray(), has_response=True): self.has_response = has_response self.request = PKT(src, dst, cmd, arg, data) diff --git a/py9b/link/bleak.py b/py9b/link/bleak.py index bac8987..7e27273 100644 --- a/py9b/link/bleak.py +++ b/py9b/link/bleak.py @@ -92,7 +92,9 @@ class BleakLink(BaseLink): fut.result(10) async def _connect(self, port): - self._client = BleakClient(port[1], device=self.device) + if isinstance(port, tuple): + port = port[1] + self._client = BleakClient(port, device=self.device) await self._client.connect() print("connected") await self._client.start_notify(_tx_char_uuid, self._data_received) diff --git a/py9b/transport/base.py b/py9b/transport/base.py index e3eb316..0e45f13 100644 --- a/py9b/transport/base.py +++ b/py9b/transport/base.py @@ -31,7 +31,7 @@ class BaseTransport(object): def recv(self): raise NotImplementedError() - def send(self, src, dst, cmd, arg, data=""): + def send(self, src, dst, cmd, arg, data=bytearray()): raise NotImplementedError() def execute(self, command): diff --git a/py9b/transport/packet.py b/py9b/transport/packet.py index cc7a21d..4e87df7 100644 --- a/py9b/transport/packet.py +++ b/py9b/transport/packet.py @@ -3,7 +3,7 @@ from .base import BaseTransport as BT class BasePacket(object): - def __init__(self, src=0, dst=0, cmd=0, arg=0, data=""): + def __init__(self, src=0, dst=0, cmd=0, arg=0, data=bytearray()): self.src = src self.dst = dst self.cmd = cmd