Compare commits
2 Commits
138af0da7a
...
2990cc14b8
Author | SHA1 | Date |
---|---|---|
Vadim Yanitskiy | 2990cc14b8 | |
Vadim Yanitskiy | f9759d1024 |
6
peer.py
6
peer.py
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
import logging as log
|
import logging as log
|
||||||
|
|
||||||
from typing import Any
|
from typing import Any, Optional
|
||||||
from construct import Const, Container, Int16ul
|
from construct import Const, Container, Int16ul
|
||||||
|
|
||||||
from transport import Transport
|
from transport import Transport
|
||||||
|
@ -63,9 +63,11 @@ 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) -> Container:
|
def recv(self) -> Optional[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:])
|
||||||
|
|
|
@ -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=int,
|
group.add_argument('--serial-timeout', metavar='TIMEOUT', type=float, default=0.5,
|
||||||
help='Serial port timeout')
|
help='Serial port read timeout (default %(default)s)')
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
@ -30,15 +30,19 @@ 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 '''
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue