Refactor EcuData classes to include new fields parsed from logger.xml

for new DS2 protocol
This commit is contained in:
Dale Schultz 2014-12-22 19:09:06 -05:00
parent 2d9bbf4b97
commit c4961b8159
5 changed files with 137 additions and 11 deletions

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com * Copyright (C) 2006-2014 RomRaider.com
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -23,4 +23,9 @@ public interface EcuData extends LoggerData {
EcuAddress getAddress(); EcuAddress getAddress();
String getGroup();
String getSubgroup();
int getGroupSize();
} }

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com * Copyright (C) 2006-2014 RomRaider.com
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -50,30 +50,37 @@ public final class EcuDerivedParameterImpl implements EcuParameter {
setEcuDatas(ecuDatas); setEcuDatas(ecuDatas);
} }
@Override
public String getId() { public String getId() {
return id; return id;
} }
@Override
public String getName() { public String getName() {
return name; return name;
} }
@Override
public String getDescription() { public String getDescription() {
return description; return description;
} }
@Override
public EcuAddress getAddress() { public EcuAddress getAddress() {
return address; return address;
} }
@Override
public EcuDataConvertor getSelectedConvertor() { public EcuDataConvertor getSelectedConvertor() {
return convertors[selectedConvertorIndex]; return convertors[selectedConvertorIndex];
} }
@Override
public EcuDataConvertor[] getConvertors() { public EcuDataConvertor[] getConvertors() {
return convertors; return convertors;
} }
@Override
public void selectConvertor(EcuDataConvertor convertor) { public void selectConvertor(EcuDataConvertor convertor) {
if (convertor != getSelectedConvertor()) { if (convertor != getSelectedConvertor()) {
for (int i = 0; i < convertors.length; i++) { for (int i = 0; i < convertors.length; i++) {
@ -86,23 +93,42 @@ public final class EcuDerivedParameterImpl implements EcuParameter {
} }
} }
@Override
public EcuDataType getDataType() { public EcuDataType getDataType() {
return PARAMETER; return PARAMETER;
} }
@Override
public boolean isSelected() { public boolean isSelected() {
return selected; return selected;
} }
@Override
public void setSelected(boolean selected) { public void setSelected(boolean selected) {
this.selected = selected; this.selected = selected;
} }
@Override
public void addConvertorUpdateListener(ConvertorUpdateListener listener) { public void addConvertorUpdateListener(ConvertorUpdateListener listener) {
checkNotNull(listener, "listener"); checkNotNull(listener, "listener");
listeners.add(listener); listeners.add(listener);
} }
@Override
public String getGroup() {
return null;
}
@Override
public String getSubgroup() {
return null;
}
@Override
public int getGroupSize() {
return 0;
}
private EcuAddress buildCombinedAddress(EcuData[] ecuDatas) { private EcuAddress buildCombinedAddress(EcuData[] ecuDatas) {
String[] addresses = new String[0]; String[] addresses = new String[0];
for (EcuData ecuData : ecuDatas) { for (EcuData ecuData : ecuDatas) {

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com * Copyright (C) 2006-2014 RomRaider.com
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -22,6 +22,7 @@ package com.romraider.logger.ecu.definition;
import static com.romraider.logger.ecu.definition.EcuDataType.PARAMETER; import static com.romraider.logger.ecu.definition.EcuDataType.PARAMETER;
import static com.romraider.util.ParamChecker.checkNotNull; import static com.romraider.util.ParamChecker.checkNotNull;
import static com.romraider.util.ParamChecker.checkNotNullOrEmpty; import static com.romraider.util.ParamChecker.checkNotNullOrEmpty;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -30,12 +31,18 @@ public final class EcuParameterImpl implements EcuParameter {
private final String name; private final String name;
private final String description; private final String description;
private final EcuAddress address; private final EcuAddress address;
private final String group;
private final String subgroup;
private final int groupsize;
private final EcuDataConvertor[] convertors; private final EcuDataConvertor[] convertors;
private final Set<ConvertorUpdateListener> listeners = new HashSet<ConvertorUpdateListener>(); private final Set<ConvertorUpdateListener> listeners = new HashSet<ConvertorUpdateListener>();
private int selectedConvertorIndex; private int selectedConvertorIndex;
private boolean selected; private boolean selected;
public EcuParameterImpl(String id, String name, String description, EcuAddress address, EcuDataConvertor[] convertors) { public EcuParameterImpl(
String id, String name, String description, EcuAddress address,
String group, String subgroup, String groupsize,
EcuDataConvertor[] convertors) {
checkNotNullOrEmpty(id, "id"); checkNotNullOrEmpty(id, "id");
checkNotNullOrEmpty(name, "name"); checkNotNullOrEmpty(name, "name");
checkNotNull(description, "description"); checkNotNull(description, "description");
@ -45,33 +52,58 @@ public final class EcuParameterImpl implements EcuParameter {
this.name = name; this.name = name;
this.description = description; this.description = description;
this.address = address; this.address = address;
this.group = group == null ? null : group.toLowerCase();
this.subgroup = subgroup == null ? null : subgroup.toLowerCase();
this.groupsize = groupsize == null ? 0 : Integer.parseInt(groupsize);
this.convertors = convertors; this.convertors = convertors;
} }
@Override
public String getId() { public String getId() {
return id; return id;
} }
@Override
public String getName() { public String getName() {
return name; return name;
} }
@Override
public String getDescription() { public String getDescription() {
return description; return description;
} }
@Override
public EcuAddress getAddress() { public EcuAddress getAddress() {
return address; return address;
} }
@Override
public String getGroup() {
return group;
}
@Override
public String getSubgroup() {
return subgroup;
}
@Override
public int getGroupSize() {
return groupsize;
}
@Override
public EcuDataConvertor getSelectedConvertor() { public EcuDataConvertor getSelectedConvertor() {
return convertors[selectedConvertorIndex]; return convertors[selectedConvertorIndex];
} }
@Override
public EcuDataConvertor[] getConvertors() { public EcuDataConvertor[] getConvertors() {
return convertors; return convertors;
} }
@Override
public void selectConvertor(EcuDataConvertor convertor) { public void selectConvertor(EcuDataConvertor convertor) {
if (convertor != getSelectedConvertor()) { if (convertor != getSelectedConvertor()) {
for (int i = 0; i < convertors.length; i++) { for (int i = 0; i < convertors.length; i++) {
@ -84,18 +116,22 @@ public final class EcuParameterImpl implements EcuParameter {
} }
} }
@Override
public EcuDataType getDataType() { public EcuDataType getDataType() {
return PARAMETER; return PARAMETER;
} }
@Override
public boolean isSelected() { public boolean isSelected() {
return selected; return selected;
} }
@Override
public void setSelected(boolean selected) { public void setSelected(boolean selected) {
this.selected = selected; this.selected = selected;
} }
@Override
public void addConvertorUpdateListener(ConvertorUpdateListener listener) { public void addConvertorUpdateListener(ConvertorUpdateListener listener) {
checkNotNull(listener, "listener"); checkNotNull(listener, "listener");
listeners.add(listener); listeners.add(listener);

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com * Copyright (C) 2006-2014 RomRaider.com
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -28,12 +28,18 @@ public final class EcuSwitchImpl implements EcuSwitch {
private final String name; private final String name;
private final String description; private final String description;
private final EcuAddress address; private final EcuAddress address;
private final String group;
private final String subgroup;
private final int groupsize;
private final EcuDataConvertor[] convertors; private final EcuDataConvertor[] convertors;
private int selectedConvertorIndex; private int selectedConvertorIndex;
private boolean fileLogController; private boolean fileLogController;
private boolean selected; private boolean selected;
public EcuSwitchImpl(String id, String name, String description, EcuAddress address, EcuDataConvertor[] convertors) { public EcuSwitchImpl(
String id, String name, String description, EcuAddress address,
String group, String subgroup, String groupsize,
EcuDataConvertor[] convertors) {
checkNotNullOrEmpty(id, "id"); checkNotNullOrEmpty(id, "id");
checkNotNullOrEmpty(name, "name"); checkNotNullOrEmpty(name, "name");
checkNotNull(description, "description"); checkNotNull(description, "description");
@ -43,33 +49,58 @@ public final class EcuSwitchImpl implements EcuSwitch {
this.name = name; this.name = name;
this.description = description; this.description = description;
this.address = address; this.address = address;
this.group = group;
this.subgroup = subgroup;
this.groupsize = groupsize == null ? 0 : Integer.parseInt(groupsize);
this.convertors = convertors; this.convertors = convertors;
} }
@Override
public String getId() { public String getId() {
return id; return id;
} }
@Override
public String getName() { public String getName() {
return name; return name;
} }
@Override
public String getDescription() { public String getDescription() {
return description; return description;
} }
@Override
public EcuAddress getAddress() { public EcuAddress getAddress() {
return address; return address;
} }
@Override
public String getGroup() {
return group;
}
@Override
public String getSubgroup() {
return subgroup;
}
@Override
public int getGroupSize() {
return groupsize;
}
@Override
public EcuDataConvertor getSelectedConvertor() { public EcuDataConvertor getSelectedConvertor() {
return convertors[selectedConvertorIndex]; return convertors[selectedConvertorIndex];
} }
@Override
public EcuDataConvertor[] getConvertors() { public EcuDataConvertor[] getConvertors() {
return convertors; return convertors;
} }
@Override
public void selectConvertor(EcuDataConvertor convertor) { public void selectConvertor(EcuDataConvertor convertor) {
for (int i = 0; i < convertors.length; i++) { for (int i = 0; i < convertors.length; i++) {
EcuDataConvertor dataConvertor = convertors[i]; EcuDataConvertor dataConvertor = convertors[i];
@ -79,14 +110,17 @@ public final class EcuSwitchImpl implements EcuSwitch {
} }
} }
@Override
public EcuDataType getDataType() { public EcuDataType getDataType() {
return SWITCH; return SWITCH;
} }
@Override
public boolean isSelected() { public boolean isSelected() {
return selected; return selected;
} }
@Override
public void setSelected(boolean selected) { public void setSelected(boolean selected) {
this.selected = selected; this.selected = selected;
} }

View File

@ -82,6 +82,9 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
private static final String ATTR_LENGTH = "length"; private static final String ATTR_LENGTH = "length";
private static final String ATTR_ECUBIT = "ecubit"; private static final String ATTR_ECUBIT = "ecubit";
private static final String ATTR_UNITS = "units"; private static final String ATTR_UNITS = "units";
private static final String ATTR_GROUP = "group";
private static final String ATTR_SUBGROUP = "subgroup";
private static final String ATTR_GROUPSIZE = "groupsize";
private static final String ATTR_EXPRESSION = "expr"; private static final String ATTR_EXPRESSION = "expr";
private static final String ATTR_FORMAT = "format"; private static final String ATTR_FORMAT = "format";
private static final String ATTR_BYTE = "byte"; private static final String ATTR_BYTE = "byte";
@ -119,6 +122,9 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
private String desc; private String desc;
private String ecuByteIndex; private String ecuByteIndex;
private String ecuBit; private String ecuBit;
private String group;
private String subgroup;
private String groupsize;
private String ecuIds; private String ecuIds;
private List<String> addrStrings = new ArrayList<String>(); private List<String> addrStrings = new ArrayList<String>();
private boolean EcuAddressCreated; private boolean EcuAddressCreated;
@ -144,6 +150,7 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
private String testerAddr; private String testerAddr;
private List<Module> moduleList; private List<Module> moduleList;
private Map<String, Collection<Module>> transportList; private Map<String, Collection<Module>> transportList;
public LoggerDefinitionHandler(String protocol, String fileLoggingControllerSwitchId, EcuInit ecuInit) { public LoggerDefinitionHandler(String protocol, String fileLoggingControllerSwitchId, EcuInit ecuInit) {
checkNotNullOrEmpty(protocol, "protocol"); checkNotNullOrEmpty(protocol, "protocol");
checkNotNullOrEmpty(fileLoggingControllerSwitchId, "fileLoggingControllerSwitchId"); checkNotNullOrEmpty(fileLoggingControllerSwitchId, "fileLoggingControllerSwitchId");
@ -179,6 +186,9 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
desc = attributes.getValue(ATTR_DESC); desc = attributes.getValue(ATTR_DESC);
ecuByteIndex = attributes.getValue(ATTR_ECUBYTEINDEX); ecuByteIndex = attributes.getValue(ATTR_ECUBYTEINDEX);
ecuBit = attributes.getValue(ATTR_ECUBIT); ecuBit = attributes.getValue(ATTR_ECUBIT);
group = attributes.getValue(ATTR_GROUP);
subgroup = attributes.getValue(ATTR_SUBGROUP);
groupsize = attributes.getValue(ATTR_GROUPSIZE);
target = attributes.getValue(ATTR_TARGET); target = attributes.getValue(ATTR_TARGET);
resetLists(); resetLists();
} else if (TAG_ADDRESS.equals(qName)) { } else if (TAG_ADDRESS.equals(qName)) {
@ -214,6 +224,9 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
desc = attributes.getValue(ATTR_DESC); desc = attributes.getValue(ATTR_DESC);
ecuByteIndex = attributes.getValue(ATTR_ECUBYTEINDEX); ecuByteIndex = attributes.getValue(ATTR_ECUBYTEINDEX);
ecuBit = attributes.getValue(ATTR_BIT); ecuBit = attributes.getValue(ATTR_BIT);
group = attributes.getValue(ATTR_GROUP);
subgroup = attributes.getValue(ATTR_SUBGROUP);
groupsize = attributes.getValue(ATTR_GROUPSIZE);
target = attributes.getValue(ATTR_TARGET); target = attributes.getValue(ATTR_TARGET);
address = new EcuAddressImpl(attributes.getValue(ATTR_BYTE), 1, Integer.valueOf(attributes.getValue(ATTR_BIT))); address = new EcuAddressImpl(attributes.getValue(ATTR_BYTE), 1, Integer.valueOf(attributes.getValue(ATTR_BIT)));
resetLists(); resetLists();
@ -221,6 +234,9 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
id = attributes.getValue(ATTR_ID); id = attributes.getValue(ATTR_ID);
name = attributes.getValue(ATTR_NAME); name = attributes.getValue(ATTR_NAME);
desc = attributes.getValue(ATTR_DESC); desc = attributes.getValue(ATTR_DESC);
group = attributes.getValue(ATTR_GROUP);
subgroup = attributes.getValue(ATTR_SUBGROUP);
groupsize = attributes.getValue(ATTR_GROUPSIZE);
target = attributes.getValue(ATTR_TARGET); target = attributes.getValue(ATTR_TARGET);
resetLists(); resetLists();
ecuAddressMap = new HashMap<String, EcuAddress>(); ecuAddressMap = new HashMap<String, EcuAddress>();
@ -286,7 +302,8 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
if (convertorList.isEmpty()) { if (convertorList.isEmpty()) {
convertorList.add(new EcuParameterConvertorImpl()); convertorList.add(new EcuParameterConvertorImpl());
} }
EcuParameter param = new EcuParameterImpl(id, name, desc, address, EcuParameter param = new EcuParameterImpl(
id, name, desc, address, group, subgroup, groupsize,
convertorList.toArray(new EcuDataConvertor[convertorList.size()])); convertorList.toArray(new EcuDataConvertor[convertorList.size()]));
params.add(param); params.add(param);
ecuDataMap.put(param.getId(), param); ecuDataMap.put(param.getId(), param);
@ -305,7 +322,9 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
if (convertorList.isEmpty()) { if (convertorList.isEmpty()) {
convertorList.add(new EcuParameterConvertorImpl()); convertorList.add(new EcuParameterConvertorImpl());
} }
EcuParameter param = new EcuParameterImpl(id, name, desc, ecuAddressMap.get(ecuInit.getEcuId()), EcuParameter param = new EcuParameterImpl(
id, name, desc, ecuAddressMap.get(ecuInit.getEcuId()),
group, subgroup, groupsize,
convertorList.toArray(new EcuDataConvertor[convertorList.size()])); convertorList.toArray(new EcuDataConvertor[convertorList.size()]));
params.add(param); params.add(param);
ecuDataMap.put(param.getId(), param); ecuDataMap.put(param.getId(), param);
@ -321,16 +340,22 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
if (ecuByteIndex == null || ecuBit == null || ecuInit == null || isSupportedParameter(ecuInit, if (ecuByteIndex == null || ecuBit == null || ecuInit == null || isSupportedParameter(ecuInit,
ecuByteIndex, ecuBit)) { ecuByteIndex, ecuBit)) {
EcuDataConvertor[] convertors = new EcuDataConvertor[]{new EcuSwitchConvertorImpl(address.getBit())}; EcuDataConvertor[] convertors = new EcuDataConvertor[]{new EcuSwitchConvertorImpl(address.getBit())};
EcuSwitch ecuSwitch = new EcuSwitchImpl(id, name, desc, address, convertors); EcuSwitch ecuSwitch = new EcuSwitchImpl(
id, name, desc, address,
group, subgroup, groupsize, convertors);
switches.add(ecuSwitch); switches.add(ecuSwitch);
ecuDataMap.put(ecuSwitch.getId(), ecuSwitch); ecuDataMap.put(ecuSwitch.getId(), ecuSwitch);
if (id.equalsIgnoreCase(fileLoggingControllerSwitchId)) { if (id.equalsIgnoreCase(fileLoggingControllerSwitchId)) {
fileLoggingControllerSwitch = new EcuSwitchImpl(id, name, desc, address, convertors); fileLoggingControllerSwitch = new EcuSwitchImpl(
id, name, desc, address,
group, subgroup, groupsize, convertors);
} }
} }
} else if (TAG_DTCODE.equals(qName)) { } else if (TAG_DTCODE.equals(qName)) {
final EcuDataConvertor[] convertors = new EcuDataConvertor[]{new EcuDtcConvertorImpl(address.getBit())}; final EcuDataConvertor[] convertors = new EcuDataConvertor[]{new EcuDtcConvertorImpl(address.getBit())};
final EcuSwitch ecuSwitch = new EcuSwitchImpl(id, name, desc, address, convertors); final EcuSwitch ecuSwitch = new EcuSwitchImpl(
id, name, desc, address,
group, subgroup, groupsize, convertors);
dtcodes.add(ecuSwitch); dtcodes.add(ecuSwitch);
ecuDataMap.put(ecuSwitch.getId(), ecuSwitch); ecuDataMap.put(ecuSwitch.getId(), ecuSwitch);
} else if (TAG_TRANSPORT.equals(qName)) { } else if (TAG_TRANSPORT.equals(qName)) {