r4722 - developers/werner/neocon

werner at docs.openmoko.org werner at docs.openmoko.org
Sat Oct 18 01:34:19 CEST 2008


Author: werner
Date: 2008-10-18 01:34:17 +0200 (Sat, 18 Oct 2008)
New Revision: 4722

Modified:
   developers/werner/neocon/README
   developers/werner/neocon/neocon.c
Log:
Add manual switch to next device with ~n to solve problem of dead or useless
devices on which we get stuck because they don't generate an error.

- neocon.c (scan): use pointer instead of index (beautification)
- neocon.c (scan, copy), README: let user manually switch to next line with ~n
- neocon.c (open_first_tty, main): select next tty instead of first, rename
  open_first_tty accordingly
- neocon.c (main): print device name when opening a tty
- README: the lockup issue has already been resolved a while ago



Modified: developers/werner/neocon/README
===================================================================
--- developers/werner/neocon/README	2008-10-17 23:32:18 UTC (rev 4721)
+++ developers/werner/neocon/README	2008-10-17 23:34:17 UTC (rev 4722)
@@ -20,12 +20,10 @@
 To leave neocon, type "~.". The escape character (~) can be changed
 with the option "-e escape".
 
+To manually switch to the next device, enter "~n".
 
+
 Known issues
 ------------
 
-Sometimes, the USB stack locks up without neocon ever noticing.
-To reproduce:
-
-- neocon with ttyACM* to u-boot
-- in u-boot, reset
+- the escape character is sent to the target

Modified: developers/werner/neocon/neocon.c
===================================================================
--- developers/werner/neocon/neocon.c	2008-10-17 23:32:18 UTC (rev 4721)
+++ developers/werner/neocon/neocon.c	2008-10-17 23:34:17 UTC (rev 4722)
@@ -37,6 +37,7 @@
 
 static char *const *ttys;
 static int num_ttys;
+static int curr_tty = -1; /* start with first tty */
 static speed_t speed = B115200;
 static struct termios console, tty;
 static FILE *log = NULL;
@@ -112,12 +113,13 @@
 }
 
 
-static int open_first_tty(void)
+static int open_next_tty(void)
 {
     int i, fd = -1;
 
     for (i = 0; i != num_ttys; i++) {
-	fd = open(ttys[i], O_RDWR | O_NDELAY);
+	curr_tty = (curr_tty+1) % num_ttys;
+	fd = open(ttys[curr_tty], O_RDWR | O_NDELAY);
 	if (fd >= 0)
 	    break;
     }
@@ -127,25 +129,34 @@
 }
 
 
-static void scan(const char *s, size_t len)
+/*
+ * Return 1 if the user manually forces a device change.
+ */
+
+
+static int scan(const char *s, size_t len)
 {
     static int state = 0;
-    size_t i;
+    const char *p;
+    int res = 0;
 
-    for (i = 0; i != len; i++)
+    for (p = s; p != s+len; p++)
 	switch (state) {
 	    case 0:
-		if (s[i] == escape)
+		if (*p == escape)
 		    state++;
 		else
 		    state = 0;
 		break;
 	    case 1:
-		if (s[i] == '.')
+		if (*p == '.')
 		    exit(0);
+		if (*p == 'n')
+		    res = 1;
 		state = 0;
 		break;
 	}
+    return res;
 }
 
 
@@ -217,15 +228,18 @@
 {
     char buffer[MAX_BUF];
     ssize_t got, wrote, pos;
- 
+
     got = read(in, buffer, single ? 1 : sizeof(buffer));
     if (got <= 0)
 	return 0;
-    if (from_user)
-	scan(buffer, got);
-    else
+    if (from_user) {
+	if (scan(buffer, got))
+	    return 0;
+    }
+    else {
 	if (log)
 	    do_log(buffer, got);
+    }
     for (pos = 0; pos != got; pos += wrote) {
 	wrote = write(out, buffer+pos, got-pos);
 	if (wrote < 0)
@@ -257,6 +271,7 @@
 {
     if (tcsetattr(0, TCSANOW, &console) < 0)
 	perror("tcsetattr");
+    write(1, "\n", 1);
 }
 
 
@@ -335,9 +350,13 @@
 	int res;
 
 	if (fd < 0) {
-	    fd = open_first_tty();
-	    if (fd > 0)
-		write_string("\r\n[Open]\r\n");
+	    fd = open_next_tty();
+	    if (fd > 0) {
+		char buf[1024]; /* enough :-) */
+
+		sprintf(buf, "\r\r[Open %s]\r\n", ttys[curr_tty]);
+		write_string(buf);
+	    }
 	}
 	FD_ZERO(&set);
 	if (!throttle)




More information about the commitlog mailing list