Fixed logger definition loading

This commit is contained in:
Robin K 2021-06-18 12:30:17 +02:00
parent 18cdecba88
commit 73b42f198b
4 changed files with 50 additions and 16 deletions

View File

@ -580,7 +580,7 @@ public final class EcuLogger extends AbstractFrame implements MessageListener {
}
loadResult = String.format(
"%sloaded protocol %s: %d parameters, %d switches from def version %s.",
"%sloaded protocol %s: %d parameters, %d switches from def version %s. ",
loadResult,
getSettings().getLoggerProtocol(),
ecuParams.size(),
@ -1612,12 +1612,16 @@ public final class EcuLogger extends AbstractFrame implements MessageListener {
return inString.replaceAll("[A-Z]{3}", newString);
}
private Transport getTransportById(String id) {
private Transport getTransportById(String id) {
Transport loggerTransport = null;
for (Transport transport : getTransportMap().keySet()) {
Map<Transport, Collection<Module>> transportMap = getTransportMap();
for (Transport transport : transportMap.keySet()) {
if (transport.getId().equalsIgnoreCase(id))
loggerTransport = transport;
}
return loggerTransport;
}

View File

@ -167,14 +167,14 @@ public final class QueryManagerImpl implements QueryManager {
while (!stop) {
Module target = settings.getDestinationTarget();
if(target == null) {
if(target == null || settings.getLoggerPort() == null ) {
notifyStopped();
}
else {
notifyConnecting();
}
if (!settings.isLogExternalsOnly() && (target != null && doEcuInit(target))) {
if (!settings.isLogExternalsOnly() && (target != null && settings.getLoggerPort() != null && doEcuInit(target))) {
notifyReading();
runLogger(target);
} else if (settings.isLogExternalsOnly()) {
@ -193,11 +193,6 @@ public final class QueryManagerImpl implements QueryManager {
if (dataUpdater != null) {
dataUpdater.stopUpdater();
try {
dataUpdater.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
@ -247,13 +242,14 @@ public final class QueryManagerImpl implements QueryManager {
try {
txManager.start();
if(dataUpdater == null || !dataUpdater.isRunning()) {
if(dataUpdater == null) {
dataUpdater = new AsyncDataUpdateHandler(updateHandlers);
}
dataUpdater.start();
if(dataUpdater != null && dataUpdater.isRunning()) {
dataUpdater.stopUpdater();
}
dataUpdater = new AsyncDataUpdateHandler(updateHandlers);
dataUpdater.start();
boolean lastPollState = settings.isFastPoll();
while (!stop) {
pollState.setFastPoll(settings.isFastPoll());

View File

@ -25,6 +25,8 @@ import com.romraider.logger.ecu.definition.xml.EcuDefinitionHandler;
import com.romraider.logger.ecu.definition.xml.LoggerDefinitionHandler;
import com.romraider.logger.ecu.exception.ConfigurationException;
import com.romraider.util.ResourceUtil;
import com.romraider.util.SettingsManager;
import com.romraider.Settings;
import static com.romraider.util.ParamChecker.checkNotNull;
import static com.romraider.util.ParamChecker.checkNotNullOrEmpty;
@ -93,6 +95,10 @@ public final class EcuDataLoaderImpl implements EcuDataLoader {
LoggerDefinitionHandler handler = new LoggerDefinitionHandler(
protocol, fileLoggingControllerSwitchId, ecuInit);
getSaxParser().parse(inputStream, handler, loggerConfigFilePath);
Settings s = SettingsManager.getSettings();
Map<Transport, Collection<Module>> transportMap;
ecuParameters = handler.getEcuParameters();
ecuSwitches = handler.getEcuSwitches();
fileLoggingControllerSwitch = handler.getFileLoggingControllerSwitch();
@ -100,6 +106,33 @@ public final class EcuDataLoaderImpl implements EcuDataLoader {
defVersion = handler.getVersion();
dtcodes = handler.getEcuCodes();
protocolList = handler.getProtocols();
//If settings use protocol that new definition does not contain --> Use first values of new def.
boolean valid = true;
if(!protocolList.containsKey(s.getLoggerProtocol())){
valid = false;
}
else {
transportMap = protocolList.get(s.getLoggerProtocol());
boolean found = false;
for (Transport transport : transportMap.keySet()) {
if (transport.getId().equalsIgnoreCase(s.getTransportProtocol())) {
found = true;
break;
}
}
valid = found;
}
if(!valid) {
protocol = protocolList.keySet().iterator().next();
s.setLoggerProtocol(protocol);
s.setTransportProtocol(protocolList.values().iterator().next().keySet().iterator().next().getId());
}
} finally {
inputStream.close();
}

View File

@ -437,6 +437,7 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
}
public Map<String, Map<Transport, Collection<Module>>> getProtocols() {
/*
if (protocolMap.get(protocol).isEmpty()) {
final Module module = new Module(
"ecu", new byte[]{0x10}, "Engine Control Unit",
@ -447,7 +448,7 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
transportMap = new HashMap<Transport, Collection<Module>>();
transportMap.put(transport, moduleList);
protocolMap.put(protocol, transportMap);
}
}*/
return protocolMap;
}