00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "global.h"
00020 #include "uart.h"
00021 #include "rprintf.h"
00022
00023 #include "input.h"
00024
00025 #ifndef INPUT_GETBYTE
00026 #define INPUT_GETBYTE uart1GetByte
00027 #endif
00028
00029
00030
00031
00032 u08 inputString(u08 termChar, u08 termLen, u08* data)
00033 {
00034 int s=-1;
00035 u08 length=0;
00036
00037 while(length < termLen)
00038 {
00039
00040 s = -1;
00041 while(s == -1)
00042 {
00043 s = INPUT_GETBYTE();
00044 }
00045
00046
00047 if(s == 0x08)
00048 {
00049 if(length > 0)
00050 {
00051
00052 rprintfChar(0x08);
00053 rprintfChar(' ');
00054 rprintfChar(0x08);
00055 length--;
00056 }
00057 }
00058 else if(s == termChar)
00059 {
00060
00061 data[length] = 0;
00062 break;
00063 }
00064 else
00065 {
00066
00067 rprintfChar(s);
00068
00069 data[length++] = s;
00070 }
00071 }
00072 return length;
00073 }
00074
00075 u08 asciiHexToByte(u08* string)
00076 {
00077
00078 return (asciiHexToNibble(string[0])<<4) + asciiHexToNibble(string[1]);
00079 }
00080
00081 u08 asciiHexToNibble(u08 character)
00082 {
00083
00084 if((character >= 0x30) && (character <= 0x39))
00085 return character-0x30;
00086 else if((character >= 'A') && (character <= 'F'))
00087 return character-'A'+10;
00088 else if((character >= 'a') && (character <= 'f'))
00089 return character-'a'+10;
00090 else return 0;
00091 }