altos: Make cmd echo per-connection instead of global
authorKeith Packard <keithp@keithp.com>
Sat, 2 Apr 2011 00:25:07 +0000 (17:25 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 2 Apr 2011 00:25:07 +0000 (17:25 -0700)
Allow different connections to use different echo values, permitting
the packet link to turn off echo while the USB link still has it on.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/ao.h
src/ao_cmd.c
src/ao_stdio.c

index b92e623f040fb06741ada8978a544cede17c4d12..9b375894e0f20cd4c41aeaf110b88bbaed52324e 100644 (file)
--- a/src/ao.h
+++ b/src/ao.h
@@ -1178,8 +1178,10 @@ struct ao_stdio {
        char    (*pollchar)(void);
        void    (*putchar)(char c) __reentrant;
        void    (*flush)(void);
+       uint8_t echo;
 };
 
+extern __xdata struct ao_stdio ao_stdios[];
 extern __data int8_t ao_cur_stdio;
 extern __data int8_t ao_num_stdios;
 
@@ -1188,6 +1190,9 @@ flush(void);
 
 extern __xdata uint8_t ao_stdin_ready;
 
+uint8_t
+ao_echo(void);
+
 void
 ao_add_stdio(char (*pollchar)(void),
             void (*putchar)(char) __reentrant,
index 50d5b96fd9afe4a9355377ebd764a753efe244d4..c738a3e04ab741d4a8148c0bec60c61ae9506204 100644 (file)
@@ -21,7 +21,6 @@ __xdata uint16_t ao_cmd_lex_i;
 __xdata uint32_t ao_cmd_lex_u32;
 __xdata char   ao_cmd_lex_c;
 __xdata enum ao_cmd_status ao_cmd_status;
-static __xdata uint8_t lex_echo;
 
 #define CMD_LEN        32
 
@@ -41,7 +40,7 @@ static void
 readline(void)
 {
        __xdata char c;
-       if (lex_echo)
+       if (ao_echo())
                put_string("> ");
        cmd_len = 0;
        for (;;) {
@@ -50,7 +49,7 @@ readline(void)
                /* backspace/delete */
                if (c == '\010' || c == '\177') {
                        if (cmd_len != 0) {
-                               if (lex_echo)
+                               if (ao_echo())
                                        put_string("\010 \010");
                                --cmd_len;
                        }
@@ -60,7 +59,7 @@ readline(void)
                /* ^U */
                if (c == '\025') {
                        while (cmd_len != 0) {
-                               if (lex_echo)
+                               if (ao_echo())
                                        put_string("\010 \010");
                                --cmd_len;
                        }
@@ -72,18 +71,18 @@ readline(void)
                        c = '\n';
 
                if (c == '\n') {
-                       if (lex_echo)
+                       if (ao_echo())
                                putchar('\n');
                        break;
                }
 
                if (cmd_len >= CMD_LEN - 2) {
-                       if (lex_echo)
+                       if (ao_echo())
                                putchar('\007');
                        continue;
                }
                cmd_line[cmd_len++] = c;
-               if (lex_echo)
+               if (ao_echo())
                        putchar(c);
        }
        cmd_line[cmd_len++] = '\n';
@@ -198,7 +197,8 @@ static void
 echo(void)
 {
        ao_cmd_hex();
-       lex_echo = ao_cmd_lex_i != 0;
+       if (ao_cmd_status == ao_cmd_success)
+               ao_stdios[ao_cur_stdio].echo = ao_cmd_lex_i != 0;
 }
 
 static void
@@ -272,7 +272,6 @@ ao_cmd(void)
        __code struct ao_cmds * __xdata cs;
        void (*__xdata func)(void);
 
-       lex_echo = 1;
        for (;;) {
                readline();
 #if HAS_CMD_FILTER
index 3dd457f7c63959d6da9b70363aca0d4db44960e4..ec3b6607b2e8cfb5ea1cf567a9ea98d22b2eda46 100644 (file)
@@ -23,7 +23,7 @@
 
 #define AO_NUM_STDIOS  (HAS_USB + PACKET_HAS_SLAVE + USE_SERIAL_STDIN)
 
-static __xdata struct ao_stdio stdios[AO_NUM_STDIOS];
+__xdata struct ao_stdio ao_stdios[AO_NUM_STDIOS];
 __data int8_t ao_cur_stdio;
 __data int8_t ao_num_stdios;
 
@@ -31,15 +31,15 @@ void
 putchar(char c)
 {
        if (c == '\n')
-               (*stdios[ao_cur_stdio].putchar)('\r');
-       (*stdios[ao_cur_stdio].putchar)(c);
+               (*ao_stdios[ao_cur_stdio].putchar)('\r');
+       (*ao_stdios[ao_cur_stdio].putchar)(c);
 }
 
 void
 flush(void)
 {
-       if (stdios[ao_cur_stdio].flush)
-               stdios[ao_cur_stdio].flush();
+       if (ao_stdios[ao_cur_stdio].flush)
+               ao_stdios[ao_cur_stdio].flush();
 }
 
 __xdata uint8_t ao_stdin_ready;
@@ -51,7 +51,7 @@ getchar(void) __reentrant __critical
        int8_t stdio = ao_cur_stdio;
 
        for (;;) {
-               c = stdios[stdio].pollchar();
+               c = ao_stdios[stdio].pollchar();
                if (c != AO_READ_AGAIN)
                        break;
                if (++stdio == ao_num_stdios)
@@ -63,6 +63,12 @@ getchar(void) __reentrant __critical
        return c;
 }
 
+uint8_t
+ao_echo(void)
+{
+       return ao_stdios[ao_cur_stdio].echo;
+}
+
 void
 ao_add_stdio(char (*pollchar)(void),
             void (*putchar)(char),
@@ -70,8 +76,9 @@ ao_add_stdio(char (*pollchar)(void),
 {
        if (ao_num_stdios == AO_NUM_STDIOS)
                ao_panic(AO_PANIC_STDIO);
-       stdios[ao_num_stdios].pollchar = pollchar;
-       stdios[ao_num_stdios].putchar = putchar;
-       stdios[ao_num_stdios].flush = flush;
+       ao_stdios[ao_num_stdios].pollchar = pollchar;
+       ao_stdios[ao_num_stdios].putchar = putchar;
+       ao_stdios[ao_num_stdios].flush = flush;
+       ao_stdios[ao_num_stdios].echo = 1;
        ao_num_stdios++;
 }