From f1e83d938b09b23c7b2703f68a65435c86f63547 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 14 Mar 2019 09:33:58 -0400 Subject: [PATCH 1/2] Add carrier detect to autocons sample For genesis, not necessarily relevant, but may be very relevant for OS behaviors in other contexts. --- misc/autocons.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/misc/autocons.py b/misc/autocons.py index 5c5bf127..ebd13466 100644 --- a/misc/autocons.py +++ b/misc/autocons.py @@ -1,3 +1,4 @@ +import fcntl import os import struct import termios @@ -46,6 +47,8 @@ def do_serial_config(): currattr = termios.tcgetattr(ttyf) currattr[4:6] = [0, termiobaud[retval['speed']]] termios.tcsetattr(ttyf, termios.TCSANOW, currattr) + retval['connected'] = bool(struct.unpack(' Date: Thu, 14 Mar 2019 13:05:59 -0400 Subject: [PATCH 2/2] Update to follow DCD The DCD signal can be used to detect remote connect attempt --- misc/autocons.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/misc/autocons.py b/misc/autocons.py index ebd13466..4b6555a0 100644 --- a/misc/autocons.py +++ b/misc/autocons.py @@ -1,7 +1,10 @@ import fcntl import os +import signal import struct +import subprocess import termios +import time addrtoname = { 0x3f8: '/dev/ttyS0', @@ -49,12 +52,39 @@ def do_serial_config(): termios.tcsetattr(ttyf, termios.TCSANOW, currattr) retval['connected'] = bool(struct.unpack(' {0} >&0 2>&1'.format(serialinfo['tty'])) + running = False + while True: + if running and running.poll() is not None: + running = False + if running and not is_connected(serialinfo['tty']): + try: + running.terminate() + running.wait() + except Exception: + pass + time.sleep(0.5) + running = subprocess.Popen(['/bin/sh', '-c', 'exec screen -x console <> {0} >&0 2>&1'.format(serialinfo['tty'])]) + time.sleep(0.5) + try: + running.terminate() + running.wait() + except Exception: + pass + running = False + elif not running and is_connected(serialinfo['tty']): + running = subprocess.Popen(['/bin/sh', '-c', 'exec screen -x console <> {0} >&0 2>&1'.format(serialinfo['tty'])]) + time.sleep(0.5)