/usr/bin/irtext2udp is in lirc 0.10.0-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | #! /usr/bin/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('<H', payload)
else:
payload = 0
if parts[0].startswith('pulse'):
payload += (1 << 15)
buf = struct.pack('<H', payload)
buf = struct.pack('<L', ticks)
os.write(1, buf)
def main():
""" Indeed: main function. """
parser = argparse.ArgumentParser()
parser.add_argument(
"-r", "--resolution", "--clocktick", default=1000000 / 16384,
type=int, help="Resolution (us per tick ), see irtext2udp(1).")
parser.add_argument(
"-v", "--version", action="store_true", help="Print version.")
parser.add_argument(
'infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
args = parser.parse_args()
if args.version:
print(config.VERSION)
sys.exit(0)
irtext2udp(args.infile, args.resolution)
if __name__ == "__main__":
main()
|