ORTP-L_WiiRemoteTest
Dependencies: Motordriver mbed FatFileSystem
Fork of WallbotTypeN by
BlueUSB/Utils.cpp@1:df4118878dc4, 2013-03-29 (annotated)
- Committer:
- passionvirus
- Date:
- Fri Mar 29 09:05:28 2013 +0000
- Revision:
- 1:df4118878dc4
- Parent:
- 0:425791fe4b42
init
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:425791fe4b42 | 1 | |
jksoft | 0:425791fe4b42 | 2 | |
jksoft | 0:425791fe4b42 | 3 | #include "mbed.h" |
jksoft | 0:425791fe4b42 | 4 | #include "Utils.h" |
jksoft | 0:425791fe4b42 | 5 | |
jksoft | 0:425791fe4b42 | 6 | void printfBytes(const char* s, const u8* data, int len) |
jksoft | 0:425791fe4b42 | 7 | { |
jksoft | 0:425791fe4b42 | 8 | printf("%s %d:",s,len); |
jksoft | 0:425791fe4b42 | 9 | if (len > 256) |
jksoft | 0:425791fe4b42 | 10 | len = 256; |
jksoft | 0:425791fe4b42 | 11 | while (len-- > 0) |
jksoft | 0:425791fe4b42 | 12 | printf(" %02X",*data++); |
jksoft | 0:425791fe4b42 | 13 | printf("\n"); |
jksoft | 0:425791fe4b42 | 14 | } |
jksoft | 0:425791fe4b42 | 15 | |
jksoft | 0:425791fe4b42 | 16 | void printHexLine(const u8* d, int addr, int len) |
jksoft | 0:425791fe4b42 | 17 | { |
jksoft | 0:425791fe4b42 | 18 | printf("%04X ",addr); |
jksoft | 0:425791fe4b42 | 19 | int i; |
jksoft | 0:425791fe4b42 | 20 | for (i = 0; i < len; i++) |
jksoft | 0:425791fe4b42 | 21 | printf("%02X ",d[i]); |
jksoft | 0:425791fe4b42 | 22 | for (;i < 16; i++) |
jksoft | 0:425791fe4b42 | 23 | printf(" "); |
jksoft | 0:425791fe4b42 | 24 | char s[16+1]; |
jksoft | 0:425791fe4b42 | 25 | memset(s,0,sizeof(s)); |
jksoft | 0:425791fe4b42 | 26 | for (i = 0; i < len; i++) |
jksoft | 0:425791fe4b42 | 27 | { |
jksoft | 0:425791fe4b42 | 28 | int c = d[i]; |
jksoft | 0:425791fe4b42 | 29 | if (c < 0x20 || c > 0x7E) |
jksoft | 0:425791fe4b42 | 30 | c = '.'; |
jksoft | 0:425791fe4b42 | 31 | s[i] = c; |
jksoft | 0:425791fe4b42 | 32 | } |
jksoft | 0:425791fe4b42 | 33 | printf("%s\n",s); |
jksoft | 0:425791fe4b42 | 34 | } |
jksoft | 0:425791fe4b42 | 35 | |
jksoft | 0:425791fe4b42 | 36 | void printHex(const u8* d, int len) |
jksoft | 0:425791fe4b42 | 37 | { |
jksoft | 0:425791fe4b42 | 38 | int addr = 0; |
jksoft | 0:425791fe4b42 | 39 | while (len) |
jksoft | 0:425791fe4b42 | 40 | { |
jksoft | 0:425791fe4b42 | 41 | int count = len; |
jksoft | 0:425791fe4b42 | 42 | if (count > 16) |
jksoft | 0:425791fe4b42 | 43 | count = 16; |
jksoft | 0:425791fe4b42 | 44 | printHexLine(d+addr,addr,count); |
jksoft | 0:425791fe4b42 | 45 | addr += 16; |
jksoft | 0:425791fe4b42 | 46 | len -= count; |
jksoft | 0:425791fe4b42 | 47 | } |
jksoft | 0:425791fe4b42 | 48 | } |