summary history branches tags files
commit:a6e84ccf90226f0e4719e58413fe95c54fd1ec5b
author:Trevor Bentley
committer:Trevor Bentley
date:Wed Oct 22 23:58:31 2025 +0200
parents:5f6dcc4e88a59c7d7524285c03b5c73dee5dcfdb
add folding cli arguments and documentation
diff --git a/saleae_usb_pcap.py b/saleae_usb_pcap.py
line changes: +31/-4
index 1c2d86c..b4433a9
--- a/saleae_usb_pcap.py
+++ b/saleae_usb_pcap.py
@@ -32,6 +32,7 @@ import csv
 import os
 import struct
 import sys
+import textwrap
 
 from datetime import datetime
 from enum import Enum
@@ -355,12 +356,38 @@ def csv_to_pcap(csvfile, pcapfile, unfolded=False, fold_over_sof=False, fold_max
 
 
 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__":