Changeset 147 for misc


Ignore:
Timestamp:
Jul 14, 2010, 11:23:43 PM (14 years ago)
Author:
Rick van der Zwet
Message:

Better logging & debugging

File:
1 edited

Legend:

Unmodified
Added
Removed
  • misc/serial-sniffer.py

    r146 r147  
    44# sniffer (DIY schemes avaiable).
    55# HOST -> DEVICE at /dev/ttyUSB0 and DEVICE -> HOST at /dev/ttyUSB1
     6#
     7# NOTE: Use Cheap USB-to-Serial devices else you might run into trouble with
     8# 'smart' buffering and/or not clearing properly failing devices for example:
     9# - ID 0557:2008 ATEN International Co., Ltd UC-232A Serial Port [pl2303]
    610#
    711# $Id$
     
    1216import os
    1317import sys
     18
     19DEBUG = False
    1420
    1521# Stolen from http://snippets.dzone.com/posts/show/7682
     
    4147   return " ".join(["%02x" % ord(x) for x in s])
    4248
     49def perror(s):
     50   sys.stderr.write("[ERROR] %s\n" % s)
     51
     52def pdebug(s):
     53   if DEBUG:
     54     sys.stderr.write("[DEBUG] %s\n" % s)
     55
    4356def main():
    4457  while 1:
     
    4962    while send_buffer == "" or recv_buffer == "":
    5063      if send_buffer == "":
     64        pdebug("trying to read send_buffer")
    5165        while 1:
    5266          try:
    53             with Watchdog(3):
     67            with Watchdog(1):
    5468              send_buffer += send.read(1)
    5569          except Watchdog:
    5670            break
    5771      else:
    58          sys.stderr.write("# send_buffer filled %s" % str_to_hex(send_buffer))
     72         pdebug("send_buffer filled %s" % str_to_hex(send_buffer))
    5973 
    6074      if recv_buffer == "":
     75        pdebug("trying to read recv_buffer")
    6176        while 1:
    6277          try:
     
    6681            break
    6782      else:
    68          sys.stderr.write("# recv_buffer filled %s" % str_to_hex(recv_buffer))
     83         pdebug("recv_buffer filled %s" % str_to_hex(recv_buffer))
    6984 
    7085    # Try to fetch comment if we have any
Note: See TracChangeset for help on using the changeset viewer.