Changeset 6fe1ab4 in mainline for uspace/app/usbinfo/dump.c
- Timestamp:
- 2011-01-14T14:09:24Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4989d73
- Parents:
- 5f635ca
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/usbinfo/dump.c
r5f635ca r6fe1ab4 48 48 49 49 #define INDENT " " 50 #define PRINTLINE(indent, fmt, ...) printf("%s" fmt, get_indent(indent), __VA_ARGS__) 50 51 #define BYTES_PER_LINE 12 51 52 … … 84 85 }; 85 86 86 void dump_buffer(const char *msg, const uint8_t *buffer, size_t length) 87 static const char *get_indent(size_t level) 88 { 89 static const char *indents[] = { 90 INDENT, 91 INDENT INDENT, 92 INDENT INDENT INDENT, 93 INDENT INDENT INDENT INDENT, 94 INDENT INDENT INDENT INDENT INDENT 95 }; 96 static size_t indents_count = sizeof(indents)/sizeof(indents[0]); 97 if (level >= indents_count) { 98 return indents[indents_count - 1]; 99 } 100 return indents[level]; 101 } 102 103 void dump_buffer(const char *msg, size_t indent, 104 const uint8_t *buffer, size_t length) 87 105 { 88 106 if (msg != NULL) { … … 91 109 92 110 size_t i; 111 if (length > 0) { 112 printf("%s", get_indent(indent)); 113 } 93 114 for (i = 0; i < length; i++) { 94 printf(" 115 printf("0x%02X", buffer[i]); 95 116 if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0)) 96 117 || (i + 1 == length)) { 97 118 printf("\n"); 119 if (i + 1 < length) { 120 printf("%s", get_indent(indent)); 121 } 122 } else { 123 printf(" "); 98 124 } 99 125 } … … 130 156 } 131 157 132 printf(INDENT"bLength = %d\n", d->length);133 printf(INDENT"bDescriptorType = 0x%02x\n", d->descriptor_type);134 printf(INDENT"bcdUSB = %d (" BCD_FMT ")\n", d->usb_spec_version,158 PRINTLINE(indent, "bLength = %d\n", d->length); 159 PRINTLINE(indent, "bDescriptorType = 0x%02x\n", d->descriptor_type); 160 PRINTLINE(indent, "bcdUSB = %d (" BCD_FMT ")\n", d->usb_spec_version, 135 161 BCD_ARGS(d->usb_spec_version)); 136 printf(INDENT"bDeviceClass = 0x%02x\n", d->device_class);137 printf(INDENT"bDeviceSubClass = 0x%02x\n", d->device_subclass);138 printf(INDENT"bDeviceProtocol = 0x%02x\n", d->device_protocol);139 printf(INDENT"bMaxPacketSize0 = %d\n", d->max_packet_size);140 printf(INDENT"idVendor = %d\n", d->vendor_id);141 printf(INDENT"idProduct = %d\n", d->product_id);142 printf(INDENT"bcdDevice = %d\n", d->device_version);143 printf(INDENT"iManufacturer = %d\n", d->str_manufacturer);144 printf(INDENT"iProduct = %d\n", d->str_product);145 printf(INDENT"iSerialNumber = %d\n", d->str_serial_number);146 printf(INDENT"bNumConfigurations = %d\n", d->configuration_count);162 PRINTLINE(indent, "bDeviceClass = 0x%02x\n", d->device_class); 163 PRINTLINE(indent, "bDeviceSubClass = 0x%02x\n", d->device_subclass); 164 PRINTLINE(indent, "bDeviceProtocol = 0x%02x\n", d->device_protocol); 165 PRINTLINE(indent, "bMaxPacketSize0 = %d\n", d->max_packet_size); 166 PRINTLINE(indent, "idVendor = %d\n", d->vendor_id); 167 PRINTLINE(indent, "idProduct = %d\n", d->product_id); 168 PRINTLINE(indent, "bcdDevice = %d\n", d->device_version); 169 PRINTLINE(indent, "iManufacturer = %d\n", d->str_manufacturer); 170 PRINTLINE(indent, "iProduct = %d\n", d->str_product); 171 PRINTLINE(indent, "iSerialNumber = %d\n", d->str_serial_number); 172 PRINTLINE(indent, "bNumConfigurations = %d\n", d->configuration_count); 147 173 } 148 174 … … 158 184 bool remote_wakeup = d->attributes & 32; 159 185 160 printf(INDENT"bLength = %d\n", d->length);161 printf(INDENT"bDescriptorType = 0x%02x\n", d->descriptor_type);162 printf(INDENT"wTotalLength = %d\n", d->total_length);163 printf(INDENT"bNumInterfaces = %d\n", d->interface_count);164 printf(INDENT"bConfigurationValue = %d\n", d->configuration_number);165 printf(INDENT"iConfiguration = %d\n", d->str_configuration);166 printf(INDENT"bmAttributes = %d [%s%s%s]\n", d->attributes,186 PRINTLINE(indent, "bLength = %d\n", d->length); 187 PRINTLINE(indent, "bDescriptorType = 0x%02x\n", d->descriptor_type); 188 PRINTLINE(indent, "wTotalLength = %d\n", d->total_length); 189 PRINTLINE(indent, "bNumInterfaces = %d\n", d->interface_count); 190 PRINTLINE(indent, "bConfigurationValue = %d\n", d->configuration_number); 191 PRINTLINE(indent, "iConfiguration = %d\n", d->str_configuration); 192 PRINTLINE(indent, "bmAttributes = %d [%s%s%s]\n", d->attributes, 167 193 self_powered ? "self-powered" : "", 168 194 (self_powered & remote_wakeup) ? ", " : "", 169 195 remote_wakeup ? "remote-wakeup" : ""); 170 printf(INDENT"MaxPower = %d (%dmA)\n", d->max_power,196 PRINTLINE(indent, "MaxPower = %d (%dmA)\n", d->max_power, 171 197 2 * d->max_power); 172 198 } … … 199 225 void dump_descriptor_generic(size_t indent, uint8_t *descr, size_t size) 200 226 { 201 dump_buffer(NULL, descr, size);227 dump_buffer(NULL, indent, descr, size); 202 228 } 203 229 … … 220 246 if (descriptor == NULL) { 221 247 return; 222 }223 while (depth > 0) {224 printf(" ");225 depth--;226 248 } 227 249 int type = (int) *(descriptor + 1); … … 241 263 #undef _TYPE 242 264 } 243 printf(" 0x%02x (%s)\n", type, name);265 printf("%s%s (0x%02X):\n", get_indent(depth), name, type); 244 266 dump_descriptor_by_type(depth, descriptor, descriptor[0]); 245 267 … … 264 286 uint8_t *ptr = data->data; 265 287 printf("Descriptor tree:\n"); 266 dump_tree_internal(parser, data, ptr, 1);288 dump_tree_internal(parser, data, ptr, 0); 267 289 } 268 290
Note:
See TracChangeset
for help on using the changeset viewer.