add folding cli arguments and documentation
import os
import struct
import sys
+import textwrap
from datetime import datetime
from enum import Enum
def main():
- parser = argparse.ArgumentParser()
- parser.add_argument('csv', help="input CSV file exported from Saleae Logic")
- parser.add_argument('pcap', help="output pcap file (will be overwritten)")
+ parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
+ description=textwrap.dedent("""
+ Takes a CSV file exported from Saleae Logic's USB analyzer in
+ 'bytes' decoder mode and outputs a pcapng file compatible with
+ Wireshark.
+
+ ----
+
+ By default, this script detects some duplicate packets or
+ combinations of packets and "folds" them into a "repeated X times"
+ syslog metadata packet to cut down on noise. This behavior can be
+ customized:
+
+ - Specify '--unfolded' to disable folding entirely and output
+ every individual packet identified.
+
+ - Specify '--fold-max' to change the maximum number of packets
+ that can be folded into one packet.
+
+ - Specify '--fold-over-sof' to allow folding to continue even if
+ when SOF packets are present in between. Otherwise very long
+ folds will be interrupted periodically by SOF packets.
+
+ ----
+ """))
+ parser.add_argument('csv_file', help="input CSV file exported from Saleae Logic")
+ parser.add_argument('pcap_file', help="output pcap file (will be overwritten)")
parser.add_argument('-u', '--unfolded', action='store_true', help="don't fold repeated events, output all packets")
+ parser.add_argument('-s', '--fold-over-sof', action='store_true', help="don't stop folding for SOF packets")
+ parser.add_argument('-m', '--fold-max', type=int, default=1024, help="maximum duplicate packets to fold into one (default: 1024)")
args = parser.parse_args()
- csv_to_pcap(args.csv, args.pcap, unfolded=args.unfolded)
+ csv_to_pcap(args.csv, args.pcap, unfolded=args.unfolded, fold_over_sof=args.fold_over_sof, fold_max=args.fold_max)
if __name__ == "__main__":