mirror of https://github.com/rusefi/RomRaider.git
sorted out connection and profile loading behaviour
git-svn-id: https://svn2.assembla.com/svn/romraider/trunk@113 38686702-15cf-42e4-a595-3071df8bf5ea
This commit is contained in:
parent
35ea9a49a9
commit
a4c9e7c3c9
|
@ -67,6 +67,7 @@ public class Settings implements Serializable {
|
|||
private int tableClickCount = 1; // number of clicks to open table
|
||||
|
||||
private String loggerPort = "";
|
||||
private String loggerPortDefault = "";
|
||||
private String loggerProtocol = "SSM";
|
||||
private String loggerConfigFilePath = "logger.xml";
|
||||
private String loggerProfileFilePath = "profile.xml";
|
||||
|
@ -315,6 +316,14 @@ public class Settings implements Serializable {
|
|||
this.loggerPort = loggerPort;
|
||||
}
|
||||
|
||||
public String getLoggerPortDefault() {
|
||||
return loggerPortDefault;
|
||||
}
|
||||
|
||||
public void setLoggerPortDefault(String loggerPortDefault) {
|
||||
this.loggerPortDefault = loggerPortDefault;
|
||||
}
|
||||
|
||||
public String getLoggerProtocol() {
|
||||
return loggerProtocol;
|
||||
}
|
||||
|
|
|
@ -56,11 +56,14 @@ public final class SerialPortRefresher implements Runnable {
|
|||
}
|
||||
|
||||
private void refreshPortList() {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
listener.refreshPortList(listSerialPorts(), defaultLoggerPort);
|
||||
}
|
||||
});
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> listSerialPorts() {
|
||||
|
|
|
@ -40,6 +40,7 @@ import com.romraider.logger.ecu.definition.EcuSwitch;
|
|||
import com.romraider.logger.ecu.definition.ExternalData;
|
||||
import com.romraider.logger.ecu.definition.ExternalDataImpl;
|
||||
import com.romraider.logger.ecu.definition.LoggerData;
|
||||
import com.romraider.logger.ecu.exception.PortNotFoundException;
|
||||
import com.romraider.logger.ecu.external.ExternalDataItem;
|
||||
import com.romraider.logger.ecu.external.ExternalDataSource;
|
||||
import com.romraider.logger.ecu.external.ExternalDataSourceLoader;
|
||||
|
@ -49,6 +50,7 @@ import com.romraider.logger.ecu.profile.UserProfileImpl;
|
|||
import com.romraider.logger.ecu.profile.UserProfileItem;
|
||||
import com.romraider.logger.ecu.profile.UserProfileItemImpl;
|
||||
import com.romraider.logger.ecu.profile.UserProfileLoader;
|
||||
import static com.romraider.logger.ecu.profile.UserProfileLoader.BACKUP_PATH;
|
||||
import com.romraider.logger.ecu.profile.UserProfileLoaderImpl;
|
||||
import com.romraider.logger.ecu.ui.DataRegistrationBroker;
|
||||
import com.romraider.logger.ecu.ui.DataRegistrationBrokerImpl;
|
||||
|
@ -75,6 +77,7 @@ import com.romraider.logger.ecu.ui.playback.PlaybackManagerImpl;
|
|||
import com.romraider.logger.ecu.ui.swing.layout.BetterFlowLayout;
|
||||
import com.romraider.logger.ecu.ui.swing.menubar.EcuLoggerMenuBar;
|
||||
import com.romraider.logger.ecu.ui.swing.menubar.action.ToggleButtonAction;
|
||||
import static com.romraider.logger.ecu.ui.swing.menubar.util.FileHelper.saveProfileToFile;
|
||||
import com.romraider.logger.ecu.ui.swing.vertical.VerticalTextIcon;
|
||||
import static com.romraider.logger.ecu.ui.swing.vertical.VerticalTextIcon.ROTATE_LEFT;
|
||||
import com.romraider.logger.ecu.ui.tab.injector.InjectorTab;
|
||||
|
@ -135,6 +138,7 @@ import java.awt.event.WindowListener;
|
|||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.File;
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
import java.util.ArrayList;
|
||||
import static java.util.Collections.sort;
|
||||
import java.util.HashMap;
|
||||
|
@ -204,7 +208,6 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
private EcuInit ecuInit;
|
||||
private JToggleButton logToFileButton;
|
||||
private List<ExternalDataSource> externalDataSources;
|
||||
|
||||
private List<EcuParameter> ecuParams;
|
||||
|
||||
public EcuLogger(Settings settings) {
|
||||
|
@ -252,6 +255,7 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
ecuIdLabel.setText(buildEcuInfoLabelText(ECU_ID_LABEL, ecuId));
|
||||
LOGGER.info("Loading logger config for new ECU (ecuid: " + ecuId + ")...");
|
||||
loadLoggerParams();
|
||||
loadUserProfile(settings.getLoggerProfileFilePath());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -313,14 +317,20 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
}
|
||||
|
||||
private void startPortRefresherThread() {
|
||||
SerialPortRefresher serialPortRefresher = new SerialPortRefresher(portsComboBox, settings.getLoggerPort());
|
||||
SerialPortRefresher serialPortRefresher = new SerialPortRefresher(portsComboBox, settings.getLoggerPortDefault());
|
||||
runAsDaemon(serialPortRefresher);
|
||||
// wait until port refresher fully started before continuing
|
||||
long start = currentTimeMillis();
|
||||
while (!serialPortRefresher.isStarted()) {
|
||||
checkSerialPortRefresherTimeout(start);
|
||||
sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkSerialPortRefresherTimeout(long start) {
|
||||
if (currentTimeMillis() - start > 5000) throw new PortNotFoundException("Timeout while finding serial ports");
|
||||
}
|
||||
|
||||
private void initUserInterface() {
|
||||
// add menubar to frame
|
||||
setJMenuBar(buildMenubar());
|
||||
|
@ -390,14 +400,11 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
public void loadUserProfile(String profileFilePath) {
|
||||
try {
|
||||
UserProfileLoader profileLoader = new UserProfileLoaderImpl();
|
||||
UserProfile profile = profileLoader.loadProfile(profileFilePath);
|
||||
setSelectedPort(profile);
|
||||
if (isLogging()) restartLogging();
|
||||
String path = isNullOrEmpty(profileFilePath) ? UserProfileLoader.BACKUP_PATH : profileFilePath;
|
||||
UserProfile profile = profileLoader.loadProfile(path);
|
||||
applyUserProfile(profile);
|
||||
File profileFile = new File(profileFilePath);
|
||||
if (profileFile.exists()) {
|
||||
reportMessageInTitleBar("Profile: " + profileFile.getAbsolutePath());
|
||||
}
|
||||
File profileFile = new File(path);
|
||||
if (profileFile.exists()) reportMessageInTitleBar("Profile: " + profileFile.getAbsolutePath());
|
||||
} catch (Exception e) {
|
||||
reportError(e);
|
||||
}
|
||||
|
@ -463,13 +470,6 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
}
|
||||
}
|
||||
|
||||
private void setSelectedPort(UserProfile profile) {
|
||||
if (profile != null) {
|
||||
settings.setLoggerPort(profile.getSerialPort());
|
||||
portsComboBox.setSelectedItem(profile.getSerialPort());
|
||||
}
|
||||
}
|
||||
|
||||
private void addConvertorUpdateListeners(List<EcuParameter> ecuParams) {
|
||||
for (EcuParameter ecuParam : ecuParams) {
|
||||
ecuParam.addConvertorUpdateListener(fileUpdateHandler);
|
||||
|
@ -578,7 +578,7 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
graphTabSwitchListTableModel.getParameterRows(), dashboardTabSwitchListTableModel.getParameterRows());
|
||||
Map<String, UserProfileItem> externalProfileItems = getProfileItems(dataTabExternalListTableModel.getParameterRows(),
|
||||
graphTabExternalListTableModel.getParameterRows(), dashboardTabExternalListTableModel.getParameterRows());
|
||||
return new UserProfileImpl((String) portsComboBox.getSelectedItem(), paramProfileItems, switchProfileItems, externalProfileItems);
|
||||
return new UserProfileImpl(paramProfileItems, switchProfileItems, externalProfileItems);
|
||||
}
|
||||
|
||||
private Map<String, UserProfileItem> getProfileItems(List<ParameterRow> dataTabRows, List<ParameterRow> graphTabRows, List<ParameterRow> dashTabRows) {
|
||||
|
@ -948,9 +948,8 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
}
|
||||
|
||||
public void startLogging() {
|
||||
String port = (String) portsComboBox.getSelectedItem();
|
||||
String port = settings.getLoggerPort();
|
||||
if (isNullOrEmpty(port)) return;
|
||||
settings.setLoggerPort(port);
|
||||
controller.start();
|
||||
}
|
||||
|
||||
|
@ -987,19 +986,25 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
|
|||
} catch (Exception e) {
|
||||
LOGGER.warn("Error stopping logger", e);
|
||||
} finally {
|
||||
rememberWindowProperties();
|
||||
saveSettings();
|
||||
backupCurrentProfile();
|
||||
}
|
||||
}
|
||||
|
||||
private void saveSettings() {
|
||||
new SettingsManagerImpl().save(settings);
|
||||
}
|
||||
|
||||
private void rememberWindowProperties() {
|
||||
settings.setLoggerPortDefault((String) portsComboBox.getSelectedItem());
|
||||
settings.setLoggerWindowMaximized(getExtendedState() == MAXIMIZED_BOTH);
|
||||
settings.setLoggerWindowSize(getSize());
|
||||
settings.setLoggerWindowLocation(getLocation());
|
||||
new SettingsManagerImpl().save(settings);
|
||||
}
|
||||
|
||||
private void backupCurrentProfile() {
|
||||
try {
|
||||
saveProfileToFile(getCurrentProfile(), new File(BACKUP_PATH));
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Error backing up profile", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanUpUpdateHandlers() {
|
||||
|
|
|
@ -26,8 +26,6 @@ import com.romraider.logger.ecu.definition.LoggerData;
|
|||
|
||||
public interface UserProfile {
|
||||
|
||||
String getSerialPort();
|
||||
|
||||
boolean contains(LoggerData loggerData);
|
||||
|
||||
boolean isSelectedOnLiveDataTab(LoggerData loggerData);
|
||||
|
|
|
@ -36,22 +36,16 @@ public final class UserProfileImpl implements UserProfile {
|
|||
private final Map<String, UserProfileItem> params;
|
||||
private final Map<String, UserProfileItem> switches;
|
||||
private final Map<String, UserProfileItem> external;
|
||||
private final String serialPort;
|
||||
|
||||
public UserProfileImpl(String serialPort, Map<String, UserProfileItem> params, Map<String, UserProfileItem> switches, Map<String, UserProfileItem> external) {
|
||||
public UserProfileImpl(Map<String, UserProfileItem> params, Map<String, UserProfileItem> switches, Map<String, UserProfileItem> external) {
|
||||
checkNotNull(params, "params");
|
||||
checkNotNull(switches, "switches");
|
||||
checkNotNull(external, "external");
|
||||
this.serialPort = serialPort;
|
||||
this.params = params;
|
||||
this.switches = switches;
|
||||
this.external = external;
|
||||
}
|
||||
|
||||
public String getSerialPort() {
|
||||
return serialPort;
|
||||
}
|
||||
|
||||
public boolean contains(LoggerData loggerData) {
|
||||
checkNotNull(loggerData, "loggerData");
|
||||
return getMap(loggerData).keySet().contains(loggerData.getId());
|
||||
|
@ -78,9 +72,7 @@ public final class UserProfileImpl implements UserProfile {
|
|||
String defaultUnits = getUserProfileItem(loggerData).getUnits();
|
||||
if (defaultUnits != null && loggerData.getConvertors().length > 1) {
|
||||
for (EcuDataConvertor convertor : loggerData.getConvertors()) {
|
||||
if (defaultUnits.equals(convertor.getUnits())) {
|
||||
return convertor;
|
||||
}
|
||||
if (defaultUnits.equals(convertor.getUnits())) return convertor;
|
||||
}
|
||||
throw new ConfigurationException("Unknown default units, '" + defaultUnits + "', specified for [" + loggerData.getId() + "] " + loggerData.getName());
|
||||
}
|
||||
|
@ -97,9 +89,6 @@ public final class UserProfileImpl implements UserProfile {
|
|||
builder.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>").append(NEW_LINE);
|
||||
builder.append("<!DOCTYPE profile SYSTEM \"profile.dtd\">").append(NEW_LINE).append(NEW_LINE);
|
||||
builder.append("<profile>").append(NEW_LINE);
|
||||
if (!isNullOrEmpty(serialPort)) {
|
||||
builder.append(" <serial port=\"").append(serialPort).append("\"/>").append(NEW_LINE);
|
||||
}
|
||||
if (!params.isEmpty()) {
|
||||
builder.append(" <parameters>").append(NEW_LINE);
|
||||
appendLoggerDataElements(builder, "parameter", params, true);
|
||||
|
@ -123,18 +112,10 @@ public final class UserProfileImpl implements UserProfile {
|
|||
for (String id : dataMap.keySet()) {
|
||||
UserProfileItem item = dataMap.get(id);
|
||||
builder.append(" <").append(dataType).append(" id=\"").append(id).append("\"");
|
||||
if (item.isLiveDataSelected()) {
|
||||
builder.append(" livedata=\"selected\"");
|
||||
}
|
||||
if (item.isGraphSelected()) {
|
||||
builder.append(" graph=\"selected\"");
|
||||
}
|
||||
if (item.isDashSelected()) {
|
||||
builder.append(" dash=\"selected\"");
|
||||
}
|
||||
if (showUnits && !isNullOrEmpty(item.getUnits())) {
|
||||
builder.append(" units=\"").append(item.getUnits()).append("\"");
|
||||
}
|
||||
if (item.isLiveDataSelected()) builder.append(" livedata=\"selected\"");
|
||||
if (item.isGraphSelected()) builder.append(" graph=\"selected\"");
|
||||
if (item.isDashSelected()) builder.append(" dash=\"selected\"");
|
||||
if (showUnits && !isNullOrEmpty(item.getUnits())) builder.append(" units=\"").append(item.getUnits()).append("\"");
|
||||
builder.append("/>").append(NEW_LINE);
|
||||
}
|
||||
}
|
||||
|
@ -144,15 +125,10 @@ public final class UserProfileImpl implements UserProfile {
|
|||
}
|
||||
|
||||
private Map<String, UserProfileItem> getMap(LoggerData loggerData) {
|
||||
if (loggerData instanceof EcuParameter) {
|
||||
return params;
|
||||
} else if (loggerData instanceof EcuSwitch) {
|
||||
return switches;
|
||||
} else if (loggerData instanceof ExternalData) {
|
||||
return external;
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Unknown LoggerData type: " + loggerData.getClass());
|
||||
}
|
||||
if (loggerData instanceof EcuParameter) return params;
|
||||
else if (loggerData instanceof EcuSwitch) return switches;
|
||||
else if (loggerData instanceof ExternalData) return external;
|
||||
else throw new UnsupportedOperationException("Unknown LoggerData type: " + loggerData.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,5 +22,7 @@
|
|||
package com.romraider.logger.ecu.profile;
|
||||
|
||||
public interface UserProfileLoader {
|
||||
String BACKUP_PATH = "profile_backup.xml";
|
||||
|
||||
UserProfile loadProfile(String filePath);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ public final class UserProfileLoaderImpl implements UserProfileLoader {
|
|||
|
||||
public UserProfile loadProfile(String userProfileFilePath) {
|
||||
checkNotNullOrEmpty(userProfileFilePath, "userProfileFilePath");
|
||||
LOGGER.info("Loading profile: " + userProfileFilePath);
|
||||
try {
|
||||
InputStream inputStream = new BufferedInputStream(new FileInputStream(new File(userProfileFilePath)));
|
||||
try {
|
||||
|
|
|
@ -66,7 +66,7 @@ public final class UserProfileHandler extends DefaultHandler {
|
|||
}
|
||||
|
||||
public UserProfile getUserProfile() {
|
||||
return new UserProfileImpl(serialPort, params, switches, external);
|
||||
return new UserProfileImpl(params, switches, external);
|
||||
}
|
||||
|
||||
private UserProfileItem getUserProfileItem(Attributes attributes) {
|
||||
|
|
|
@ -70,10 +70,8 @@ public final class SerialPortComboBox extends JComboBox implements SerialPortRef
|
|||
for (String port : ports) {
|
||||
addItem(port);
|
||||
}
|
||||
if (selectedPort != null) {
|
||||
if (ports.contains(selectedPort)) {
|
||||
if (selectedPort != null && ports.contains(selectedPort)) {
|
||||
setSelectedItem(selectedPort);
|
||||
}
|
||||
settings.setLoggerPort(selectedPort);
|
||||
} else {
|
||||
setSelectedIndex(0);
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
|
||||
package com.romraider.xml;
|
||||
|
||||
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
|
||||
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
|
||||
import com.romraider.Settings;
|
||||
import com.romraider.swing.JProgressPane;
|
||||
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
|
||||
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
|
||||
import javax.imageio.metadata.IIOMetadataNode;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -233,6 +233,11 @@ public final class DOMSettingsBuilder {
|
|||
private IIOMetadataNode buildLogger(Settings settings) {
|
||||
IIOMetadataNode loggerSettings = new IIOMetadataNode("logger");
|
||||
|
||||
// serial connection
|
||||
IIOMetadataNode serial = new IIOMetadataNode("serial");
|
||||
serial.setAttribute("port", settings.getLoggerPortDefault());
|
||||
loggerSettings.appendChild(serial);
|
||||
|
||||
// window maximized
|
||||
IIOMetadataNode maximized = new IIOMetadataNode("maximized");
|
||||
maximized.setAttribute("value", String.valueOf((settings.isLoggerWindowMaximized())));
|
||||
|
|
|
@ -213,7 +213,10 @@ public final class DOMSettingsUnmarshaller {
|
|||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
n = nodes.item(i);
|
||||
|
||||
if (n.getNodeType() == ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("maximized")) {
|
||||
if (n.getNodeType() == ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("serial")) {
|
||||
settings.setLoggerPortDefault(unmarshallAttribute(n, "port", ""));
|
||||
|
||||
} else if (n.getNodeType() == ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("maximized")) {
|
||||
settings.setLoggerWindowMaximized(unmarshallAttribute(n, "value", false));
|
||||
|
||||
} else if (n.getNodeType() == ELEMENT_NODE && n.getNodeName().equalsIgnoreCase("size")) {
|
||||
|
|
Loading…
Reference in New Issue