mirror of https://github.com/rusefi/RomRaider.git
J2534 API updated to remove dependency on J/Invoke
J2534 API refactored to use JNA 3.4.0 TXS plugin refactored by nitros@romraider.forum Removed OpenPort 2.0 specific package (op20) as it is now supported in the J2534 API Including com4j-x86.dll to ensure it is present in the install directory to avoid write permission issues on Win7 Commented out call to macro_svn_revision in build.xml for the time being, buildnumber will default to 0
This commit is contained in:
parent
1763ac9ddc
commit
f42670241f
11
.classpath
11
.classpath
|
@ -28,6 +28,15 @@
|
|||
<classpathentry kind="lib" path="lib/common/jdic.jar"/>
|
||||
<classpathentry kind="lib" path="lib/common/jfreechart-1.0.9.jar"/>
|
||||
<classpathentry kind="lib" path="lib/common/jcommon-1.0.12.jar"/>
|
||||
<classpathentry kind="lib" path="lib/common/jinvoke-3.0.3.jar"/>
|
||||
<classpathentry kind="lib" path="C:/repositories/RomRaider/lib/common/jna.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="http://twall.github.com/jna/3.4.0/javadoc/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="C:/repositories/RomRaider/lib/common/platform.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="http://twall.github.com/jna/3.4.0/javadoc/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="build/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -77,8 +77,8 @@
|
|||
<property name="optimize" value="on"/>
|
||||
<property name="deprecation" value="on"/>
|
||||
|
||||
<!-- get the current svn revision (needed by version.properties) - if repository is unavailable, this will be zero -->
|
||||
<macro_svn_revision repository="https://svn2.assembla.com/svn/romraider" property="svn.revision"/>
|
||||
<!-- get the current svn revision (needed by version.properties) - if repository is unavailable, this will be zero
|
||||
<macro_svn_revision repository="https://svn2.assembla.com/svn/romraider" property="svn.revision"/> -->
|
||||
|
||||
<!-- Set the buildnumber to be the revision fetched from the repository, but default to zero for
|
||||
offline work -->
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
|||
datasource.class=com.romraider.logger.external.txstuner.plugin.TxsTunerDataSource
|
||||
datasource.class=com.romraider.logger.external.txs.plugin.TxsTunerDataSource
|
|
@ -0,0 +1 @@
|
|||
datasource.class=com.romraider.logger.external.txs.plugin.TxsUtecLogger1DataSource
|
|
@ -25,6 +25,8 @@ import static com.romraider.util.proxy.Proxifier.proxy;
|
|||
import com.romraider.util.proxy.TimerWrapper;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
import static com.romraider.util.Platform.isPlatform;
|
||||
import static com.romraider.util.Platform.WINDOWS;
|
||||
|
||||
public final class ConnectionManagerFactory {
|
||||
private static final Logger LOGGER = getLogger(ConnectionManagerFactory.class);
|
||||
|
@ -41,7 +43,9 @@ public final class ConnectionManagerFactory {
|
|||
|
||||
private static ConnectionManager manager(String portName, ConnectionProperties connectionProperties) {
|
||||
try {
|
||||
LOGGER.info("Trying J2534 connection...");
|
||||
if (!isPlatform(WINDOWS))
|
||||
throw new RuntimeException ("J2534 is not support on this platform");
|
||||
LOGGER.info("Trying J2534 connection...");
|
||||
return new J2534ConnectionManager(connectionProperties);
|
||||
} catch (Throwable t) {
|
||||
LOGGER.info("J2534 connection not available [" + t.getClass().getName() + ": " + t.getMessage() + "], trying serial connection...");
|
||||
|
|
|
@ -19,32 +19,24 @@
|
|||
|
||||
package com.romraider.io.j2534.api;
|
||||
|
||||
import com.romraider.io.connection.ConnectionManager;
|
||||
import com.romraider.io.connection.ConnectionProperties;
|
||||
import com.romraider.io.j2534.op20.Old_J2534OpenPort20;
|
||||
import com.romraider.logger.ecu.comms.manager.PollingState;
|
||||
|
||||
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;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.FLAG_ISO9141_NO_CHECKSUM;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.PROTOCOL_ISO9141;
|
||||
import static com.romraider.io.protocol.ssm.SSMChecksumCalculator.calculateChecksum;
|
||||
import static com.romraider.util.HexUtil.asHex;
|
||||
import static com.romraider.util.ParamChecker.checkNotNull;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import static java.lang.System.arraycopy;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.romraider.io.connection.ConnectionManager;
|
||||
import com.romraider.io.connection.ConnectionProperties;
|
||||
import com.romraider.io.j2534.api.J2534Impl.Config;
|
||||
import com.romraider.io.j2534.api.J2534Impl.Flag;
|
||||
import com.romraider.io.j2534.api.J2534Impl.Protocol;
|
||||
import com.romraider.logger.ecu.comms.manager.PollingState;
|
||||
|
||||
public final class J2534ConnectionManager implements ConnectionManager {
|
||||
private static final Logger LOGGER = getLogger(J2534ConnectionManager.class);
|
||||
private final J2534 api = new Old_J2534OpenPort20(PROTOCOL_ISO9141);
|
||||
// private final J2534 api = new J2534OpenPort20(PROTOCOL_ISO9141);
|
||||
// private final J2534 api = proxy(new Old_J2534OpenPort20(PROTOCOL_ISO9141), TimerWrapper.class);
|
||||
// private final J2534 api = proxy(new J2534OpenPort20(PROTOCOL_ISO9141), TimerWrapper.class);
|
||||
private J2534 api = new J2534Impl(Protocol.ISO9141);
|
||||
private int channelId;
|
||||
private int deviceId;
|
||||
private int msgId;
|
||||
|
@ -126,7 +118,7 @@ public final class J2534ConnectionManager implements ConnectionManager {
|
|||
deviceId = api.open();
|
||||
try {
|
||||
version(deviceId);
|
||||
channelId = api.connect(deviceId, FLAG_ISO9141_NO_CHECKSUM, baudRate);
|
||||
channelId = api.connect(deviceId, Flag.ISO9141_NO_CHECKSUM.getValue(), baudRate);
|
||||
setConfig(channelId);
|
||||
msgId = api.startPassMsgFilter(channelId, (byte) 0x00, (byte) 0x00);
|
||||
} catch (Exception e) {
|
||||
|
@ -142,10 +134,10 @@ public final class J2534ConnectionManager implements ConnectionManager {
|
|||
}
|
||||
|
||||
private void setConfig(int channelId) {
|
||||
ConfigItem p1Max = new ConfigItem(CONFIG_P1_MAX, 2);
|
||||
ConfigItem p3Min = new ConfigItem(CONFIG_P3_MIN, 0);
|
||||
ConfigItem p4Min = new ConfigItem(CONFIG_P4_MIN, 0);
|
||||
ConfigItem loopback = new ConfigItem(CONFIG_LOOPBACK, 1);
|
||||
ConfigItem p1Max = new ConfigItem(Config.P1_MAX.getValue(), 2);
|
||||
ConfigItem p3Min = new ConfigItem(Config.P3_MIN.getValue(), 0);
|
||||
ConfigItem p4Min = new ConfigItem(Config.P4_MIN.getValue(), 0);
|
||||
ConfigItem loopback = new ConfigItem(Config.LOOPBACK.getValue(), 1);
|
||||
api.setConfig(channelId, p1Max, p3Min, p4Min, loopback);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,845 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.io.j2534.api;
|
||||
|
||||
import static com.romraider.io.j2534.api.J2534_v0404.PassThruClose;
|
||||
import static com.romraider.io.j2534.api.J2534_v0404.PassThruConnect;
|
||||
import static com.romraider.io.j2534.api.J2534_v0404.PassThruDisconnect;
|
||||
import static com.romraider.io.j2534.api.J2534_v0404.PassThruGetLastError;
|
||||
import static com.romraider.io.j2534.api.J2534_v0404.PassThruIoctl;
|
||||
import static com.romraider.io.j2534.api.J2534_v0404.PassThruOpen;
|
||||
import static com.romraider.io.j2534.api.J2534_v0404.PassThruReadMsgs;
|
||||
import static com.romraider.io.j2534.api.J2534_v0404.PassThruReadVersion;
|
||||
import static com.romraider.io.j2534.api.J2534_v0404.PassThruStartMsgFilter;
|
||||
import static com.romraider.io.j2534.api.J2534_v0404.PassThruStopMsgFilter;
|
||||
import static com.romraider.io.j2534.api.J2534_v0404.PassThruWriteMsgs;
|
||||
import static com.romraider.util.HexUtil.asHex;
|
||||
import static com.romraider.util.ThreadUtil.sleep;
|
||||
import static java.lang.System.arraycopy;
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.romraider.io.j2534.api.J2534_v0404.PASSTHRU_MSG;
|
||||
import com.romraider.io.j2534.api.J2534_v0404.SCONFIG;
|
||||
import com.romraider.io.j2534.api.J2534_v0404.SCONFIG.ByReference;
|
||||
import com.romraider.io.j2534.api.J2534_v0404.SCONFIG_LIST;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.NativeLong;
|
||||
import com.sun.jna.ptr.NativeLongByReference;
|
||||
|
||||
/**
|
||||
* J2534 Implementation of the Native library wrapper <b>J2534 v0404</b>
|
||||
*/
|
||||
public final class J2534Impl implements J2534 {
|
||||
private static final Logger LOGGER = getLogger(J2534Impl.class);
|
||||
private final NativeLong protocolID;
|
||||
|
||||
/**
|
||||
* Enum class representing the J2534-1 protocols with methods to
|
||||
* translate the mnemonic and numerical values.
|
||||
*/
|
||||
public enum Protocol {
|
||||
J1850VPW (0x01),
|
||||
J1850PWM (0x02),
|
||||
ISO9141 (0x03),
|
||||
ISO14230 (0x04),
|
||||
CAN (0x05),
|
||||
ISO15765 (0x06),
|
||||
SCI_A_ENGINE (0x07), // OP2.0: Not supported
|
||||
SCI_A_TRANS (0x08), // OP2.0: Not supported
|
||||
SCI_B_ENGINE (0x09), // OP2.0: Not supported
|
||||
SCI_B_TRANS (0x0A), // OP2.0: Not supported
|
||||
UNDEFINED (0xFFFFFFFF); // Returned when no match is found for get()
|
||||
|
||||
private static final Map<Integer, Protocol> lookup
|
||||
= new HashMap<Integer, Protocol>();
|
||||
|
||||
static {
|
||||
for(Protocol s : EnumSet.allOf(Protocol.class))
|
||||
lookup.put(s.getValue(), s);
|
||||
}
|
||||
|
||||
private int value;
|
||||
|
||||
private Protocol(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the numeric value associated with the <b>Protocol</b>
|
||||
* mnemonic string.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value - numeric value to be translated.
|
||||
* @return the <b>Protocol</b> mnemonic mapped to the numeric
|
||||
* value or UNDEFINED if value is undefined.
|
||||
*/
|
||||
public static Protocol get(int value) {
|
||||
if (lookup.containsKey(value)) {
|
||||
return lookup.get(value);
|
||||
}
|
||||
else return UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum class representing the J2534-1 protocol flags with methods to
|
||||
* translate the mnemonic and numerical values.
|
||||
*/
|
||||
public enum Flag {
|
||||
ISO9141_NO_CHECKSUM (0x0200),
|
||||
UNDEFINED (0xFFFFFFFF); // Returned when no match is found for get()
|
||||
|
||||
private static final Map<Integer, Flag> lookup
|
||||
= new HashMap<Integer, Flag>();
|
||||
|
||||
static {
|
||||
for(Flag s : EnumSet.allOf(Flag.class))
|
||||
lookup.put(s.getValue(), s);
|
||||
}
|
||||
|
||||
private int value;
|
||||
|
||||
private Flag(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the numeric value associated with the <b>Flag</b>
|
||||
* mnemonic string.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value - numeric value to be translated.
|
||||
* @return the <b>Flag</b> mnemonic mapped to the numeric
|
||||
* value or UNDEFINED if value is undefined.
|
||||
*/
|
||||
public static Flag get(int value) {
|
||||
if (lookup.containsKey(value)) {
|
||||
return lookup.get(value);
|
||||
}
|
||||
else return UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum class representing the J2534/2 extention types with methods to
|
||||
* translate the mnemonic and numerical values.
|
||||
*/
|
||||
public enum Extention {
|
||||
CAN_CH1 (0x00009000),
|
||||
J1850VPW_CH1 (0x00009080),
|
||||
J1850PWM_CH1 (0x00009160),
|
||||
ISO9141_CH1 (0x00009240),
|
||||
ISO9141_CH2 (0x00009241),
|
||||
ISO9141_CH3 (0x00009242),
|
||||
ISO9141_K (0x00009240),
|
||||
ISO9141_L (0x00009241), // OP2.0: ISO9141 communications over the L line
|
||||
ISO9141_INNO (0x00009242), // OP2.0: RS-232 receive-only via the 2.5mm jack
|
||||
ISO14230_CH1 (0x00009320),
|
||||
ISO14230_CH2 (0x00009321),
|
||||
ISO14230_K (0x00009320),
|
||||
ISO14230_L (0x00009321), // OP2.0: ISO14230 communications over the L line
|
||||
ISO15765_CH1 (0x00009400),
|
||||
UNDEFINED (0xFFFFFFFF); // Returned when no match is found for get()
|
||||
|
||||
private static final Map<Integer, Extention> lookup
|
||||
= new HashMap<Integer, Extention>();
|
||||
|
||||
static {
|
||||
for(Extention s : EnumSet.allOf(Extention.class))
|
||||
lookup.put(s.getValue(), s);
|
||||
}
|
||||
|
||||
private int value;
|
||||
|
||||
private Extention(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the numeric value associated with the <b>Extention</b>
|
||||
* mnemonic string.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value - numeric value to be translated.
|
||||
* @return the <b>Extention</b> mnemonic mapped to the numeric
|
||||
* value or UNDEFINED if value is undefined.
|
||||
*/
|
||||
public static Extention get(int value) {
|
||||
if (lookup.containsKey(value)) {
|
||||
return lookup.get(value);
|
||||
}
|
||||
else return UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum class representing the J2534-1 filter types with methods to
|
||||
* translate the mnemonic and numerical values.
|
||||
*/
|
||||
public enum Filter {
|
||||
PASS_FILTER (0x01),
|
||||
BLOCK_FILTER (0x02),
|
||||
FLOW_CONTROL_FILTER (0x03),
|
||||
UNDEFINED (0xFFFFFFFF); // Returned when no match is found for get()
|
||||
|
||||
private static final Map<Integer, Filter> lookup
|
||||
= new HashMap<Integer, Filter>();
|
||||
|
||||
static {
|
||||
for(Filter s : EnumSet.allOf(Filter.class))
|
||||
lookup.put(s.getValue(), s);
|
||||
}
|
||||
|
||||
private int value;
|
||||
|
||||
private Filter(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the numeric value associated with the <b>Filter</b>
|
||||
* mnemonic string.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value - numeric value to be translated.
|
||||
* @return the <b>Filter</b> mnemonic mapped to the numeric
|
||||
* value or UNDEFINED if value is undefined.
|
||||
*/
|
||||
public static Filter get(int value) {
|
||||
if (lookup.containsKey(value)) {
|
||||
return lookup.get(value);
|
||||
}
|
||||
else return UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
// IOCTL IDs
|
||||
// J2534-1
|
||||
/**
|
||||
* Enum class representing the J2534-1 IOCTL types with methods to
|
||||
* translate the mnemonic and numerical values.
|
||||
*/
|
||||
public enum IOCtl {
|
||||
GET_CONFIG (0x01),
|
||||
SET_CONFIG (0x02),
|
||||
READ_VBATT (0x03),
|
||||
FIVE_BAUD_INIT (0x04),
|
||||
FAST_INIT (0x05),
|
||||
CLEAR_TX_BUFFER (0x07),
|
||||
CLEAR_RX_BUFFER (0x08),
|
||||
CLEAR_PERIODIC_MSGS (0x09),
|
||||
CLEAR_MSG_FILTERS (0x0A),
|
||||
CLEAR_FUNCT_MSG_LOOKUP_TABLE (0x0B),
|
||||
ADD_TO_FUNCT_MSG_LOOKUP_TABLE (0x0C),
|
||||
DELETE_FROM_FUNCT_MSG_LOOUP_TABLE (0x0D),
|
||||
READ_PROG_VOLTAGE (0x0E),
|
||||
UNDEFINED (0xFFFFFFFF);
|
||||
// Returned when no match is found for get()
|
||||
|
||||
private static final Map<Integer, IOCtl> lookup
|
||||
= new HashMap<Integer, IOCtl>();
|
||||
|
||||
static {
|
||||
for(IOCtl s : EnumSet.allOf(IOCtl.class))
|
||||
lookup.put(s.getValue(), s);
|
||||
}
|
||||
|
||||
private int value;
|
||||
|
||||
private IOCtl(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the numeric value associated with the <b>IOCtl</b>
|
||||
* mnemonic string.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value - numeric value to be translated.
|
||||
* @return the <b>IOCtl</b> mnemonic mapped to the numeric
|
||||
* value or UNDEFINED if value is undefined.
|
||||
*/
|
||||
public static IOCtl get(int value) {
|
||||
if (lookup.containsKey(value)) {
|
||||
return lookup.get(value);
|
||||
}
|
||||
else return UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum class representing the J2534-1 Get/Set config parameters with methods to
|
||||
* translate the mnemonic and numerical values.
|
||||
*/
|
||||
public enum Config {
|
||||
DATA_RATE (0x01),
|
||||
LOOPBACK (0x03),
|
||||
NODE_ADDRESS (0x04), // OP2.0: Not yet supported
|
||||
NETWORK_LINE (0x05), // OP2.0: Not yet supported
|
||||
P1_MIN (0x06), // J2534 says this may not be changed
|
||||
P1_MAX (0x07),
|
||||
P2_MIN (0x08), // J2534 says this may not be changed
|
||||
P2_MAX (0x09), // J2534 says this may not be changed
|
||||
P3_MIN (0x0A),
|
||||
P3_MAX (0x0B), // J2534 says this may not be changed
|
||||
P4_MIN (0x0C),
|
||||
P4_MAX (0x0D), // J2534 says this may not be changed
|
||||
W0 (0x19),
|
||||
W1 (0x0E),
|
||||
W2 (0x0F),
|
||||
W3 (0x10),
|
||||
W4 (0x11),
|
||||
W5 (0x12),
|
||||
TIDLE (0x13),
|
||||
TINIL (0x14),
|
||||
TWUP (0x15),
|
||||
PARITY (0x16),
|
||||
BIT_SAMPLE_POINT(0x17), // OP2.0: Not yet supported
|
||||
SYNC_JUMP_WIDTH (0x18), // OP2.0: Not yet supported
|
||||
T1_MAX (0x1A),
|
||||
T2_MAX (0x1B),
|
||||
T3_MAX (0x24),
|
||||
T4_MAX (0x1C),
|
||||
T5_MAX (0x1D),
|
||||
ISO15765_BS (0x1E),
|
||||
ISO15765_STMIN (0x1F),
|
||||
DATA_BITS (0x20),
|
||||
FIVE_BAUD_MOD (0x21),
|
||||
BS_TX (0x22),
|
||||
STMIN_TX (0x23),
|
||||
ISO15765_WFT_MAX(0x25),
|
||||
UNDEFINED (0xFFFFFFFF); // Returned when no match is found for get()
|
||||
|
||||
private static final Map<Integer, Config> lookup
|
||||
= new HashMap<Integer, Config>();
|
||||
|
||||
static {
|
||||
for(Config s : EnumSet.allOf(Config.class))
|
||||
lookup.put(s.getValue(), s);
|
||||
}
|
||||
|
||||
private int value;
|
||||
|
||||
private Config(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the numeric value associated with the <b>Config</b>
|
||||
* mnemonic string.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value - numeric value to be translated.
|
||||
* @return the <b>Config</b> mnemonic mapped to the numeric
|
||||
* value or RESERVED if value is undefined.
|
||||
*/
|
||||
public static Config get(int value) {
|
||||
if (lookup.containsKey(value)) {
|
||||
return lookup.get(value);
|
||||
}
|
||||
else return UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum class representing the J2534-1 return error values with methods to
|
||||
* translate the mnemonic and numerical values.
|
||||
*/
|
||||
public enum Status {
|
||||
NOERROR (0x00),
|
||||
ERR_NOT_SUPPORTED (0x01),
|
||||
ERR_INVALID_CHANNEL_ID (0x02),
|
||||
ERR_INVALID_PROTOCOL_ID (0x03),
|
||||
ERR_NULL_PARAMETER (0x04),
|
||||
ERR_INVALID_IOCTL_VALUE (0x05),
|
||||
ERR_INVALID_FLAGS (0x06),
|
||||
ERR_FAILED (0x07),
|
||||
ERR_DEVICE_NOT_CONNECTED (0x08),
|
||||
ERR_TIMEOUT (0x09),
|
||||
ERR_INVALID_MSG (0x0A),
|
||||
ERR_INVALID_TIME_INTERVAL(0x0B),
|
||||
ERR_EXCEEDED_LIMIT (0x0C),
|
||||
ERR_INVALID_MSG_ID (0x0D),
|
||||
ERR_DEVICE_IN_USE (0x0E),
|
||||
ERR_INVALID_IOCTL_ID (0x0F),
|
||||
ERR_BUFFER_EMPTY (0x10),
|
||||
ERR_BUFFER_FULL (0x11),
|
||||
ERR_BUFFER_OVERFLOW (0x12),
|
||||
ERR_PIN_INVALID (0x13),
|
||||
ERR_CHANNEL_IN_USE (0x14),
|
||||
ERR_MSG_PROTOCOL_ID (0x15),
|
||||
ERR_INVALID_FILTER_ID (0x16),
|
||||
ERR_NO_FLOW_CONTROL (0x17),
|
||||
ERR_NOT_UNIQUE (0x18),
|
||||
ERR_INVALID_BAUDRATE (0x19),
|
||||
ERR_INVALID_DEVICE_ID (0x1A),
|
||||
ERR_INVALID_DEVICE_ID_OP2(0x20), // OP2.0 Tactrix specific
|
||||
ERR_OEM_VOLTAGE_TOO_LOW (0x78), // OP2.0 Tactrix specific
|
||||
ERR_OEM_VOLTAGE_TOO_HIGH (0x77), // OP2.0 Tactrix specific
|
||||
UNDEFINED (0xFFFFFFFF); // Returned when no match is found for get()
|
||||
|
||||
private static final Map<Integer, Status> lookup
|
||||
= new HashMap<Integer, Status>();
|
||||
|
||||
static {
|
||||
for(Status s : EnumSet.allOf(Status.class))
|
||||
lookup.put(s.getValue(), s);
|
||||
}
|
||||
|
||||
private int value;
|
||||
|
||||
private Status(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the numeric value associated with the <b>Status</b>
|
||||
* mnemonic string.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value - numeric value to be translated.
|
||||
* @return the <b>Status</b> mnemonic mapped to the numeric
|
||||
* value or UNDEFINED if value is undefined.
|
||||
*/
|
||||
public static Status get(int value) {
|
||||
if (lookup.containsKey(value)) {
|
||||
return lookup.get(value);
|
||||
}
|
||||
else return UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor declaration
|
||||
* @param protocolID - numeric ID specified by J2534-1
|
||||
* @exception J2534Exception on various non-zero return status
|
||||
* @deprecated
|
||||
*/
|
||||
public J2534Impl(int protocolID) {
|
||||
this.protocolID = new NativeLong(protocolID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor declaration
|
||||
* @param protocol - <b>Protocol</b> enum specified by J2534-1
|
||||
* @exception J2534Exception on various non-zero return status
|
||||
*/
|
||||
public J2534Impl(Protocol protocol) {
|
||||
this.protocolID = new NativeLong(protocol.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Establish a connection and initialize the PassThru device.
|
||||
* @return DeviceID of PassThru device
|
||||
*/
|
||||
public int open() {
|
||||
NativeLongByReference pDeviceID = new NativeLongByReference();
|
||||
NativeLong ret = PassThruOpen(null, pDeviceID);
|
||||
if (ret.intValue() != Status.NOERROR.getValue()) handleError(
|
||||
"PassThruOpen", ret.intValue());
|
||||
return pDeviceID.getValue().intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the PassThru device firmware version,
|
||||
* DLL version, and the J2534 implmenation version.
|
||||
* @param deviceId - of PassThru device
|
||||
* @return an instance of <b>Version</b>
|
||||
* @see Version
|
||||
*/
|
||||
public Version readVersion(int deviceId) {
|
||||
ByteBuffer pFirmwareVersion = ByteBuffer.allocate(80);
|
||||
ByteBuffer pDllVersion = ByteBuffer.allocate(80);
|
||||
ByteBuffer pApiVersion = ByteBuffer.allocate(80);
|
||||
NativeLong ret = PassThruReadVersion(
|
||||
new NativeLong(deviceId),
|
||||
pFirmwareVersion,
|
||||
pDllVersion,
|
||||
pApiVersion
|
||||
);
|
||||
if (ret.intValue() != Status.NOERROR.getValue()) handleError(
|
||||
"PassThruReadVersion", ret.intValue());
|
||||
return new Version(
|
||||
Native.toString(pFirmwareVersion.array()),
|
||||
Native.toString(pDllVersion.array()),
|
||||
Native.toString(pApiVersion.array()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Establish a logical conneciton with a protocol channel of the specified
|
||||
* device.
|
||||
* @param deviceId - of PassThru device
|
||||
* @param flags - protocol specific options
|
||||
* @param baud - vehicle network communication rate
|
||||
* @return a handle to the open communications channel
|
||||
*/
|
||||
public int connect(int deviceId, int flags, int baud) {
|
||||
NativeLongByReference pChannelID = new NativeLongByReference();
|
||||
NativeLong ret = PassThruConnect(
|
||||
new NativeLong(deviceId),
|
||||
protocolID,
|
||||
new NativeLong(flags),
|
||||
new NativeLong(baud),
|
||||
pChannelID
|
||||
);
|
||||
if (ret.intValue() != Status.NOERROR.getValue()) handleError(
|
||||
"PassThruConnect", ret.intValue());
|
||||
return pChannelID.getValue().intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures various PassThru parameters.
|
||||
* @param channelId - handle to the open communications channel
|
||||
* @param items - values of multiple parameters can be set
|
||||
* in an array of ConfigItem
|
||||
*/
|
||||
public void setConfig(int channelId, ConfigItem... items) {
|
||||
if (items.length == 0) return;
|
||||
SCONFIG[] sConfigs = sConfigs(items);
|
||||
SCONFIG_LIST list = sConfigList(sConfigs);
|
||||
NativeLong ioctlID = new NativeLong();
|
||||
ioctlID.setValue(IOCtl.SET_CONFIG.getValue());
|
||||
NativeLong ret = PassThruIoctl(
|
||||
new NativeLong(channelId),
|
||||
ioctlID,
|
||||
list.getPointer(),
|
||||
null
|
||||
);
|
||||
if (ret.intValue() != Status.NOERROR.getValue()) handleError(
|
||||
"PassThruIoctl (SET_CONFIG)", ret.intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve various PassThru configuration parameters.
|
||||
* @param channelId - handle to the open communications channel
|
||||
* @param parameters - values of multiple parameters can be retrieved
|
||||
* by setting an array of integer parameter IDs
|
||||
* @return an array of <b>ConfigItem</b>
|
||||
* @see ConfigItem
|
||||
*/
|
||||
public ConfigItem[] getConfig(int channelId, int... parameters) {
|
||||
if (parameters.length == 0) return new ConfigItem[0];
|
||||
SCONFIG[] sConfigs = sConfigs(parameters);
|
||||
SCONFIG_LIST input = sConfigList(sConfigs);
|
||||
NativeLong ioctlID = new NativeLong();
|
||||
ioctlID.setValue(IOCtl.GET_CONFIG.getValue());
|
||||
NativeLong ret = PassThruIoctl(
|
||||
new NativeLong(channelId),
|
||||
ioctlID,
|
||||
input.getPointer(),
|
||||
null
|
||||
);
|
||||
if (ret.intValue() != Status.NOERROR.getValue()) handleError(
|
||||
"PassThruIoctl (GET_CONFIG)", ret.intValue());
|
||||
return configItems(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup network protocol filter(s) to selectively restrict or limit
|
||||
* messages received. Then purge the PassThru device's receive buffer.
|
||||
* @param channelId - handle to the open communications channel
|
||||
* @param mask - used to isolate the receive message
|
||||
* header section(s) of interest
|
||||
* @param pattern - a message pattern to compare with the receive messages
|
||||
* @return the message filter ID to be used to later stop the filter
|
||||
*/
|
||||
public int startPassMsgFilter(int channelId, byte mask, byte pattern) {
|
||||
PASSTHRU_MSG maskMsg = passThruMessage(mask);
|
||||
PASSTHRU_MSG patternMsg = passThruMessage(pattern);
|
||||
|
||||
NativeLongByReference msgId = new NativeLongByReference();
|
||||
msgId.setValue(new NativeLong(0));
|
||||
NativeLong ret = PassThruStartMsgFilter(
|
||||
new NativeLong(channelId),
|
||||
new NativeLong(Filter.PASS_FILTER.getValue()),
|
||||
maskMsg.getPointer(),
|
||||
patternMsg.getPointer(),
|
||||
null,
|
||||
msgId
|
||||
);
|
||||
if (ret.intValue() != Status.NOERROR.getValue()) handleError(
|
||||
"PassThruStartMsgFilter", ret.intValue());
|
||||
|
||||
ret = PassThruIoctl(
|
||||
new NativeLong(channelId),
|
||||
new NativeLong(IOCtl.CLEAR_RX_BUFFER.getValue()),
|
||||
null,
|
||||
null
|
||||
);
|
||||
if (ret.intValue() != Status.NOERROR.getValue()) handleError(
|
||||
"PassThruIoctl (CLEAR_RX_BUFFER)", ret.intValue());
|
||||
return msgId.getValue().intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message through the existing communication channel to the vehicle.
|
||||
* @param channelId - handle to the open communications channel
|
||||
* @param data - data bytes to be transmitted to the vehicle network
|
||||
* @param timeout - maximum time (in milliseconds) for write completion
|
||||
*/
|
||||
public void writeMsg(int channelId, byte[] data, long timeout) {
|
||||
PASSTHRU_MSG msg = passThruMessage(data);
|
||||
LOGGER.trace("Write Msg: " + toString(msg));
|
||||
NativeLongByReference numMsg = new NativeLongByReference();
|
||||
numMsg.setValue(new NativeLong(1));
|
||||
NativeLong ret = PassThruWriteMsgs(
|
||||
new NativeLong(channelId),
|
||||
msg.getPointer(),
|
||||
numMsg,
|
||||
new NativeLong(timeout)
|
||||
);
|
||||
if (ret.intValue() != Status.NOERROR.getValue()) handleError(
|
||||
"PassThruWriteMsgs", ret.intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a message through the existing communication channel from the vehicle.
|
||||
* @param channelId - handle to the open communications channel
|
||||
* @param response - data array to be populated with the vehicle network message
|
||||
* @param timeout - maximum time (in milliseconds) for read completion
|
||||
*/
|
||||
public void readMsg(int channelId, byte[] response, long timeout) {
|
||||
int index = 0;
|
||||
long end = currentTimeMillis() + timeout;
|
||||
do {
|
||||
PASSTHRU_MSG msg = doReadMsg(channelId);
|
||||
LOGGER.trace("Read Msg: " + toString(msg));
|
||||
if (!isResponse(msg)) continue;
|
||||
arraycopy(msg.data, 0, response, index, msg.dataSize.intValue());
|
||||
index += msg.dataSize.intValue();
|
||||
} while (currentTimeMillis() <= end && index < response.length - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a message through the existing communication channel from the vehicle.
|
||||
* @param channelId - handle to the open communications channel
|
||||
* @param maxWait - maximum time (in milliseconds) for read completion
|
||||
* @return bytes read from the vehicle network
|
||||
*/
|
||||
public byte[] readMsg(int channelId, long maxWait) {
|
||||
List<byte[]> responses = new ArrayList<byte[]>();
|
||||
long end = currentTimeMillis() + maxWait;
|
||||
do {
|
||||
PASSTHRU_MSG msg = doReadMsg(channelId);
|
||||
LOGGER.trace("Read Msg: " + toString(msg));
|
||||
if (isResponse(msg)) responses.add(data(msg));
|
||||
sleep(2);
|
||||
} while (currentTimeMillis() <= end);
|
||||
return concat(responses);
|
||||
}
|
||||
|
||||
public void stopMsgFilter(int channelId, int msgId) {
|
||||
NativeLong ret = PassThruStopMsgFilter(
|
||||
new NativeLong(channelId),
|
||||
new NativeLong(msgId)
|
||||
);
|
||||
if (ret.intValue() != Status.NOERROR.getValue()) handleError(
|
||||
"PassThruStopMsgFilter", ret.intValue());
|
||||
}
|
||||
|
||||
public void disconnect(int channelId) {
|
||||
NativeLong ret = PassThruDisconnect(new NativeLong(channelId));
|
||||
if (ret.intValue() != Status.NOERROR.getValue()) handleError(
|
||||
"PassThruDisconnect", ret.intValue());
|
||||
}
|
||||
|
||||
public void close(int deviceId) {
|
||||
NativeLong ret = PassThruClose(new NativeLong(deviceId));
|
||||
if (ret.intValue() != Status.NOERROR.getValue()) handleError(
|
||||
"PassThruClose", ret.intValue());
|
||||
}
|
||||
|
||||
private byte[] concat(List<byte[]> responses) {
|
||||
int length = 0;
|
||||
for (byte[] response : responses) length += response.length;
|
||||
byte[] result = new byte[length];
|
||||
int index = 0;
|
||||
for (byte[] response : responses) {
|
||||
if (response.length == 0) continue;
|
||||
System.arraycopy(response, 0, result, index, response.length);
|
||||
index += response.length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String toString(PASSTHRU_MSG msg) {
|
||||
byte[] bytes = new byte[msg.dataSize.intValue()];
|
||||
arraycopy(msg.data, 0, bytes, 0, bytes.length);
|
||||
String str = String.format(
|
||||
"[protocolID=%d | rxStatus=%d | txFlags=%d | timestamp=%x |" +
|
||||
" dataSize=%d | extraDataIndex=%d | data=%s]",
|
||||
msg.protocolID.intValue(),
|
||||
msg.rxStatus.intValue(),
|
||||
msg.txFlags.intValue(),
|
||||
msg.timestamp.intValue(),
|
||||
msg.dataSize.intValue(),
|
||||
msg.extraDataIndex.intValue(),
|
||||
asHex(bytes));
|
||||
return str;
|
||||
}
|
||||
|
||||
private boolean isResponse(PASSTHRU_MSG msg) {
|
||||
if (msg.timestamp.intValue() == 0) return false;
|
||||
if ((msg.rxStatus.intValue() & 0x00) == 0x00) return true;
|
||||
return msg.rxStatus.intValue() == 0x01;
|
||||
}
|
||||
|
||||
private PASSTHRU_MSG doReadMsg(int channelId) {
|
||||
PASSTHRU_MSG msg = passThruMessage();
|
||||
NativeLongByReference pNumMsgs = new NativeLongByReference();
|
||||
pNumMsgs.setValue(new NativeLong(1));
|
||||
NativeLong status = PassThruReadMsgs(
|
||||
new NativeLong(channelId),
|
||||
msg.getPointer(),
|
||||
pNumMsgs,
|
||||
new NativeLong(50)
|
||||
);
|
||||
if (status.intValue() != Status.NOERROR.getValue() &&
|
||||
status.intValue() != Status.ERR_TIMEOUT.getValue() &&
|
||||
status.intValue() != Status.ERR_BUFFER_EMPTY.getValue())
|
||||
handleError("PassThruReadMsgs", status.intValue());
|
||||
msg.read();
|
||||
return msg;
|
||||
}
|
||||
|
||||
private ConfigItem[] configItems(SCONFIG_LIST sConfigs) {
|
||||
SCONFIG.ByReference[] configs =
|
||||
(ByReference[]) sConfigs.configPtr.toArray(
|
||||
sConfigs.numOfParams.intValue());
|
||||
ConfigItem[] items = new ConfigItem[configs.length];
|
||||
for (int i = 0; i < configs.length; i++) {
|
||||
configs[i].read();
|
||||
items[i] = new ConfigItem(
|
||||
configs[i].parameter.intValue(),
|
||||
configs[i].value.intValue());
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private SCONFIG[] sConfigs(ConfigItem... items) {
|
||||
SCONFIG[] sConfigs =
|
||||
(SCONFIG[]) new SCONFIG.ByReference().toArray(items.length);
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
sConfigs[i].parameter = new NativeLong(items[i].parameter);
|
||||
sConfigs[i].value = new NativeLong(items[i].value);
|
||||
}
|
||||
// for (SCONFIG sc : sConfigs) {
|
||||
// sc.write();
|
||||
// System.out.printf("%s%n", sc);
|
||||
// }
|
||||
return sConfigs;
|
||||
}
|
||||
|
||||
private SCONFIG[] sConfigs(int... parameters) {
|
||||
SCONFIG[] sConfigs =
|
||||
(SCONFIG[]) new SCONFIG.ByReference().toArray(parameters.length);
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
sConfigs[i].parameter = new NativeLong(parameters[i]);
|
||||
sConfigs[i].value = new NativeLong(-1);
|
||||
}
|
||||
return sConfigs;
|
||||
}
|
||||
|
||||
private SCONFIG_LIST sConfigList(SCONFIG[] sConfigs) {
|
||||
SCONFIG_LIST list = new SCONFIG_LIST();
|
||||
list.numOfParams = new NativeLong(sConfigs.length);
|
||||
list.configPtr = (SCONFIG.ByReference) sConfigs[0];
|
||||
list.write();
|
||||
// System.out.printf("list:%n%s%n", list);
|
||||
return list;
|
||||
}
|
||||
|
||||
private PASSTHRU_MSG passThruMessage(byte... data) {
|
||||
PASSTHRU_MSG msg = passThruMessage();
|
||||
msg.dataSize = new NativeLong(data.length);
|
||||
arraycopy(data, 0, msg.data, 0, data.length);
|
||||
msg.write();
|
||||
return msg;
|
||||
}
|
||||
|
||||
private PASSTHRU_MSG passThruMessage() {
|
||||
PASSTHRU_MSG msg = new PASSTHRU_MSG();
|
||||
msg.protocolID = protocolID;
|
||||
return msg;
|
||||
}
|
||||
|
||||
private byte[] data(PASSTHRU_MSG msg) {
|
||||
int length = msg.dataSize.intValue();
|
||||
byte[] data = new byte[length];
|
||||
arraycopy(msg.data, 0, data, 0, length);
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the text description for the most recent non-zero error
|
||||
* and throw an exception.
|
||||
* @param operation - string containing the name of the method for which
|
||||
* the error occurred
|
||||
* @param status - the method's numeric error value
|
||||
* @exception J2534Exception on various non-zero return status
|
||||
* @see J2534_v0404
|
||||
*/
|
||||
private static void handleError(String operation, int status) {
|
||||
ByteBuffer error = ByteBuffer.allocate(255);
|
||||
PassThruGetLastError(error);
|
||||
String errString = String.format("%s error [%d]:%s, msg: %s%n",
|
||||
operation, status, Status.get(status), Native.toString(error.array()));
|
||||
throw new J2534Exception(errString);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.io.j2534.api;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.NativeLibrary;
|
||||
import com.sun.jna.NativeLong;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.ptr.NativeLongByReference;
|
||||
/**
|
||||
* JNA Wrapper for Native library <b>J2534 v0404</b><br>
|
||||
*/
|
||||
public class J2534_v0404 implements Library {
|
||||
public static final String JNA_LIBRARY_NAME = "op20pt32";
|
||||
public static final NativeLibrary JNA_NATIVE_LIB =
|
||||
NativeLibrary.getInstance(J2534_v0404.JNA_LIBRARY_NAME);
|
||||
static {
|
||||
Native.register(J2534_v0404.JNA_LIBRARY_NAME);
|
||||
}
|
||||
|
||||
public static native NativeLong PassThruOpen(
|
||||
Pointer pName,
|
||||
NativeLongByReference pDeviceID
|
||||
);
|
||||
public static native NativeLong PassThruClose(
|
||||
NativeLong DeviceID
|
||||
);
|
||||
public static native NativeLong PassThruConnect(
|
||||
NativeLong DeviceID,
|
||||
NativeLong protocolID,
|
||||
NativeLong flags,
|
||||
NativeLong baud,
|
||||
NativeLongByReference pChannelID
|
||||
);
|
||||
public static native NativeLong PassThruDisconnect(
|
||||
NativeLong channelID
|
||||
);
|
||||
public static native NativeLong PassThruReadMsgs(
|
||||
NativeLong ChannelID,
|
||||
Pointer pMsg,
|
||||
NativeLongByReference pNumMsgs,
|
||||
NativeLong Timeout
|
||||
);
|
||||
public static native NativeLong PassThruWriteMsgs(
|
||||
NativeLong ChannelID,
|
||||
Pointer pMsg,
|
||||
NativeLongByReference pNumMsgs,
|
||||
NativeLong Timeout
|
||||
);
|
||||
public static native NativeLong PassThruStartPeriodicMsg(
|
||||
NativeLong channelID,
|
||||
Pointer pMsg,
|
||||
NativeLongByReference pMsgID,
|
||||
NativeLong timeInterval
|
||||
);
|
||||
public static native NativeLong PassThruStopPeriodicMsg(
|
||||
NativeLong channelID,
|
||||
NativeLong msgID
|
||||
);
|
||||
public static native NativeLong PassThruStartMsgFilter(
|
||||
NativeLong ChannelID,
|
||||
NativeLong FilterType,
|
||||
Pointer pMaskMsg,
|
||||
Pointer pPatternMsg,
|
||||
Pointer pFlowControlMsg,
|
||||
NativeLongByReference pMsgID
|
||||
);
|
||||
public static native NativeLong PassThruStopMsgFilter(
|
||||
NativeLong channelID,
|
||||
NativeLong msgID
|
||||
);
|
||||
public static native NativeLong PassThruSetProgrammingVoltage(
|
||||
NativeLong pinNumber,
|
||||
NativeLong voltage
|
||||
);
|
||||
public static native NativeLong PassThruReadVersion(
|
||||
NativeLong DeviceID,
|
||||
ByteBuffer pFirmwareVersion,
|
||||
ByteBuffer pDllVersion,
|
||||
ByteBuffer pApiVersion
|
||||
);
|
||||
public static native NativeLong PassThruGetLastError(
|
||||
ByteBuffer pErrorDescription
|
||||
);
|
||||
public static native NativeLong PassThruIoctl(
|
||||
NativeLong channelID,
|
||||
NativeLong ioctlID,
|
||||
Pointer pInput,
|
||||
Pointer pOutput
|
||||
);
|
||||
|
||||
public static class SCONFIG extends Structure {
|
||||
public NativeLong parameter;
|
||||
public NativeLong value;
|
||||
public SCONFIG() {
|
||||
super();
|
||||
initFieldOrder();
|
||||
}
|
||||
protected void initFieldOrder() {
|
||||
setFieldOrder(new String[]{"parameter", "value"});
|
||||
}
|
||||
public static class ByReference
|
||||
extends SCONFIG
|
||||
implements Structure.ByReference {
|
||||
}
|
||||
public static class ByValue
|
||||
extends SCONFIG
|
||||
implements Structure.ByValue {
|
||||
}
|
||||
}
|
||||
|
||||
public static class SCONFIG_LIST extends Structure {
|
||||
public NativeLong numOfParams;
|
||||
public SCONFIG.ByReference configPtr;
|
||||
public SCONFIG_LIST() {
|
||||
super();
|
||||
initFieldOrder();
|
||||
}
|
||||
protected void initFieldOrder() {
|
||||
setFieldOrder(new String[]{"numOfParams", "configPtr"});
|
||||
}
|
||||
public static class ByReference
|
||||
extends SCONFIG_LIST
|
||||
implements Structure.ByReference {
|
||||
}
|
||||
public static class ByValue
|
||||
extends SCONFIG_LIST
|
||||
implements Structure.ByValue {
|
||||
}
|
||||
}
|
||||
|
||||
public static class PASSTHRU_MSG extends Structure {
|
||||
public NativeLong protocolID;
|
||||
public NativeLong rxStatus;
|
||||
public NativeLong txFlags;
|
||||
public NativeLong timestamp;
|
||||
public NativeLong dataSize;
|
||||
public NativeLong extraDataIndex;
|
||||
public byte[] data = new byte[4128];
|
||||
public PASSTHRU_MSG() {
|
||||
super();
|
||||
initFieldOrder();
|
||||
}
|
||||
protected void initFieldOrder() {
|
||||
setFieldOrder(new String[]{
|
||||
"protocolID", "rxStatus", "txFlags",
|
||||
"timestamp", "dataSize", "extraDataIndex", "data"});
|
||||
}
|
||||
public static class ByReference
|
||||
extends PASSTHRU_MSG
|
||||
implements Structure.ByReference {
|
||||
}
|
||||
public static class ByValue
|
||||
extends PASSTHRU_MSG
|
||||
implements Structure.ByValue {
|
||||
}
|
||||
}
|
||||
|
||||
public static class SBYTE_ARRAY extends Structure {
|
||||
public NativeLong numOfBytes;
|
||||
public Pointer bytePtr;
|
||||
public SBYTE_ARRAY() {
|
||||
super();
|
||||
initFieldOrder();
|
||||
}
|
||||
protected void initFieldOrder() {
|
||||
setFieldOrder(new String[]{"numOfBytes", "bytePtr"});
|
||||
}
|
||||
public static class ByReference
|
||||
extends SBYTE_ARRAY
|
||||
implements Structure.ByReference {
|
||||
}
|
||||
public static class ByValue
|
||||
extends SBYTE_ARRAY
|
||||
implements Structure.ByValue {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,41 +19,35 @@
|
|||
|
||||
package com.romraider.io.j2534.api;
|
||||
|
||||
import com.romraider.io.j2534.op20.Old_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;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.FLAG_ISO9141_NO_CHECKSUM;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.PROTOCOL_ISO9141;
|
||||
import static com.romraider.util.HexUtil.asHex;
|
||||
import static com.romraider.util.LogManager.initDebugLogging;
|
||||
|
||||
public final class TestJ2534 {
|
||||
private static final J2534 api = new Old_J2534OpenPort20(PROTOCOL_ISO9141);
|
||||
// private static final J2534 api = new J2534OpenPort20(PROTOCOL_ISO9141);
|
||||
import com.romraider.io.j2534.api.J2534Impl.Config;
|
||||
import com.romraider.io.j2534.api.J2534Impl.Flag;
|
||||
import com.romraider.io.j2534.api.J2534Impl.Protocol;
|
||||
|
||||
public static void main(String[] args) {
|
||||
initDebugLogging();
|
||||
ecuInit();
|
||||
}
|
||||
public class TestJ2534 {
|
||||
private static final J2534 api = new J2534Impl(Protocol.ISO9141);
|
||||
|
||||
private static void ecuInit() {
|
||||
public TestJ2534() {
|
||||
int deviceId = api.open();
|
||||
try {
|
||||
version(deviceId);
|
||||
int channelId = api.connect(deviceId, FLAG_ISO9141_NO_CHECKSUM, 4800);
|
||||
int channelId = api.connect(deviceId, Flag.ISO9141_NO_CHECKSUM.getValue(), 4800);
|
||||
try {
|
||||
setConfig(channelId);
|
||||
getConfig(channelId);
|
||||
|
||||
int msgId = api.startPassMsgFilter(channelId, (byte) 0x00, (byte) 0x00);
|
||||
try {
|
||||
|
||||
byte[] ecuInit = {(byte) 0x80, (byte) 0x10, (byte) 0xF0, (byte) 0x01, (byte) 0xBF, (byte) 0x40};
|
||||
byte[] ecuInit = {
|
||||
(byte) 0x80, (byte) 0x10, (byte) 0xF0,
|
||||
(byte) 0x01, (byte) 0xBF, (byte) 0x40};
|
||||
|
||||
api.writeMsg(channelId, ecuInit, 55L);
|
||||
System.out.println("Request = " + asHex(ecuInit));
|
||||
|
||||
byte[] response = api.readMsg(channelId, 2000L);
|
||||
byte[] response = api.readMsg(channelId, 1000L);
|
||||
System.out.println("Response = " + asHex(response));
|
||||
|
||||
} finally {
|
||||
|
@ -69,14 +63,34 @@ public final class TestJ2534 {
|
|||
|
||||
private static void version(int deviceId) {
|
||||
Version version = api.readVersion(deviceId);
|
||||
System.out.println("Version => firmware: " + version.firmware + ", dll: " + version.dll + ", api: " + version.api);
|
||||
System.out.printf("Version => Firmware:[%s], DLL:[%s], API:[%s]%n",
|
||||
version.firmware, version.dll, version.api);
|
||||
}
|
||||
|
||||
private static void setConfig(int channelId) {
|
||||
ConfigItem p1Max = new ConfigItem(CONFIG_P1_MAX, 2);
|
||||
ConfigItem p3Min = new ConfigItem(CONFIG_P3_MIN, 0);
|
||||
ConfigItem p4Min = new ConfigItem(CONFIG_P4_MIN, 0);
|
||||
ConfigItem loopback = new ConfigItem(CONFIG_LOOPBACK, 1);
|
||||
ConfigItem p1Max = new ConfigItem(Config.P1_MAX.getValue(), 2);
|
||||
ConfigItem p3Min = new ConfigItem(Config.P3_MIN.getValue(), 0);
|
||||
ConfigItem p4Min = new ConfigItem(Config.P4_MIN.getValue(), 0);
|
||||
ConfigItem loopback = new ConfigItem(Config.LOOPBACK.getValue(), 1);
|
||||
api.setConfig(channelId, p1Max, p3Min, p4Min, loopback);
|
||||
}
|
||||
|
||||
private static void getConfig(int channelId) {
|
||||
ConfigItem[] configs = api.getConfig(
|
||||
channelId,
|
||||
Config.LOOPBACK.getValue(),
|
||||
Config.P1_MAX.getValue(),
|
||||
Config.P3_MIN.getValue(),
|
||||
Config.P4_MIN.getValue());
|
||||
int i = 1;
|
||||
for (ConfigItem item : configs) {
|
||||
System.out.printf("Config item %d: Parameter: %d, value:%d%n",
|
||||
i, item.parameter, item.value);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String args[]){
|
||||
TestJ2534 a = new TestJ2534();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.io.j2534.op20;
|
||||
|
||||
import static com.ice.jni.registry.Registry.HKEY_LOCAL_MACHINE;
|
||||
import static com.ice.jni.registry.Registry.openSubkey;
|
||||
import com.ice.jni.registry.RegistryException;
|
||||
import com.ice.jni.registry.RegistryKey;
|
||||
import static com.ice.jni.registry.RegistryKey.ACCESS_READ;
|
||||
import com.ice.jni.registry.RegistryValue;
|
||||
import static com.ice.jni.registry.RegistryValue.REG_DWORD;
|
||||
import static com.ice.jni.registry.RegistryValue.REG_SZ;
|
||||
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.util.Enumeration;
|
||||
|
||||
public final class J2534DllLocator {
|
||||
private static final Logger LOGGER = getLogger(J2534DllLocator.class);
|
||||
|
||||
private J2534DllLocator() {
|
||||
}
|
||||
|
||||
public static File locate() {
|
||||
try {
|
||||
RegistryKey software = openSubkey(HKEY_LOCAL_MACHINE, "SOFTWARE", ACCESS_READ);
|
||||
RegistryKey passThruSupport = software.openSubKey("PassThruSupport.04.04");
|
||||
Enumeration<?> vendors = passThruSupport.keyElements();
|
||||
while (vendors.hasMoreElements()) {
|
||||
String vendor = (String) vendors.nextElement();
|
||||
RegistryKey vendorKey = passThruSupport.openSubKey(vendor);
|
||||
if (!valueExists(vendorKey, "ISO9141", REG_DWORD)) continue;
|
||||
if (dwordValue(vendorKey, "ISO9141") != 1) continue;
|
||||
if (!valueExists(vendorKey, "FunctionLibrary", REG_SZ)) continue;
|
||||
File f = new File(stringValue(vendorKey, "FunctionLibrary"));
|
||||
if (f.exists()) return f;
|
||||
}
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
LOGGER.info("Error determining J2534 library location: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String stringValue(RegistryKey key, String name) throws RegistryException {
|
||||
byte[] bytes = valueOf(key, name);
|
||||
return new String(bytes);
|
||||
}
|
||||
|
||||
private static int dwordValue(RegistryKey key, String name) throws RegistryException {
|
||||
byte[] bytes = valueOf(key, name);
|
||||
return asUnsignedInt(bytes);
|
||||
}
|
||||
|
||||
private static byte[] valueOf(RegistryKey key, String name) throws RegistryException {
|
||||
RegistryValue value = key.getValue(name);
|
||||
return value.getByteData();
|
||||
}
|
||||
|
||||
public static boolean valueExists(RegistryKey key, String name, int type) {
|
||||
try {
|
||||
Enumeration<?> elements = key.valueElements();
|
||||
while (elements.hasMoreElements()) {
|
||||
String element = (String) elements.nextElement();
|
||||
if (!element.equals(name)) continue;
|
||||
RegistryValue value = key.getValue(element);
|
||||
return value.getType() == type;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,252 +0,0 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.io.j2534.op20;
|
||||
|
||||
import com.romraider.io.j2534.api.ConfigItem;
|
||||
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.IOCTL_GET_CONFIG;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.IOCTL_SET_CONFIG;
|
||||
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;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.PassThruGetLastError;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.PassThruIoctl;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.PassThruOpen;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.PassThruReadMsgs;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.PassThruReadVersion;
|
||||
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_ERR_TIMEOUT;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.STATUS_NOERROR;
|
||||
import static com.romraider.util.HexUtil.asHex;
|
||||
import static java.lang.System.arraycopy;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class J2534OpenPort20 implements J2534 {
|
||||
private static final Logger LOGGER = getLogger(J2534OpenPort20.class);
|
||||
private final int protocol;
|
||||
|
||||
public J2534OpenPort20(int protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public int open() {
|
||||
int[] deviceId = {0};
|
||||
int status = PassThruOpen(null, deviceId);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
return deviceId[0];
|
||||
}
|
||||
|
||||
public Version readVersion(int deviceId) {
|
||||
byte[] firmware = new byte[80];
|
||||
byte[] dll = new byte[80];
|
||||
byte[] api = new byte[80];
|
||||
int status = PassThruReadVersion(deviceId, firmware, dll, api);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
return new Version(toString(firmware), toString(dll), toString(api));
|
||||
}
|
||||
|
||||
public int connect(int deviceId, int flags, int baud) {
|
||||
int[] channelId = {0};
|
||||
int status = PassThruConnect(deviceId, protocol, flags, baud, channelId);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
return channelId[0];
|
||||
}
|
||||
|
||||
public void setConfig(int channelId, ConfigItem... items) {
|
||||
if (items.length == 0) return;
|
||||
SConfig[] sConfigs = sConfigs(items);
|
||||
SConfigList list = sConfigList(sConfigs);
|
||||
int status = PassThruIoctl(channelId, IOCTL_SET_CONFIG, list, null);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
}
|
||||
|
||||
public ConfigItem[] getConfig(int channelId, int... parameters) {
|
||||
if (parameters.length == 0) return configItems();
|
||||
SConfig[] sConfigs = sConfigs(parameters);
|
||||
SConfigList input = sConfigList(sConfigs);
|
||||
int status = PassThruIoctl(channelId, IOCTL_GET_CONFIG, input, null);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
return configItems(input.ConfigPtr);
|
||||
}
|
||||
|
||||
public int startPassMsgFilter(int channelId, byte mask, byte pattern) {
|
||||
PassThruMessage maskMsg = passThruMessage(mask);
|
||||
PassThruMessage patternMsg = passThruMessage(pattern);
|
||||
int[] msgId = {0};
|
||||
int status = PassThruStartMsgFilter(channelId, FILTER_PASS, maskMsg, patternMsg, null, msgId);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
return msgId[0];
|
||||
}
|
||||
|
||||
public void writeMsg(int channelId, byte[] data, long timeout) {
|
||||
PassThruMessage msg = passThruMessage(data);
|
||||
LOGGER.trace("Write Msg: " + toString(msg));
|
||||
int[] pNumMsgs = {1};
|
||||
int status = PassThruWriteMsgs(channelId, msg, pNumMsgs, (int) timeout);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
}
|
||||
|
||||
public void readMsg(int channelId, byte[] response, long timeout) {
|
||||
byte[] data = readMsg(channelId, timeout);
|
||||
arraycopy(data, 0, response, 0, response.length);
|
||||
}
|
||||
|
||||
public byte[] readMsg(int channelId, long maxWait) {
|
||||
byte[] data = doReadMsg(channelId, (int) maxWait);
|
||||
LOGGER.trace("Response: " + asHex(data));
|
||||
return data;
|
||||
}
|
||||
|
||||
// FIX - Optimise & cleanup!!!
|
||||
private byte[] doReadMsg(int channelId, int timeout) {
|
||||
PassThruMessage msg1 = passThruMessage();
|
||||
PassThruMessage msg2 = passThruMessage();
|
||||
PassThruMessage msg3 = passThruMessage();
|
||||
PassThruMessage msg4 = passThruMessage();
|
||||
PassThruMessage[] msgs = {msg1, msg2, msg3, msg4};
|
||||
int[] pNumMsgs = {4};
|
||||
int status = PassThruReadMsgs(channelId, msgs, pNumMsgs, timeout);
|
||||
if (status != STATUS_NOERROR && status != STATUS_ERR_TIMEOUT) handleError(status);
|
||||
LOGGER.trace("Read Msg: " + toString(msg2) + toString(msg4));
|
||||
List<byte[]> responses = new ArrayList<byte[]>();
|
||||
responses.add(data(msg2));
|
||||
responses.add(data(msg4));
|
||||
return concat(responses);
|
||||
}
|
||||
|
||||
private byte[] concat(List<byte[]> responses) {
|
||||
int length = 0;
|
||||
for (byte[] response : responses) length += response.length;
|
||||
byte[] result = new byte[length];
|
||||
int index = 0;
|
||||
for (byte[] response : responses) {
|
||||
if (response.length == 0) continue;
|
||||
System.arraycopy(response, 0, result, index, response.length);
|
||||
index += response.length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String toString(PassThruMessage msg) {
|
||||
byte[] bytes = new byte[msg.DataSize];
|
||||
arraycopy(msg.Data, 0, bytes, 0, bytes.length);
|
||||
return "[ProtocolID=" + msg.ProtocolID + "|RxStatus=" + msg.RxStatus + "|TxFlags=" + msg.TxFlags + "|Timestamp=" + msg.Timestamp + "|ExtraDataIndex=" + msg.ExtraDataIndex + "|DataSize=" + msg.DataSize + "|Data=" + asHex(bytes) + "]";
|
||||
}
|
||||
|
||||
private boolean isResponse(PassThruMessage msg) {
|
||||
if (msg.RxStatus != 0x00) return false;
|
||||
return msg.Timestamp != 0;
|
||||
}
|
||||
|
||||
public void stopMsgFilter(int channelId, int msgId) {
|
||||
int status = PassThruStopMsgFilter(channelId, msgId);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
}
|
||||
|
||||
public void disconnect(int channelId) {
|
||||
int status = PassThruDisconnect(channelId);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
}
|
||||
|
||||
public void close(int deviceId) {
|
||||
int status = PassThruClose(deviceId);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
}
|
||||
|
||||
private ConfigItem[] configItems(SConfig... sConfigs) {
|
||||
ConfigItem[] items = new ConfigItem[sConfigs.length];
|
||||
for (int i = 0; i < sConfigs.length; i++) {
|
||||
SConfig sConfig = sConfigs[i];
|
||||
items[i] = new ConfigItem(sConfig.Parameter, sConfig.Value);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private SConfig[] sConfigs(ConfigItem... items) {
|
||||
SConfig[] sConfigs = new SConfig[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
SConfig sconfig = new SConfig();
|
||||
sconfig.Parameter = items[i].parameter;
|
||||
sconfig.Value = items[i].value;
|
||||
sConfigs[i] = sconfig;
|
||||
}
|
||||
return sConfigs;
|
||||
}
|
||||
|
||||
private SConfig[] sConfigs(int... parameters) {
|
||||
SConfig[] sConfigs = new SConfig[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
SConfig sConfig = new SConfig();
|
||||
sConfig.Parameter = parameters[i];
|
||||
sConfigs[i] = sConfig;
|
||||
}
|
||||
return sConfigs;
|
||||
}
|
||||
|
||||
private SConfigList sConfigList(SConfig[] sconfigs) {
|
||||
SConfigList input = new SConfigList();
|
||||
input.NumOfParams = sconfigs.length;
|
||||
input.ConfigPtr = sconfigs;
|
||||
return input;
|
||||
}
|
||||
|
||||
private PassThruMessage passThruMessage(byte... data) {
|
||||
PassThruMessage msg = passThruMessage();
|
||||
arraycopy(data, 0, msg.Data, 0, data.length);
|
||||
msg.DataSize = data.length;
|
||||
return msg;
|
||||
}
|
||||
|
||||
private PassThruMessage passThruMessage() {
|
||||
PassThruMessage msg = new PassThruMessage();
|
||||
msg.ProtocolID = protocol;
|
||||
return msg;
|
||||
}
|
||||
|
||||
private byte[] data(PassThruMessage msg) {
|
||||
int length = msg.DataSize;
|
||||
byte[] data = new byte[length];
|
||||
arraycopy(msg.Data, 0, data, 0, length);
|
||||
return data;
|
||||
}
|
||||
|
||||
private void handleError(int status) {
|
||||
byte[] error = new byte[80];
|
||||
PassThruGetLastError(error);
|
||||
throw new J2534Exception("Error: [" + status + "] " + toString(error));
|
||||
}
|
||||
|
||||
private String toString(byte[] bytes) {
|
||||
String msg = "";
|
||||
for (int b : bytes) {
|
||||
if (b == 0x00) continue;
|
||||
msg += (char) b;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
}
|
|
@ -1,259 +0,0 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.io.j2534.op20;
|
||||
|
||||
import com.romraider.io.j2534.api.ConfigItem;
|
||||
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.IOCTL_GET_CONFIG;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.IOCTL_SET_CONFIG;
|
||||
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;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.PassThruGetLastError;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.PassThruIoctl;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.PassThruOpen;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.PassThruReadMsgs;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.PassThruReadVersion;
|
||||
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_ERR_TIMEOUT;
|
||||
import static com.romraider.io.j2534.op20.OpenPort20.STATUS_NOERROR;
|
||||
import static com.romraider.util.HexUtil.asHex;
|
||||
import static com.romraider.util.ThreadUtil.sleep;
|
||||
import static java.lang.System.arraycopy;
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
import org.apache.log4j.Logger;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class Old_J2534OpenPort20 implements J2534 {
|
||||
private static final Logger LOGGER = getLogger(J2534OpenPort20.class);
|
||||
private final int protocol;
|
||||
|
||||
public Old_J2534OpenPort20(int protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public int open() {
|
||||
int[] deviceId = {0};
|
||||
int status = PassThruOpen(null, deviceId);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
return deviceId[0];
|
||||
}
|
||||
|
||||
public Version readVersion(int deviceId) {
|
||||
byte[] firmware = new byte[80];
|
||||
byte[] dll = new byte[80];
|
||||
byte[] api = new byte[80];
|
||||
int status = PassThruReadVersion(deviceId, firmware, dll, api);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
return new Version(toString(firmware), toString(dll), toString(api));
|
||||
}
|
||||
|
||||
public int connect(int deviceId, int flags, int baud) {
|
||||
int[] channelId = {0};
|
||||
int status = PassThruConnect(deviceId, protocol, flags, baud, channelId);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
return channelId[0];
|
||||
}
|
||||
|
||||
public void setConfig(int channelId, ConfigItem... items) {
|
||||
if (items.length == 0) return;
|
||||
SConfig[] sConfigs = sConfigs(items);
|
||||
SConfigList list = sConfigList(sConfigs);
|
||||
int status = PassThruIoctl(channelId, IOCTL_SET_CONFIG, list, null);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
}
|
||||
|
||||
public ConfigItem[] getConfig(int channelId, int... parameters) {
|
||||
if (parameters.length == 0) return configItems();
|
||||
SConfig[] sConfigs = sConfigs(parameters);
|
||||
SConfigList input = sConfigList(sConfigs);
|
||||
int status = PassThruIoctl(channelId, IOCTL_GET_CONFIG, input, null);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
return configItems(input.ConfigPtr);
|
||||
}
|
||||
|
||||
public int startPassMsgFilter(int channelId, byte mask, byte pattern) {
|
||||
PassThruMessage maskMsg = passThruMessage(mask);
|
||||
PassThruMessage patternMsg = passThruMessage(pattern);
|
||||
int[] msgId = {0};
|
||||
int status = PassThruStartMsgFilter(channelId, FILTER_PASS, maskMsg, patternMsg, null, msgId);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
return msgId[0];
|
||||
}
|
||||
|
||||
public void writeMsg(int channelId, byte[] data, long timeout) {
|
||||
PassThruMessage msg = passThruMessage(data);
|
||||
LOGGER.trace("Write Msg: " + toString(msg));
|
||||
int[] pNumMsgs = {1};
|
||||
int status = PassThruWriteMsgs(channelId, msg, pNumMsgs, (int) timeout);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
}
|
||||
|
||||
public void readMsg(int channelId, byte[] response, long timeout) {
|
||||
int index = 0;
|
||||
long end = currentTimeMillis() + timeout;
|
||||
do {
|
||||
PassThruMessage msg = doReadMsg(channelId);
|
||||
LOGGER.trace("Read Msg: " + toString(msg));
|
||||
if (!isResponse(msg)) continue;
|
||||
arraycopy(msg.Data, 0, response, index, msg.DataSize);
|
||||
index += msg.DataSize;
|
||||
} while (currentTimeMillis() <= end && index < response.length - 1);
|
||||
}
|
||||
|
||||
public byte[] readMsg(int channelId, long maxWait) {
|
||||
List<byte[]> responses = new ArrayList<byte[]>();
|
||||
long end = currentTimeMillis() + maxWait;
|
||||
do {
|
||||
PassThruMessage msg = doReadMsg(channelId);
|
||||
LOGGER.trace("Read Msg: " + toString(msg));
|
||||
if (isResponse(msg)) responses.add(data(msg));
|
||||
sleep(2);
|
||||
} while (currentTimeMillis() <= end);
|
||||
return concat(responses);
|
||||
}
|
||||
|
||||
private byte[] concat(List<byte[]> responses) {
|
||||
int length = 0;
|
||||
for (byte[] response : responses) length += response.length;
|
||||
byte[] result = new byte[length];
|
||||
int index = 0;
|
||||
for (byte[] response : responses) {
|
||||
if (response.length == 0) continue;
|
||||
System.arraycopy(response, 0, result, index, response.length);
|
||||
index += response.length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String toString(PassThruMessage msg) {
|
||||
byte[] bytes = new byte[msg.DataSize];
|
||||
arraycopy(msg.Data, 0, bytes, 0, bytes.length);
|
||||
return "[ProtocolID=" + msg.ProtocolID + "|RxStatus=" + msg.RxStatus + "|TxFlags=" + msg.TxFlags + "|Timestamp=" + msg.Timestamp + "|ExtraDataIndex=" + msg.ExtraDataIndex + "|DataSize=" + msg.DataSize + "|Data=" + asHex(bytes) + "]";
|
||||
}
|
||||
|
||||
private boolean isResponse(PassThruMessage msg) {
|
||||
if (msg.Timestamp == 0) return false;
|
||||
if (msg.RxStatus == 0x00) return true;
|
||||
return msg.RxStatus == 0x01;
|
||||
}
|
||||
|
||||
private PassThruMessage doReadMsg(int channelId) {
|
||||
PassThruMessage msg = passThruMessage();
|
||||
int[] pNumMsgs = {1};
|
||||
int status = PassThruReadMsgs(channelId, msg, pNumMsgs, 0);
|
||||
if (status != STATUS_NOERROR && status != STATUS_ERR_TIMEOUT) handleError(status);
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void stopMsgFilter(int channelId, int msgId) {
|
||||
int status = PassThruStopMsgFilter(channelId, msgId);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
}
|
||||
|
||||
public void disconnect(int channelId) {
|
||||
int status = PassThruDisconnect(channelId);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
}
|
||||
|
||||
public void close(int deviceId) {
|
||||
int status = PassThruClose(deviceId);
|
||||
if (status != STATUS_NOERROR) handleError(status);
|
||||
}
|
||||
|
||||
private ConfigItem[] configItems(SConfig... sConfigs) {
|
||||
ConfigItem[] items = new ConfigItem[sConfigs.length];
|
||||
for (int i = 0; i < sConfigs.length; i++) {
|
||||
SConfig sConfig = sConfigs[i];
|
||||
items[i] = new ConfigItem(sConfig.Parameter, sConfig.Value);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private SConfig[] sConfigs(ConfigItem... items) {
|
||||
SConfig[] sConfigs = new SConfig[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
SConfig sconfig = new SConfig();
|
||||
sconfig.Parameter = items[i].parameter;
|
||||
sconfig.Value = items[i].value;
|
||||
sConfigs[i] = sconfig;
|
||||
}
|
||||
return sConfigs;
|
||||
}
|
||||
|
||||
private SConfig[] sConfigs(int... parameters) {
|
||||
SConfig[] sConfigs = new SConfig[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
SConfig sConfig = new SConfig();
|
||||
sConfig.Parameter = parameters[i];
|
||||
sConfigs[i] = sConfig;
|
||||
}
|
||||
return sConfigs;
|
||||
}
|
||||
|
||||
private SConfigList sConfigList(SConfig[] sconfigs) {
|
||||
SConfigList input = new SConfigList();
|
||||
input.NumOfParams = sconfigs.length;
|
||||
input.ConfigPtr = sconfigs;
|
||||
return input;
|
||||
}
|
||||
|
||||
private PassThruMessage passThruMessage(byte... data) {
|
||||
PassThruMessage msg = passThruMessage();
|
||||
arraycopy(data, 0, msg.Data, 0, data.length);
|
||||
msg.DataSize = data.length;
|
||||
return msg;
|
||||
}
|
||||
|
||||
private PassThruMessage passThruMessage() {
|
||||
PassThruMessage msg = new PassThruMessage();
|
||||
msg.ProtocolID = protocol;
|
||||
return msg;
|
||||
}
|
||||
|
||||
private byte[] data(PassThruMessage msg) {
|
||||
int length = msg.DataSize;
|
||||
byte[] data = new byte[length];
|
||||
arraycopy(msg.Data, 0, data, 0, length);
|
||||
return data;
|
||||
}
|
||||
|
||||
private void handleError(int status) {
|
||||
byte[] error = new byte[80];
|
||||
PassThruGetLastError(error);
|
||||
throw new J2534Exception("Error: [" + status + "] " + toString(error));
|
||||
}
|
||||
|
||||
private String toString(byte[] bytes) {
|
||||
String msg = "";
|
||||
for (int b : bytes) {
|
||||
if (b == 0x00) continue;
|
||||
msg += (char) b;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.io.j2534.op20;
|
||||
|
||||
import com.jinvoke.JInvoke;
|
||||
import com.jinvoke.NativeImport;
|
||||
|
||||
public final class OpenPort20 {
|
||||
private static final String OP20PT32_DLL = "op20pt32";
|
||||
|
||||
// FIX - Split out and separate these
|
||||
public static final int STATUS_NOERROR = 0x00;
|
||||
public static final int STATUS_ERR_TIMEOUT = 0x09;
|
||||
public static final int PROTOCOL_ISO9141 = 3;
|
||||
public static final int FLAG_NONE = 0x00;
|
||||
public static final int FLAG_ISO9141_NO_CHECKSUM = 0x00000200;
|
||||
public static final int FILTER_PASS = 0x00000001;
|
||||
public static final int IOCTL_GET_CONFIG = 0x01;
|
||||
public static final int IOCTL_SET_CONFIG = 0x02;
|
||||
public static final int CONFIG_DATA_RATE = 0x01;
|
||||
public static final int CONFIG_LOOPBACK = 0x03;
|
||||
public static final int CONFIG_P1_MAX = 0x07;
|
||||
public static final int CONFIG_P3_MIN = 0x0A;
|
||||
public static final int CONFIG_P4_MIN = 0x0C;
|
||||
|
||||
static {
|
||||
JInvoke.initialize();
|
||||
}
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruOpen(String pName, int[] pDeviceID);
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruClose(int DeviceID);
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruReadVersion(int DeviceID, byte[] pFirmwareVersion, byte[] pDllVersion, byte[] pApiVersion);
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruGetLastError(byte[] pErrorDescription);
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruConnect(int DeviceID, int ProtocolID, int Flags, int BaudRate, int[] pChannelID);
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruDisconnect(int ChannelID);
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruStartMsgFilter(int ChannelID, int FilterType, PassThruMessage pMaskMsg, PassThruMessage pPatternMsg, PassThruMessage pFlowControlMsg, int[] pMsgID);
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruStopMsgFilter(int ChannelID, int MsgID);
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruIoctl(int ChannelID, int IoctlID, SConfigList pInput, SConfigList pOutput);
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruIoctl(int ChannelID, int IoctlID, SByteArray pInput, SByteArray pOutput);
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruWriteMsgs(int ChannelID, PassThruMessage pMsg, int[] pNumMsgs, int Timeout);
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruReadMsgs(int ChannelID, PassThruMessage pMsg, int[] pNumMsgs, int Timeout);
|
||||
|
||||
@NativeImport(library = OP20PT32_DLL)
|
||||
public static native int PassThruReadMsgs(int ChannelID, PassThruMessage[] pMsgs, int[] pNumMsgs, int Timeout);
|
||||
|
||||
// FIX - Add support for these too...
|
||||
// @NativeImport(library = OP20PT32_DLL)
|
||||
// public static native int PassThruSetProgrammingVoltage(int DeviceID, int PinNumber, int Voltage);
|
||||
|
||||
// @NativeImport(library = OP20PT32_DLL)
|
||||
// public static native int PassThruStartPeriodicMsg(int ChannelID, PassThruMessage pMsg, int[] pMsgID, int TimeInterval);
|
||||
|
||||
// @NativeImport(library = OP20PT32_DLL)
|
||||
// public static native int PassThruStopPeriodicMsg(int ChannelID, int MsgID);
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.io.j2534.op20;
|
||||
|
||||
import com.jinvoke.Embedded;
|
||||
import com.jinvoke.NativeStruct;
|
||||
|
||||
@NativeStruct
|
||||
public final class PassThruMessage {
|
||||
public int ProtocolID; /* vehicle network protocol */
|
||||
public int RxStatus; /* receive message status */
|
||||
public int TxFlags; /* transmit message flags */
|
||||
public int Timestamp; /* receive message timestamp(in microseconds) */
|
||||
public int DataSize; /* byte size of message payload in the Data array */
|
||||
public int ExtraDataIndex; /* start of extra data(i.e. CRC, checksum, etc) in Data array */
|
||||
@Embedded(length = 4128)
|
||||
public byte[] Data = new byte[4128]; /* message payload or data */
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.io.j2534.op20;
|
||||
|
||||
import com.jinvoke.NativeStruct;
|
||||
|
||||
@NativeStruct
|
||||
public final class SConfig {
|
||||
public int Parameter;
|
||||
public int Value;
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.io.j2534.op20;
|
||||
|
||||
import com.jinvoke.NativeStruct;
|
||||
|
||||
@NativeStruct
|
||||
public final class SConfigList {
|
||||
public int NumOfParams;
|
||||
public SConfig[] ConfigPtr;
|
||||
}
|
|
@ -57,8 +57,10 @@ import com.romraider.logger.ecu.ui.handler.file.FileLoggerControllerSwitchMonito
|
|||
|
||||
public final class QueryManagerImpl implements QueryManager {
|
||||
private static final Logger LOGGER = Logger.getLogger(QueryManagerImpl.class);
|
||||
private final List<StatusChangeListener> listeners = synchronizedList(new ArrayList<StatusChangeListener>());
|
||||
private final Map<String, Query> queryMap = synchronizedMap(new HashMap<String, Query>());
|
||||
private final List<StatusChangeListener> listeners =
|
||||
synchronizedList(new ArrayList<StatusChangeListener>());
|
||||
private final Map<String, Query> queryMap =
|
||||
synchronizedMap(new HashMap<String, Query>());
|
||||
private final Map<String, Query> addList = new HashMap<String, Query>();
|
||||
private final List<String> removeList = new ArrayList<String>();
|
||||
private static final PollingState pollState = new PollingStateImpl();
|
||||
|
@ -72,9 +74,14 @@ public final class QueryManagerImpl implements QueryManager {
|
|||
private boolean started;
|
||||
private boolean stop;
|
||||
|
||||
public QueryManagerImpl(Settings settings, EcuInitCallback ecuInitCallback, MessageListener messageListener,
|
||||
public QueryManagerImpl(Settings settings,
|
||||
EcuInitCallback ecuInitCallback,
|
||||
MessageListener messageListener,
|
||||
DataUpdateHandler... dataUpdateHandlers) {
|
||||
checkNotNull(settings, ecuInitCallback, messageListener, dataUpdateHandlers);
|
||||
checkNotNull(settings,
|
||||
ecuInitCallback,
|
||||
messageListener,
|
||||
dataUpdateHandlers);
|
||||
this.settings = settings;
|
||||
this.ecuInitCallback = ecuInitCallback;
|
||||
this.messageListener = messageListener;
|
||||
|
@ -151,8 +158,10 @@ public final class QueryManagerImpl implements QueryManager {
|
|||
}
|
||||
|
||||
try {
|
||||
LoggerConnection connection = getConnection(settings.getLoggerProtocol(), settings.getLoggerPort(),
|
||||
settings.getLoggerConnectionProperties());
|
||||
LoggerConnection connection =
|
||||
getConnection(settings.getLoggerProtocol(),
|
||||
settings.getLoggerPort(),
|
||||
settings.getLoggerConnectionProperties());
|
||||
try {
|
||||
messageListener.reportMessage("Sending " + target + " Init...");
|
||||
connection.ecuInit(ecuInitCallback, id);
|
||||
|
@ -162,7 +171,8 @@ public final class QueryManagerImpl implements QueryManager {
|
|||
connection.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
messageListener.reportMessage("Unable to send " + target + " init - check cable is connected and ignition is on.");
|
||||
messageListener.reportMessage("Unable to send " + target +
|
||||
" init - check cable is connected and ignition is on.");
|
||||
logError(e);
|
||||
return false;
|
||||
}
|
||||
|
@ -244,15 +254,19 @@ public final class QueryManagerImpl implements QueryManager {
|
|||
|
||||
private void sendEcuQueries(TransmissionManager txManager) {
|
||||
List<EcuQuery> ecuQueries = filterEcuQueries(queryMap.values());
|
||||
if (fileLoggerQuery != null && settings.isFileLoggingControllerSwitchActive()) ecuQueries.add(fileLoggerQuery);
|
||||
if (fileLoggerQuery != null &&
|
||||
settings.isFileLoggingControllerSwitchActive())
|
||||
ecuQueries.add(fileLoggerQuery);
|
||||
txManager.sendQueries(ecuQueries, pollState);
|
||||
}
|
||||
|
||||
private void sendExternalQueries() {
|
||||
List<ExternalQuery> externalQueries = filterExternalQueries(queryMap.values());
|
||||
List<ExternalQuery> externalQueries =
|
||||
filterExternalQueries(queryMap.values());
|
||||
for (ExternalQuery externalQuery : externalQueries) {
|
||||
//FIXME: This is a hack!!
|
||||
externalQuery.setResponse(externalQuery.getLoggerData().getSelectedConvertor().convert(null));
|
||||
externalQuery.setResponse(
|
||||
externalQuery.getLoggerData().getSelectedConvertor().convert(null));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ public class Test implements MTSEvents {
|
|||
|
||||
private MTS mts;
|
||||
private EventCookie connectionEventCookie;
|
||||
private int count = 0;
|
||||
|
||||
public Test() {
|
||||
mts = null;
|
||||
|
@ -39,7 +40,7 @@ public class Test implements MTSEvents {
|
|||
String inputName = mts.inputName();
|
||||
int inputType = mts.inputType();
|
||||
|
||||
System.out.printf("%s : %d%n", inputName, inputType);
|
||||
System.out.printf("inputName:%s, inputType:%d%n", inputName, inputType);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,24 +81,28 @@ public class Test implements MTSEvents {
|
|||
|
||||
System.out.printf("Found %d ports.%n", portCount);
|
||||
|
||||
// set the current port before attempting to connect
|
||||
mts.currentPort(0);
|
||||
String portName = mts.portName();
|
||||
|
||||
System.out.printf("Set current port to 0; port name = %s%n", portName);
|
||||
|
||||
// register for MTS component events
|
||||
connectionEventCookie = mts.advise(MTSEvents.class, this);
|
||||
|
||||
// attempt to connect to the specified device
|
||||
System.out.println("connect() called.");
|
||||
mts.connect();
|
||||
|
||||
// show available inputs
|
||||
printAvailableInputs();
|
||||
|
||||
// set the current port before attempting to connect
|
||||
for (int i = 0; i < portCount; i++) {
|
||||
mts.currentPort(i);
|
||||
String portName = mts.portName();
|
||||
|
||||
System.out.printf("Current MTS port is %d; port name = %s%n", i, portName);
|
||||
|
||||
// attempt to connect to the specified device
|
||||
System.out.println("connect() called.");
|
||||
mts.connect();
|
||||
|
||||
// show available inputs
|
||||
printAvailableInputs();
|
||||
mts.disconnect();
|
||||
}
|
||||
// attempt to get data
|
||||
// mts.currentInput(0);
|
||||
mts.currentPort(0);
|
||||
mts.connect();
|
||||
mts.startData();
|
||||
|
||||
// notes:
|
||||
|
@ -123,7 +128,7 @@ public class Test implements MTSEvents {
|
|||
|
||||
// retrieve 10 samples
|
||||
// getSamples(10);
|
||||
waitFor(20000);
|
||||
waitFor(60000);
|
||||
|
||||
// dispose of the event handler instance
|
||||
connectionEventCookie.close();
|
||||
|
@ -150,17 +155,23 @@ public class Test implements MTSEvents {
|
|||
public void newData() {
|
||||
int i;
|
||||
float data = 0f;
|
||||
// for (i = 0; i < mts.inputCount(); i++) {
|
||||
i=0;
|
||||
for (i = 0; i < mts.inputCount(); i++) {
|
||||
// i=0;
|
||||
mts.currentInput(i);
|
||||
float min = mts.inputMinValue();
|
||||
float max = mts.inputMaxValue();
|
||||
data = mts.inputSample();
|
||||
data = ((max - min) * ((float) data / 1024f)) + min;
|
||||
float multiplier = mts.inputAFRMultiplier();
|
||||
int sampleMeaning = mts.inputFunction();
|
||||
System.out.printf("newData raised for Input: %02d, Function: %d, Data: %f,\tMultiplier: %f%n", i, sampleMeaning, data, multiplier);
|
||||
// }
|
||||
float sample = mts.inputSample();
|
||||
data = ((max - min) * ((float) sample / 1024f)) + min;
|
||||
// float multiplier = mts.inputAFRMultiplier();
|
||||
// int sampleMeaning = mts.inputFunction();
|
||||
String str = String.format(
|
||||
"%d, InputNo: %02d, InputName: %s, InputType: %d, DeviceName: %s, DeviceType: %d, DeviceChannel: %d, Units: %s, Multiplier: %f, MinValue: %f, MaxValue: %f, Sample: %f, Data: %f",
|
||||
count, i, mts.inputName(), mts.inputType(), mts.inputDeviceName(), mts.inputDeviceType(), mts.inputDeviceChannel(), mts.inputUnit(), mts.inputAFRMultiplier(), mts.inputMinValue(), mts.inputMaxValue(), sample, data);
|
||||
|
||||
System.out.printf("%s%n", str);
|
||||
// System.out.printf("newData raised for Input: %02d, Function: %d, Data: %f,\tMultiplier: %f%n", i, sampleMeaning, data, multiplier);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,12 +16,11 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.txstuner.io;
|
||||
package com.romraider.logger.external.txs.io;
|
||||
|
||||
import com.romraider.io.connection.ConnectionProperties;
|
||||
|
||||
public final class TxsTunerConnectionProperties implements ConnectionProperties {
|
||||
public final class TxsConnectionProperties implements ConnectionProperties {
|
||||
public int getBaudRate() {
|
||||
return 19200;
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.txs.io;
|
||||
|
||||
import static com.romraider.util.ParamChecker.isNullOrEmpty;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.romraider.io.connection.ConnectionProperties;
|
||||
import com.romraider.io.serial.connection.SerialConnection;
|
||||
import com.romraider.io.serial.connection.SerialConnectionImpl;
|
||||
import com.romraider.logger.external.core.Stoppable;
|
||||
import com.romraider.logger.external.txs.plugin.TxsDataItem;
|
||||
|
||||
public final class TxsRunner implements Stoppable{
|
||||
|
||||
private static final Logger LOGGER = getLogger(TxsRunner.class);
|
||||
private static final ConnectionProperties CONNECTION_PROPS =
|
||||
new TxsConnectionProperties();
|
||||
private static final String WHITESPACE_REGEX = "\\s+";
|
||||
private static final String SPLIT_DELIMITER = " ";
|
||||
private static final byte[] EXIT = new byte[]{24};
|
||||
|
||||
private final HashMap<Integer, TxsDataItem> dataItems;
|
||||
private final SerialConnection connection;
|
||||
|
||||
private boolean stop;
|
||||
private String txsLogger;
|
||||
private String txsDevice;
|
||||
|
||||
public TxsRunner(
|
||||
String port,
|
||||
HashMap<Integer, TxsDataItem> dataItems,
|
||||
String logger,
|
||||
String device) {
|
||||
this.connection = new SerialConnectionImpl(port, CONNECTION_PROPS);
|
||||
this.dataItems = dataItems;
|
||||
this.txsLogger = logger;
|
||||
this.txsDevice = device;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
//Convert string into bytes[]
|
||||
byte[] device = txsDevice.getBytes();
|
||||
byte[] logger = this.txsLogger.getBytes();
|
||||
|
||||
//Exit to main screen
|
||||
connection.write(EXIT);
|
||||
//wait for exit to complete.
|
||||
Thread.sleep(250L);
|
||||
|
||||
String response = connection.readLine();
|
||||
//Send command to switch device: utec / tuner.
|
||||
connection.write(device);
|
||||
|
||||
//Read and Trace response switching device.
|
||||
response = connection.readLine();
|
||||
LOGGER.trace("TXS Runner Response: " + response);
|
||||
|
||||
//Start device logger
|
||||
connection.write(logger);
|
||||
|
||||
while (!stop) {
|
||||
//Get Response from TXS Device
|
||||
response = connection.readLine();
|
||||
|
||||
//Continue if no data was received.
|
||||
if (isNullOrEmpty(response)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Trace response
|
||||
LOGGER.trace("TXS Runner Response: " + response);
|
||||
//Split Values for parsing
|
||||
String[] values = SplitUtecString(response);
|
||||
//Set Data Item Values
|
||||
SetDataItemValues(values);
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
LOGGER.error("Error occurred", t);
|
||||
}
|
||||
finally {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
stop = true;
|
||||
connection.close();
|
||||
}
|
||||
|
||||
private String[] SplitUtecString(String value) {
|
||||
try {
|
||||
value = value.trim();
|
||||
value = value.replaceAll(WHITESPACE_REGEX, SPLIT_DELIMITER);
|
||||
String[] utecArray = value.split(SPLIT_DELIMITER);
|
||||
return utecArray;
|
||||
}
|
||||
catch (Exception e) {
|
||||
return new String[]{};
|
||||
}
|
||||
}
|
||||
|
||||
private void SetDataItemValues(String[] values) {
|
||||
for(int i = 0; i < values.length ; i++) {
|
||||
//GetDataItem via Index Hash defined in DataSoruce
|
||||
TxsDataItem dataItem = dataItems.get(i);
|
||||
|
||||
if(dataItem != null) {
|
||||
//Set value to dataItem
|
||||
dataItem.setData(parseDouble(values[i]));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private double parseDouble(String value) {
|
||||
try {
|
||||
//try to parse value.
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
catch (Exception e) {
|
||||
//return 0 if value could not be parsed.
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.txstuner.plugin;
|
||||
package com.romraider.logger.external.txs.plugin;
|
||||
|
||||
import static com.romraider.logger.external.core.ExternalDataConvertorLoader.loadConvertors;
|
||||
|
||||
|
@ -26,22 +26,24 @@ import com.romraider.logger.external.core.DataListener;
|
|||
import com.romraider.logger.external.core.ExternalDataItem;
|
||||
import com.romraider.logger.external.core.ExternalSensorConversions;
|
||||
|
||||
public final class TxsTunerDataItem implements ExternalDataItem, DataListener {
|
||||
private EcuDataConvertor[] convertors;
|
||||
public final class TxsDataItem implements ExternalDataItem, DataListener {
|
||||
private EcuDataConvertor[] convertors;
|
||||
private final String name;
|
||||
private double data;
|
||||
|
||||
public TxsTunerDataItem(ExternalSensorConversions... convertorList) {
|
||||
super();
|
||||
convertors = new EcuDataConvertor[convertorList.length];
|
||||
convertors = loadConvertors(this, convertors, convertorList);
|
||||
public TxsDataItem(String name, ExternalSensorConversions... convertorList) {
|
||||
super();
|
||||
this.name = name;
|
||||
convertors = new EcuDataConvertor[convertorList.length];
|
||||
convertors = loadConvertors(this, convertors, convertorList);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "TXS Tuner AFR";
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return "TXS Tuner Wideband data";
|
||||
return name + " data";
|
||||
}
|
||||
|
||||
public double getData() {
|
||||
|
@ -55,5 +57,4 @@ public final class TxsTunerDataItem implements ExternalDataItem, DataListener {
|
|||
public EcuDataConvertor[] getConvertors() {
|
||||
return convertors;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.txs.plugin;
|
||||
|
||||
import com.romraider.logger.ecu.ui.handler.dash.GaugeMinMax;
|
||||
import com.romraider.logger.external.core.ExternalSensorConversions;
|
||||
|
||||
public enum TxsSensorConversions implements ExternalSensorConversions{
|
||||
TXS_RPM ("rpm", "x", "0", new GaugeMinMax(0,10000,1000)),
|
||||
TXS_BOOST ("psi", "x", "0.0", new GaugeMinMax(-100,100,5)),
|
||||
TXS_MAFV ("mafv", "x", "0.00", new GaugeMinMax(0,5,0.05)),
|
||||
TXS_TPS ("tps", "x", "0", new GaugeMinMax(0,100,5)),
|
||||
TXS_LOAD ("load", "x", "0", new GaugeMinMax(0,100,10)),
|
||||
TXS_KNOCK ("knock", "x", "0", new GaugeMinMax(0,100,1)),
|
||||
TXS_IGN ("ign", "x", "0.00", new GaugeMinMax(-15,60,5)),
|
||||
TXS_IDC ("%", "x", "0", new GaugeMinMax(0,125,5)),
|
||||
TXS_MAPVE ("mapve", "x", "0", new GaugeMinMax(0,200,5)),
|
||||
TXS_MODFUEL ("modfuel %", "x", "0.00", new GaugeMinMax(-50,50,.05));
|
||||
|
||||
private final String units;
|
||||
private final String expression;
|
||||
private final String format;
|
||||
private final GaugeMinMax gaugeMinMax;
|
||||
|
||||
TxsSensorConversions(String units, String expression,
|
||||
String format, GaugeMinMax gaugeMinMax) {
|
||||
this.units = units;
|
||||
this.expression = expression;
|
||||
this.format = format;
|
||||
this.gaugeMinMax = gaugeMinMax;
|
||||
}
|
||||
|
||||
public String units() { return units; }
|
||||
public String expression() { return expression; }
|
||||
public String format() { return format; }
|
||||
public GaugeMinMax gaugeMinMax() {return gaugeMinMax; }
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.txs.plugin;
|
||||
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_146;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_147;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_155;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_172;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_34;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_64;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_90;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.LAMBDA;
|
||||
import static com.romraider.logger.external.txs.plugin.TxsSensorConversions.TXS_KNOCK;
|
||||
import static com.romraider.logger.external.txs.plugin.TxsSensorConversions.TXS_RPM;
|
||||
import static com.romraider.util.ThreadUtil.runAsDaemon;
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.Action;
|
||||
|
||||
import com.romraider.logger.ecu.EcuLogger;
|
||||
import com.romraider.logger.external.core.ExternalDataItem;
|
||||
import com.romraider.logger.external.core.ExternalDataSource;
|
||||
import com.romraider.logger.external.txs.io.TxsRunner;
|
||||
|
||||
public class TxsTunerDataSource implements ExternalDataSource {
|
||||
|
||||
private static final String LOGGER = "1";
|
||||
private static final String DEVICE = "t";
|
||||
private static final String DEVICE_NAME = "TXS Tuner ";
|
||||
private static final int TUNER_LITE_AFR = 0;
|
||||
private static final int TUNER_PRO_RPM = 0;
|
||||
private static final int TUNER_PRO_AFR = 1;
|
||||
private static final int TUNER_PRO_KNOCK = 11;
|
||||
|
||||
private final HashMap<Integer, TxsDataItem> dataItems =
|
||||
new HashMap<Integer, TxsDataItem>();
|
||||
private TxsRunner runner;
|
||||
private String port;
|
||||
|
||||
{
|
||||
dataItems.put(TUNER_LITE_AFR, new TxsDataItem(DEVICE_NAME + "Lite AFR", AFR_147, LAMBDA, AFR_90, AFR_146, AFR_64, AFR_155, AFR_172, AFR_34));
|
||||
dataItems.put(TUNER_PRO_RPM, new TxsDataItem(DEVICE_NAME + "Pro Knock", TXS_RPM));
|
||||
dataItems.put(TUNER_PRO_AFR, new TxsDataItem(DEVICE_NAME + "Pro AFR", AFR_147, LAMBDA, AFR_90, AFR_146, AFR_64, AFR_155, AFR_172, AFR_34));
|
||||
dataItems.put(TUNER_PRO_KNOCK, new TxsDataItem(DEVICE_NAME + "Pro Knock", TXS_KNOCK));
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return getClass().getName();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return DEVICE_NAME + "Logger";
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return "0.01";
|
||||
}
|
||||
|
||||
public List<? extends ExternalDataItem> getDataItems() {
|
||||
return unmodifiableList(new ArrayList<TxsDataItem>(dataItems.values()));
|
||||
}
|
||||
|
||||
public Action getMenuAction(EcuLogger logger) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPort(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
runner = new TxsRunner(port, dataItems, LOGGER, DEVICE);
|
||||
runAsDaemon(runner);
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if(runner!=null) {
|
||||
runner.stop();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.txs.plugin;
|
||||
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_146;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_147;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_155;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_172;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_34;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_64;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_90;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.LAMBDA;
|
||||
import static com.romraider.logger.external.txs.plugin.TxsSensorConversions.TXS_BOOST;
|
||||
import static com.romraider.logger.external.txs.plugin.TxsSensorConversions.TXS_IDC;
|
||||
import static com.romraider.logger.external.txs.plugin.TxsSensorConversions.TXS_IGN;
|
||||
import static com.romraider.logger.external.txs.plugin.TxsSensorConversions.TXS_KNOCK;
|
||||
import static com.romraider.logger.external.txs.plugin.TxsSensorConversions.TXS_LOAD;
|
||||
import static com.romraider.logger.external.txs.plugin.TxsSensorConversions.TXS_MAFV;
|
||||
import static com.romraider.logger.external.txs.plugin.TxsSensorConversions.TXS_MAPVE;
|
||||
import static com.romraider.logger.external.txs.plugin.TxsSensorConversions.TXS_MODFUEL;
|
||||
import static com.romraider.logger.external.txs.plugin.TxsSensorConversions.TXS_RPM;
|
||||
import static com.romraider.logger.external.txs.plugin.TxsSensorConversions.TXS_TPS;
|
||||
import static com.romraider.util.ThreadUtil.runAsDaemon;
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.Action;
|
||||
|
||||
import com.romraider.logger.ecu.EcuLogger;
|
||||
import com.romraider.logger.external.core.ExternalDataItem;
|
||||
import com.romraider.logger.external.core.ExternalDataSource;
|
||||
import com.romraider.logger.external.txs.io.TxsRunner;
|
||||
|
||||
public class TxsUtecLogger1DataSource implements ExternalDataSource {
|
||||
private static final String LOGGER = "1";
|
||||
private static final String DEVICE = "u";
|
||||
private static final String DEVICE_NAME = "TXS UTEC ";
|
||||
private static final int RPM = 0;
|
||||
private static final int BOOST = 1;
|
||||
private static final int MAFV = 2;
|
||||
private static final int TPS = 3;
|
||||
private static final int LOAD = 4;
|
||||
private static final int KNOCK = 5;
|
||||
private static final int ECUIGN = 7;
|
||||
private static final int IDC = 8;
|
||||
private static final int MODIGN = 9;
|
||||
private static final int MAPVE_MODFUEL = 10;
|
||||
private static final int MODMAFV = 12;
|
||||
private static final int AFR = 13;
|
||||
|
||||
private final HashMap<Integer, TxsDataItem> dataItems =
|
||||
new HashMap<Integer, TxsDataItem>();
|
||||
private TxsRunner runner;
|
||||
private String port;
|
||||
|
||||
{
|
||||
dataItems.put(RPM, new TxsDataItem(DEVICE_NAME + "RPM", TXS_RPM));
|
||||
dataItems.put(BOOST, new TxsDataItem(DEVICE_NAME + "BOOST", TXS_BOOST));
|
||||
dataItems.put(MAFV, new TxsDataItem(DEVICE_NAME + "MAFV", TXS_MAFV));
|
||||
dataItems.put(TPS, new TxsDataItem(DEVICE_NAME + "TPS", TXS_TPS));
|
||||
dataItems.put(LOAD, new TxsDataItem(DEVICE_NAME + "LOAD", TXS_LOAD));
|
||||
dataItems.put(KNOCK, new TxsDataItem(DEVICE_NAME + "KNOCK", TXS_KNOCK));
|
||||
dataItems.put(ECUIGN, new TxsDataItem(DEVICE_NAME + "ECUIGN", TXS_IGN));
|
||||
dataItems.put(IDC, new TxsDataItem(DEVICE_NAME + "IDC", TXS_IDC));
|
||||
dataItems.put(MODIGN, new TxsDataItem(DEVICE_NAME + "MODIGN", TXS_IGN));
|
||||
dataItems.put(MAPVE_MODFUEL, new TxsDataItem(DEVICE_NAME + "MAPVE/MODFUEL", TXS_MODFUEL, TXS_MAPVE));
|
||||
dataItems.put(MODMAFV, new TxsDataItem(DEVICE_NAME + "MODMAFV", TXS_MAFV));
|
||||
dataItems.put(AFR, new TxsDataItem(DEVICE_NAME + "AFR", AFR_147, LAMBDA, AFR_90, AFR_146, AFR_64, AFR_155, AFR_172, AFR_34));
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return getClass().getName();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return DEVICE_NAME + "Logger";
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return "0.01";
|
||||
}
|
||||
|
||||
public List<? extends ExternalDataItem> getDataItems() {
|
||||
return unmodifiableList(new ArrayList<TxsDataItem>(dataItems.values()));
|
||||
}
|
||||
|
||||
public Action getMenuAction(EcuLogger logger) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPort(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
runner = new TxsRunner(port, dataItems, LOGGER, DEVICE);
|
||||
runAsDaemon(runner);
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if(runner!=null) {
|
||||
runner.stop();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
|
||||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.txstuner.io;
|
||||
|
||||
import static com.romraider.util.ParamChecker.isNullOrEmpty;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.romraider.io.serial.connection.SerialConnection;
|
||||
import com.romraider.io.serial.connection.SerialConnectionImpl;
|
||||
import com.romraider.logger.external.core.Stoppable;
|
||||
import com.romraider.logger.external.txstuner.plugin.TxsTunerDataItem;
|
||||
|
||||
public final class TxsTunerRunner implements Stoppable {
|
||||
private static final Logger LOGGER = getLogger(TxsTunerRunner.class);
|
||||
private static final TxsTunerConnectionProperties CONNECTION_PROPS = new TxsTunerConnectionProperties();
|
||||
private static final String TXS_TUNER = "t";
|
||||
private static final String TXS_LOGGER = "1";
|
||||
private static final String SPLIT_DELIMITER = " ";
|
||||
private final SerialConnection connection;
|
||||
private final TxsTunerDataItem dataItem;
|
||||
private boolean stop;
|
||||
|
||||
public TxsTunerRunner(String port, TxsTunerDataItem dataItem) {
|
||||
this.connection = new SerialConnectionImpl(port, CONNECTION_PROPS);
|
||||
this.dataItem = dataItem;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
byte[] tuner = TXS_TUNER.getBytes();
|
||||
byte[] logger = TXS_LOGGER.getBytes();
|
||||
|
||||
//Send T to switch to tuner if connected to utec.
|
||||
connection.write(tuner);
|
||||
String response = connection.readLine();
|
||||
LOGGER.trace("TXS Tuner Response: " + response);
|
||||
|
||||
//Start TXS tuner logger
|
||||
connection.write(logger);
|
||||
response = connection.readLine();
|
||||
LOGGER.trace("TXS Tuner Response: " + response);
|
||||
|
||||
while (!stop) {
|
||||
response = connection.readLine();
|
||||
LOGGER.trace("TXS Tuner Response: " + response);
|
||||
if (!isNullOrEmpty(response)) dataItem.setData(parseString(response));
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
LOGGER.error("Error occurred", t);
|
||||
} finally {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
stop = true;
|
||||
connection.close();
|
||||
}
|
||||
|
||||
private double parseString(String value){
|
||||
try{
|
||||
value = value.trim();
|
||||
String[] substr = value.split(SPLIT_DELIMITER);
|
||||
return Double.parseDouble(substr[0]);
|
||||
}
|
||||
catch (Exception e){
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.logger.external.txstuner.plugin;
|
||||
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_146;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_147;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_155;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_172;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_34;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_64;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.AFR_90;
|
||||
import static com.romraider.logger.external.core.SensorConversionsAFR.LAMBDA;
|
||||
import static com.romraider.util.ThreadUtil.runAsDaemon;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.Action;
|
||||
|
||||
import com.romraider.logger.ecu.EcuLogger;
|
||||
import com.romraider.logger.external.core.ExternalDataItem;
|
||||
import com.romraider.logger.external.core.ExternalDataSource;
|
||||
import com.romraider.logger.external.txstuner.io.TxsTunerRunner;
|
||||
|
||||
public class TxsTunerDataSource implements ExternalDataSource {
|
||||
|
||||
private TxsTunerDataItem dataItem = new TxsTunerDataItem(AFR_147, LAMBDA, AFR_90, AFR_146, AFR_64, AFR_155, AFR_172, AFR_34);
|
||||
private TxsTunerRunner runner;
|
||||
private String port;
|
||||
|
||||
public String getId() {
|
||||
return getClass().getName();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "TXS Tuner AFR";
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return "0.02";
|
||||
}
|
||||
|
||||
public List<? extends ExternalDataItem> getDataItems() {
|
||||
return asList(dataItem);
|
||||
}
|
||||
|
||||
public Action getMenuAction(EcuLogger logger) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setPort(String port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
runner = new TxsTunerRunner(port, dataItem);
|
||||
runAsDaemon(runner);
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (runner != null) runner.stop();
|
||||
}
|
||||
}
|
|
@ -20,18 +20,20 @@
|
|||
package com.romraider.swing;
|
||||
|
||||
import static com.romraider.Version.PRODUCT_NAME;
|
||||
import static com.romraider.util.Platform.LINUX;
|
||||
import static com.romraider.util.Platform.MAC_OS_X;
|
||||
import static com.romraider.util.Platform.isPlatform;
|
||||
import static javax.swing.UIManager.getCrossPlatformLookAndFeelClassName;
|
||||
import static javax.swing.UIManager.getSystemLookAndFeelClassName;
|
||||
import static javax.swing.UIManager.setLookAndFeel;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public final class LookAndFeelManager {
|
||||
private static final Logger LOGGER = Logger.getLogger(LookAndFeelManager.class);
|
||||
private static final String OS_NAME = "os.name";
|
||||
private static final String MAC_OS_X = "Mac OS X";
|
||||
private static final String LINUX = "Linux";
|
||||
|
||||
private LookAndFeelManager() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
@ -58,10 +60,6 @@ public final class LookAndFeelManager {
|
|||
}
|
||||
}
|
||||
|
||||
private static boolean isPlatform(String platform) {
|
||||
return System.getProperties().getProperty(OS_NAME).toLowerCase().contains(platform.toLowerCase());
|
||||
}
|
||||
|
||||
private static String getLookAndFeel() {
|
||||
// if (true) return "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";
|
||||
// Linux has issues with the gtk look and feel themes.
|
||||
|
|
|
@ -1,28 +1,31 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.io.j2534.op20;
|
||||
|
||||
import com.jinvoke.NativeStruct;
|
||||
|
||||
@NativeStruct
|
||||
public final class SByteArray {
|
||||
public int NumOfBytes;
|
||||
public byte[] BytePtr;
|
||||
}
|
||||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
package com.romraider.util;
|
||||
|
||||
public final class Platform {
|
||||
public static final String LINUX = "Linux";
|
||||
public static final String MAC_OS_X = "Mac OS X";
|
||||
public static final String WINDOWS = "Windows";
|
||||
private static final String OS_NAME = "os.name";
|
||||
|
||||
public static boolean isPlatform(String platform) {
|
||||
return System.getProperties().getProperty(OS_NAME).toLowerCase().contains(platform.toLowerCase());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue