110 lines
3.7 KiB
Python
110 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Debug script for the custom IR protocol decoder
|
|
"""
|
|
|
|
import json
|
|
import sys
|
|
import os
|
|
from custom_ir_protocol import CustomIRProtocol
|
|
|
|
def debug_single_signal():
|
|
"""Debug a single 71-pulse signal in detail"""
|
|
|
|
# Load captured signals
|
|
with open("ir_analysis_20250927_190536.json", 'r') as f:
|
|
signals = json.load(f)
|
|
|
|
# Get first 71-pulse signal
|
|
signal = None
|
|
for s in signals:
|
|
if s['pulse_count'] == 71:
|
|
signal = s
|
|
break
|
|
|
|
if not signal:
|
|
print("No 71-pulse signal found!")
|
|
return
|
|
|
|
# Create custom protocol decoder
|
|
protocol = CustomIRProtocol("DEBUG_CUSTOM")
|
|
|
|
print("Debugging 71-pulse signal:")
|
|
print("=" * 50)
|
|
|
|
pulses = signal['pulses']
|
|
print(f"Total pulses: {len(pulses)}")
|
|
print()
|
|
|
|
# Convert to the format expected by the decoder
|
|
formatted_pulses = []
|
|
for j, duration_us in enumerate(pulses):
|
|
is_pulse = (j % 2 == 0) # Alternating pulse/space
|
|
duration_seconds = duration_us / 1000000.0
|
|
formatted_pulses.append((is_pulse, duration_seconds))
|
|
|
|
# Convert to microseconds for analysis
|
|
pulse_times = [duration * 1000000 for _, duration in formatted_pulses]
|
|
|
|
print("Header analysis:")
|
|
if len(pulse_times) >= 2:
|
|
header_pulse = pulse_times[0]
|
|
header_space = pulse_times[1]
|
|
print(f" Header pulse: {header_pulse:.0f}μs (expected: {protocol.HEADER_PULSE}μs)")
|
|
print(f" Header space: {header_space:.0f}μs (expected: {protocol.HEADER_SPACE}μs)")
|
|
print(f" Header pulse match: {protocol._is_timing_match(header_pulse, protocol.HEADER_PULSE)}")
|
|
print(f" Header space match: {protocol._is_timing_match(header_space, protocol.HEADER_SPACE)}")
|
|
print()
|
|
|
|
# Find data end
|
|
data_end = protocol._find_data_end(pulse_times[2:])
|
|
print(f"Data end found at index: {data_end}")
|
|
print(f"Data section length: {data_end} pulses")
|
|
print()
|
|
|
|
# Analyze data bits
|
|
if data_end:
|
|
data_pulses = pulse_times[2:2+data_end]
|
|
print(f"Data pulses to analyze: {len(data_pulses)}")
|
|
print()
|
|
|
|
print("First 10 data bit pairs:")
|
|
for i in range(0, min(20, len(data_pulses)), 2):
|
|
if i + 1 < len(data_pulses):
|
|
pulse_time = data_pulses[i]
|
|
space_time = data_pulses[i + 1]
|
|
|
|
pulse_match = protocol._is_timing_match(pulse_time, protocol.BIT_PULSE)
|
|
space_0_match = protocol._is_timing_match(space_time, protocol.BIT_0_SPACE)
|
|
space_1_match = protocol._is_timing_match(space_time, protocol.BIT_1_SPACE)
|
|
|
|
bit_value = "?"
|
|
if space_0_match:
|
|
bit_value = "0"
|
|
elif space_1_match:
|
|
bit_value = "1"
|
|
|
|
print(f" Bit {i//2}: {pulse_time:.0f}μs pulse, {space_time:.0f}μs space -> {bit_value}")
|
|
print(f" Pulse match: {pulse_match}, Space 0 match: {space_0_match}, Space 1 match: {space_1_match}")
|
|
|
|
print()
|
|
|
|
# Try to decode
|
|
print("Attempting decode...")
|
|
address, command = protocol._decode_data_bits(data_pulses)
|
|
print(f"Decode result: address={address}, command={command}")
|
|
|
|
if address is not None and command is not None:
|
|
result = f"CUSTOM_{address:04X}_{command:04X}"
|
|
print(f"Final result: {result}")
|
|
else:
|
|
print("Decode failed!")
|
|
|
|
# Try the full decode
|
|
print("\nFull decode attempt:")
|
|
result = protocol.decode(formatted_pulses)
|
|
print(f"Full decode result: {result}")
|
|
|
|
if __name__ == "__main__":
|
|
debug_single_signal()
|