Changeset 147


Ignore:
Timestamp:
09/20/2008 09:34:08 PM (5 years ago)
Author:
kascade
Message:

add j2534 support

Location:
trunk/src/com/romraider/io/j2534
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/romraider/io/j2534/api/J2534.java

    r144 r147  
    1818    void writeMsg(int channelId, byte[] data); 
    1919 
    20     byte[] readMsg(int channelId); 
     20    byte[] readMsg(int channelId, long timeout); 
    2121 
    2222    void stopMsgFilter(int channelId, int msgId); 
  • trunk/src/com/romraider/io/j2534/op20/J2534OpenPort20.java

    r144 r147  
    2020import static com.romraider.io.j2534.op20.OpenPort20.PassThruWriteMsgs; 
    2121import static com.romraider.io.j2534.op20.OpenPort20.STATUS_NOERROR; 
     22import static com.romraider.util.HexUtil.asHex; 
     23import static java.lang.System.currentTimeMillis; 
    2224 
    2325public final class J2534OpenPort20 implements J2534 { 
     
    9092 
    9193    // FIX - Needs to check msg type and retry until msg received 
    92     public byte[] readMsg(int channelId) { 
     94    public byte[] readMsg(int channelId, long timeout) { 
     95        long end = currentTimeMillis() + timeout; 
     96        do { 
     97            PassThruMessage msg = doReadMsg(channelId); 
     98            System.out.println("Response: [ProtocolID=" + msg.ProtocolID + "|RxStatus=" + msg.RxStatus + "|TxFlags=" + msg.TxFlags + "|Timestamp=" + msg.Timestamp + "|DataSize=" + msg.DataSize + "|Data=" + asHex(msg.Data) + "]"); 
     99            if (isResponse(msg)) return data(msg); 
     100        } while (currentTimeMillis() <= end); 
     101        throw new J2534Exception("Read timeout."); 
     102    } 
     103 
     104    private boolean isResponse(PassThruMessage msg) { 
     105        // FIX - Complete! 
     106        return false; 
     107    } 
     108 
     109    private PassThruMessage doReadMsg(int channelId) { 
    93110        PassThruMessage msg = passThruMessage(); 
    94111        int[] pNumMsgs = {1}; 
    95112        int status = PassThruReadMsgs(channelId, msg, pNumMsgs, 0); 
    96113        if (status != STATUS_NOERROR) handleError(status); 
    97         return data(msg); 
     114        return msg; 
    98115    } 
    99116 
Note: See TracChangeset for help on using the changeset viewer.