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.
legit-fork
informatic 2019-10-23 17:48:30 +02:00
parent d4fa8a29e6
commit bdeb675bf3
5 changed files with 14 additions and 6 deletions

View File

@ -17,7 +17,7 @@ PING_RETRIES = 20
def checksum(s, data): def checksum(s, data):
for c in data: for c in data:
s += ord(c) s += c
return s & 0xFFFFFFFF return s & 0xFFFFFFFF
@ -99,7 +99,7 @@ parser.add_argument(
"--interface", "--interface",
help="communication interface, default: %(default)s", help="communication interface, default: %(default)s",
type=str.lower, type=str.lower,
choices=("ble", "serial", "tcp", "blefleet"), choices=("ble", "serial", "tcp", "blefleet", "bleak"),
default="ble", default="ble",
) )
@ -149,6 +149,12 @@ elif args.interface == "blefleet":
except: except:
exit("BLE is not supported on your system !") exit("BLE is not supported on your system !")
link = BLELink() 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: else:
exit("!!! BUG !!! Unknown interface selected: " + args.interface) exit("!!! BUG !!! Unknown interface selected: " + args.interface)

View File

@ -7,7 +7,7 @@ class InvalidResponse(Exception):
class BaseCommand(object): 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.has_response = has_response
self.request = PKT(src, dst, cmd, arg, data) self.request = PKT(src, dst, cmd, arg, data)

View File

@ -92,7 +92,9 @@ class BleakLink(BaseLink):
fut.result(10) fut.result(10)
async def _connect(self, port): 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() await self._client.connect()
print("connected") print("connected")
await self._client.start_notify(_tx_char_uuid, self._data_received) await self._client.start_notify(_tx_char_uuid, self._data_received)

View File

@ -31,7 +31,7 @@ class BaseTransport(object):
def recv(self): def recv(self):
raise NotImplementedError() raise NotImplementedError()
def send(self, src, dst, cmd, arg, data=""): def send(self, src, dst, cmd, arg, data=bytearray()):
raise NotImplementedError() raise NotImplementedError()
def execute(self, command): def execute(self, command):

View File

@ -3,7 +3,7 @@ from .base import BaseTransport as BT
class BasePacket(object): 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.src = src
self.dst = dst self.dst = dst
self.cmd = cmd self.cmd = cmd