incomplete addition of ecu specific parameters to logger based on ecu id (IAM, Engine Load)

git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@396 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
kascade 2007-01-02 11:49:45 +00:00
parent 6e74e03d1f
commit 03434c9146
7 changed files with 137 additions and 29 deletions

View File

@ -2,10 +2,14 @@
<!ELEMENT byte ( #PCDATA ) >
<!ELEMENT address ( byte+ ) >
<!ELEMENT ecu ( byte+ ) >
<!ATTLIST ecu id CDATA #REQUIRED >
<!ELEMENT address ( ecu+ | byte+ ) >
<!ELEMENT ref EMPTY >
<!ATTLIST ref id IDREF #REQUIRED >
<!ATTLIST ref ecuparam CDATA #IMPLIED >
<!ATTLIST ref parameter IDREF #IMPLIED >
<!ELEMENT depends ( ref+ ) >
@ -33,7 +37,14 @@
<!ELEMENT switches ( switch+ ) >
<!ELEMENT protocol ( parameters*, switches* ) >
<!ELEMENT ecuparam ( address, conversions ) >
<!ATTLIST ecuparam desc CDATA #REQUIRED >
<!ATTLIST ecuparam name CDATA #REQUIRED >
<!ATTLIST ecuparam id ID #REQUIRED >
<!ELEMENT ecuparams ( ecuparam+ ) >
<!ELEMENT protocol ( parameters?, switches?, ecuparams? ) >
<!ATTLIST protocol id ID #REQUIRED >
<!ELEMENT protocols ( protocol+ ) >

View File

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE logger SYSTEM "logger.dtd">
<logger>
<protocols>
<protocol id="SSM">
<parameters>
<parameter id="P1" name="Engine Load" desc="">
@ -818,7 +819,7 @@
</parameter>
<!-- JDM STI specific - START -->
<parameter id="P89" name="Ign. Corr. AK (Neg. Knock Comp.)" desc="Removes Ignition timing when pinging and knocking occurs.">
<parameter id="P150" name="Ign. Corr. AK (Neg. Knock Comp.)" desc="Removes Ignition timing when pinging and knocking occurs.">
<address>
<byte>0x020C60</byte>
</address>
@ -827,7 +828,7 @@
</conversions>
</parameter>
<parameter id="P90" name="Ign. Corr. AT (Coarse Correc.)" desc="Ignition Correction table variables, affected by the IAM and AK.">
<parameter id="P151" name="Ign. Corr. AT (Coarse Correc.)" desc="Ignition Correction table variables, affected by the IAM and AK.">
<address>
<byte>0x020C61</byte>
</address>
@ -836,7 +837,8 @@
</conversions>
</parameter>
<parameter id="P91" name="Ign. Corr. AP (Learnt Correc.)" desc="Ignition learnt over a period of time. The ECU adds a bit to the knock correction if the car is working well with already high ignition correction values.">
<parameter id="P152" name="Ign. Corr. AP (Learnt Correc.)"
desc="Ignition learnt over a period of time. The ECU adds a bit to the knock correction if the car is working well with already high ignition correction values.">
<address>
<byte>0x020C65</byte>
</address>
@ -852,8 +854,8 @@
<parameter id="P200" name="Engine Load (Calculated)" desc="Engine load as calculated from MAF and RPM.">
<depends>
<ref id="P8"/>
<ref id="P12"/>
<ref parameter="P8"/>
<ref parameter="P12"/>
</depends>
<conversions>
<conversion units="2*grams/rev" expr="(P12*60)/P8*2" format="0.00"/>
@ -864,18 +866,19 @@
<parameter id="P201" name="Injector Duty Cycle" desc="">
<depends>
<ref id="P8"/>
<ref id="P21"/>
<ref parameter="P8"/>
<ref parameter="P21"/>
</depends>
<conversions>
<conversion units="%" expr="(P8*P21)/1200" format="0.00"/>
</conversions>
</parameter>
<parameter id="P202" name="Manifold Relative Pressure (Corrected)" desc="Difference between Manifold Absolute Pressure and Atmospheric Pressure.">
<parameter id="P202" name="Manifold Relative Pressure (Corrected)"
desc="Difference between Manifold Absolute Pressure and Atmospheric Pressure.">
<depends>
<ref id="P7"/>
<ref id="P24"/>
<ref parameter="P7"/>
<ref parameter="P24"/>
</depends>
<conversions>
<conversion units="psi" expr="[P7:psi]-[P24:psi]" format="0.00"/>
@ -885,6 +888,7 @@
</parameters>
<switches>
<switch id="S1" name="AT Vehicle ID" desc="" byte="0x000061" bit="6"/>
@ -957,6 +961,57 @@
<switch id="S68" name="Accelerator Switch" desc="" byte="0x000121" bit="1"/>
</switches>
<ecuparams>
<ecuparam id="E1" name="IAM" desc="Ignition Advance Multiplier">
<address>
<ecu id="3152584006">
<byte>0xFFFFFF</byte>
</ecu>
<ecu id="3152584007,3152584008">
<byte>0xEEEEEE</byte>
</ecu>
</address>
<conversions>
<conversion units="IAM" expr="x" format="0"/>
</conversions>
</ecuparam>
<ecuparam id="E2" name="Engine Load (16bit)" desc="Engine Load (16bit)">
<address>
<ecu id="1234567890,0123654789">
<byte>0xFFFFFF</byte>
</ecu>
</address>
<conversions>
<conversion units="grams" expr="x/32" format="0.00"/>
</conversions>
</ecuparam>
<ecuparam id="E3" name="Engine Load (32bit)" desc="Engine Load (32bit)">
<address>
<ecu id="3152584006">
<byte>0xFFFFFE</byte>
<byte>0xFFFFFF</byte>
</ecu>
<ecu id="3152584007">
<byte>0xFFFFFE</byte>
<byte>0xFFFFFF</byte>
</ecu>
<ecu id="3152584008,3152584009">
<byte>0xFFFFFE</byte>
<byte>0xFFFFFF</byte>
</ecu>
</address>
<conversions>
<conversion units="grams" expr="x/256" format="0.00"/>
</conversions>
</ecuparam>
</ecuparams>
</protocol>
</protocols>
</logger>

View File

@ -95,8 +95,9 @@ TODO: Clean up this class!
So much to do, so little time....
Autoconnect Stuff:
TODO: Add reconnect/refresh connection button/menu item.
TODO: Finish ecu init callback - parse it, etc
TODO: Finish ecu init callback
TODO: Add extra ecu init parsing & only display parameters supported by ecu, or all if unknown ecu.
TODO: Finish ecu specific parameters (IAM, Engine Load)
*/
public final class EcuLogger extends JFrame implements WindowListener, PropertyChangeListener, MessageListener {
@ -104,6 +105,7 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
private static final String HEADING_PARAMETERS = "Parameters";
private static final String HEADING_SWITCHES = "Switches";
private Settings settings;
private String ecuId;
private LoggerController controller;
private JLabel statusBarLabel;
private JTabbedPane tabbedPane;
@ -146,7 +148,8 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
// TODO: Do something useful with this!!
EcuInitCallback ecuInitCallback = new EcuInitCallback() {
public void callback(EcuInit ecuInit) {
System.out.println("ECU ID = " + ecuInit.getEcuId());
ecuId = ecuInit.getEcuId();
System.out.println("ECU ID = " + ecuId);
}
};
@ -204,7 +207,7 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
public void reloadUserProfile(String profileFilePath) {
try {
EcuDataLoader dataLoader = new EcuDataLoaderImpl();
dataLoader.loadFromXml(settings.getLoggerConfigFilePath(), settings.getLoggerProtocol());
dataLoader.loadFromXml(settings.getLoggerConfigFilePath(), settings.getLoggerProtocol(), ecuId);
loadUserProfile(dataLoader, profileFilePath);
File profileFile = new File(profileFilePath);
if (profileFile.exists()) {

View File

@ -25,7 +25,7 @@ import java.util.List;
public interface EcuDataLoader {
void loadFromXml(String loggerConfigFilePath, String protocol);
void loadFromXml(String loggerConfigFilePath, String protocol, String ecuId);
List<EcuParameter> getEcuParameters();

View File

@ -37,12 +37,13 @@ public final class EcuDataLoaderImpl implements EcuDataLoader {
private List<EcuParameter> ecuParameters = new ArrayList<EcuParameter>();
private List<EcuSwitch> ecuSwitches = new ArrayList<EcuSwitch>();
public void loadFromXml(String loggerConfigFilePath, String protocol) {
public void loadFromXml(String loggerConfigFilePath, String protocol, String ecuId) {
checkNotNullOrEmpty(loggerConfigFilePath, "loggerConfigFilePath");
checkNotNullOrEmpty(protocol, "protocol");
try {
InputStream inputStream = new BufferedInputStream(new FileInputStream(new File(loggerConfigFilePath)));
try {
LoggerDefinitionHandler handler = new LoggerDefinitionHandler(protocol);
LoggerDefinitionHandler handler = new LoggerDefinitionHandler(protocol, ecuId);
getSaxParser().parse(inputStream, handler);
ecuParameters = handler.getEcuParameters();
ecuSwitches = handler.getEcuSwitches();

View File

@ -55,6 +55,8 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
private static final String TAG_BYTE = "byte";
private static final String TAG_REF = "ref";
private static final String TAG_SWITCH = "switch";
private static final String TAG_ECUPARAM = "ecuparam";
private static final String TAG_ECU = "ecu";
private static final String ATTR_ID = "id";
private static final String ATTR_NAME = "name";
private static final String ATTR_DESC = "desc";
@ -63,27 +65,32 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
private static final String ATTR_FORMAT = "format";
private static final String ATTR_BYTE = "byte";
private static final String ATTR_BIT = "bit";
private static final String ATTR_PARAMETER = "parameter";
private static final String ATTR_FILELOGCONTROLLER = "filelogcontroller";
private final String protocol;
private final String ecuId;
private List<EcuParameter> params;
private List<EcuSwitch> switches;
private Map<String, EcuData> ecuDataMap;
private String id;
private String name;
private String desc;
private String ecuIds;
private Set<String> addressList;
private Set<String> dependsList;
private Map<String, String[]> ecuAddressMap;
private boolean derived;
private int bit;
private boolean fileLogController;
private Set<EcuDataConvertor> convertorList;
private Set<EcuDerivedParameterConvertor> derivedConvertorList;
private StringBuilder charBuffer;
private String protocol;
private boolean parseProtocol;
public LoggerDefinitionHandler(String protocol) {
public LoggerDefinitionHandler(String protocol, String ecuId) {
checkNotNullOrEmpty(protocol, "protocol");
this.protocol = protocol;
this.ecuId = ecuId;
}
public void startDocument() {
@ -102,12 +109,13 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
desc = attributes.getValue(ATTR_DESC);
} else if (TAG_ADDRESS.equals(qName)) {
addressList = new LinkedHashSet<String>();
ecuAddressMap = new HashMap<String, String[]>();
derived = false;
} else if (TAG_DEPENDS.equals(qName)) {
dependsList = new LinkedHashSet<String>();
derived = true;
} else if (TAG_REF.equals(qName)) {
dependsList.add(attributes.getValue(ATTR_ID));
dependsList.add(attributes.getValue(ATTR_PARAMETER));
} else if (TAG_CONVERSIONS.equals(qName)) {
convertorList = new LinkedHashSet<EcuDataConvertor>();
derivedConvertorList = new LinkedHashSet<EcuDerivedParameterConvertor>();
@ -127,6 +135,13 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
addressList.add(attributes.getValue(ATTR_BYTE));
bit = Integer.valueOf(attributes.getValue(ATTR_BIT));
fileLogController = YES.equals(attributes.getValue(ATTR_FILELOGCONTROLLER));
} else if (TAG_ECUPARAM.equals(qName)) {
id = attributes.getValue(ATTR_ID);
name = attributes.getValue(ATTR_NAME);
desc = attributes.getValue(ATTR_DESC);
} else if (TAG_ECU.equals(qName)) {
ecuIds = attributes.getValue(ATTR_ID);
addressList = new LinkedHashSet<String>();
}
}
charBuffer = new StringBuilder();
@ -154,18 +169,26 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
param = new EcuDerivedParameterImpl(id, name, desc, dependencies.toArray(new EcuData[dependencies.size()]),
derivedConvertorList.toArray(new EcuDerivedParameterConvertor[derivedConvertorList.size()]));
} else {
String[] addresses = new String[addressList.size()];
addressList.toArray(addresses);
String[] addresses = toArray(addressList);
param = new EcuParameterImpl(id, name, desc, addresses, convertorList.toArray(new EcuDataConvertor[convertorList.size()]));
}
params.add(param);
ecuDataMap.put(param.getId(), param);
} else if (TAG_SWITCH.equals(qName)) {
String[] addresses = new String[addressList.size()];
addressList.toArray(addresses);
EcuSwitch ecuSwitch = new EcuSwitchImpl(id, name, desc, addresses, new EcuDataConvertor[]{new EcuSwitchConvertorImpl(bit)}, fileLogController);
EcuSwitch ecuSwitch = new EcuSwitchImpl(id, name, desc, toArray(addressList), new EcuDataConvertor[]{new EcuSwitchConvertorImpl(bit)}, fileLogController);
switches.add(ecuSwitch);
ecuDataMap.put(ecuSwitch.getId(), ecuSwitch);
} else if (TAG_ECUPARAM.equals(qName)) {
if (ecuId != null && ecuAddressMap.containsKey(ecuId)) {
EcuParameter param = new EcuParameterImpl(id, name, desc, ecuAddressMap.get(ecuId), convertorList.toArray(new EcuDataConvertor[convertorList.size()]));
params.add(param);
ecuDataMap.put(param.getId(), param);
}
} else if (TAG_ECU.equals(qName)) {
String[] addresses = toArray(addressList);
for (String ecuId : ecuIds.split(",")) {
ecuAddressMap.put(ecuId, addresses);
}
}
}
}
@ -177,4 +200,11 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
public List<EcuSwitch> getEcuSwitches() {
return switches;
}
private String[] toArray(Set<String> set) {
String[] addresses = new String[set.size()];
set.toArray(addresses);
return addresses;
}
}

View File

@ -22,6 +22,7 @@
package enginuity.util;
import java.util.Collection;
import java.util.Map;
public final class ParamChecker {
@ -58,6 +59,12 @@ public final class ParamChecker {
}
}
public static void checkNotNullOrEmpty(Map<?, ?> param, String paramName) {
if (param == null || param.isEmpty()) {
throw new IllegalArgumentException("Parameter " + paramName + " must not be null or empty");
}
}
public static void checkGreaterThanZero(int param, String paramName) {
if (param <= 0) {
throw new IllegalArgumentException("Parameter " + paramName + " must be > 0");
@ -73,4 +80,5 @@ public final class ParamChecker {
public static boolean isNullOrEmpty(String param) {
return param == null || param.length() == 0;
}
}