// Path: usbtools/src/main/java/io/trygvis/usb/tools/ztex/ZtexFpgaState.java
// public class ZtexFpgaState {
//     public final boolean configured;
//     public final byte checksum;
//     public final int bytesTransferred;
//     public final int initB;
// 
//     public ZtexFpgaState(boolean configured, byte checksum, int bytesTransferred, int initB) {
//         this.configured = configured;
//         this.checksum = checksum;
//         this.bytesTransferred = bytesTransferred;
//         this.initB = initB;
//     }
// 
//     public static ZtexFpgaState ztexFpgaStateFromBytes(byte[] bytes) {
//         if(bytes.length < 7) {
//             throw new RuntimeException("Invalid FPGA state descriptor, expected at least 7 bytes, got " + bytes.length + " bytes.");
//         }
//         return new ZtexFpgaState(bytes[0] == 0,
//             bytes[1],
//             toInt(bytes[2], bytes[3], bytes[4], bytes[5]),
//             UsbUtil.unsignedInt(bytes[6]));
//     }
// 
//     public String toString() {
//         if(!configured) {
//             return "Configured: no, checksum=" + toHexString(checksum) + ", bytesTransferred=" + bytesTransferred + ", initB=" + initB + ".";
//         }
//         return "Configured: yes, checksum=" + toHexString(checksum) + ", bytesTransferred=" + bytesTransferred + ", initB=" + initB + ".";
//     }
// }


import static java.lang.System.*;
import static io.trygvis.usb.tools.ztex.ZtexFpgaState.*;
import javax.usb.*;
import javax.usb.util.*;
import java.io.*;
        int size = vendorRequest(usbDevice, (byte) 0x22, (short) 0, (short) 0, buf);

        if (size != 40) {
            throw new ZtexException("Invalid Ztex device descriptor: expected the descriptor to be 40 bytes, was " + size + ".");
        }

        try {
            byte[] productId = new byte[4];
            arraycopy(buf, 6, productId, 0, 4);
            byte[] intefaceCapabilities = new byte[6];
            arraycopy(buf, 12, intefaceCapabilities, 0, 6);

            ZtexDeviceDescriptor deviceDescriptor = new ZtexDeviceDescriptor(buf[0],
                buf[1],
                new String(buf, 2, 4, "ascii"),
                productId,
                buf[10],
                buf[11],
                intefaceCapabilities);

            return new ZtexDevice(usbDevice, deviceDescriptor);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }

    // -----------------------------------------------------------------------
    // FPGA Configuration
    // -----------------------------------------------------------------------

// Path: usbtools/src/main/java/io/trygvis/usb/tools/ztex/ZtexFpgaState.java
// public class ZtexFpgaState {
//     public final boolean configured;
//     public final byte checksum;
//     public final int bytesTransferred;
//     public final int initB;
// 
//     public ZtexFpgaState(boolean configured, byte checksum, int bytesTransferred, int initB) {
//         this.configured = configured;
//         this.checksum = checksum;
//         this.bytesTransferred = bytesTransferred;
//         this.initB = initB;
//     }
// 
//     public static ZtexFpgaState ztexFpgaStateFromBytes(byte[] bytes) {
//         if(bytes.length < 7) {
//             throw new RuntimeException("Invalid FPGA state descriptor, expected at least 7 bytes, got " + bytes.length + " bytes.");
//         }
//         return new ZtexFpgaState(bytes[0] == 0,
//             bytes[1],
//             toInt(bytes[2], bytes[3], bytes[4], bytes[5]),
//             UsbUtil.unsignedInt(bytes[6]));
//     }
// 
//     public String toString() {
//         if(!configured) {
//             return "Configured: no, checksum=" + toHexString(checksum) + ", bytesTransferred=" + bytesTransferred + ", initB=" + initB + ".";
//         }
//         return "Configured: yes, checksum=" + toHexString(checksum) + ", bytesTransferred=" + bytesTransferred + ", initB=" + initB + ".";
//     }
// }


// Path: usbtools/src/main/java/io/trygvis/usb/tools/ztex/ZtexDevice.java
import static java.lang.System.*;
import static io.trygvis.usb.tools.ztex.ZtexFpgaState.*;
import javax.usb.*;
import javax.usb.util.*;
import java.io.*;

        int size = vendorRequest(usbDevice, (byte) 0x22, (short) 0, (short) 0, buf);

        if (size != 40) {
            throw new ZtexException("Invalid Ztex device descriptor: expected the descriptor to be 40 bytes, was " + size + ".");
        }

        try {
            byte[] productId = new byte[4];
            arraycopy(buf, 6, productId, 0, 4);
            byte[] intefaceCapabilities = new byte[6];
            arraycopy(buf, 12, intefaceCapabilities, 0, 6);

            ZtexDeviceDescriptor deviceDescriptor = new ZtexDeviceDescriptor(buf[0],
                buf[1],
                new String(buf, 2, 4, "ascii"),
                productId,
                buf[10],
                buf[11],
                intefaceCapabilities);

            return new ZtexDevice(usbDevice, deviceDescriptor);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }

    // -----------------------------------------------------------------------
    // FPGA Configuration
    // -----------------------------------------------------------------------

    public ZtexFpgaState getFpgaState() throws UsbException {