Changed build.xml back, extended Transport Class, implemented error checking for missing rxtx library

This commit is contained in:
Robin K 2020-04-18 12:16:39 +02:00
parent 94b3ac73a4
commit bd8e6aba62
10 changed files with 157 additions and 64 deletions

View File

@ -20,11 +20,7 @@
<classpathentry kind="lib" path="lib/common/cmutimelex.jar"/>
<classpathentry kind="lib" path="lib/common/en_us.jar"/>
<classpathentry kind="lib" path="lib/common/freetts.jar"/>
<classpathentry exported="true" kind="lib" path="lib/common/RXTXcomm.jar">
<attributes>
<attribute name="javadoc_location" value="http://users.frii.com/jarvi/rxtx/doc/"/>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="romraider/lib/windows"/>
</attributes>
<classpathentry kind="lib" path="lib/common/RXTXcomm.jar">
</classpathentry>
<classpathentry kind="lib" path="lib/windows/jdic_stub.jar"/>
<classpathentry kind="lib" path="lib/common/jdic.jar"/>

View File

@ -75,7 +75,7 @@
<!-- java compiler properties -->
<property name="javac.source" value="1.6" />
<property name="javac.target" value="1.6" />
<property name="bootclasspath.dir" value="D:\Documents\EclipseProjects\RomRaider"/>
<property name="bootclasspath.dir" value="C:\Program Files (x86)\Java\jdk1.6.0_45\jre\lib"/>
<property name="debug" value="off" />
<property name="deprecation" value="on" />
<property name="javac.verbose" value="off" />

View File

