mirror of https://github.com/rusefi/RomRaider.git
op20 updates
git-svn-id: https://svn2.assembla.com/svn/romraider/trunk@215 38686702-15cf-42e4-a595-3071df8bf5ea
This commit is contained in:
parent
83103c04ae
commit
f579ce169e
|
@ -43,7 +43,7 @@ public final class ConnectionManagerFactory {
|
|||
try {
|
||||
return new J2534ConnectionManager(connectionProperties);
|
||||
} catch (Throwable t) {
|
||||
LOGGER.info("J2534 connection not available [" + t.getClass().getName() + ": " + t.getMessage() + "], trying serial connection...", t);
|
||||
LOGGER.info("J2534 connection not available [" + t.getClass().getName() + ": " + t.getMessage() + "], trying serial connection...");
|
||||
return new SerialConnectionManager(portName, connectionProperties);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
package com.romraider.io.j2534.api;
|
||||
|
||||
public interface J2534 {
|
||||
boolean isSupported();
|
||||
|
||||
int open();
|
||||
|
||||
Version readVersion(int deviceId);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package com.romraider.io.j2534.api;
|
||||
|
||||
import com.romraider.io.j2534.op20.J2534OpenPort20;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.CONFIG_LOOPBACK;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.CONFIG_P1_MAX;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.CONFIG_P3_MIN;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.CONFIG_P4_MIN;
|
||||
|
@ -33,7 +34,7 @@ public final class TestJ2534 {
|
|||
|
||||
public static void main(String[] args) {
|
||||
initDebugLogging();
|
||||
if (api.isSupported()) ecuInit();
|
||||
ecuInit();
|
||||
}
|
||||
|
||||
private static void ecuInit() {
|
||||
|
@ -74,6 +75,7 @@ public final class TestJ2534 {
|
|||
ConfigItem p1Max = new ConfigItem(CONFIG_P1_MAX, 2);
|
||||
ConfigItem p3Min = new ConfigItem(CONFIG_P3_MIN, 0);
|
||||
ConfigItem p4Min = new ConfigItem(CONFIG_P4_MIN, 0);
|
||||
api.setConfig(channelId, p1Max, p3Min, p4Min);
|
||||
ConfigItem loopback = new ConfigItem(CONFIG_LOOPBACK, 1);
|
||||
api.setConfig(channelId, p1Max, p3Min, p4Min, loopback);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,39 +31,15 @@ import static com.romraider.util.ByteUtil.asUnsignedInt;
|
|||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public final class OpenPort20Manager {
|
||||
private static final Logger LOGGER = getLogger(OpenPort20Manager.class);
|
||||
private static final String OP20PT32_DLL_LOCATION = "lib/windows/j2534.dll";
|
||||
private static boolean SUPPORTED;
|
||||
public final class J2534DllLocator {
|
||||
private static final Logger LOGGER = getLogger(J2534DllLocator.class);
|
||||
|
||||
private OpenPort20Manager() {
|
||||
private J2534DllLocator() {
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
SUPPORTED = init2();
|
||||
}
|
||||
|
||||
private static boolean init2() {
|
||||
File dll = findLibrary();
|
||||
if (dll == null) return false;
|
||||
try {
|
||||
copy(dll, new File(OP20PT32_DLL_LOCATION));
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Error initialising OP20 dll", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isSupported() {
|
||||
return SUPPORTED;
|
||||
}
|
||||
|
||||
private static File findLibrary() {
|
||||
public static File locate() {
|
||||
try {
|
||||
RegistryKey software = openSubkey(HKEY_LOCAL_MACHINE, "SOFTWARE", ACCESS_READ);
|
||||
RegistryKey passThruSupport = software.openSubKey("PassThruSupport.04.04");
|
||||
|
@ -113,24 +89,4 @@ public final class OpenPort20Manager {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void copy(File from, File to) {
|
||||
LOGGER.info("Copying: " + from.getAbsolutePath() + " => " + to.getAbsolutePath());
|
||||
try {
|
||||
FileReader in = new FileReader(from);
|
||||
try {
|
||||
FileWriter out = new FileWriter(to);
|
||||
try {
|
||||
int c;
|
||||
while ((c = in.read()) != -1) out.write(c);
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -48,17 +48,12 @@ import java.util.List;
|
|||
|
||||
public final class J2534OpenPort20 implements J2534 {
|
||||
private static final Logger LOGGER = getLogger(J2534OpenPort20.class);
|
||||
private final boolean supported = OpenPort20.isSupported();
|
||||
private final int protocol;
|
||||
|
||||
public J2534OpenPort20(int protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public boolean isSupported() {
|
||||
return supported;
|
||||
}
|
||||
|
||||
public int open() {
|
||||
int[] deviceId = {0};
|
||||
int status = PassThruOpen(null, deviceId);
|
||||
|
|
|
@ -50,17 +50,12 @@ import java.util.List;
|
|||
|
||||
public final class Old_J2534OpenPort20 implements J2534 {
|
||||
private static final Logger LOGGER = getLogger(J2534OpenPort20.class);
|
||||
private final boolean supported = OpenPort20.isSupported();
|
||||
private final int protocol;
|
||||
|
||||
public Old_J2534OpenPort20(int protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public boolean isSupported() {
|
||||
return supported;
|
||||
}
|
||||
|
||||
public int open() {
|
||||
int[] deviceId = {0};
|
||||
int status = PassThruOpen(null, deviceId);
|
||||
|
|
|
@ -23,7 +23,7 @@ import com.jinvoke.JInvoke;
|
|||
import com.jinvoke.NativeImport;
|
||||
|
||||
public final class OpenPort20 {
|
||||
private static final String OP20PT32_DLL = "C:/windows/system32/op20pt32.dll";
|
||||
private static final String OP20PT32_DLL = "op20pt32";
|
||||
|
||||
// FIX - Split out and separate these
|
||||
public static final int STATUS_NOERROR = 0x00;
|
||||
|
@ -41,14 +41,9 @@ public final class OpenPort20 {
|
|||
public static final int CONFIG_P4_MIN = 0x0C;
|
||||
|
||||
static {
|
||||
OpenPort20Manager.init();
|
||||
JInvoke.initialize();
|
||||
}
|
||||
|
||||
public static boolean isSupported() {
|
||||
return OpenPort20Manager.isSupported();
|
||||
}
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruOpen(String pName, int[] pDeviceID);
|
||||
|
||||
|
|
Loading…
Reference in New Issue