mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-02-02 11:01:53 +08:00
refactoring
This commit is contained in:
@@ -57,9 +57,9 @@ class _SpiPhyConnection(BasePhyConnection):
|
||||
self.__xfer = xfer
|
||||
self.__read_timeout = read_timeout
|
||||
|
||||
def send(self, request: bytes) -> bytes:
|
||||
assert len(request) == 8
|
||||
assert request[0] == 0x33
|
||||
def send(self, req: bytes) -> bytes:
|
||||
assert len(req) == 8
|
||||
assert req[0] == 0x33
|
||||
|
||||
deadline_ts = time.monotonic() + self.__read_timeout
|
||||
dummy = b"\x00" * 10
|
||||
@@ -70,26 +70,26 @@ class _SpiPhyConnection(BasePhyConnection):
|
||||
get_logger(0).error("SPI timeout reached while garbage reading")
|
||||
return b""
|
||||
|
||||
self.__xfer(request)
|
||||
self.__xfer(req)
|
||||
|
||||
response: list[int] = []
|
||||
resp: list[int] = []
|
||||
deadline_ts = time.monotonic() + self.__read_timeout
|
||||
found = False
|
||||
while time.monotonic() < deadline_ts:
|
||||
for byte in self.__xfer(b"\x00" * (9 - len(response))):
|
||||
for byte in self.__xfer(b"\x00" * (9 - len(resp))):
|
||||
if not found:
|
||||
if byte == 0:
|
||||
continue
|
||||
found = True
|
||||
response.append(byte)
|
||||
if len(response) == 8:
|
||||
resp.append(byte)
|
||||
if len(resp) == 8:
|
||||
break
|
||||
if len(response) == 8:
|
||||
if len(resp) == 8:
|
||||
break
|
||||
else:
|
||||
get_logger(0).error("SPI timeout reached while responce waiting")
|
||||
return b""
|
||||
return bytes(response)
|
||||
return bytes(resp)
|
||||
|
||||
|
||||
class _SpiPhy(BasePhy): # pylint: disable=too-many-instance-attributes
|
||||
|
||||
Reference in New Issue
Block a user