#!/usr/bin/env python3 """ Filter converting printable input of pulse/space such as generated by mode2(1) to the binary representation used by the udp driver. Valid input lines looks like pulse 12345 space 23456 All other type of input is silently ignored. Lengths are in microsecods. """ import argparse import os import struct import sys import config def irtext2udp(file_, resolution): """ Convert pulse/space printable data to udp driver binary format. """ for line in file_: parts = line.split() if len(parts) != 2 or not parts[0] in ["pulse", "space"]: continue try: duration = int(parts[1]) except ValueError: continue ticks = int(duration / resolution) if ticks < (1 << 15): payload = ticks if parts[0].startswith('pulse'): payload += (1 << 15) buf = struct.pack('