Ejemplo n.º 1
0
def run(options):
    ser = serial.Serial(options.port, options.baud, timeout=options.timeout)

    logger = logging.getLogger("root")
    logger.setLevel(logging.INFO)
    formatter = SerialLoggerFormatter(uscgFormat=options.uscgFormat, mark=options.mark, stationId=options.stationId)

    prologue = "# START LOGGING UTC seconds since the epoch: %(created)f\n"
    prologue += "# SPEED:       " + str(options.baud) + "\n"
    prologue += "# PORT:        " + str(options.port) + "\n"
    prologue += "# TIMEOUT:     " + str(options.timeout) + "\n"
    prologue += "# STATIONID:   " + str(options.stationId) + "\n"
    prologue += "# DAEMON MODE: " + str(options.daemonMode) + "\n"
    # getlogin is not happy as a daemon
    # prologue+='# USER:        '******'\n'
    epilogue = "# STOP LOGGING UTC seconds since the epoch: %(created)f\n"
    rollover = "# Log roll over\n"
    fh = MidnightRotatingFileHandler(options.log_prefix, epilogue=epilogue, prologue=prologue, rollover=rollover)
    fh.setFormatter(formatter)
    logger.addHandler(fh)

    if options.tcpOutput:
        ptsh = PassThroughServerHandler(options)
        ptsh.setFormatter(formatter)
        logger.addHandler(ptsh)

    if options.udpTarget is not None and ":" in options.udpTarget:
        uaddr, uport = options.udpTarget.split(":", 1)
        uport = int(uport)
        uaddr = (uaddr, uport)
        udpSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        udpSocket.connect(uaddr)
    else:
        udpSocket = None

    if not options.daemonMode:
        ch = logging.StreamHandler()
        ch.setFormatter(formatter)
        logger.addHandler(ch)

    while True:
        # import time
        # time.sleep(5)
        # logger.info("hello")
        line = ser.readline().strip()
        logger.info(line)
        if udpSocket is not None:
            try:
                udpSocket.send(line + "\r\n")
            except:
                pass
Ejemplo n.º 2
0
def run(options):
    ser = serial.Serial(options.port, options.baud, timeout=options.timeout)

    logger = logging.getLogger("root")
    logger.setLevel(logging.INFO)
    formatter = SerialLoggerFormatter(uscgFormat=options.uscgFormat,
                                      mark=options.mark,
                                      stationId=options.stationId)

    prologue = '# START LOGGING UTC seconds since the epoch: %(created)f\n'
    prologue += '# SPEED:       ' + str(options.baud) + '\n'
    prologue += '# PORT:        ' + str(options.port) + '\n'
    prologue += '# TIMEOUT:     ' + str(options.timeout) + '\n'
    prologue += '# STATIONID:   ' + str(options.stationId) + '\n'
    prologue += '# DAEMON MODE: ' + str(options.daemonMode) + '\n'
    # getlogin is not happy as a daemon
    #prologue+='# USER:        '******'\n'
    epilogue = '# STOP LOGGING UTC seconds since the epoch: %(created)f\n'
    rollover = "# Log roll over\n"
    fh = MidnightRotatingFileHandler(options.log_prefix,
                                     epilogue=epilogue,
                                     prologue=prologue,
                                     rollover=rollover)
    fh.setFormatter(formatter)
    logger.addHandler(fh)

    if options.tcpOutput:
        ptsh = PassThroughServerHandler(options)
        ptsh.setFormatter(formatter)
        logger.addHandler(ptsh)

    if not options.daemonMode:
        ch = logging.StreamHandler()
        ch.setFormatter(formatter)
        logger.addHandler(ch)

    while True:
        # import time
        # time.sleep(5)
        # logger.info("hello")
        line = ser.readline().strip()
        logger.info(line)
Ejemplo n.º 3
0
def run(options):
    ser = serial.Serial(options.port, options.baud, timeout=options.timeout)

    logger = logging.getLogger("root")
    logger.setLevel(logging.INFO)
    formatter = SerialLoggerFormatter(uscgFormat=options.uscgFormat,
                                      mark=options.mark,
                                      stationId=options.stationId)

    prologue = '# START LOGGING UTC seconds since the epoch: %(created)f\n'
    prologue+='# SPEED:       ' + str(options.baud)+'\n'
    prologue+='# PORT:        ' + str(options.port)+'\n'
    prologue+='# TIMEOUT:     ' + str(options.timeout)+'\n'
    prologue+='# STATIONID:   ' + str(options.stationId)+'\n'
    prologue+='# DAEMON MODE: ' + str(options.daemonMode)+'\n'
    # getlogin is not happy as a daemon
    #prologue+='# USER:        '******'\n'
    epilogue = '# STOP LOGGING UTC seconds since the epoch: %(created)f\n'
    rollover = "# Log roll over\n"
    fh = MidnightRotatingFileHandler(options.log_prefix,
                                     epilogue=epilogue,
                                     prologue=prologue,
                                     rollover=rollover)
    fh.setFormatter(formatter)
    logger.addHandler(fh)

    if options.tcpOutput:
        ptsh = PassThroughServerHandler(options)
        ptsh.setFormatter(formatter)
        logger.addHandler(ptsh)

    if not options.daemonMode:
        ch = logging.StreamHandler()
        ch.setFormatter(formatter)
        logger.addHandler(ch)

    while True:
        # import time
        # time.sleep(5)
        # logger.info("hello")
        line = ser.readline().strip()
        logger.info(line)