mirror of https://github.com/rusefi/RomRaider.git
classes moved around, support added for logger config file
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@240 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
f8e3ceb40c
commit
4075687214
|
@ -2,13 +2,7 @@ package enginuity.logger;
|
|||
|
||||
import enginuity.Settings;
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.definition.EcuParameterImpl;
|
||||
import enginuity.logger.definition.convertor.AcceleratorOpeningAngleConvertor;
|
||||
import enginuity.logger.definition.convertor.AirFuelRatioLambdaConvertor;
|
||||
import enginuity.logger.definition.convertor.EngineSpeedConvertor;
|
||||
import enginuity.logger.definition.convertor.ExhaustGasTemperatureConvertor;
|
||||
import enginuity.logger.definition.convertor.GenericTemperatureConvertor;
|
||||
import enginuity.logger.definition.convertor.ThrottleOpeningAngleConvertor;
|
||||
import enginuity.logger.definition.EcuParameterLoaderImpl;
|
||||
import enginuity.logger.ui.LoggerDataTableModel;
|
||||
import enginuity.logger.ui.ParameterListTableModel;
|
||||
import enginuity.logger.ui.ParameterRegistrationBroker;
|
||||
|
@ -51,29 +45,8 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
//add to container
|
||||
getContentPane().add(splitPane);
|
||||
|
||||
// add test address to log (0x000008 = coolant temp, 8bit)
|
||||
final EcuParameter ecuParam1 = new EcuParameterImpl("Coolant Temperature", "Coolant temperature in degrees C", new String[]{"0x000008"}, new GenericTemperatureConvertor());
|
||||
paramListTableModel.addParam(ecuParam1);
|
||||
|
||||
// add test address to log (0x000106 = EGT, 8bit)
|
||||
final EcuParameter ecuParam2 = new EcuParameterImpl("EGT", "Exhaust gas temperature in degrees C", new String[]{"0x000106"}, new ExhaustGasTemperatureConvertor());
|
||||
paramListTableModel.addParam(ecuParam2);
|
||||
|
||||
// add test address to log (0x000046 = air/fuel ratio, 8bit)
|
||||
final EcuParameter ecuParam3 = new EcuParameterImpl("AFR", "Air/Fuel Ratio in Lambda", new String[]{"0x000046"}, new AirFuelRatioLambdaConvertor());
|
||||
paramListTableModel.addParam(ecuParam3);
|
||||
|
||||
// add test address to log (0x000029 = accelerator opening angle, 8bit)
|
||||
final EcuParameter ecuParam4 = new EcuParameterImpl("Accel Opening Angle", "Accelerator opening angle in %", new String[]{"0x000029"}, new AcceleratorOpeningAngleConvertor());
|
||||
paramListTableModel.addParam(ecuParam4);
|
||||
|
||||
// add test address to log (0x000015 = accelerator opening angle, 8bit)
|
||||
final EcuParameter ecuParam5 = new EcuParameterImpl("Throttle Opening Angle", "Throttle opening angle in %", new String[]{"0x000015"}, new ThrottleOpeningAngleConvertor());
|
||||
paramListTableModel.addParam(ecuParam5);
|
||||
|
||||
// add test address to log (0x00000E 0x00000F = engine speed, 16bit)
|
||||
final EcuParameter ecuParam6 = new EcuParameterImpl("Engine Speed", "Engine speed in rpm", new String[]{"0x00000E", "0x00000F"}, new EngineSpeedConvertor());
|
||||
paramListTableModel.addParam(ecuParam6);
|
||||
// load ecu params from logger config
|
||||
loadEcuParamsFromConfig();
|
||||
|
||||
}
|
||||
|
||||
|
@ -165,6 +138,18 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
return new JScrollPane(dashboardPanel, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER);
|
||||
}
|
||||
|
||||
private void loadEcuParamsFromConfig() {
|
||||
//TODO: get config file path from settings - handle errors here better too!
|
||||
try {
|
||||
List<EcuParameter> ecuParams = new EcuParameterLoaderImpl().loadFromXml("C:\\_user\\workspaces\\enginuity\\trunk\\src\\enginuity\\logger\\logger.xml");
|
||||
for (EcuParameter ecuParam : ecuParams) {
|
||||
paramListTableModel.addParam(ecuParam);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void windowOpened(WindowEvent windowEvent) {
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package enginuity.logger;
|
||||
|
||||
import enginuity.Settings;
|
||||
import enginuity.logger.comms.SerialPortDiscoverer;
|
||||
import enginuity.logger.comms.SerialPortDiscovererImpl;
|
||||
import enginuity.logger.io.serial.SerialPortDiscoverer;
|
||||
import enginuity.logger.io.serial.SerialPortDiscovererImpl;
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.manager.QueryManager;
|
||||
import enginuity.logger.manager.QueryManagerImpl;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EcuParameterLoader {
|
||||
|
||||
List<EcuParameter> loadFromXml(String loggerXmlPath);
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
import enginuity.logger.exception.ConfigurationException;
|
||||
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
||||
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import java.io.InputStream;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.List;
|
||||
|
||||
public final class EcuParameterLoaderImpl implements EcuParameterLoader {
|
||||
|
||||
public List<EcuParameter> loadFromXml(String loggerXmlPath) {
|
||||
checkNotNullOrEmpty(loggerXmlPath, "loggerXmlPath");
|
||||
try {
|
||||
InputStream inputStream = new BufferedInputStream(new FileInputStream(loggerXmlPath));
|
||||
try {
|
||||
SAXParser parser = getSaxParserFactory().newSAXParser();
|
||||
LoggerDefinitionHandler handler = new LoggerDefinitionHandler();
|
||||
parser.parse(inputStream, handler);
|
||||
return handler.getEcuParameters();
|
||||
} finally {
|
||||
inputStream.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ConfigurationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private SAXParserFactory getSaxParserFactory() {
|
||||
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
|
||||
parserFactory.setNamespaceAware(false);
|
||||
parserFactory.setValidating(false);
|
||||
parserFactory.setXIncludeAware(false);
|
||||
return parserFactory;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
import enginuity.logger.definition.convertor.EcuParameterConvertor;
|
||||
import enginuity.logger.exception.ConfigurationException;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class LoggerDefinitionHandler extends DefaultHandler {
|
||||
private static final String TAG_PARAMETER = "parameter";
|
||||
private static final String TAG_CONVERTOR = "convertor";
|
||||
private static final String TAG_BYTE = "byte";
|
||||
private static final String ATTR_ID = "id";
|
||||
private static final String ATTR_DESC = "desc";
|
||||
private List<EcuParameter> params;
|
||||
private String paramName;
|
||||
private String paramDesc;
|
||||
private List<String> addressList;
|
||||
private EcuParameterConvertor convertor;
|
||||
private StringBuilder charBuffer;
|
||||
|
||||
public void startDocument() {
|
||||
params = new ArrayList<EcuParameter>();
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||
if (TAG_PARAMETER.equals(qName)) {
|
||||
paramName = attributes.getValue(ATTR_ID);
|
||||
paramDesc = attributes.getValue(ATTR_DESC);
|
||||
addressList = new ArrayList<String>();
|
||||
}
|
||||
charBuffer = new StringBuilder();
|
||||
}
|
||||
|
||||
public void characters(char[] ch, int start, int length) {
|
||||
charBuffer.append(ch, start, length);
|
||||
}
|
||||
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
if (TAG_BYTE.equals(qName)) {
|
||||
addressList.add(charBuffer.toString());
|
||||
} else if (TAG_CONVERTOR.equals(qName)) {
|
||||
try {
|
||||
convertor = (EcuParameterConvertor) Class.forName(charBuffer.toString().trim()).newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new ConfigurationException(e);
|
||||
}
|
||||
} else if (TAG_PARAMETER.equals(qName)) {
|
||||
String[] addresses = new String[addressList.size()];
|
||||
addressList.toArray(addresses);
|
||||
EcuParameter param = new EcuParameterImpl(paramName, paramDesc, addresses, convertor);
|
||||
params.add(param);
|
||||
}
|
||||
}
|
||||
|
||||
public List<EcuParameter> getEcuParameters() {
|
||||
return params;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package enginuity.logger.exception;
|
||||
|
||||
public final class ConfigurationException extends RuntimeException {
|
||||
|
||||
public ConfigurationException() {
|
||||
}
|
||||
|
||||
public ConfigurationException(String string) {
|
||||
super(string);
|
||||
}
|
||||
|
||||
public ConfigurationException(String string, Throwable throwable) {
|
||||
super(string, throwable);
|
||||
}
|
||||
|
||||
public ConfigurationException(Throwable throwable) {
|
||||
super(throwable);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package enginuity.logger.protocol;
|
||||
package enginuity.logger.exception;
|
||||
|
||||
public final class InvalidResponseException extends RuntimeException {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package enginuity.logger.comms;
|
||||
package enginuity.logger.io.serial;
|
||||
|
||||
import enginuity.logger.query.RegisteredQuery;
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
package enginuity.logger.comms;
|
||||
package enginuity.logger.io.serial;
|
||||
|
||||
import enginuity.logger.exception.NotConnectedException;
|
||||
import enginuity.logger.exception.PortNotFoundException;
|
||||
import enginuity.logger.exception.SerialCommunicationException;
|
||||
import enginuity.logger.exception.UnsupportedPortTypeException;
|
||||
import enginuity.logger.protocol.ConnectionProperties;
|
||||
import enginuity.logger.protocol.Protocol;
|
||||
import enginuity.logger.io.serial.protocol.ConnectionProperties;
|
||||
import enginuity.logger.io.serial.protocol.Protocol;
|
||||
import enginuity.logger.query.RegisteredQuery;
|
||||
import enginuity.logger.io.serial.SerialConnection;
|
||||
import static enginuity.util.HexUtil.asHex;
|
||||
import static enginuity.util.ParamChecker.checkGreaterThanZero;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
|
@ -1,4 +1,4 @@
|
|||
package enginuity.logger.comms;
|
||||
package enginuity.logger.io.serial;
|
||||
|
||||
import gnu.io.CommPortIdentifier;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package enginuity.logger.comms;
|
||||
package enginuity.logger.io.serial;
|
||||
|
||||
import gnu.io.CommPortIdentifier;
|
||||
import static gnu.io.CommPortIdentifier.PORT_SERIAL;
|
||||
|
@ -8,6 +8,8 @@ import java.util.ArrayList;
|
|||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import enginuity.logger.io.serial.SerialPortDiscoverer;
|
||||
|
||||
public final class SerialPortDiscovererImpl implements SerialPortDiscoverer {
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
|
@ -1,4 +1,4 @@
|
|||
package enginuity.logger.protocol;
|
||||
package enginuity.logger.io.serial.protocol;
|
||||
|
||||
public interface ConnectionProperties {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package enginuity.logger.protocol;
|
||||
package enginuity.logger.io.serial.protocol;
|
||||
|
||||
import enginuity.logger.query.RegisteredQuery;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package enginuity.logger.protocol;
|
||||
package enginuity.logger.io.serial.protocol;
|
||||
|
||||
import enginuity.logger.exception.UnsupportedProtocolException;
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package enginuity.logger.protocol;
|
||||
package enginuity.logger.io.serial.protocol;
|
||||
|
||||
import enginuity.logger.query.RegisteredQuery;
|
||||
import enginuity.logger.exception.InvalidResponseException;
|
||||
import static enginuity.util.ByteUtil.asByte;
|
||||
import static enginuity.util.ByteUtil.asInt;
|
||||
import static enginuity.util.HexUtil.asHex;
|
||||
|
@ -21,9 +22,9 @@ public final class SSMProtocol implements Protocol {
|
|||
private static final byte READ_ADDRESS_RESPONSE = (byte) 0xE8;
|
||||
private static final byte ECU_INIT_COMMAND = (byte) 0xBF;
|
||||
private static final byte ECU_INIT_RESPONSE = (byte) 0xFF;
|
||||
private static final int RESPONSE_NON_DATA_BYTES = 6;
|
||||
private static final int ADDRESS_SIZE = 3;
|
||||
private static final int DATA_SIZE = 1;
|
||||
private static final int RESPONSE_NON_DATA_BYTES = 6;
|
||||
private static final int REQUEST_NON_DATA_BYTES = 7;
|
||||
|
||||
public byte[] constructReadMemoryRequest(RegisteredQuery query, int numBytes) {
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<logger>
|
||||
<protocols>
|
||||
<protocol id="SSM">
|
||||
<parameters>
|
||||
<parameter id="Coolant Temperature" desc="Engine coolant temperature reading.">
|
||||
<address>
|
||||
<byte>0x000008</byte>
|
||||
</address>
|
||||
<convertor>enginuity.logger.definition.convertor.GenericTemperatureConvertor</convertor>
|
||||
</parameter>
|
||||
<parameter id="Engine Speed" desc="Engine speed in Revolutions Per Minute.">
|
||||
<address>
|
||||
<byte>0x00000E</byte>
|
||||
<byte>0x00000F</byte>
|
||||
</address>
|
||||
<convertor>enginuity.logger.definition.convertor.EngineSpeedConvertor</convertor>
|
||||
</parameter>
|
||||
<parameter id="Throttle Opening Angle" desc="Engine throttle opening angle.">
|
||||
<address>
|
||||
<byte>0x000015</byte>
|
||||
</address>
|
||||
<convertor>enginuity.logger.definition.convertor.ThrottleOpeningAngleConvertor</convertor>
|
||||
</parameter>
|
||||
<parameter id="Accelerator Opening Angle" desc="Accelerator pedal opening angle.">
|
||||
<address>
|
||||
<byte>0x000029</byte>
|
||||
</address>
|
||||
<convertor>enginuity.logger.definition.convertor.AcceleratorOpeningAngleConvertor</convertor>
|
||||
</parameter>
|
||||
<parameter id="EGT" desc="Exhaust gas temperature reading.">
|
||||
<address>
|
||||
<byte>0x000106</byte>
|
||||
</address>
|
||||
<convertor>enginuity.logger.definition.convertor.ExhaustGasTemperatureConvertor</convertor>
|
||||
</parameter>
|
||||
|
||||
<!-- More to come!! -->
|
||||
|
||||
</parameters>
|
||||
</protocol>
|
||||
</protocols>
|
||||
</logger>
|
|
@ -1,12 +1,12 @@
|
|||
package enginuity.logger.manager;
|
||||
|
||||
import enginuity.Settings;
|
||||
import enginuity.logger.comms.SerialConnection;
|
||||
import enginuity.logger.comms.SerialConnectionImpl;
|
||||
import enginuity.logger.io.serial.SerialConnection;
|
||||
import enginuity.logger.io.serial.SerialConnectionImpl;
|
||||
import enginuity.logger.exception.NotConnectedException;
|
||||
import enginuity.logger.exception.SerialCommunicationException;
|
||||
import enginuity.logger.protocol.Protocol;
|
||||
import enginuity.logger.protocol.ProtocolFactory;
|
||||
import enginuity.logger.io.serial.protocol.Protocol;
|
||||
import enginuity.logger.io.serial.protocol.ProtocolFactory;
|
||||
import enginuity.logger.query.LoggerCallback;
|
||||
import enginuity.logger.query.RegisteredQuery;
|
||||
import enginuity.util.HexUtil;
|
||||
|
|
Loading…
Reference in New Issue