add j2534 support

git-svn-id: https://svn2.assembla.com/svn/romraider/trunk@147 38686702-15cf-42e4-a595-3071df8bf5ea
This commit is contained in:
kascade 2008-09-20 21:34:08 +00:00
parent e4dec1012f
commit 7871c05a80
2 changed files with 20 additions and 3 deletions

View File

@ -17,7 +17,7 @@ public interface J2534 {
void writeMsg(int channelId, byte[] data);
byte[] readMsg(int channelId);
byte[] readMsg(int channelId, long timeout);
void stopMsgFilter(int channelId, int msgId);

View File

@ -19,6 +19,8 @@ import static com.romraider.io.j2534.op20.OpenPort20.PassThruStartMsgFilter;
import static com.romraider.io.j2534.op20.OpenPort20.PassThruStopMsgFilter;
import static com.romraider.io.j2534.op20.OpenPort20.PassThruWriteMsgs;
import static com.romraider.io.j2534.op20.OpenPort20.STATUS_NOERROR;
import static com.romraider.util.HexUtil.asHex;
import static java.lang.System.currentTimeMillis;
public final class J2534OpenPort20 implements J2534 {
private final boolean supported = OpenPort20.isSupported();
@ -89,12 +91,27 @@ public final class J2534OpenPort20 implements J2534 {
}
// FIX - Needs to check msg type and retry until msg received
public byte[] readMsg(int channelId) {
public byte[] readMsg(int channelId, long timeout) {
long end = currentTimeMillis() + timeout;
do {
PassThruMessage msg = doReadMsg(channelId);
System.out.println("Response: [ProtocolID=" + msg.ProtocolID + "|RxStatus=" + msg.RxStatus + "|TxFlags=" + msg.TxFlags + "|Timestamp=" + msg.Timestamp + "|DataSize=" + msg.DataSize + "|Data=" + asHex(msg.Data) + "]");
if (isResponse(msg)) return data(msg);
} while (currentTimeMillis() <= end);
throw new J2534Exception("Read timeout.");
}
private boolean isResponse(PassThruMessage msg) {
// FIX - Complete!
return false;
}
private PassThruMessage doReadMsg(int channelId) {
PassThruMessage msg = passThruMessage();
int[] pNumMsgs = {1};
int status = PassThruReadMsgs(channelId, msg, pNumMsgs, 0);
if (status != STATUS_NOERROR) handleError(status);
return data(msg);
return msg;
}
public void stopMsgFilter(int channelId, int msgId) {