System.out.println(HidPacketProtocol.uint8ToInt(response[0]));
for (int i = 1; i + 4 < response.length; i += 5) {
- // TODO OUTPUT THE TYPE AS WELL
+ int devType = HidPacketProtocol.uint8ToInt(response[i]);
+ String devTypeStr = "Unknown";
+ switch (devType) {
+ case 0: devTypeStr = "SD"; break;
+ case 1: devTypeStr = "SPIFLASH"; break;
+ }
+
int capacity = (HidPacketProtocol.uint8ToInt(response[i + 1]) << 24) |
(HidPacketProtocol.uint8ToInt(response[i + 2]) << 16) |
(HidPacketProtocol.uint8ToInt(response[i + 3]) << 8) |
(HidPacketProtocol.uint8ToInt(response[i + 4]));
- System.out.print("Found storage device with capacity: ");
+ System.out.print("Found storage device type " + devTypeStr + " with capacity: ");
System.out.println(capacity * 512L);
}
/*
- 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);
private Set<Quirks> quirks;
+ private int storageDevice;
+
public DiskConfig(
Type type,
long sdSectorStart,
this.revision = other.revision;
this.serial = other.serial;
this.quirks = new HashSet<>(other.quirks);
+ this.storageDevice = other.storageDevice;
}
public DiskConfig(
this.serial = this.pad("12345678", 16);
this.quirks = new HashSet<Quirks>();
+
+ this.storageDevice = 0;
}
public DiskConfig(byte[] in) {
this.revision = new String(in, 42, 4, StandardCharsets.US_ASCII);
this.serial = new String(in, 46, 16, StandardCharsets.US_ASCII);
- this.quirks = Quirks.fromBitmask(BitUtil.letohs(in, 52));
+ this.quirks = Quirks.fromBitmask(BitUtil.letohs(in, 62));
+
+ storageDevice = BitUtil.uint8ToInt(in[64]);
}
public byte[] asBytes() {
byte[] out = new byte[LENGTH];
- out[0] = BitUtil.intToUint8((this.scsiId & 0x07) | (this.active ? 0 : 0x80));
+ out[0] = BitUtil.intToUint8((this.scsiId & 0x07) | (this.active ? 0x80 : 0));
out[1] = BitUtil.intToUint8(this.deviceType.getValue());
out[2] = 0; // flagsDeprecated
System.arraycopy(this.serial.getBytes(StandardCharsets.US_ASCII), 0, out, 46, 16);
var quirksMask = BitUtil.getMask(this.quirks);
- out[52] = BitUtil.longToUint8(quirksMask);
- out[53] = BitUtil.longToUint8(quirksMask >> 8);
+ out[62] = BitUtil.longToUint8(quirksMask);
+ out[63] = BitUtil.longToUint8(quirksMask >> 8);
+
+ out[64] = BitUtil.intToUint8((this.scsiId & 0x07) == 1 ? 1 : 0);
return out;
}