@ -178,17 +178,20 @@ public final class ElmConnection {
try {
return (SerialPort) portIdentifier.open(this.getClass().getName(), connectTimeout);
} catch (PortInUseException e) {
throw new SerialCommunicationException("Port is currently in use: " + portIdentifier.getName());
throw new SerialCommunicationException("Port is currently in use: "
+ portIdentifier.getName());
}
}
private void checkIsSerialPort(CommPortIdentifier portIdentifier) {
if (portIdentifier.getPortType() != PORT_SERIAL) {
throw new UnsupportedPortTypeException("Port type " + portIdentifier.getPortType() + " not supported - must be serial.");
throw new UnsupportedPortTypeException("Port type "
+ portIdentifier.getPortType() + " not supported - must be serial.");
}
}
private void initSerialPort(SerialPort serialPort, int baudrate, int dataBits, int stopBits, int parity) {
private void initSerialPort(SerialPort serialPort, int baudrate, int dataBits,
int stopBits, int parity) {
try {
serialPort.setFlowControlMode(FLOWCONTROL_NONE);
serialPort.setSerialPortParams(baudrate, dataBits, stopBits, parity);

View File

@ -33,7 +33,6 @@ import com.romraider.io.connection.ConnectionManager;
import com.romraider.io.connection.ConnectionProperties;
import com.romraider.logger.ecu.comms.manager.PollingState;
import com.romraider.logger.ecu.definition.Module;
import com.romraider.logger.ecu.exception.SerialCommunicationException;
public final class ElmConnectionManager implements ConnectionManager {
@ -41,56 +40,52 @@ public final class ElmConnectionManager implements ConnectionManager {
private static final Logger LOGGER = getLogger(ElmConnectionManager.class);
private final ElmConnection connection;
private final ConnectionProperties connectionProperties;
// private final ConnectionProperties connectionProperties;
private int elmMode = 0;
private final long timeout;
private long readTimeout;
//private final long timeout;
//private long readTimeout;
private ElmConnectionManager(String portName, ConnectionProperties connectionProperties) {
checkNotNullOrEmpty(portName, "portName");
checkNotNull(connectionProperties, "connectionProperties");
this.connectionProperties = connectionProperties;
timeout = connectionProperties.getConnectTimeout();
readTimeout = timeout;
// this.connectionProperties = connectionProperties;
// timeout = connectionProperties.getConnectTimeout();
// readTimeout = timeout;
connection = new ElmConnection(portName);
}
private int parseProtocolType(String protocol) {
String s = protocol.toLowerCase();
String s = protocol.toLowerCase().trim();
switch(s) {
case "automatic":
if(s.equals("automatic"))
return 0;
case "saej1850-pwm":
else if(s.equals("saej1850-pwm"))
return 1;
case "sae1850-vpw":
else if(s.equals("sae1850-vpw"))
return 2;
case "iso9141-2":
else if(s.equals("iso9141-2"))
return 3;
case "iso4230-4kwp-5":
else if(s.equals("iso4230-4kwp-5"))
return 4;
case "iso14230-4kwp-fast":
else if(s.equals("iso14230-4kwp-fast"))
return 5;
//Fallthrough, so it works with the default CAN OBD setting
case "iso15765":
case "iso15765-4can11-500":
else if(s.equals("iso15765") || s.equals("iso15765-4can11-500"))
return 6;
case "iso15765-4can29-500":
else if(s.equals("iso15765-4can29-500"))
return 7;
case "iso15765-4can11-250":
else if(s.equals("iso15765-4can11-250"))
return 8;
case "iso15765-4can29-250":
else if(s.equals("iso15765-4can29-250"))
return 9;
case "isoj1939-250":
return 10;
}
return -1;
else if(s.equals("isoj1939-250"))
return 10;
else
return -1;
}
public static ElmConnectionManager getInstance(String portName, ConnectionProperties connectionProperties) {
public static ElmConnectionManager getInstance(String portName,
ConnectionProperties connectionProperties) {
if(instance == null) {
instance = new ElmConnectionManager(portName, connectionProperties);
}
@ -141,7 +136,8 @@ public final class ElmConnectionManager implements ConnectionManager {
elmMode = parseProtocolType(transportProtcol);
if(elmMode == -1) {
LOGGER.error("Unknown ELM Protocol, check xml for available modes! Supplied mode: " + transportProtcol);
LOGGER.error("Unknown ELM Protocol, check xml for"
+ " available modes! Supplied mode: " + transportProtcol);
return false;
}
@ -298,12 +294,14 @@ public final class ElmConnectionManager implements ConnectionManager {
@Override
public void send(byte[] request, byte[] response, PollingState pollState) {
throw new java.lang.UnsupportedOperationException("Send does not work with bytes on ELM Connection");
throw new java.lang.UnsupportedOperationException("Send does not work"
+ " with bytes on ELM Connection");
}
@Override
public byte[] send(byte[] bytes) {
throw new java.lang.UnsupportedOperationException("Send does not work with bytes on ELM Connection");
throw new java.lang.UnsupportedOperationException("Send does not work"
+ " with bytes on ELM Connection");
}
}

View File

@ -22,21 +22,37 @@ package com.romraider.io.serial.port;
import gnu.io.CommPortIdentifier;
import static gnu.io.CommPortIdentifier.PORT_SERIAL;
import static gnu.io.CommPortIdentifier.getPortIdentifiers;
import static org.apache.log4j.Logger.getLogger;
import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
public final class SerialPortDiscovererImpl implements SerialPortDiscoverer {
private static final Logger LOGGER = getLogger(SerialPortDiscovererImpl.class);
@SuppressWarnings({"unchecked"})
public List<CommPortIdentifier> listPorts() {
List<CommPortIdentifier> serialPortIdentifiers = new ArrayList<CommPortIdentifier>();
Enumeration<CommPortIdentifier> portEnum = getPortIdentifiers();
while (portEnum.hasMoreElements()) {
CommPortIdentifier portIdentifier = portEnum.nextElement();
if (portIdentifier.getPortType() == PORT_SERIAL) {
serialPortIdentifiers.add(portIdentifier);
}
try {
Enumeration<CommPortIdentifier> portEnum = getPortIdentifiers();
while (portEnum.hasMoreElements()) {
CommPortIdentifier portIdentifier = portEnum.nextElement();
if (portIdentifier.getPortType() == PORT_SERIAL) {
serialPortIdentifiers.add(portIdentifier);
}
}
}
catch(NoClassDefFoundError e) {
LOGGER.error("Could not load RXTX library!");
}
catch(UnsatisfiedLinkError e) {
LOGGER.error("Could not load RXTX library!");
}
return serialPortIdentifiers;
}
}

View File

@ -53,22 +53,18 @@ public final class ELMOBDLoggerConnection implements LoggerConnection {
}
@Override
//ToDo
public void ecuReset(Module module, int resetCode) {
/*
byte[] request = protocol.constructEcuResetRequest(module, resetCode);
LOGGER.debug(String.format("%s Reset Request ---> %s", module, asHex(request)));
byte[] response = manager.send(request);
byte[] processedResponse = protocol.preprocessResponse( request, response, new PollingStateImpl());
LOGGER.debug(String.format("%s Reset Response <--- %s",module, asHex(processedResponse)));
protocol.processEcuResetResponse(processedResponse);*/
}
@Override
public void ecuInit(EcuInitCallback callback, Module module) {
String moduleStr = concatBytes(module.getAddress());
String testerStr = concatBytes(module.getTester());
boolean result = manager.resetAndInit(settings.getTransportProtocol(), moduleStr, testerStr);
boolean result = manager.resetAndInit(settings.getTransportProtocol(),
moduleStr, testerStr);
if(!result) {
throw new SerialCommunicationException("ELM327 was not found!");
@ -95,7 +91,8 @@ public final class ELMOBDLoggerConnection implements LoggerConnection {
@Override
public final void sendAddressReads(Collection<EcuQuery> queries, Module module, PollingState pollState) {
public final void sendAddressReads(Collection<EcuQuery> queries, Module module,
PollingState pollState) {
final int obdQueryListLength = queries.size();
for (int i = 0; i < obdQueryListLength; i++) {

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2014 RomRaider.com
* Copyright (C) 2006-2020 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
@ -38,14 +38,18 @@ public final class LoggerConnectionFactory {
return instantiateConnection(protocolName, manager);
}
private static LoggerConnection instantiateConnection(String protocolName, ConnectionManager manager) {
if(manager.getClass() == ElmConnectionManager.class && protocolName.equals("OBD")) {
private static LoggerConnection instantiateConnection(String protocolName,
ConnectionManager manager) {
if(manager.getClass() == ElmConnectionManager.class &&
protocolName.equals("OBD")) {
return new ELMOBDLoggerConnection((ElmConnectionManager)manager);
}
else {
try {
Class<?> cls = Class.forName(LoggerConnectionFactory.class.getPackage().getName() + "." + protocolName + "LoggerConnection");
return (LoggerConnection) cls.getConstructor(ConnectionManager.class).newInstance(manager);
Class<?> cls = Class.forName(LoggerConnectionFactory.
class.getPackage().getName() + "." + protocolName + "LoggerConnection");
return (LoggerConnection) cls.getConstructor(
ConnectionManager.class).newInstance(manager);
} catch (Exception e) {
manager.close();
throw new UnsupportedProtocolException(protocolName, e);

View File

@ -25,6 +25,11 @@ public final class Transport {
private final String id;
private final String name;
private final String description;
private int baudRateOverride = 500000;
private boolean extendedCANID = false; //11 or 29
private boolean saePWM = true; //PWM or VPW
private boolean isoKWPFast = false; //Fast or 5 Baud init
public Transport(String id, String name, String description) {
checkNotNull(name, "id");
@ -34,7 +39,7 @@ public final class Transport {
this.name = name;
this.description = description;
}
public String getId() {
return id;
}
@ -51,4 +56,74 @@ public final class Transport {
public String toString() {
return name;
}
/*
*
* These settings are used by the ELM327 Connection to define the protocol further
*
*/
public boolean isExtendedCANID() {
return extendedCANID;
}
public void setExtendedCANID(String value) {
if(value == null) return;
if(value.trim().equals("11")) this.extendedCANID = false;
else
this.extendedCANID = true;
}
public void setExtendedCANID(boolean extendedCANID) {
this.extendedCANID = extendedCANID;
}
public int getBaudRateOverride() {
return baudRateOverride;
}
public void setBaudRateOverride(String baudRateOverride) {
if(baudRateOverride == null) return;
int rate = Integer.parseInt(baudRateOverride);
this.baudRateOverride = rate;
}
public void setBaudRateOverride(int baudRateOverride) {
this.baudRateOverride = baudRateOverride;
}
public boolean isSaePWM() {
return saePWM;
}
public void setSaePWM(String saePWM) {
if(saePWM == null) return;
if(saePWM.toLowerCase().trim().equals("pwm")) this.saePWM = true;
else
this.saePWM = false;
}
public void setSaePWM(boolean saePWM) {
this.saePWM = saePWM;
}
public boolean isIsoKWPFast() {
return isoKWPFast;
}
public void setIsoKWPFast(String isoKWPFast) {
if(isoKWPFast == null )return;
if(isoKWPFast.toLowerCase().trim().equals("fast")) this.isoKWPFast = true;
else
this.isoKWPFast = false;
}
public void setIsoKWPFast(boolean isoKWPFast) {
this.isoKWPFast = isoKWPFast;
}
}

View File

@ -97,6 +97,9 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
private static final String ATTR_STORAGETYPE = "storagetype";
private static final String ATTR_ENDIAN = "endian";
private static final String ATTR_BAUD = "baud";
private static final String ATTR_CANID = "canid";
private static final String ATTR_SAE = "sae";
private static final String ATTR_KWP = "kwp";
private static final String ATTR_DATABITS = "databits";
private static final String ATTR_STOPBITS = "stopbits";
private static final String ATTR_PARITY = "parity";
@ -205,6 +208,10 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
desc = attributes.getValue(ATTR_DESC);
transport = new Transport(id, name, desc);
moduleList = new ArrayList<Module>();
transport.setBaudRateOverride(attributes.getValue(ATTR_BAUD));
transport.setExtendedCANID(attributes.getValue(ATTR_CANID));
transport.setIsoKWPFast(attributes.getValue(ATTR_KWP));
transport.setSaePWM(attributes.getValue(ATTR_SAE));
} else if (TAG_MODULE.equals(qName)) {
id = attributes.getValue(ATTR_ID);
final String modAddr = attributes.getValue(ATTR_ADDRESS);

View File

@ -43,9 +43,6 @@ import com.romraider.logger.external.core.ExternalDataSource;
import com.romraider.logger.external.innovate.generic.mts.io.MTSConnector;
import com.romraider.logger.external.innovate.generic.mts.io.MTSRunner;
import sun.misc.ExtensionInstallationException;
public final class Lm2MtsDataSource implements ExternalDataSource {
private static final Logger LOGGER = getLogger(Lm2MtsDataSource.class);
private Map<Integer, Lm2MtsDataItem> dataItems = new HashMap<Integer, Lm2MtsDataItem>();