Commit 894f031e78eb3f237f44a9069280f3a334f61937
authorMichel Pollet <buserror@gmail.com>
Thu, 5 Apr 2012 12:36:20 +0000 (13:36 +0100)
committerMichel Pollet <buserror@gmail.com>
Thu, 5 Apr 2012 12:36:20 +0000 (13:36 +0100)
You can now launch an xterm with picocom by setting environment
SIMAVR_UART_XTERM. This could (will) be improved.

Also, the uart_pty symlinks the pty pathname to /tmp/simavr-uart-X
so you can rely on a constant pathname.

Signed-off-by: Michel Pollet <buserror@gmail.com>
examples/parts/uart_pty.c

index b44282502c2b78516c766432ccef258f0a13a237..2f95e603c90e9a759f1a7f85f851c3a1d81a030f 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include <sys/select.h>
+#include <stdlib.h>
 #include <pthread.h>
 #include <string.h>
 #include <stdio.h>
@@ -183,5 +184,19 @@ void uart_pty_connect(uart_pty_t * p, char uart)
                avr_irq_register_notify(xon, uart_pty_xon_hook, p);
        if (xoff)
                avr_irq_register_notify(xoff, uart_pty_xoff_hook, p);
+
+       char link[128];
+       sprintf(link, "/tmp/simavr-uart%c", uart);
+       unlink(link);
+       if (symlink(p->slavename, link) != 0) {
+               fprintf(stderr, "WARN %s: Can't create %s: %s", __func__, link, strerror(errno));
+       } else {
+               printf("%s: %s now points to %s\n", __func__, link, p->slavename);
+       }
+       if (getenv("SIMAVR_UART_XTERM")) {
+               char cmd[256];
+               sprintf(cmd, "nohup xterm -e picocom -b 115200 %s >/dev/null 2>&1 &", p->slavename);
+               system(cmd);
+       }
 }