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