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.
This commit is contained in:
parent
d4fa8a29e6
commit
bdeb675bf3
5 changed files with 14 additions and 6 deletions
10
fwupd.py
10
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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue