add j2534 support

git-svn-id: https://svn2.assembla.com/svn/romraider/trunk@143 38686702-15cf-42e4-a595-3071df8bf5ea
This commit is contained in:
kascade 2008-09-20 12:34:39 +00:00
parent 9c4e2c5a57
commit 81d593bef8
3 changed files with 18 additions and 13 deletions

View File

@ -7,7 +7,7 @@ public interface J2534 {
Version readVersion(int deviceId);
int connect(int deviceId);
int connect(int deviceId, int flags, int baud);
void setConfig(int channelId, ConfigItem... items);

View File

@ -4,9 +4,11 @@ import com.romraider.io.j2534.op20.J2534OpenPort20;
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;
import static com.romraider.io.j2534.op20.OpenPort20.FLAG_NONE;
import static com.romraider.io.j2534.op20.OpenPort20.PROTOCOL_ISO9141;
public final class TestJ2534 {
private static final J2534 api = new J2534OpenPort20();
private static final J2534 api = new J2534OpenPort20(PROTOCOL_ISO9141);
public static void main(String[] args) {
if (!api.isSupported()) return;
@ -17,7 +19,7 @@ public final class TestJ2534 {
int deviceId = api.open();
try {
version(deviceId);
int channelId = api.connect(deviceId);
int channelId = api.connect(deviceId, FLAG_NONE, 4800);
try {
setConfig(channelId);
int msgId = api.startPassMsgFilter(channelId, (byte) 0x00, (byte) 0x00);

View File

@ -5,10 +5,8 @@ import com.romraider.io.j2534.api.J2534;
import com.romraider.io.j2534.api.J2534Exception;
import com.romraider.io.j2534.api.Version;
import static com.romraider.io.j2534.op20.OpenPort20.FILTER_PASS;
import static com.romraider.io.j2534.op20.OpenPort20.FLAG_NONE;
import static com.romraider.io.j2534.op20.OpenPort20.IOCTL_GET_CONFIG;
import static com.romraider.io.j2534.op20.OpenPort20.IOCTL_SET_CONFIG;
import static com.romraider.io.j2534.op20.OpenPort20.PROTOCOL_ISO9141;
import static com.romraider.io.j2534.op20.OpenPort20.PassThruClose;
import static com.romraider.io.j2534.op20.OpenPort20.PassThruConnect;
import static com.romraider.io.j2534.op20.OpenPort20.PassThruDisconnect;
@ -24,6 +22,11 @@ import static com.romraider.io.j2534.op20.OpenPort20.STATUS_NOERROR;
public final class J2534OpenPort20 implements J2534 {
private final boolean supported = OpenPort20.isSupported();
private final int protocol;
public J2534OpenPort20(int protocol) {
this.protocol = protocol;
}
public boolean isSupported() {
return supported;
@ -45,9 +48,9 @@ public final class J2534OpenPort20 implements J2534 {
return new Version(toString(firmware), toString(dll), toString(api));
}
public int connect(int deviceId) {
public int connect(int deviceId, int flags, int baud) {
int[] channelId = {0};
int status = PassThruConnect(deviceId, PROTOCOL_ISO9141, FLAG_NONE, 4800, channelId);
int status = PassThruConnect(deviceId, protocol, flags, baud, channelId);
if (status != STATUS_NOERROR) handleError(status);
return channelId[0];
}
@ -145,33 +148,33 @@ public final class J2534OpenPort20 implements J2534 {
return input;
}
private static PassThruMessage passThruMessage(byte... data) {
private PassThruMessage passThruMessage(byte... data) {
PassThruMessage msg = passThruMessage();
System.arraycopy(data, 0, msg.Data, 0, data.length);
msg.DataSize = data.length;
return msg;
}
private static PassThruMessage passThruMessage() {
private PassThruMessage passThruMessage() {
PassThruMessage msg = new PassThruMessage();
msg.ProtocolID = PROTOCOL_ISO9141;
msg.ProtocolID = protocol;
return msg;
}
private static byte[] data(PassThruMessage msg) {
private byte[] data(PassThruMessage msg) {
int length = msg.DataSize;
byte[] data = new byte[length];
System.arraycopy(msg.Data, 0, data, 0, length);
return data;
}
private static void handleError(int status) {
private void handleError(int status) {
byte[] error = new byte[80];
PassThruGetLastError(error);
throw new J2534Exception("Error: [" + status + "] " + toString(error));
}
private static String toString(byte[] bytes) {
private String toString(byte[] bytes) {
String msg = "";
for (int b : bytes) {
if (b == 0x00) continue;