import struct def parse_saleae_analog(filepath): with open(filepath, 'rb') as f: # 1. Parse the Main Header # Format: < (little-endian), 8s (8-byte string), i (int32), i (int32), Q (uint64) header_data = f.read(24) # 8 + 4 + 4 + 8 bytes identifier, version, data_type, waveform_count = struct.unpack('<8s i i Q', header_data) print(f"Identifier: {identifier.decode('ascii', errors='ignore')}") print(f"Version: {version}") print(f"Type: {data_type}") print(f"Waveforms: {waveform_count}") print("-" * 20) # 2. Iterate through each waveform for w in range(waveform_count): # Parse Waveform Header # Format: <, d (double), d (double), d (double), q (int64), Q (uint64) wave_header_data = f.read(40) # 8 + 8 + 8 + 8 + 8 bytes begin_time, trigger_time, sample_rate, downsample, num_samples = struct.unpack(' threshold: bitstream.append('0') # Dominant else: bitstream.append('1') # Recessive print(f" First 50 raw digital bits: {''.join(bitstream[:50])}") # Run the parser parse_saleae_analog('./patched.bin')