Commit 19e2a50f authored by Vincent van Beveren's avatar Vincent van Beveren

Updated FTDI library, minor changes

parent fd822bf9
......@@ -4,7 +4,5 @@ TODO:
- Drop lua for Javascript
- Documentation!
- libusb support for Linux (Proprietary FTDI drivers are a hassle under Linux)
Future:
- Maybe move away from XML (yeah, its kind of essiential), and move to a simpler
configuration format like YAML, libconfuse or JSON
- Migrate to gradle
- Move away from XML (yeah, its kind of essiential) to YAML
......@@ -132,7 +132,7 @@ public abstract class DataSource {
{
writeMedia(ctx, off + i, Arrays.copyOfRange(data, i, i + 8));
try {
Thread.sleep(10);
Thread.sleep(30);
} catch (InterruptedException e) {
}
......
......@@ -31,7 +31,7 @@
<javac srcdir="${src}" destdir="${build}" source="1.6" target="1.6" includeantruntime="no">
<classpath>
<pathelement location="../nikhef-tools/nikhef-tools.jar"/>
<pathelement location="lib/jna-4.3.0.jar"/>
<pathelement location="lib/jna-4.4.0.jar"/>
</classpath>
</javac>
</target>
......
......@@ -57,6 +57,7 @@ interface FTD2XX extends Library {
InputStream in = null;
FileOutputStream fos = null;
File fileOut = null;
String res;
System.setProperty("jna.library.path",
System.getProperty("java.io.tmpdir"));
......@@ -69,7 +70,7 @@ interface FTD2XX extends Library {
"/natives/x86_64/libftd2xx.so");
} else if (Platform.isWindows()) {
in = Loader.class.getResourceAsStream(
"/natives/x86_64/ftd2xx.dll");
"/natives/x86_64/ftd2xx64.dll");
}
} else {
if (Platform.isLinux()) {
......@@ -92,7 +93,6 @@ interface FTD2XX extends Library {
int count;
byte[] buf = new byte[1024];
while ((count = in.read(buf, 0, buf.length)) > 0) {
fos.write(buf, 0, count);
}
......@@ -105,24 +105,22 @@ interface FTD2XX extends Library {
in.close();
} catch (IOException ex) {
}
if (fos != null) {
try {
fos.close();
} catch (IOException ex) {
}
}
String res;
if (Platform.isMac()) {
StringTokenizer st = new StringTokenizer(
fileOut.getName(), ".");
res = st.nextToken().substring(3);
} else {
res = fileOut.getName();
}
return res;
}
if (Platform.isMac()) {
StringTokenizer st = new StringTokenizer(
fileOut.getName(), ".");
res = st.nextToken().substring(3);
} else {
res = fileOut.getName();
}
return res;
} else {
throw new Error("Not supported OS");
}
......@@ -130,6 +128,7 @@ interface FTD2XX extends Library {
}
final FTD2XX INSTANCE = (FTD2XX) Native.loadLibrary(
Loader.getNative(), FTD2XX.class);
public final static int FT_FLAGS_OPENED = 0x00000001;
public final static int FT_LIST_NUMBER_ONLY = 0x80000,
FT_LIST_BY_INDEX = 0x40000000,
......
......@@ -23,23 +23,24 @@
*/
package com.ftdi;
import com.ftdi.FTD2XX.FT_DEVICE_LIST_INFO_NODE;
import com.sun.jna.Memory;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.ByteByReference;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import nl.nikhef.tools.Utils;
import com.ftdi.FTD2XX.FT_DEVICE_LIST_INFO_NODE;
import com.sun.jna.Library;
import com.sun.jna.Memory;
import com.sun.jna.NativeLibrary;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.ByteByReference;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
/**
* Java class to communicate easily to a FTDI device.
......@@ -47,7 +48,11 @@ import nl.nikhef.tools.Utils;
*/
public class FTDevice {
private static final Logger LOG = Logger.getLogger(FTDevice.class.getSimpleName());
static private final FTD2XX ftd2xx = FTD2XX.INSTANCE;
private final int devID, devLocationID, flag;
private final DeviceType devType;
private Pointer ftHandle;
......@@ -55,6 +60,7 @@ public class FTDevice {
private FTDeviceInputStream fTDeviceInputStream = null;
private FTDeviceOutputStream fTDeviceOutputStream = null;
private boolean open = false;
private static boolean firstTime = true;
private FTDevice(DeviceType devType, int devID, int devLocationID,
String devSerialNumber, String devDescription, Pointer ftHandle,
......@@ -183,6 +189,11 @@ public class FTDevice {
public static List<FTDevice> getDevices(boolean isIncludeOpenedDevices)
throws FTD2XXException {
IntByReference devNum = new IntByReference();
if (firstTime) {
LOG.info("Loaded native library from " + FTDevice.getNativeLibraryLocation());
firstTime = false;
}
ensureFTStatus(ftd2xx.FT_CreateDeviceInfoList(devNum));
......@@ -782,4 +793,14 @@ public class FTDevice {
}
super.finalize();
}
public static String getNativeLibraryLocation() {
try {
Library.Handler handler = (Library.Handler)Proxy.getInvocationHandler(ftd2xx);
NativeLibrary nl = handler.getNativeLibrary();
return nl.getFile().toString();
} catch (Exception e) {
return "<unknown>";
}
}
}
......@@ -89,6 +89,8 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
private static final int SCAN_DEVICE_DELAY = 2;
private static final Logger LOG = Logger.getLogger(SaFariPark.class.getSimpleName());
private DeviceManager _devMgr;
private EditPane _tabEdit;
private ActiveLogArea _logOut;
......@@ -104,7 +106,7 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
private ModuleManager _modMgr;
private DollyPanel _dp;
private Properties buildProps;
private static Properties buildProps;
private Action _selectOverlays = new ExtendedAbstractAction("Select overlays", Resources.getIcon("books"), "Select which SFP+ overlays to load") {
......@@ -184,8 +186,6 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
_appCtx = appCtx;
setLayout(new BorderLayout());
loadBuildProps();
setTitle("SaFariPark " + getFullRevision());
setSize(640, 480);
setIconImage(Resources.getImage("appicon"));
......@@ -259,10 +259,10 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
private void loadBuildProps() {
private static void loadBuildProps() {
buildProps = new Properties();
try {
InputStream is = getClass().getResourceAsStream("build.properties");
InputStream is = SaFariPark.class.getResourceAsStream("build.properties");
if (is != null)
{
buildProps.load(is);
......@@ -275,7 +275,7 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
private String getFullRevision() {
private static String getFullRevision() {
if (buildProps == null) {
return "(development)";
......@@ -345,7 +345,7 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
public static void main(String[] args)
{
SaFariPark.loadBuildProps();
Locale.setDefault(Locale.US);
try {
......@@ -372,7 +372,8 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
globalLogger.removeHandler(handler);
}
if (args.length == 2 && args[0].equals("--setdpi")){
......@@ -429,6 +430,8 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
System.getProperty("os.name"),
System.getProperty("os.version"),
System.getProperty("os.arch"));
pw.printf("SaFariPark=%s\n", SaFariPark.getFullRevision());
pw.println("Error trace:");
e.printStackTrace(pw);
......@@ -515,6 +518,17 @@ public class SaFariPark extends JFrame implements BaySelectionListener, WindowLi
}
});
LOG.info("SaFariPark " + SaFariPark.getFullRevision());
LOG.info(String.format("%s Java %s (%s bit) and %s (OS=%s, %s)\n",
System.getProperty("java.vendor"),
System.getProperty("java.version"),
System.getProperty("sun.arch.data.model") ,
System.getProperty("os.name"),
System.getProperty("os.version"),
System.getProperty("os.arch")));
}
public void deinit() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment