System.out.println(HidPacketProtocol.uint8ToInt(response[0]));
for (int i = 1; i + 4 < response.length; i += 5) {
- OUTPUT THE TYPE AS WELL
+ // TODO OUTPUT THE TYPE AS WELL
int capacity = (HidPacketProtocol.uint8ToInt(response[i + 1]) << 24) |
(HidPacketProtocol.uint8ToInt(response[i + 2]) << 16) |
(HidPacketProtocol.uint8ToInt(response[i + 3]) << 8) |
System.out.print("Found storage device with capacity: ");
System.out.println(capacity * 512L);
}
+
+ // System.out.println("Erasing 1 sectors");
+ // byte[] eraseCmd = {(byte)Commands.DEV_ERASE.ordinal(), (byte)1, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)1};
+ // response = protocolDevice.sendHIDPacket(eraseCmd, 1);
+
+ System.out.println("Writing a sector");
+ byte[] writeCmd = new byte[519];
+ writeCmd[0] = (byte)Commands.DEV_WRITE.ordinal();
+ writeCmd[1] = 1; // flash
+ writeCmd[2] = 0; // Sector number
+ writeCmd[3] = 0; // Sector number
+ writeCmd[4] = 0; // Sector number
+ writeCmd[5] = 1; // Sector number
+ for (var i = 0; i < 512; ++i) {
+ writeCmd[6+i] = HidPacketProtocol.intToUint8(255 - (i % 255));
+ }
+ response = protocolDevice.sendHIDPacket(writeCmd, 1);
+
+ System.out.println("Reading a sector");
+ byte[] readCmd = {(byte)Commands.DEV_READ.ordinal(), (byte)1, (byte)0, (byte)0, (byte)0, (byte)1};
+ byte[] readResponse = protocolDevice.sendHIDPacket(readCmd, 512);
+ for (var i = 0; i < readResponse.length; ++i) {
+ System.out.println(HidPacketProtocol.uint8ToInt(readResponse[i]));
+ }
+
+ System.out.println("FLASH test complete");
}