/*!
Java host software API of ZTEX SDK
Copyright (C) 2009-2014 ZTEX GmbH.
http://www.ztex.de
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see http://www.gnu.org/licenses/.
!*/
/*
USB device with ZTEX descriptor 1 and/or Cypress EZ-USB FX2 device
*/
package ztex;
import java.io.*;
import java.util.*;
import ch.ntb.usb.*;
/**
* A class representing an EZ-USB device that supports the ZTEX descriptor 1 or an unconfigured EZ-USB device.
* Instances of this class are usually created by {@link ZtexScanBus1}.
* The following table describes the ZTEX descriptor 1.
*
*
Field name | *Offset | *Size | *Description | *||||||||||||||||||||||||
ZTEX_DESCRIPTOR_SIZE | *0 | *1 | *Size of the descriptor in bytes; must be 40 for descriptor version 1 | *||||||||||||||||||||||||
ZTEX_DESCRIPTOR_VERSION | *1 | *1 | *Descriptor version; 1 for version 1 | *||||||||||||||||||||||||
ZTEXID | *2 | *4 | *ID; must be "ZTEX" | *||||||||||||||||||||||||
PRODUCT_ID | *6 | *4 | *Four numbers (0..255) representing the product ID and firmware compatibility information. * A firmware can overwrite an installed one * if ( INSTALLED.PRODUCTID[0]==0 || PRODUCTID[0]==0 || INSTALLED.PRODUCTID[0]==PRODUCTID[0] ) && ( INSTALLED.PRODUCTID[1]==0 || PRODUCTID[1]==0 || INSTALLED.PRODUCTID[1]==PRODUCTID[1] ) && ( INSTALLED.PRODUCTID[2]==0 || PRODUCTID[2]==0 || INSTALLED.PRODUCTID[2]==PRODUCTID[2] ) && ( INSTALLED.PRODUCTID[3]==0 || PRODUCTID[3]==0 || INSTALLED.PRODUCTID[3]==PRODUCTID[3] )* Here is a list of the preserved product ID's: *
|
* ||||||||||||||||||||||||
FW_VERSION | *10 | *1 | *May be used to specify the firmware version. | *||||||||||||||||||||||||
INTERFACE_VERSION | *11 | *1 | *The interface version. This number specifies the protocol that is used for interfacing the host software. A description of interface version 1 can be found in {@link Ztex1v1} | *||||||||||||||||||||||||
INTERFACE_CAPABILITIES | *12 | *6 | *6 bytes, each bit represents a capability. If set, the capability is supported. A description of the capabilities of interface version 1 can be found in {@link Ztex1v1} | *||||||||||||||||||||||||
MODULE_RESERVED | *18 | *12 | *12 bytes for application specific use, i.e. they depend from the PRODUCT_ID | *||||||||||||||||||||||||
SN_STRING | *30 | *10 | *A serial number string of 10 characters. The default SN is "0000000000" | *
* Please read the informations about USB vendor and product ID's.
* @see #ztexProductIdMax
*/
public static final int ztexProductId = 0x100;
/**
* Largest USB product ID for ZTEX devices that support ZTEX descriptor 1: 0x1ff.
* USB product ID's from {@link #ztexProductId}+1 to ztexProductIdMax (0x101 to 0x1ff) are reserved for ZTEX devices and allow to identify products without reading the ZTEX descriptor.
*
* Please read the informations about USB vendor and product ID's.
* @see #ztexProductId
*/
public static final int ztexProductIdMax = 0x1ff;
private Usb_Device dev = null;
private boolean valid = false; // true if descriptor 1 is available
private int usbVendorId = -1;
private int usbProductId = -1;
private String manufacturerString = null;
private String productString = null;
private String snString = null;
private byte productId[] = { 0,0,0,0 }; // product ID from the ZTEX descriptor, not the USB product ID
private byte fwVersion = 0;
private byte interfaceVersion = 0;
private byte interfaceCapabilities[] = { 0,0,0,0, 0,0 };
private byte moduleReserved[] = { 0,0,0,0, 0,0,0,0, 0,0,0,0 };
// ******* byteArrayString *****************************************************
/**
* Produces a nice string representation of an array of bytes.
* @param buf A byte array.
* @return a nice string
*/
public static String byteArrayString ( byte buf[] ) {
String s = new String( "" );
for ( int i = 0; i Error running this command: diff: : No such file or directory
* The given product ID is compatible
* if ( this.productId(0)==0 || productId0<=0 || this.productId(0)==productId0 ) &&
( this.productId(0)==0 || productId1<=0 || this.productId(1)==productId1 ) &&
( this.productId(2)==0 || productId2<=0 || this.productId(2)==productId2 ) &&
( this.productId(3)==0 || productId3<=0 || this.productId(3)==productId3 )
* @param productId0 Byte 0 of the given product ID
* @param productId1 Byte 1 of the given product ID
* @param productId2 Byte 2 of the given product ID
* @param productId3 Byte 3 of the given product ID
* @return true if the given product ID is compatible
*/
public final boolean compatible( int productId0, int productId1, int productId2, int productId3 ) {
return ( productId[0]==0 || productId0<=0 || (productId[0] & 255) == productId0 ) &&
( productId[1]==0 || productId1<=0 || (productId[1] & 255) == productId1 ) &&
( productId[2]==0 || productId2<=0 || (productId[2] & 255) == productId2 ) &&
( productId[3]==0 || productId3<=0 || (productId[3] & 255) == productId3 );
}
// ******* dev *****************************************************************
/**
* Returns the USB device.
* @return the USB device.
*/
public final Usb_Device dev() {
return dev;
}
// ******* valid ***************************************************************
/**
* Returns true if ZTEX descriptor 1 is available.
* @return true if ZTEX descriptor 1 is available.
*/
public final boolean valid() {
return valid;
}
// ******* usbVendorId *********************************************************
/**
* Returns the USB vendor ID of the device.
* @return the USB vendor ID of the device.
*/
public final int usbVendorId() {
return usbVendorId;
}
// ******* usbProductId *********************************************************
/**
* Returns the USB product ID of the device.
* @return the USB product ID of the device.
*/
public final int usbProductId() {
return usbProductId;
}
// ******* manufacturerString **************************************************
/**
* Returns the manufacturer string of the device.
* @return the manufacturer string of the device.
*/
public final String manufacturerString() {
return manufacturerString;
}
// ******* productString *******************************************************
/**
* Returns the product string of the device.
* @return the product string of the device.
*/
public final String productString() {
return productString;
}
// ******* snString ************************************************************
/**
* Returns the serial number string of the device.
* @return the serial number string of the device.
*/
public final String snString() {
return snString;
}
// ******* productId ***********************************************************
/**
* Returns the product ID (all 4 bytes).
* @return PRODUCT_ID, see above.
*/
public final byte[] productId() {
return productId;
}
/**
* Returns byte i of the product ID.
* @return PRODUCT_ID[i], see above.
* @param i index
*/
public int productId( int i ) {
return productId[i] & 255;
}
// ******* fwVersion ***********************************************************
/**
* Returns the firmware version.
* @return FW_VERSION, see above.
*/
public final int fwVersion() {
return fwVersion & 255;
}
// ******* interfaceVersion *****************************************************
/**
* Returns the interface version.
* @return INTERFACE_VERSION, see above.
*/
public final int interfaceVersion() {
return interfaceVersion & 255;
}
// ******* interfaceCapabilities ************************************************
/**
* Returns the interface capabilities (all 6 bytes).
* @return INTERFACE_CAPABILITIES, see above.
*/
public final byte[] interfaceCapabilities() {
return interfaceCapabilities;
}
/**
* Returns byte i of the interface capabilities.
* @return INTERFACE_CAPABILITIES[i], see above.
* @param i index
*/
public final int interfaceCapabilities( int i ) {
return interfaceCapabilities[i] & 255;
}
/**
* Returns byte i, bit j of the interface capabilities.
* @return INTERFACE_CAPABILITIES[i].j, see above.
* @param i byte index
* @param j bit index
*/
public final boolean interfaceCapabilities( int i, int j ) {
return (i>=0) && (i<=5) && (j>=0) && (j<8) &&
(((interfaceCapabilities[i] & 255) & (1 << j)) != 0);
}
// ******* moduleReserved ******************************************************
/**
* Returns the application specific information (all 12 bytes).
* @return MODULE_RESERVED, see above.
*/
public final byte[] moduleReserved() {
return moduleReserved;
}
/**
* Returns byte i of the application specific information.
* @return MODULE_RESERVED[i], see above.
* @param i index
*/
public final int moduleReserved( int i ) {
return moduleReserved[i] & 255;
}
}
diff -w -U 5 "/tmp/C5xm6K" ""