Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FatFileSystem TB6612FNG2 mbed
usb/Utils.cpp@0:de03cbbcd0ff, 2015-11-30 (annotated)
- Committer:
- mbed_Cookbook_SE
- Date:
- Mon Nov 30 09:32:15 2015 +0000
- Revision:
- 0:de03cbbcd0ff
??
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 1 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 2 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 3 | #include "mbed.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 4 | #include "Utils.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 5 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 6 | void printfBytes(const char* s, const u8* data, int len) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 7 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 8 | printf("%s %d:",s,len); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 9 | if (len > 256) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 10 | len = 256; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 11 | while (len-- > 0) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 12 | printf(" %02X",*data++); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 13 | printf("\n"); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 14 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 15 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 16 | void printHexLine(const u8* d, int addr, int len) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 17 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 18 | printf("%04X ",addr); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 19 | int i; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 20 | for (i = 0; i < len; i++) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 21 | printf("%02X ",d[i]); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 22 | for (;i < 16; i++) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 23 | printf(" "); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 24 | char s[16+1]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 25 | memset(s,0,sizeof(s)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 26 | for (i = 0; i < len; i++) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 27 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 28 | int c = d[i]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 29 | if (c < 0x20 || c > 0x7E) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 30 | c = '.'; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 31 | s[i] = c; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 32 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 33 | printf("%s\n",s); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 34 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 35 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 36 | void printHex(const u8* d, int len) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 37 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 38 | int addr = 0; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 39 | while (len) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 40 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 41 | int count = len; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 42 | if (count > 16) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 43 | count = 16; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 44 | printHexLine(d+addr,addr,count); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 45 | addr += 16; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 46 | len -= count; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 47 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 48 | } |