Hello!
This is a (bugfixed) variant of a patch I sent here in 2002. Apparently
only parts of it got applied back then. This is against 0.71.
This patch adds prettyprinting of Unit and Unit Exponent Global Items to
lsusb.c, because they're really annoying to calculate manually. It
should work for all cases.
A diff beween old and new (patched) lsusb output contains lots of
Item(Global): Unit, data= [ 0x03 0x10 ] 4099
+ System: English Linear, Unit: Seconds
Item(Global): Unit Exponent, data= [ 0xfd ] 253
+ Unit Exponent: -3
and
Item(Global): Unit, data= [ 0x14 0x00 ] 20
+ System: English Rotation, Unit: Degrees
Also (And this bit I'm not sure about) I added a few missing Collection
parts. They didn't make any difference on my devices, but it seems right
that they should be there.
(Oh, and a misindent and missing "break" that doesn't hurt now, but
it's the kind of thing that can cause a bug when the next case is added.)
/August.
----------------------------8<-------------------------
--- lsusb.c-orig 2006-02-08 01:54:25.000000000 +0100
+++ lsusb.c 2006-02-12 02:03:24.000000000 +0100
@@ -499,6 +499,57 @@
}
}
+static void dump_unit(unsigned int data, unsigned int len)
+{
+ char *systems[5] = { "None", "SI Linear", "SI Rotation", "English
Linear", "English Rotation" };
+
+ char *units[5][8] = {
+ { "None", "None", "None", "None", "None", "None", "None",
"None" },
+ { "None", "Centimeter", "Gram", "Seconds", "Kelvin",
"Ampere", "Candela", "None" },
+ { "None", "Radians", "Gram", "Seconds", "Kelvin",
"Ampere", "Candela", "None" },
+ { "None", "Inch", "Slug", "Seconds", "Fahrenheit",
"Ampere", "Candela", "None" },
+ { "None", "Degrees", "Slug", "Seconds", "Fahrenheit",
"Ampere", "Candela", "None" },
+ };
+
+ unsigned int i;
+ unsigned int sys;
+ int earlier_unit = 0;
+
+ /* First nibble tells us which system we're in. */
+ sys = data & 0xf;
+ data >>= 4;
+
+ if(sys > 4) {
+ if(sys == 0xf)
+ printf("System: Vendor defined, Unit: (unknown)\n");
+ else
+ printf("System: Reserved, Unit: (unknown)\n");
+ return;
+ } else {
+ printf("System: %s, Unit: ", systems[sys]);
+ }
+ for (i=1 ; i<len*2 ; i++) {
+ char nibble = data & 0xf;
+ data >>= 4;
+ if (nibble != 0) {
+ if(earlier_unit++ > 0)
+ printf("*");
+ printf("%s", units[sys][i]);
+ if(nibble != 1) {
+ /* This is a _signed_ nibble(!) */
+
+ int val = nibble & 0x7;
+ if(nibble & 0x08)
+ val = -((0x7 & ~val) +1);
+ printf("^%d", val);
+ }
+ }
+ }
+ if(earlier_unit == 0)
+ printf("(None)");
+ printf("\n");
+}
+
/* ---------------------------------------------------------------------- */
/*
@@ -1374,6 +1425,15 @@
printf("%s%s\n", indent, names_hutus((hut << 16) +
data));
break;
+ case 0x54 : /* Unit Exponent */
+ printf("%sUnit Exponent: %i\n", indent, (signed
char)data);
+ break;
+
+ case 0x64 : /* Unit */
+ printf("%s", indent);
+ dump_unit(data, bsize);
+ break;
+
case 0xa0 : /* Collection */
printf("%s", indent);
switch (data) {
@@ -1388,7 +1448,23 @@
case 0x02:
printf("Logical\n");
break;
-
+
+ case 0x03:
+ printf("Report\n");
+ break;
+
+ case 0x04:
+ printf("Named Array\n");
+ break;
+
+ case 0x05:
+ printf("Usage Switch\n");
+ break;
+
+ case 0x06:
+ printf("Usage Modifier\n");
+ break;
+
default:
if(data & 0x80)
printf("Vendor defined\n");
@@ -1411,7 +1487,8 @@
data & 0x40 ? "Null_State": "No_Null_Position",
data & 0x80 ? "Volatile": "Non_Volatile",
data &0x100 ? "Buffered Bytes": "Bitfield"
- );
+ );
+ break;
}
i += 1 + bsize;
}
--
Björn Augustsson Sysadmin IT Systems & Services
Chalmers tekniska högskola Chalmers University of Technology
"Damn spooky analog crap." -- John Carmack.
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel