From 1c6e8b363be27dc2b66d6200bccadd810cb9d8e3 Mon Sep 17 00:00:00 2001 From: Malte Bublitz Date: Sun, 15 Oct 2023 18:02:31 +0200 Subject: [PATCH] Added a FIFO bridge --- fifo_bridge.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 fifo_bridge.py diff --git a/fifo_bridge.py b/fifo_bridge.py new file mode 100755 index 0000000..d5535c6 --- /dev/null +++ b/fifo_bridge.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +import os +import sys +import time +import mapid + + +FIFO = "/tmp/mapid.fifo" + + +def main(): + global FIFO + if len(sys.argv) == 2: + FIFO = sys.argv[1] + + m = mapid.MAPIDCP() + + os.mkfifo(FIFO) + time.sleep(0.2) + print("Created FIFO " + FIFO, file=sys.stderr) + # f = open(FIFO, "w") + # f.write("\n") + # f.close() + # print("Created FIFO " + FIFO, file=sys.stderr) + f = open(FIFO, "r") + print("Opened FIFO for reading", file=sys.stderr) + m.cls() + m.line(1) + m.echo("fifo_bridge.py") + m.line(2) + m.echo(FIFO) + + keep_going = True + while keep_going: + try: + line = f.readline().strip("\n") + m._cmd(line) + except KeyboardInterrupt: + keep_going = False + print() + + os.remove(FIFO) + print("Removed FIFO.", file=sys.stderr) + + +if __name__ == "__main__": + main() +