mirror of https://github.com/rusefi/RomRaider.git
updated logger xml parsing - broken atm
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@610 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
b31f143e8f
commit
7f80a5741c
|
@ -2,6 +2,7 @@
|
|||
|
||||
<!ELEMENT address ( #PCDATA ) >
|
||||
<!ATTLIST address length CDATA #IMPLIED >
|
||||
<!ATTLIST address bit ( 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 ) #IMPLIED >
|
||||
|
||||
<!ELEMENT ecu ( address+ ) >
|
||||
<!ATTLIST ecu id CDATA #REQUIRED >
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
package enginuity.logger.ecu.comms.query;
|
||||
|
||||
import enginuity.logger.ecu.definition.EcuData;
|
||||
import static enginuity.util.HexUtil.asBytes;
|
||||
import static enginuity.util.HexUtil.asHex;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
|
||||
|
@ -36,12 +35,12 @@ public final class EcuQueryImpl implements EcuQuery {
|
|||
checkNotNull(ecuData, callback);
|
||||
this.ecuData = ecuData;
|
||||
this.callback = callback;
|
||||
bytes = getAddressBytes(ecuData);
|
||||
bytes = ecuData.getAddress().getBytes();
|
||||
hex = asHex(bytes);
|
||||
}
|
||||
|
||||
public String[] getAddresses() {
|
||||
return ecuData.getAddresses();
|
||||
return ecuData.getAddress().getAddresses();
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
|
@ -67,17 +66,4 @@ public final class EcuQueryImpl implements EcuQuery {
|
|||
public String toString() {
|
||||
return "0x" + getHex();
|
||||
}
|
||||
|
||||
private byte[] getAddressBytes(EcuData ecuData) {
|
||||
String[] addresses = ecuData.getAddresses();
|
||||
byte[] bytes = new byte[0];
|
||||
for (String address : addresses) {
|
||||
byte[] tmp1 = asBytes(address);
|
||||
byte[] tmp2 = new byte[bytes.length + tmp1.length];
|
||||
System.arraycopy(bytes, 0, tmp2, 0, bytes.length);
|
||||
System.arraycopy(tmp1, 0, tmp2, bytes.length, tmp1.length);
|
||||
bytes = tmp2;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package enginuity.logger.ecu.definition;
|
||||
|
||||
public interface EcuAddress {
|
||||
|
||||
String[] getAddresses();
|
||||
|
||||
byte[] getBytes();
|
||||
|
||||
int getBit();
|
||||
|
||||
int getLength();
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package enginuity.logger.ecu.definition;
|
||||
|
||||
import static enginuity.util.HexUtil.asBytes;
|
||||
import static enginuity.util.HexUtil.hexToInt;
|
||||
import static enginuity.util.HexUtil.intToHexString;
|
||||
import static enginuity.util.ParamChecker.checkGreaterThanZero;
|
||||
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public final class EcuAddressImpl implements EcuAddress {
|
||||
private final String[] addresses;
|
||||
private final byte[] bytes;
|
||||
private final int bit;
|
||||
|
||||
|
||||
public EcuAddressImpl(String address, int length, int bit) {
|
||||
checkNotNullOrEmpty(address, "address");
|
||||
checkGreaterThanZero(length, "length");
|
||||
this.addresses = buildAddresses(address, length);
|
||||
this.bytes = getAddressBytes(addresses);
|
||||
this.bit = bit;
|
||||
}
|
||||
|
||||
public EcuAddressImpl(String[] addresses) {
|
||||
checkNotNullOrEmpty(addresses, "addresses");
|
||||
this.addresses = addresses;
|
||||
this.bytes = getAddressBytes(addresses);
|
||||
this.bit = -1;
|
||||
}
|
||||
|
||||
public String[] getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public int getBit() {
|
||||
return bit;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return addresses.length;
|
||||
}
|
||||
|
||||
private String[] buildAddresses(String startAddress, int addressLength) {
|
||||
List<String> addresses = new LinkedList<String>();
|
||||
int start = hexToInt(startAddress);
|
||||
for (int i = 0; i < addressLength; i++) {
|
||||
addresses.add(padAddress(intToHexString(start + i), startAddress.length()));
|
||||
}
|
||||
// System.out.println(startAddress + ":" + addressLength + " => " + addresses);
|
||||
return addresses.toArray(new String[addresses.size()]);
|
||||
}
|
||||
|
||||
private String padAddress(String address, int length) {
|
||||
if (address.length() == length) {
|
||||
return address;
|
||||
} else {
|
||||
StringBuilder builder = new StringBuilder(length);
|
||||
builder.append("0x");
|
||||
String s = address.substring(2);
|
||||
for (int i = 0; i < length - s.length() - 2; i++) {
|
||||
builder.append('0');
|
||||
}
|
||||
builder.append(s);
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] getAddressBytes(String[] addresses) {
|
||||
byte[] bytes = new byte[0];
|
||||
for (String address : addresses) {
|
||||
byte[] tmp1 = asBytes(address);
|
||||
byte[] tmp2 = new byte[bytes.length + tmp1.length];
|
||||
System.arraycopy(bytes, 0, tmp2, 0, bytes.length);
|
||||
System.arraycopy(tmp1, 0, tmp2, bytes.length, tmp1.length);
|
||||
bytes = tmp2;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
}
|
|
@ -23,6 +23,6 @@ package enginuity.logger.ecu.definition;
|
|||
|
||||
public interface EcuData extends LoggerData {
|
||||
|
||||
String[] getAddresses();
|
||||
EcuAddress getAddress();
|
||||
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public final class EcuDerivedParameterConvertorImpl implements EcuDerivedParamet
|
|||
String exp = expression;
|
||||
int index = 0;
|
||||
for (EcuData ecuData : ecuDatas) {
|
||||
int length = ecuData.getAddresses().length;
|
||||
int length = ecuData.getAddress().getLength();
|
||||
byte[] tmp = new byte[length];
|
||||
System.arraycopy(bytes, index, tmp, 0, length);
|
||||
ExpressionInfo expressionInfo = expressionInfoMap.get(ecuData.getId());
|
||||
|
|
|
@ -33,7 +33,7 @@ public final class EcuDerivedParameterImpl implements EcuParameter {
|
|||
private final String name;
|
||||
private final String description;
|
||||
private final EcuDerivedParameterConvertor[] convertors;
|
||||
private final String[] addresses;
|
||||
private final EcuAddress address;
|
||||
private final Set<ConvertorUpdateListener> listeners = new HashSet<ConvertorUpdateListener>();
|
||||
private int selectedConvertorIndex = 0;
|
||||
|
||||
|
@ -47,7 +47,7 @@ public final class EcuDerivedParameterImpl implements EcuParameter {
|
|||
this.name = name;
|
||||
this.description = description;
|
||||
this.convertors = convertors;
|
||||
addresses = setAddresses(ecuDatas);
|
||||
this.address = buildCombinedAddress(ecuDatas);
|
||||
setEcuDatas(ecuDatas);
|
||||
}
|
||||
|
||||
|
@ -63,8 +63,8 @@ public final class EcuDerivedParameterImpl implements EcuParameter {
|
|||
return description;
|
||||
}
|
||||
|
||||
public String[] getAddresses() {
|
||||
return addresses;
|
||||
public EcuAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public EcuDataConvertor getSelectedConvertor() {
|
||||
|
@ -96,16 +96,16 @@ public final class EcuDerivedParameterImpl implements EcuParameter {
|
|||
listeners.add(listener);
|
||||
}
|
||||
|
||||
private String[] setAddresses(EcuData[] ecuDatas) {
|
||||
private EcuAddress buildCombinedAddress(EcuData[] ecuDatas) {
|
||||
String[] addresses = new String[0];
|
||||
for (EcuData ecuData : ecuDatas) {
|
||||
String[] newAddresses = ecuData.getAddresses();
|
||||
String[] newAddresses = ecuData.getAddress().getAddresses();
|
||||
String[] tmp = new String[addresses.length + newAddresses.length];
|
||||
System.arraycopy(addresses, 0, tmp, 0, addresses.length);
|
||||
System.arraycopy(newAddresses, 0, tmp, addresses.length, newAddresses.length);
|
||||
addresses = tmp;
|
||||
}
|
||||
return addresses;
|
||||
return new EcuAddressImpl(addresses);
|
||||
}
|
||||
|
||||
private void setEcuDatas(EcuData[] ecuDatas) {
|
||||
|
|
|
@ -32,21 +32,21 @@ public final class EcuParameterImpl implements EcuParameter {
|
|||
private final String id;
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final String[] addresses;
|
||||
private final EcuAddress address;
|
||||
private final EcuDataConvertor[] convertors;
|
||||
private final Set<ConvertorUpdateListener> listeners = new HashSet<ConvertorUpdateListener>();
|
||||
private int selectedConvertorIndex = 0;
|
||||
|
||||
public EcuParameterImpl(String id, String name, String description, String[] address, EcuDataConvertor[] convertors) {
|
||||
public EcuParameterImpl(String id, String name, String description, EcuAddress address, EcuDataConvertor[] convertors) {
|
||||
checkNotNullOrEmpty(name, "id");
|
||||
checkNotNullOrEmpty(name, "name");
|
||||
checkNotNull(description, "description");
|
||||
checkNotNullOrEmpty(address, "addresses");
|
||||
checkNotNull(address, "address");
|
||||
checkNotNullOrEmpty(convertors, "convertors");
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.addresses = address;
|
||||
this.address = address;
|
||||
this.convertors = convertors;
|
||||
}
|
||||
|
||||
|
@ -62,8 +62,8 @@ public final class EcuParameterImpl implements EcuParameter {
|
|||
return description;
|
||||
}
|
||||
|
||||
public String[] getAddresses() {
|
||||
return addresses;
|
||||
public EcuAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public EcuDataConvertor getSelectedConvertor() {
|
||||
|
@ -100,5 +100,4 @@ public final class EcuParameterImpl implements EcuParameter {
|
|||
listener.notifyConvertorUpdate(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,21 +29,21 @@ public final class EcuSwitchImpl implements EcuSwitch {
|
|||
private final String id;
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final String[] addresses;
|
||||
private final EcuAddress address;
|
||||
private final EcuDataConvertor[] convertors;
|
||||
private int selectedConvertorIndex = 0;
|
||||
private boolean fileLogController;
|
||||
|
||||
public EcuSwitchImpl(String id, String name, String description, String[] address, EcuDataConvertor[] convertors) {
|
||||
public EcuSwitchImpl(String id, String name, String description, EcuAddress address, EcuDataConvertor[] convertors) {
|
||||
checkNotNullOrEmpty(id, "id");
|
||||
checkNotNullOrEmpty(name, "name");
|
||||
checkNotNull(description, "description");
|
||||
checkNotNullOrEmpty(address, "addresses");
|
||||
checkNotNull(address, "address");
|
||||
checkNotNullOrEmpty(convertors, "convertors");
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.addresses = address;
|
||||
this.address = address;
|
||||
this.convertors = convertors;
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,8 @@ public final class EcuSwitchImpl implements EcuSwitch {
|
|||
return description;
|
||||
}
|
||||
|
||||
public String[] getAddresses() {
|
||||
return addresses;
|
||||
public EcuAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public EcuDataConvertor getSelectedConvertor() {
|
||||
|
|
|
@ -31,11 +31,7 @@ import enginuity.logger.ecu.definition.EcuDerivedParameterConvertorImpl;
|
|||
import enginuity.logger.ecu.definition.EcuDerivedParameterImpl;
|
||||
import enginuity.logger.ecu.definition.EcuParameter;
|
||||
import enginuity.logger.ecu.definition.EcuParameterConvertorImpl;
|
||||
import enginuity.logger.ecu.definition.EcuParameterImpl;
|
||||
import enginuity.logger.ecu.definition.EcuSwitch;
|
||||
import enginuity.logger.ecu.definition.EcuSwitchConvertorImpl;
|
||||
import enginuity.logger.ecu.definition.EcuSwitchImpl;
|
||||
import enginuity.util.HexUtil;
|
||||
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
@ -44,7 +40,6 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -138,6 +133,8 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
|
|||
} else if (TAG_ADDRESS.equals(qName)) {
|
||||
String length = attributes.getValue(ATTR_LENGTH);
|
||||
addressLength = length == null ? 1 : Integer.valueOf(length);
|
||||
String bitx = attributes.getValue(ATTR_BIT);
|
||||
bit = bitx == null ? -1 : Integer.valueOf(bitx);
|
||||
addressList = new LinkedHashSet<String>(addressLength);
|
||||
derived = false;
|
||||
} else if (TAG_DEPENDS.equals(qName)) {
|
||||
|
@ -183,14 +180,14 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
|
|||
charBuffer.append(ch, start, length);
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME: Fix all the commented out stuff!!!
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
if (TAG_PROTOCOL.equals(qName)) {
|
||||
parseProtocol = false;
|
||||
} else if (parseProtocol) {
|
||||
if (TAG_ADDRESS.equals(qName)) {
|
||||
String startAddress = charBuffer.toString();
|
||||
addressList.addAll(getAddressList(startAddress, addressLength));
|
||||
// addressList.addAll(getAddressList(startAddress, addressLength));
|
||||
} else if (TAG_PARAMETER.equals(qName)) {
|
||||
if (derived) {
|
||||
Set<EcuData> dependencies = new HashSet<EcuData>();
|
||||
|
@ -210,27 +207,27 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
|
|||
} else {
|
||||
if (ecuByteIndex == null || ecuBit == null || ecuInit == null || isSupportedParameter(ecuInit,
|
||||
ecuByteIndex, ecuBit)) {
|
||||
EcuParameter param = new EcuParameterImpl(id, name, desc, toArray(addressList),
|
||||
convertorList.toArray(new EcuDataConvertor[convertorList.size()]));
|
||||
params.add(param);
|
||||
ecuDataMap.put(param.getId(), param);
|
||||
// EcuParameter param = new EcuParameterImpl(id, name, desc, toArray(addressList),
|
||||
// convertorList.toArray(new EcuDataConvertor[convertorList.size()]));
|
||||
// params.add(param);
|
||||
// ecuDataMap.put(param.getId(), param);
|
||||
}
|
||||
}
|
||||
} else if (TAG_SWITCH.equals(qName)) {
|
||||
EcuSwitch ecuSwitch = new EcuSwitchImpl(id, name, desc, toArray(addressList),
|
||||
new EcuDataConvertor[]{new EcuSwitchConvertorImpl(bit)});
|
||||
switches.add(ecuSwitch);
|
||||
ecuDataMap.put(ecuSwitch.getId(), ecuSwitch);
|
||||
// EcuSwitch ecuSwitch = new EcuSwitchImpl(id, name, desc, toArray(addressList),
|
||||
// new EcuDataConvertor[]{new EcuSwitchConvertorImpl(bit)});
|
||||
// switches.add(ecuSwitch);
|
||||
// ecuDataMap.put(ecuSwitch.getId(), ecuSwitch);
|
||||
if (id.equalsIgnoreCase(fileLoggingControllerSwitchId)) {
|
||||
fileLoggingControllerSwitch = new EcuSwitchImpl(id, name, desc, toArray(addressList),
|
||||
new EcuDataConvertor[]{new EcuSwitchConvertorImpl(bit)});
|
||||
// fileLoggingControllerSwitch = new EcuSwitchImpl(id, name, desc, toArray(addressList),
|
||||
// new EcuDataConvertor[]{new EcuSwitchConvertorImpl(bit)});
|
||||
}
|
||||
} else if (TAG_ECUPARAM.equals(qName)) {
|
||||
if (ecuInit != null && ecuAddressMap.containsKey(ecuInit.getEcuId())) {
|
||||
EcuParameter param = new EcuParameterImpl(id, name, desc, ecuAddressMap.get(ecuInit.getEcuId()),
|
||||
convertorList.toArray(new EcuDataConvertor[convertorList.size()]));
|
||||
params.add(param);
|
||||
ecuDataMap.put(param.getId(), param);
|
||||
// EcuParameter param = new EcuParameterImpl(id, name, desc, ecuAddressMap.get(ecuInit.getEcuId()),
|
||||
// convertorList.toArray(new EcuDataConvertor[convertorList.size()]));
|
||||
// params.add(param);
|
||||
// ecuDataMap.put(param.getId(), param);
|
||||
}
|
||||
} else if (TAG_ECU.equals(qName)) {
|
||||
String[] addresses = toArray(addressList);
|
||||
|
@ -257,31 +254,6 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
|
|||
return connectionProperties;
|
||||
}
|
||||
|
||||
private List<String> getAddressList(String startAddress, int addressLength) {
|
||||
List<String> addresses = new LinkedList<String>();
|
||||
int start = HexUtil.hexToInt(startAddress);
|
||||
for (int i = 0; i < addressLength; i++) {
|
||||
addresses.add(padAddress(HexUtil.intToHexString(start + i), startAddress.length()));
|
||||
}
|
||||
// System.out.println(startAddress + ":" + addressLength + " => " + addresses);
|
||||
return addresses;
|
||||
}
|
||||
|
||||
private String padAddress(String address, int length) {
|
||||
if (address.length() == length) {
|
||||
return address;
|
||||
} else {
|
||||
StringBuilder builder = new StringBuilder(length);
|
||||
builder.append("0x");
|
||||
String s = address.substring(2);
|
||||
for (int i = 0; i < length - s.length() - 2; i++) {
|
||||
builder.append('0');
|
||||
}
|
||||
builder.append(s);
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSupportedParameter(EcuInit ecuInit, String ecuByteIndex, String ecuBit) {
|
||||
byte[] ecuInitBytes = ecuInit.getEcuInitBytes();
|
||||
int index = Integer.parseInt(ecuByteIndex);
|
||||
|
|
Loading…
Reference in New Issue