cosmetic: switch to consistent four-spaces indent (using autopep8)

This commit is contained in:
Vadim Yanitskiy 2022-03-27 22:09:38 +03:00 committed by Vadim Yanitskiy
parent 79c2124e0c
commit 45788b2783
3 changed files with 257 additions and 256 deletions

11
peer.py
View File

@ -22,6 +22,7 @@ from typing import Any
from construct import Container, Int16ul
from proto import DbgMuxFrame
class DbgMuxPeer:
def __init__(self, sl):
self.tx_count: int = 0
@ -33,11 +34,11 @@ class DbgMuxPeer:
msg_data = DbgMuxFrame.Msg.build(msg, MsgType=msg_type)
c = Container({
'TxCount' : (self.tx_count + 1) % 256,
'RxCount' : self.rx_count % 256,
'MsgType' : msg_type,
'MsgData' : msg_data,
'FCS' : 0 # Calculated below
'TxCount': (self.tx_count + 1) % 256,
'RxCount': self.rx_count % 256,
'MsgType': msg_type,
'MsgData': msg_data,
'FCS': 0 # Calculated below
})
# ACK is a bit special

View File

@ -20,8 +20,10 @@ from construct import *
import crcmod
# DebugMux frame definition
class DbgMuxFrame:
''' DebugMux frame definition '''
# Kudos to Stefan @Sec Zehl for finding the CRC function parameters
fcs_func = crcmod.mkCrcFun(0x11021, rev=True, initCrc=0x0, xorOut=0xffff)
@ -30,7 +32,6 @@ class DbgMuxFrame:
Ident = 0x66, # 'f'
Ping = 0x67, # 'g'
Pong = 0x68, # 'h'
DPAnnounce = 0x69, # 'i'
# TODO: = 0x6a, # 'j'
ConnEstablish = 0x6b, # 'k'
@ -38,7 +39,6 @@ class DbgMuxFrame:
ConnTerminate = 0x6d, # 'm'
ConnTerminated = 0x6e, # 'n'
ConnData = 0x6f, # 'o'
# TODO: = 0x70, # 'p'
Ack = 0x71, # 'q'
)

View File

@ -28,6 +28,7 @@ import sys
from proto import DbgMuxFrame
from peer import DbgMuxPeer
class SEDbgMuxApp(cmd2.Cmd):
DESC = 'DebugMux client for [Sony] Ericsson phones and modems'
@ -57,18 +58,13 @@ class SEDbgMuxApp(cmd2.Cmd):
@cmd2.with_category(CATEGORY_CONN)
def do_connect(self, opts) -> None:
''' Connect to the modem and switch it to DebugMux mode '''
slp = {
'port' : self.argv.serial_port,
'baudrate' : self.argv.serial_baudrate,
'bytesize' : 8,
'parity' : 'N',
'stopbits' : 1,
'timeout' : self.argv.serial_timeout,
# 'xonoff' : False,
'rtscts' : False,
'dsrdtr' : False,
}
self.sl = serial.Serial(**slp)
self.sl = serial.Serial(port=self.argv.serial_port,
baudrate=self.argv.serial_baudrate,
bytesize=8, parity='N', stopbits=1,
timeout=self.argv.serial_timeout,
# xonoff=False,
rtscts=False,
dsrdtr=False)
# Test the modem
self.transceive('AT', 'OK')
@ -144,7 +140,8 @@ class SEDbgMuxApp(cmd2.Cmd):
def do_establish(self, opts) -> None:
''' Establish connection with a Data Provider '''
log.info("Establishing connection with DPRef=0x%04x", opts.DPRef)
self.peer.send(DbgMuxFrame.MsgType.ConnEstablish, dict(DPRef=opts.DPRef))
self.peer.send(DbgMuxFrame.MsgType.ConnEstablish,
dict(DPRef=opts.DPRef))
f = self.peer.recv()
assert f['MsgType'] == DbgMuxFrame.MsgType.ConnEstablished
@ -153,7 +150,8 @@ class SEDbgMuxApp(cmd2.Cmd):
self.peer.send(DbgMuxFrame.MsgType.Ack)
return
log.info("Connection established (ConnRef=0x%04x)", f['Msg']['ConnRef'])
log.info("Connection established (ConnRef=0x%04x)",
f['Msg']['ConnRef'])
# Read the messages
while True:
@ -175,7 +173,7 @@ class SEDbgMuxApp(cmd2.Cmd):
log.debug("MODEM <- %s", str(data))
self.sl.write(data)
def send_at_cmd(self, cmd: str, handle_echo:bool = True) -> None:
def send_at_cmd(self, cmd: str, handle_echo: bool = True) -> None:
self.send_data(cmd.encode() + b'\r')
if handle_echo:
self.sl.readline()
@ -195,6 +193,7 @@ class SEDbgMuxApp(cmd2.Cmd):
assert rsp == exp
break
ap = argparse.ArgumentParser(prog='sedbgmux', description=SEDbgMuxApp.DESC,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
@ -206,7 +205,8 @@ group.add_argument('--serial-baudrate', metavar='BAUDRATE', type=int, default=11
group.add_argument('--serial-timeout', metavar='TIMEOUT', type=int,
help='Serial port timeout')
log.basicConfig(format='[%(levelname)s] %(filename)s:%(lineno)d %(message)s', level=log.INFO)
log.basicConfig(
format='[%(levelname)s] %(filename)s:%(lineno)d %(message)s', level=log.INFO)
if __name__ == '__main__':
argv = ap.parse_args()