Compare commits

..

No commits in common. "2990cc14b86c68b6c75ef9740817ba75552b802a" and "138af0da7a8c4fcb7cee6ad7b393b67a289ca961" have entirely different histories.

3 changed files with 4 additions and 10 deletions

View File

@ -18,7 +18,7 @@
import logging as log import logging as log
from typing import Any, Optional from typing import Any
from construct import Const, Container, Int16ul from construct import Const, Container, Int16ul
from transport import Transport from transport import Transport
@ -63,11 +63,9 @@ class DbgMuxPeer:
if msg_type != DbgMuxFrame.MsgType.Ack: if msg_type != DbgMuxFrame.MsgType.Ack:
self.tx_count += 1 self.tx_count += 1
def recv(self) -> Optional[Container]: def recv(self) -> Container:
frame: bytes = b'' frame: bytes = b''
frame += self.io.read(2) # Magic frame += self.io.read(2) # Magic
if frame == b'':
return None
Const(b'\x42\x42').parse(frame[:2]) Const(b'\x42\x42').parse(frame[:2])
frame += self.io.read(2) # Length frame += self.io.read(2) # Length
length: int = Int16ul.parse(frame[2:]) 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)') help='Serial port path (default %(default)s)')
group.add_argument('--serial-baudrate', metavar='BAUDRATE', type=int, default=115200, group.add_argument('--serial-baudrate', metavar='BAUDRATE', type=int, default=115200,
help='Serial port speed (default %(default)s)') help='Serial port speed (default %(default)s)')
group.add_argument('--serial-timeout', metavar='TIMEOUT', type=float, default=0.5, group.add_argument('--serial-timeout', metavar='TIMEOUT', type=int,
help='Serial port read timeout (default %(default)s)') help='Serial port timeout')
log.basicConfig( log.basicConfig(
format='[%(levelname)s] %(filename)s:%(lineno)d %(message)s', level=log.INFO) format='[%(levelname)s] %(filename)s:%(lineno)d %(message)s', level=log.INFO)

View File

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