def main(): """Parse command line options """ usage = "usage: %(prog)s [options]" parser = ArgumentParser( prog='pydylogger', usage=usage, ) #formatter_class=RawTextHelpFormatter) tw = TextWrapper() mywrap = lambda x: "\n".join(tw.wrap(x)) tw.width = 80 - 25 # parser.add_argument('arglist', nargs='*', default=list(), help='N/A') parser.add_argument('-t', '--translate', action="store_true", \ dest="translate", default=False, help="Print human readable " \ "packets. Default: %(default)s") parser.add_argument('-a', '--all', action="store_true", \ dest="saveall", default=False, help="Optionally save all bytes/" \ "packets, including malformed packets. Default: %(default)s") parser.add_argument('-o', '--output', action="store", \ dest="output", default="logging_output.txt", help="Specify output " \ "file for log of packets. Default: %(default)s") # options = parser.parse_args() args = options.arglist # TODO get rid of these globals... global saveall global translate saveall = options.saveall translate = options.translate global port global baud global timing global id_dict cfg = PyDyConfigParser() cfg.read() port, baud, __, timing, __ = cfg.get_params() id_dict = cfg.get_id_to_device_dict() if saveall: print "All packets (including bad packets) will be saved in " \ "{0}".format(options.output) if translate: print "Packets will be translated for listing in this window." logger_method(outputfile=options.output) return
def main(): """Parse command line options """ usage = "usage: %(prog)s [options]" parser = ArgumentParser(prog='pydylogger', usage=usage, )#formatter_class=RawTextHelpFormatter) tw = TextWrapper() mywrap = lambda x: "\n".join(tw.wrap(x)) tw.width = 80 - 25 # parser.add_argument('arglist', nargs='*', default=list(), help='N/A') parser.add_argument('-t', '--translate', action="store_true", \ dest="translate", default=False, help="Print human readable " \ "packets. Default: %(default)s") parser.add_argument('-a', '--all', action="store_true", \ dest="saveall", default=False, help="Optionally save all bytes/" \ "packets, including malformed packets. Default: %(default)s") parser.add_argument('-o', '--output', action="store", \ dest="output", default="logging_output.txt", help="Specify output " \ "file for log of packets. Default: %(default)s") # options = parser.parse_args() args = options.arglist # TODO get rid of these globals... global saveall global translate saveall = options.saveall translate = options.translate global port global baud global timing global id_dict cfg = PyDyConfigParser() cfg.read() port, baud, __, timing, __ = cfg.get_params() id_dict = cfg.get_id_to_device_dict() if saveall: print "All packets (including bad packets) will be saved in " \ "{0}".format(options.output) if translate: print "Packets will be translated for listing in this window." logger_method(outputfile=options.output) return
def show_cmd(myid=None): """ """ # Get values from PyDyConfigParser: cfg = PyDyConfigParser() cfg.read() __, __, default_device_type, __, __ = cfg.get_params() dictCmd = device_dict[default_device_type] print "\nPrinting the command set for default device ({0}):".format(default_device_type) print "" print "In command line arguments (-c), enter the number value in column 2" print "\nCommand: Value: valid range" for key in dictCmd: if dictCmd[key][0][:3] != "BAD": # Suppress BAD entries print " {0:24}0x{1:<4X}{1:<4}{2:>8}".format(dictCmd[key][0], key, dictCmd[key][1]) return
from pydypackets import PyDyPackets from pydypackets.PyDyConfig import PyDyConfigParser cfg = PyDyConfigParser() cfg.read() port, baud, __, timing, __ = cfg.get_params() id_dict = cfg.get_id_to_device_dict() def test_vals_split_and_translate_runs(): # Ping packet for servo id 0C. testpacket = [0xff, 0xff, 0x0c, 0x02, 0x01, 0xec] PyDyPackets.vals_split_and_translate(testpacket, 2, id_dict) def test_vals_split_and_translate_keyerr(): # should fail due to lack of a servo with ID FC. testpacket = [0xff, 0xff, 0xfc, 0x02, 0x01, 0xec] PyDyPackets.vals_split_and_translate(testpacket, 2, id_dict)
def main(): """Parse command line options """ usage = "usage: %(prog)s [raw-input-file [options] ]\n" \ "Program will filter and/or translate supplied raw packets.\n" parser = ArgumentParser(prog='pydyparser', usage=usage, formatter_class=RawTextHelpFormatter) tw = TextWrapper() mywrap = lambda x: "\n".join(tw.wrap(x)) tw.width = 80 - 25 quicktext = "\n".join(["\n".join(tw.wrap(_)) for _ in ( "Arg(s) will be concatenated and treated as " "a single packet and then parsed. Input should be space-delimited " "bytes. 0xff, 255, and \\xff styles are all supported. " "If using the latter, space delimiting is optional, but you must " "wrap the sequence of bytes in quotes " "(or escape the backslashes).\n\n" "Example usage:" "\n$ pydyparser -q 255 255 12 7 3 30 0 2 0 2 195" "\n$ pydyparser -q 0xFF 0xFF 0x0C 0x07 0x03 0x1E 0x00 0x02 0x00 0x02 0xC3" "\n$ pydyparser -q \"\\xFF\\xFF\\x0C\\x07\\x03\\x1E\\x00\\x02\\x00\\x02\\xC3\"" "\n$ pydyparser -q \"\\xFF \\xFF \\x0C \\x07 \\x03 \\x1E \\x00 \\x02 \\x00 \\x02 \\xC3\"" "\n\nThese all produce output:\n" " ['ID: 12', 'write data', 'GOAL_POSITION_L ', 'Val: 512', " "'GOAL_SPEED_L', 'Val: 512', 'invalid checksum c3 (actual c9)']").splitlines()]) # parser.add_argument('arglist', nargs='*', default=list(), help=mywrap("Path to a file to parse/translate, or list of bytes " "to parse/translate if using -q flag.")) parser.add_argument('-q', '--quick', action="store_true", dest="quick", default=False, help=quicktext) parser.add_argument('-s', '--servos', action="store", dest="my_f_id", default=None, help=mywrap("A single integer " "or set of comma separated integers for servo IDs to keep " "when filtering; e.g. '-s 1,2,3'.\nDefault: %(default)s")) parser.add_argument('-i', '--instructions', action="store", dest="my_f_instr", default=None, help=mywrap("A single integer " "or set of comma separated integers for instructions to keep " "when filtering; e.g. '-i 1,2,3'.\nDefault: %(default)s")) parser.add_argument('-c', '--commands', action="store", dest="my_f_cmd", default=None, help=mywrap("A single integer " "or set of comma separated integers for commands to keep " "when filtering; e.g. '-c 1,2,3'.\nDefault: %(default)s")) parser.add_argument('-o', '--output', action="store", dest="output", default="filtered_out.txt", help=mywrap("Specify " "output file for filtered list of packets. (do `-o ''` to prevent " "output creation.) Default: %(default)s")) parser.add_argument('-t', '--translate', action="store_true", dest="translate", default=False, help=mywrap("Write filtered " "packets in human-readable form.\nDefault: %(default)s")) parser.add_argument('--time', action="store_true", dest="timestamp", default=None, help=mywrap("Appends timestamps " "to end of each translated packet (if timestamps exist). " "Default: %(default)s")) parser.add_argument('-T', '--Tally', action="store", dest="my_tally_by", default=None, help=mywrap("Tally filtered " "packets by command (cmd), instruction (instr) or servo ID (id). " "E.g.: '-T id'. Default: %(default)s")) parser.add_argument('-S', '--SyncWrite', action="store_true", dest="sync_split", default=None, help=mywrap("Split up sync-write " "packets when filtering to look for contents satisfying other " "criteria. Can also be used just to create individual packets. " "Default: %(default)s")) # options = parser.parse_args() args = options.arglist if len(args) == 0: print "Command line use requires the name of a file with a packet " \ "log. (Or a string of bytes if using --quick option.)\n" \ "Use the -h option for more help." return cfg = PyDyConfigParser() cfg.read() __, __, __, __, itit = cfg.get_params() id_dict = cfg.get_id_to_device_dict() if options.timestamp is None: options.timestamp = itit do_filtering(options, args, id_dict) return
from pydypackets import PyDyPackets from pydypackets.PyDyConfig import PyDyConfigParser cfg = PyDyConfigParser() cfg.read() port, baud, __, timing, __ = cfg.get_params() id_dict = cfg.get_id_to_device_dict() def test_vals_split_and_translate_runs(): # Ping packet for servo id 0C. testpacket = [0xff, 0xff, 0x0c, 0x02, 0x01, 0xec] PyDyPackets.vals_split_and_translate(testpacket, 2, id_dict) def test_vals_split_and_translate_keyerr(): # should fail due to lack of a servo with ID FC. testpacket = [0xff, 0xff, 0xfc, 0x02, 0x01, 0xec] PyDyPackets.vals_split_and_translate(testpacket, 2, id_dict)