当前位置: 首页>>代码示例>>Python>>正文


Python Decoder.getdfs方法代码示例

本文整理汇总了Python中decoder.Decoder.getdfs方法的典型用法代码示例。如果您正苦于以下问题:Python Decoder.getdfs方法的具体用法?Python Decoder.getdfs怎么用?Python Decoder.getdfs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在decoder.Decoder的用法示例。


在下文中一共展示了Decoder.getdfs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: capture

# 需要导入模块: from decoder import Decoder [as 别名]
# 或者: from decoder.Decoder import getdfs [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)
开发者ID:ltj,项目名称:wsncapture,代码行数:72,代码来源:linkcap.py


注:本文中的decoder.Decoder.getdfs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。