summaryrefslogtreecommitdiffstats
path: root/scripts/remote/threadstdio.py
diff options
context:
space:
mode:
authorJan Luebbe <jlu@pengutronix.de>2015-06-05 09:18:56 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2016-01-18 09:25:50 +0100
commitbe6c6e653683e86d4c7aeb2b67c62ec0895befa3 (patch)
tree16de4d407994470101aed97834a4b6249f4952cd /scripts/remote/threadstdio.py
parent06fc3557c94c2b9d43bcfab72f4a024c7860be64 (diff)
downloadbarebox-be6c6e653683e86d4c7aeb2b67c62ec0895befa3.tar.gz
barebox-be6c6e653683e86d4c7aeb2b67c62ec0895befa3.tar.xz
host side for barebox remote control
This contains the host tool for barebox remote control. It is written in Phython with its own implementation of the RATP protocol. Currently this is a very simple tool which needs more work, but the code can also be used as a library. Example output: console: '. ' console: '.. ' console: 'dev ' console: 'env ' console: 'mnt ' console: '\n' Result: BBPacketCommandReturn(exit_code=0) Signed-off-by: Jan Lübbe <j.luebbe@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Tested-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Diffstat (limited to 'scripts/remote/threadstdio.py')
-rw-r--r--scripts/remote/threadstdio.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/scripts/remote/threadstdio.py b/scripts/remote/threadstdio.py
new file mode 100644
index 0000000000..db249892ac
--- /dev/null
+++ b/scripts/remote/threadstdio.py
@@ -0,0 +1,47 @@
+#!/usr/bin/python2
+
+import os
+import sys
+import termios
+import atexit
+from threading import Thread
+from Queue import Queue, Empty
+
+class ConsoleInput(Thread):
+ def __init__(self, queue, exit='\x14'):
+ Thread.__init__(self)
+ self.daemon = True
+ self.q = queue
+ self._exit = exit
+ self.fd = sys.stdin.fileno()
+ old = termios.tcgetattr(self.fd)
+ new = termios.tcgetattr(self.fd)
+ new[3] = new[3] & ~termios.ICANON & ~termios.ECHO & ~termios.ISIG
+ new[6][termios.VMIN] = 1
+ new[6][termios.VTIME] = 0
+ termios.tcsetattr(self.fd, termios.TCSANOW, new)
+
+ def cleanup():
+ termios.tcsetattr(self.fd, termios.TCSAFLUSH, old)
+ atexit.register(cleanup)
+
+ def run(self):
+ while True:
+ c = os.read(self.fd, 1)
+ if c == self._exit:
+ self.q.put((self, None))
+ return
+ else:
+ self.q.put((self, c))
+
+if __name__ == "__main__":
+ q = Queue()
+ i = ConsoleInput(q)
+ i.start()
+ while True:
+ event = q.get(block=True)
+ src, c = event
+ if c == '\x04':
+ break
+ os.write(sys.stdout.fileno(), c.upper())
+