Changeset dec55ce in mainline


Ignore:
Timestamp:
2011-06-17T20:32:22Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e9c02b7
Parents:
54d4b9e
Message:

A bit of refactoring

File:
1 edited

Legend:

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

    r54d4b9e rdec55ce  
    6161}
    6262
     63/** Dumps HID report in raw format.
     64 *
     65 * @param iface_no USB interface the report belongs to.
     66 * @param report Report descriptor.
     67 * @param size Size of the @p report in bytes.
     68 */
     69static void dump_hid_report_raw(int iface_no, uint8_t *report, size_t size)
     70{
     71        printf("%sHID report descriptor for interface %d", get_indent(0),
     72            iface_no);
     73        for (size_t i = 0; i < size; i++) {
     74                size_t line_idx = i % BYTES_PER_LINE;
     75                if (line_idx == 0) {
     76                        printf("\n%s", get_indent(1));
     77                }
     78                printf("%02X", (int) report[i]);
     79                if (line_idx + 1 < BYTES_PER_LINE) {
     80                        printf(" ");
     81                }
     82        }
     83        printf("\n");
     84}
     85
    6386/** Retrieves HID report from given USB device and dumps it.
    6487 *
     
    7295        assert(report_size > 0);
    7396
    74         uint8_t *report = malloc(report_size);
    75         if (report == NULL) {
     97        uint8_t *raw_report = malloc(report_size);
     98        if (raw_report == NULL) {
    7699                usb_log_warning(
    77100                    "Failed to allocate %zuB, skipping interface %d.\n",
     
    84107            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE,
    85108            USB_DESCTYPE_HID_REPORT, 0, iface_no,
    86             report, report_size, &actual_report_size);
     109            raw_report, report_size, &actual_report_size);
    87110        if (rc != EOK) {
    88111                usb_log_error("Failed to retrieve HID report descriptor: %s.\n",
    89112                    str_error(rc));
    90                 free(report);
     113                free(raw_report);
    91114                return;
    92115        }
    93116
    94         printf("%sHID report descriptor for interface %d", get_indent(0),
    95             (int) iface_no);
    96         for (size_t i = 0; i < report_size; i++) {
    97                 size_t line_idx = i % BYTES_PER_LINE;
    98                 if (line_idx == 0) {
    99                         printf("\n%s", get_indent(1));
    100                 }
    101                 printf("%02X", (int) report[i]);
    102                 if (line_idx + 1 < BYTES_PER_LINE) {
    103                         printf(" ");
    104                 }
    105         }
    106         printf("\n");
     117        dump_hid_report_raw(iface_no, raw_report, report_size);
    107118
    108         free(report);
     119        free(raw_report);
    109120}
    110121
Note: See TracChangeset for help on using the changeset viewer.