OSDN Git Service

[WIP][v2.0] Loading from Srecord.
[openi2cradio/OpenI2CRadio.git] / shell_strutl.c
index ac95f47..accd770 100644 (file)
@@ -64,13 +64,14 @@ unsigned char check_eol(unsigned char *p)
         switch(c){
             case '\0':
             case '\n':
+            case '\r':
                 return 0xff;
                 break;
             default:
                 break;
         }
-        if(c < '0') return 0xff;
-        if(c > 'F') return 0xff;
+//        if(c < '0') return 0xff;
+//        if(c > 'F') return 0xff;
     }
     return 0;
 }
@@ -101,7 +102,7 @@ char str_shexheader(unsigned char *s, unsigned char *file)
     unsigned char c;
     unsigned char bytes;
     unsigned int i;
-    if(check_eol(s) != 0) return TERM_NULL;
+//    if(check_eol(s) != 0) return TERM_NULL;
 
     if((s[0] != 'S') || (s[1] != '0')) return TERM_NONSREC;
 
@@ -165,7 +166,7 @@ char str_shex2bin(unsigned char *s, unsigned char *p, unsigned long *addr, unsig
             p[pp] = c;
             i += 2;
             pp++;
-             bytes--;
+            bytes--;
         }
         if(migrate_hex(&s[i]) == 0) return TERM_SUMERR;
         c = hex2byte(&s[i]);
@@ -196,8 +197,22 @@ char str_shex2bin(unsigned char *s, unsigned char *p, unsigned long *addr, unsig
 
 void bin2hex(char *s, unsigned char v)
 {
-    s[0] = v >> 4;
-    s[1] = v & 0x0f;
+    unsigned char c;
+    c = v >> 4;
+    if(c > 9) {
+        c = c - 10 + 'A';
+    } else {
+        c = c + '0';
+    }
+    s[0] = c;
+
+    c = v & 0x0f;
+    if(c > 9) {
+        c = c - 10 + 'A';
+    } else {
+        c = c + '0';
+    }
+    s[1] = c;
     s[2] = 0x00;
 }
 
@@ -214,7 +229,7 @@ unsigned char str_bin2hex(unsigned char *s, unsigned char *p, unsigned long addr
     s[0] = 'S';
     s[1] = '2';
     if(len > 254) len = 254;
-    i = len + 1;
+    i = len + 4; //HEX
     sum = i;
     bin2hex(&s[2], i);