OSDN Git Service

[UART][SHELL] Maybe work correct:HELP FREQ
authorK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 11 Nov 2013 04:14:50 +0000 (13:14 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Mon, 11 Nov 2013 04:14:50 +0000 (13:14 +0900)
nbproject/Makefile-genesis.properties
shell_strutl.c
term_shell.c
uart_termio.c

index 4e8b12c..d37cd50 100644 (file)
@@ -1,5 +1,5 @@
 #
-#Sat Nov 09 20:07:51 JST 2013
+#Mon Nov 11 12:24:15 JST 2013
 default.languagetoolchain.dir=/opt/microchip/xc8/v1.21/bin
 com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=0b040d5e5949b59f004c7912367437ce
 default.languagetoolchain.version=1.21
index 7a47839..ac95f47 100644 (file)
@@ -307,14 +307,17 @@ unsigned char shell_strlen(char *s)
 unsigned char shell_gettok(char *dst, char *src)
 {
     unsigned char i;
+    char c;
     i = 0;
-    while(src[i] != '\0') {
-        if(src[i] == ' ') break;
-        if(src[i] == '\t') break;
-        if(src[i] == '\n') break;
-        dst[i] = src[i];
+    while(1) {
+        c = src[i];
+        if(c == '\0') break;
+        if(c == ' ') break;
+        if(c == '\t') break;
+        if(c == '\n') break;
+        dst[i] = c;
         i++;
-        if(i > 128) break;
+        if(i > 126) break;
     }
     dst[i] = '\0';
     return i;
@@ -326,14 +329,9 @@ int shell_strcmp(char *from, char *to)
     unsigned char i;
     int p = 0;
 
-    f = shell_strlen(from);
-    t = shell_strlen(to);
-    i = f;
-    if(i > t) i = t;
-    while(i != 0){
+    while(from[p] != '\0'){
         if(from[p] != to[p]) return -1;
         p++;
-        i--;
     }
     return p;
 }
@@ -346,8 +344,11 @@ long term_getuint(char *pool)
 
     do {
         c = pool[p];
-        if((c < '0') || (c > '9')) return -1;
         if(c == '\0') break;
+        if(c == '\n') break;
+        if(c == '\t') break;
+        if(c == ' ') break;
+        if((c < '0') || (c > '9')) return -1;
         i *= 10;
         i = i + (c - '0');
         p++;
index 32d992b..11abd3f 100644 (file)
 #include "term_shell.h"
 
 
-unsigned char cmd_shellstr[255];
-static char shell_strbuf[255];
-static char xarg1[128];
-static char xarg2[128];
-static char xarg3[128];
+unsigned char cmd_shellstr[127];
+static char shell_strbuf[127];
+static char xarg1[66];
+static char xarg2[66];
+static char xarg3[66];
 
 #define SHELL_CMD_NONE -1
 #define SHELL_CMD_NOTFOUND -2
@@ -189,7 +189,7 @@ static void save_to_term(unsigned char *p)
     slen = shell_gettok(xarg1, p);
     addr = 0;
 
-    if(shell_strcmp(xarg1, "INT") == 0) { // Internal EEPROM
+    if(shell_strcmp(xarg1, "INT") > 0) { // Internal EEPROM
         put_hexheader("INT_EEPROM");
         len = sizeof(__radioset_t);
         pv = &setup;
@@ -202,10 +202,10 @@ static void save_to_term(unsigned char *p)
             }
         }
         put_hexfooter();
-    } else if(shell_strcmp(xarg1, "FTBL") == 0) { // External EEPROM, Freq TBL
+    } else if(shell_strcmp(xarg1, "FTBL") > 0) { // External EEPROM, Freq TBL
         put_hexheader("EXT_FREQTBL");
         put_hexfooter();
-    } else if(shell_strcmp(xarg1, "BAND") == 0) { // band
+    } else if(shell_strcmp(xarg1, "BAND") > 0) { // band
         put_hexheader("EXT_BANDTBL");
         put_hexfooter();
     }
@@ -314,12 +314,12 @@ static void cmd_help(char *p)
     unsigned char slen;
     int f;
 
-    slen = shell_gettok(p, xarg1);
+    slen = shell_gettok(xarg1, p);
     if(slen != 0) {
         for(i = 0; i < SHELL_TOPCMDS; i++){
             f = shell_strcmp(xarg1, cmdstr[i]);
             if(f > 0) {
-                cmd_printhelp(f);
+                cmd_printhelp(i);
                 return;
             }
         }
@@ -339,7 +339,7 @@ char term_shell(unsigned int timeout)
     unsigned char c;
     int i;
     unsigned int ii;
-    char pool[128];
+    char pool[127];
 
     //cmd_shellstr[0] = '\0';
     if(timeout != 0) {
@@ -369,18 +369,18 @@ char term_shell(unsigned int timeout)
        
         ClrWdt();
         ii = shell_gettok(pool, cmd_shellstr);
-//        if(ii >= 128) return SHELL_CMD_TOOLONG;
-        if(ii >= 128) continue; // Discard
-
+//        if(ii >= 126) return SHELL_CMD_TOOLONG;
+        if(ii >= 126) continue; // Discard
         for(t = 0; t < SHELL_TOPCMDS; t++){
             i = shell_strcmp((char *)cmdstr[t], pool);
             if(i > 0) break;
         }
+
         if(cmd_shellstr[ii] == ' ') {
           //if(i <= 0) return SHELL_CMD_NOTFOUND;
           ii = shell_gettok(pool, &cmd_shellstr[ii + 1]);
        }
-       
+        if(ii >= 126) t = 127; // Error
         switch(t){
             case 0:
                 cmd_help(pool);
index 97e3419..524aada 100644 (file)
@@ -76,11 +76,16 @@ void uart_term_getstr(unsigned char *s, unsigned int timeout, unsigned char echo
               cnt = 0;
            }
            cnt++;
-            s[i] = c;
-           if((c == '\i') || (c == '\n')) break;
             if(echo != 0) uart_pushchar(c, 0); // Echoback
-            i++;
-            if(i >= 128) break;
+            if(c == '\b') { // BS
+                if(i > 0) i--;
+                s[i] = '\0';
+            } else {
+                s[i] = c;
+                i++;
+                if((c == '\t') || (c == '\n')) break; // TAB OR CR
+                if(i >= 128) break;
+            }
            tim = 0;
        } else if(timeout != 0) { // ZAP n * 100mSec.
            if(chk_powerbutton() != 0) shutdown(0xff);