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

Updated FTDI library, minor changes

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