Compare commits

...

2 Commits

Author SHA1 Message Date
Vadim Yanitskiy 2990cc14b8 SEDbgMuxApp: use non-zero default serial port read timeout
This is required for a follow-up change moving DebugMux I/O handling
into separate threads.  We need to be able to stop a thread, which
is executing blocking self.io.read() call.
2022-06-20 22:36:17 +07:00
Vadim Yanitskiy f9759d1024 Transport: mark abstract methods with @abc.abstractmethod 2022-06-20 18:48:17 +07:00
3 changed files with 10 additions and 4 deletions

View File

@ -18,7 +18,7 @@
import logging as log
from typing import Any
from typing import Any, Optional
from construct import Const, Container, Int16ul
from transport import Transport
@ -63,9 +63,11 @@ class DbgMuxPeer:
if msg_type != DbgMuxFrame.MsgType.Ack:
self.tx_count += 1
def recv(self) -> Container:
def recv(self) -> Optional[Container]:
frame: bytes = b''
frame += self.io.read(2) # Magic
if frame == b'':
return None
Const(b'\x42\x42').parse(frame[:2])
frame += self.io.read(2) # Length
length: int = Int16ul.parse(frame[2:])

View File

@ -169,8 +169,8 @@ group.add_argument('-p', '--serial-port', metavar='PORT', type=str, default='/de
help='Serial port path (default %(default)s)')
group.add_argument('--serial-baudrate', metavar='BAUDRATE', type=int, default=115200,
help='Serial port speed (default %(default)s)')
group.add_argument('--serial-timeout', metavar='TIMEOUT', type=int,
help='Serial port timeout')
group.add_argument('--serial-timeout', metavar='TIMEOUT', type=float, default=0.5,
help='Serial port read timeout (default %(default)s)')
log.basicConfig(
format='[%(levelname)s] %(filename)s:%(lineno)d %(message)s', level=log.INFO)

View File

@ -30,15 +30,19 @@ class TransportIOError(Exception):
class Transport(abc.ABC):
''' Abstract transport layer for DebugMux '''
@abc.abstractmethod
def connect(self, opts: dict) -> None:
''' Establish connection to the target and enter DebugMux mode '''
@abc.abstractmethod
def disconnect(self) -> None:
''' Escape DebugMux mode and terminate connection with the target '''
@abc.abstractmethod
def write(self, data: bytes) -> int:
''' Write the given data bytes '''
@abc.abstractmethod
def read(self, length: int = 0) -> bytes:
''' Read the given number of bytes '''