mirror of https://github.com/Desuuuu/klipper.git
avrsim: migrated to Python 3
Note that the latest simulavr 1.1.0 does not support Python 2 anymore. Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
This commit is contained in:
parent
063f9a2c02
commit
054762da3d
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python3
|
||||||
# Script to interact with simulavr by simulating a serial port.
|
# Script to interact with simulavr by simulating a serial port.
|
||||||
#
|
#
|
||||||
# Copyright (C) 2015-2018 Kevin O'Connor <kevin@koconnor.net>
|
# Copyright (C) 2015-2018 Kevin O'Connor <kevin@koconnor.net>
|
||||||
|
@ -17,7 +17,7 @@ class SerialRxPin(pysimulavr.PySimulationMember, pysimulavr.Pin):
|
||||||
pysimulavr.PySimulationMember.__init__(self)
|
pysimulavr.PySimulationMember.__init__(self)
|
||||||
self.terminal = terminal
|
self.terminal = terminal
|
||||||
self.sc = pysimulavr.SystemClock.Instance()
|
self.sc = pysimulavr.SystemClock.Instance()
|
||||||
self.delay = SIMULAVR_FREQ / baud
|
self.delay = SIMULAVR_FREQ // baud
|
||||||
self.current = 0
|
self.current = 0
|
||||||
self.pos = -1
|
self.pos = -1
|
||||||
def SetInState(self, pin):
|
def SetInState(self, pin):
|
||||||
|
@ -33,7 +33,7 @@ class SerialRxPin(pysimulavr.PySimulationMember, pysimulavr.Pin):
|
||||||
if self.pos == 1:
|
if self.pos == 1:
|
||||||
return int(self.delay * 1.5)
|
return int(self.delay * 1.5)
|
||||||
if self.pos >= SERIALBITS:
|
if self.pos >= SERIALBITS:
|
||||||
data = chr((self.current >> 1) & 0xff)
|
data = bytearray(((self.current >> 1) & 0xff,))
|
||||||
self.terminal.write(data)
|
self.terminal.write(data)
|
||||||
self.pos = -1
|
self.pos = -1
|
||||||
self.current = 0
|
self.current = 0
|
||||||
|
@ -48,10 +48,10 @@ class SerialTxPin(pysimulavr.PySimulationMember, pysimulavr.Pin):
|
||||||
self.terminal = terminal
|
self.terminal = terminal
|
||||||
self.SetPin('H')
|
self.SetPin('H')
|
||||||
self.sc = pysimulavr.SystemClock.Instance()
|
self.sc = pysimulavr.SystemClock.Instance()
|
||||||
self.delay = SIMULAVR_FREQ / baud
|
self.delay = SIMULAVR_FREQ // baud
|
||||||
self.current = 0
|
self.current = 0
|
||||||
self.pos = 0
|
self.pos = 0
|
||||||
self.queue = ""
|
self.queue = b""
|
||||||
self.sc.Add(self)
|
self.sc.Add(self)
|
||||||
def DoStep(self, trueHwStep):
|
def DoStep(self, trueHwStep):
|
||||||
if not self.pos:
|
if not self.pos:
|
||||||
|
@ -60,7 +60,7 @@ class SerialTxPin(pysimulavr.PySimulationMember, pysimulavr.Pin):
|
||||||
if not data:
|
if not data:
|
||||||
return self.delay * 100
|
return self.delay * 100
|
||||||
self.queue += data
|
self.queue += data
|
||||||
self.current = (ord(self.queue[0]) << 1) | 0x200
|
self.current = (self.queue[0] << 1) | 0x200
|
||||||
self.queue = self.queue[1:]
|
self.queue = self.queue[1:]
|
||||||
newstate = 'L'
|
newstate = 'L'
|
||||||
if self.current & (1 << self.pos):
|
if self.current & (1 << self.pos):
|
||||||
|
@ -109,7 +109,7 @@ class Pacing(pysimulavr.PySimulationMember):
|
||||||
self.next_check_clock = 0
|
self.next_check_clock = 0
|
||||||
self.rel_time = time.time()
|
self.rel_time = time.time()
|
||||||
self.best_offset = 0.
|
self.best_offset = 0.
|
||||||
self.delay = SIMULAVR_FREQ / 10000
|
self.delay = SIMULAVR_FREQ // 10000
|
||||||
self.sc.Add(self)
|
self.sc.Add(self)
|
||||||
def DoStep(self, trueHwStep):
|
def DoStep(self, trueHwStep):
|
||||||
curtime = time.time()
|
curtime = time.time()
|
||||||
|
@ -135,7 +135,7 @@ class TerminalIO:
|
||||||
def read(self):
|
def read(self):
|
||||||
try:
|
try:
|
||||||
return os.read(self.fd, 64)
|
return os.read(self.fd, 64)
|
||||||
except os.error, e:
|
except os.error as e:
|
||||||
if e.errno not in (errno.EAGAIN, errno.EWOULDBLOCK):
|
if e.errno not in (errno.EAGAIN, errno.EWOULDBLOCK):
|
||||||
pysimulavr.SystemClock.Instance().stop()
|
pysimulavr.SystemClock.Instance().stop()
|
||||||
return ""
|
return ""
|
||||||
|
@ -198,7 +198,7 @@ def main():
|
||||||
trace = Tracing(options.tracefile, options.trace)
|
trace = Tracing(options.tracefile, options.trace)
|
||||||
dev = pysimulavr.AvrFactory.instance().makeDevice(proc)
|
dev = pysimulavr.AvrFactory.instance().makeDevice(proc)
|
||||||
dev.Load(elffile)
|
dev.Load(elffile)
|
||||||
dev.SetClockFreq(SIMULAVR_FREQ / speed)
|
dev.SetClockFreq(SIMULAVR_FREQ // speed)
|
||||||
sc.Add(dev)
|
sc.Add(dev)
|
||||||
pysimulavr.cvar.sysConHandler.SetUseExit(False)
|
pysimulavr.cvar.sysConHandler.SetUseExit(False)
|
||||||
trace.load_options()
|
trace.load_options()
|
||||||
|
|
Loading…
Reference in New Issue