Changeset 6fe1ab4 in mainline


Ignore:
Timestamp:
2011-01-14T14:09:24Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4989d73
Parents:
5f635ca
Message:

`usbinfo' indents better

Location:
uspace/app/usbinfo
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/usbinfo/dump.c

    r5f635ca r6fe1ab4  
    4848
    4949#define INDENT "  "
     50#define PRINTLINE(indent, fmt, ...) printf("%s" fmt, get_indent(indent), __VA_ARGS__)
    5051#define BYTES_PER_LINE 12
    5152
     
    8485};
    8586
    86 void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
     87static 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
     103void dump_buffer(const char *msg, size_t indent,
     104    const uint8_t *buffer, size_t length)
    87105{
    88106        if (msg != NULL) {
     
    91109
    92110        size_t i;
     111        if (length > 0) {
     112                printf("%s", get_indent(indent));
     113        }
    93114        for (i = 0; i < length; i++) {
    94                 printf("  0x%02X", buffer[i]);
     115                printf("0x%02X", buffer[i]);
    95116                if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))
    96117                    || (i + 1 == length)) {
    97118                        printf("\n");
     119                        if (i + 1 < length) {
     120                                printf("%s", get_indent(indent));
     121                        }
     122                } else {
     123                        printf("  ");
    98124                }
    99125        }
     
    130156        }
    131157       
    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,
    135161            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);
    147173}
    148174
     
    158184        bool remote_wakeup = d->attributes & 32;
    159185       
    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,
    167193            self_powered ? "self-powered" : "",
    168194            (self_powered & remote_wakeup) ? ", " : "",
    169195            remote_wakeup ? "remote-wakeup" : "");
    170         printf(INDENT "MaxPower = %d (%dmA)\n", d->max_power,
     196        PRINTLINE(indent, "MaxPower = %d (%dmA)\n", d->max_power,
    171197            2 * d->max_power);
    172198}
     
    199225void dump_descriptor_generic(size_t indent, uint8_t *descr, size_t size)
    200226{
    201         dump_buffer(NULL, descr, size);
     227        dump_buffer(NULL, indent, descr, size);
    202228}
    203229
     
    220246        if (descriptor == NULL) {
    221247                return;
    222         }
    223         while (depth > 0) {
    224                 printf("  ");
    225                 depth--;
    226248        }
    227249        int type = (int) *(descriptor + 1);
     
    241263#undef _TYPE
    242264        }
    243         printf("0x%02x (%s)\n", type, name);
     265        printf("%s%s (0x%02X):\n", get_indent(depth), name, type);
    244266        dump_descriptor_by_type(depth, descriptor, descriptor[0]);
    245267       
     
    264286        uint8_t *ptr = data->data;
    265287        printf("Descriptor tree:\n");
    266         dump_tree_internal(parser, data, ptr, 1);
     288        dump_tree_internal(parser, data, ptr, 0);
    267289}
    268290
  • uspace/app/usbinfo/info.c

    r5f635ca r6fe1ab4  
    108108                return rc;
    109109        }
    110         dump_buffer("Full configuration descriptor:",
    111             full_config_descriptor, config_descriptor.total_length);
    112110
    113111        dump_descriptor_tree(full_config_descriptor,
  • uspace/app/usbinfo/usbinfo.h

    r5f635ca r6fe1ab4  
    4444#define NAME "usbinfo"
    4545
    46 void dump_buffer(const char *, const uint8_t *, size_t);
     46void dump_buffer(const char *, size_t, const uint8_t *, size_t);
    4747void dump_match_ids(match_id_list_t *matches);
    4848void dump_usb_descriptor(uint8_t *, size_t);
Note: See TracChangeset for help on using the changeset viewer.