本文整理汇总了Python中decoder.Decoder.getreplay方法的典型用法代码示例。如果您正苦于以下问题:Python Decoder.getreplay方法的具体用法?Python Decoder.getreplay怎么用?Python Decoder.getreplay使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类decoder.Decoder
的用法示例。
在下文中一共展示了Decoder.getreplay方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: capture
# 需要导入模块: from decoder import Decoder [as 别名]
# 或者: from decoder.Decoder import getreplay [as 别名]
def capture(ser, log):
readbuf = []
# check if previous marker is present
if log.markerfile_present():
logging.info('previous marker found. replaying')
(logtime, marker) = log.get_marker()
(page, seq, secs, replay_cmd) = Decoder.getdfs(marker)
logging.debug("got replay cmd: " + replay_cmd)
ser.write(replay_cmd)
# replay loop
while True:
try:
if ser.inWaiting() > 0:
data = ser.readline()
if data[0] == 'R' or data[0:4] == 'DF R':
readbuf.append(data)
if data[0:4] == 'DF E': # end of replay
break
except serial.SerialException as e:
logging.error("Serial bridge %s: %s\n", ser.portstr, e)
sys.exit(1)
except IOError as e:
logging.error("Logger: %s\n", e)
sys.exit(1)
logging.info('replay ended. writing to log')
# log replays
(secs, packet) = Decoder.getreplay(readbuf[0])
prevsecs = secs
for line in readbuf:
if line[0] == 'R': # replay packet
(secs, packet) = Decoder.getreplay(line)
if secs < prevsecs:
offset = secs
else:
offset = secs - prevsecs
logtime = logtime + timedelta(seconds=offset)
log.append(packet, logtime)
prevsecs = secs
if line[0:4] == 'DF R': # replay marker
log.append(line, logtime)
logging.info('done writing replay data to log')
# Recording loop
logging.info('recording new packets')
while True:
try:
if ser.inWaiting() > 0:
line = ser.readline()
if line[0:2] == 'OK': # ok packet
log.append(line)
elif line[0:4] == 'DF S': # store marker
log.append(line)
break
except serial.SerialException as e:
logging.error("Serial bridge %s: %s\n", ser.portstr, e)
sys.exit(1)
except IOError as e:
logging.error("Logger: %s\n", e)
sys.exit(1)
except (KeyboardInterrupt, SystemExit):
break
time.sleep(0.01) # bad CPU 'nice' hack
ser.close()
logging.info("linkcap completed")
logging.shutdown()
sys.exit(0)