Add option -x to display output values in hex in addition to decimal.
This commit is contained in:
parent
84eab9ad73
commit
9a2a66f1bb
usr.bin/usbhidctl
@ -54,6 +54,7 @@
|
|||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
int all = 0;
|
int all = 0;
|
||||||
int noname = 0;
|
int noname = 0;
|
||||||
|
int hexdump = 0;
|
||||||
static int reportid;
|
static int reportid;
|
||||||
|
|
||||||
char **names;
|
char **names;
|
||||||
@ -94,8 +95,14 @@ usage(void)
|
|||||||
{
|
{
|
||||||
extern char *__progname;
|
extern char *__progname;
|
||||||
|
|
||||||
fprintf(stderr, "usage: %s -f device [-l] [-n] [-r] [-t tablefile] [-v] name ...\n", __progname);
|
fprintf(stderr,
|
||||||
fprintf(stderr, " %s -f device [-l] [-n] [-r] [-t tablefile] [-v] -a\n", __progname);
|
"usage: %s -f device "
|
||||||
|
"[-l] [-n] [-r] [-t tablefile] [-v] [x] name ...\n",
|
||||||
|
__progname);
|
||||||
|
fprintf(stderr,
|
||||||
|
" %s -f device "
|
||||||
|
"[-l] [-n] [-r] [-t tablefile] [-v] [x] -a\n",
|
||||||
|
__progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,8 +112,8 @@ dumpitem(const char *label, struct hid_item *h)
|
|||||||
if ((h->flags & HIO_CONST) && !verbose)
|
if ((h->flags & HIO_CONST) && !verbose)
|
||||||
return;
|
return;
|
||||||
printf("%s size=%d count=%d page=%s usage=%s%s", label,
|
printf("%s size=%d count=%d page=%s usage=%s%s", label,
|
||||||
h->report_size, h->report_count,
|
h->report_size, h->report_count,
|
||||||
hid_usage_page(HID_PAGE(h->usage)),
|
hid_usage_page(HID_PAGE(h->usage)),
|
||||||
hid_usage_in_page(h->usage),
|
hid_usage_in_page(h->usage),
|
||||||
h->flags & HIO_CONST ? " Const" : "");
|
h->flags & HIO_CONST ? " Const" : "");
|
||||||
printf(", logical range %d..%d",
|
printf(", logical range %d..%d",
|
||||||
@ -130,7 +137,7 @@ dumpitems(report_desc_t r)
|
|||||||
switch (h.kind) {
|
switch (h.kind) {
|
||||||
case hid_collection:
|
case hid_collection:
|
||||||
printf("Collection page=%s usage=%s\n",
|
printf("Collection page=%s usage=%s\n",
|
||||||
hid_usage_page(HID_PAGE(h.usage)),
|
hid_usage_page(HID_PAGE(h.usage)),
|
||||||
hid_usage_in_page(h.usage));
|
hid_usage_in_page(h.usage));
|
||||||
break;
|
break;
|
||||||
case hid_endcollection:
|
case hid_endcollection:
|
||||||
@ -187,6 +194,8 @@ prdata(u_char *buf, struct hid_item *h)
|
|||||||
printf("%d", (int)data);
|
printf("%d", (int)data);
|
||||||
else
|
else
|
||||||
printf("%u", data);
|
printf("%u", data);
|
||||||
|
if (hexdump)
|
||||||
|
printf(" [0x%x]", data);
|
||||||
pos += h->report_size;
|
pos += h->report_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -204,7 +213,7 @@ dumpdata(int f, report_desc_t rd, int loop)
|
|||||||
char namebuf[10000], *namep;
|
char namebuf[10000], *namep;
|
||||||
|
|
||||||
hids = 0;
|
hids = 0;
|
||||||
for (d = hid_start_parse(rd, 1<<hid_input, reportid);
|
for (d = hid_start_parse(rd, 1<<hid_input, reportid);
|
||||||
hid_get_item(d, &h); ) {
|
hid_get_item(d, &h); ) {
|
||||||
if (h.kind == hid_collection)
|
if (h.kind == hid_collection)
|
||||||
colls[++sp] = h.usage;
|
colls[++sp] = h.usage;
|
||||||
@ -265,7 +274,7 @@ main(int argc, char **argv)
|
|||||||
int loop = 0;
|
int loop = 0;
|
||||||
char *table = 0;
|
char *table = 0;
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "af:lnrt:v")) != -1) {
|
while ((ch = getopt(argc, argv, "af:lnrt:vx")) != -1) {
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
case 'a':
|
case 'a':
|
||||||
all++;
|
all++;
|
||||||
@ -288,6 +297,9 @@ main(int argc, char **argv)
|
|||||||
case 'v':
|
case 'v':
|
||||||
verbose++;
|
verbose++;
|
||||||
break;
|
break;
|
||||||
|
case 'x':
|
||||||
|
hexdump ^= 1;
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
@ -318,9 +330,9 @@ main(int argc, char **argv)
|
|||||||
err(1, "%s", dev);
|
err(1, "%s", dev);
|
||||||
|
|
||||||
r = hid_get_report_desc(f);
|
r = hid_get_report_desc(f);
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
errx(1, "USB_GET_REPORT_DESC");
|
errx(1, "USB_GET_REPORT_DESC");
|
||||||
|
|
||||||
if (repdump) {
|
if (repdump) {
|
||||||
printf("Report descriptor:\n");
|
printf("Report descriptor:\n");
|
||||||
dumpitems(r);
|
dumpitems(r);
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
.Op Fl r
|
.Op Fl r
|
||||||
.Op Fl t Ar table
|
.Op Fl t Ar table
|
||||||
.Op Fl v
|
.Op Fl v
|
||||||
|
.Op Fl x
|
||||||
.Op Ar item ...
|
.Op Ar item ...
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
@ -75,6 +76,8 @@ Dump the report descriptor.
|
|||||||
Specify a path name for the HID usage table file.
|
Specify a path name for the HID usage table file.
|
||||||
.It Fl v
|
.It Fl v
|
||||||
Be verbose.
|
Be verbose.
|
||||||
|
.It Fl x
|
||||||
|
Dump data in hexadecimal as well as decimal.
|
||||||
.El
|
.El
|
||||||
.Sh FILES
|
.Sh FILES
|
||||||
.Pa /usr/share/misc/usb_hid_usages
|
.Pa /usr/share/misc/usb_hid_usages
|
||||||
|
Loading…
x
Reference in New Issue
Block a user