Skip to content

Commit

Permalink
rebasing feature
Browse files Browse the repository at this point in the history
  • Loading branch information
snhobbs committed Jul 22, 2024
1 parent 32aebe1 commit 7edb63f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/isp_programmer/ISPConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

_log = logging.getLogger("isp_programmer")

kTimeout = 1
kTimeout = 0.1


BAUDRATES = (9600, 19200, 38400, 57600, 115200, 230400, 460800)
Expand Down Expand Up @@ -174,7 +174,7 @@ def _flush(self):
def _read_line(self) -> str:
"""
Read until a new line is found.
Timesout if no data pulled
Times out if no data pulled
"""
line = self.iodevice.ReadLine()
return line
Expand Down Expand Up @@ -204,7 +204,7 @@ def _clear_serial(self):

def _get_return_code(self, command_string: str) -> int:
"""
No exceptions are thrown.
No exceptions are thrown. Expects echo to be turned on
"""
time.sleep(self.settings.return_code_sleep)
try:
Expand All @@ -222,7 +222,7 @@ def _get_return_code(self, command_string: str) -> int:
return self.ReturnCodes["NoStatusResponse"]

_log.debug("%s: %s", command_string, resp)
return int(resp.strip())
return int(resp)

def _write(self, string: bytes) -> None:
_log.debug(string)
Expand Down Expand Up @@ -253,9 +253,13 @@ def Unlock(self):

def SetBaudRate(self, baud_rate: int, stop_bits: int = 1):
"""
Baud Depends of FAIM config, stopbit is 1 or 2
Baud Depends of FAIM config, stopbit is 1 or 2. This can
take a few tries to work at bootup.
"""
response_code = self._write_command(f"B {baud_rate} {stop_bits}")
for _ in range(5):
response_code = self._write_command(f"B {baud_rate} {stop_bits}")
if response_code == 0:
break
_raise_return_code_error(response_code, "Set Baudrate")

def SetEcho(self, on: bool = True):
Expand Down Expand Up @@ -424,9 +428,6 @@ def MemoryLocationsEqual(
return _return_code_success(response_code)

def ReadUID(self):
"""
Raises timeout exception
"""
response_code = self._write_command("N")
_raise_return_code_error(response_code, "Read UID")
uuids = []
Expand Down Expand Up @@ -496,10 +497,16 @@ def SyncConnection(self):
sync_char = "?"
# > ?\n
self._write(bytes(sync_char, "utf-8"))
byte_in = self.iodevice.read()
byte_in = self.iodevice.read().strip().decode("utf-8")
_log.debug("Recieved: %s", byte_in)
assert isinstance(byte_in, str)
assert isinstance(sync_char, str)
if byte_in == sync_char:
# already syncronized
_log.info("Already synchronized")
self._write(bytes("\n", "utf-8"))
time.sleep(0.01)
self.reset()
return

try:
Expand Down Expand Up @@ -589,8 +596,8 @@ def __init__(self, descriptor: dict[str, typing.Any]):
self.RAMBufferSize = int(descriptor.pop("RAMBufferSize"))
self.SectorCount: int = int(descriptor.pop("SectorCount"))
self.RAMStartWrite: int = int(descriptor.pop("RAMStartWrite"))
self.CrystalFrequency = 12000 # khz == 30MHz
self.kCheckSumLocation = 7 # 0x0000001c
self.CrystalFrequency: int = 12000 # khz == 30MHz
self.kCheckSumLocation: int = 7 # 0x0000001c

assert self.RAMRange[0] > 0
assert self.RAMRange[1] > self.RAMRange[0]
Expand Down
1 change: 1 addition & 0 deletions src/isp_programmer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def gr1(ctx, **kwargs):
ctx.ensure_object(dict)
ctx.obj.update(kwargs)

logging.basicConfig()
level = logging.INFO
if kwargs["debug"]:
level = logging.DEBUG
Expand Down

0 comments on commit 7edb63f

Please sign in to comment.