|
14 | 14 | /** |
15 | 15 | * Sample application enumerating connected USB devices. |
16 | 16 | */ |
| 17 | +@SuppressWarnings("java:S106") |
17 | 18 | public class Enumerate { |
18 | 19 |
|
19 | 20 | public static void main(String[] args) { |
@@ -42,10 +43,14 @@ private static void printDevice(USBDevice device) { |
42 | 43 | for (var intf: device.interfaces()) |
43 | 44 | printInterface(intf); |
44 | 45 |
|
| 46 | + printRawDescriptor("Device descriptor", device.deviceDescriptor()); |
| 47 | + printRawDescriptor("Configuration descriptor", device.configurationDescriptor()); |
| 48 | + |
45 | 49 | System.out.println(); |
46 | 50 | System.out.println(); |
47 | 51 | } |
48 | 52 |
|
| 53 | + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") |
49 | 54 | private static void printInParens(Optional<String> text) { |
50 | 55 | if (text.isPresent()) { |
51 | 56 | System.out.printf(" (%s)%n", text.get()); |
@@ -85,4 +90,17 @@ private static void printEndpoint(USBEndpoint endpoint) { |
85 | 90 | System.out.printf(" Transfer type: %s%n", endpoint.transferType().name()); |
86 | 91 | System.out.printf(" Packet size: %d bytes%n", endpoint.packetSize()); |
87 | 92 | } |
| 93 | + |
| 94 | + private static void printRawDescriptor(String title, byte[] descriptor) { |
| 95 | + System.out.println(); |
| 96 | + System.out.println(title); |
| 97 | + |
| 98 | + int len = descriptor.length; |
| 99 | + for (int i = 0; i < len; i += 16) { |
| 100 | + System.out.printf("%04x ", i); |
| 101 | + for (int j = i; j < Math.min(i + 16, len); j += 1) |
| 102 | + System.out.printf(" %02x", descriptor[j] & 255); |
| 103 | + System.out.println(); |
| 104 | + } |
| 105 | + } |
88 | 106 | } |
0 commit comments