git-svn-id: https://svn2.assembla.com/svn/romraider/trunk@213 38686702-15cf-42e4-a595-3071df8bf5ea
This commit is contained in:
kascade 2009-01-31 02:14:55 +00:00
parent 1389ea0663
commit 5acedf6c0c
8 changed files with 250 additions and 139 deletions

Binary file not shown.

BIN
lib/windows/registry.jar Normal file

Binary file not shown.

View File

@ -19,10 +19,10 @@
package com.romraider;
import com.centerkey.utils.BareBonesBrowserLaunch;
import static com.romraider.Version.ECU_DEFS_URL;
import static com.romraider.Version.PRODUCT_NAME;
import static com.romraider.Version.VERSION;
import com.centerkey.utils.BareBonesBrowserLaunch;
import com.romraider.logger.ecu.ui.handler.table.TableUpdateHandler;
import com.romraider.maps.Rom;
import com.romraider.maps.Table;
@ -133,7 +133,7 @@ public class ECUEditor extends JFrame implements WindowListener, PropertyChangeL
if (settings.getEcuDefinitionFiles().size() <= 0) {
// no ECU definitions configured - let user choose to get latest or configure later
Object[] options = { "YES", "NO" };
Object[] options = {"Yes", "No"};
int answer = JOptionPane.showOptionDialog(null,
"No ECU Definitions Found. Go online to get latest definition file?",
"Configuration Warning",
@ -146,7 +146,7 @@ public class ECUEditor extends JFrame implements WindowListener, PropertyChangeL
BareBonesBrowserLaunch.openURL(ECU_DEFS_URL);
} else {
JOptionPane.showMessageDialog(this,
"You will need to configure ECU definitions before ROM images can be opened.\n\nTo configure, go to the menu bar and select\nECU Definitions\nFrom there, you can choose to go online or select the location of existing definition files.",
"You will need to configure ECU definitions before ROM images can be opened.\n\nTo configure, go to the menu bar and select \"ECU Definitions\".\nFrom there, you can choose to go online or select the location of existing definition files.",
"Configuration Information",
JOptionPane.INFORMATION_MESSAGE);
}

View File

@ -68,7 +68,7 @@ public class Settings implements Serializable {
private String loggerPort = "";
private String loggerPortDefault = "";
private String loggerProtocol = "SSM";
private String loggerDefinitionFilePath = "logger.xml";
private String loggerDefinitionFilePath = "";
private String loggerProfileFilePath = "";
private String loggerOutputDirPath = System.getProperty("user.home");
private String fileLoggingControllerSwitchId = "S20"; // defogger switch by default

View File

@ -22,6 +22,7 @@ package com.romraider.io.j2534.api;
import com.romraider.io.connection.ConnectionManager;
import com.romraider.io.connection.ConnectionProperties;
import com.romraider.io.j2534.op20.Old_J2534OpenPort20;
import static com.romraider.io.j2534.op20.OpenPort20.CONFIG_LOOPBACK;
import static com.romraider.io.j2534.op20.OpenPort20.CONFIG_P1_MAX;
import static com.romraider.io.j2534.op20.OpenPort20.CONFIG_P3_MIN;
import static com.romraider.io.j2534.op20.OpenPort20.CONFIG_P4_MIN;
@ -95,7 +96,8 @@ public final class J2534ConnectionManager implements ConnectionManager {
ConfigItem p1Max = new ConfigItem(CONFIG_P1_MAX, 2);
ConfigItem p3Min = new ConfigItem(CONFIG_P3_MIN, 0);
ConfigItem p4Min = new ConfigItem(CONFIG_P4_MIN, 0);
api.setConfig(channelId, p1Max, p3Min, p4Min);
ConfigItem loopback = new ConfigItem(CONFIG_LOOPBACK, 1);
api.setConfig(channelId, p1Max, p3Min, p4Min, loopback);
}
private void stopMsgFilter() {

View File

@ -0,0 +1,124 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2008 RomRaider.com
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package com.romraider.io.j2534.op20;
import static com.ice.jni.registry.Registry.HKEY_LOCAL_MACHINE;
import static com.ice.jni.registry.Registry.openSubkey;
import com.ice.jni.registry.RegistryException;
import com.ice.jni.registry.RegistryKey;
import static com.ice.jni.registry.RegistryKey.ACCESS_READ;
import com.ice.jni.registry.RegistryValue;
import static com.ice.jni.registry.RegistryValue.REG_DWORD;
import static com.ice.jni.registry.RegistryValue.REG_SZ;
import static com.romraider.util.ByteUtil.asUnsignedInt;
import org.apache.log4j.Logger;
import static org.apache.log4j.Logger.getLogger;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Enumeration;
public final class OpenPort20Manager {
private static final Logger LOGGER = getLogger(OpenPort20Manager.class);
private static final boolean SUPPORTED;
private OpenPort20Manager() {
}
static {
File library = findLibrary();
SUPPORTED = library != null;
}
public static boolean isSupported() {
return SUPPORTED;
}
private static File findLibrary() {
try {
RegistryKey software = openSubkey(HKEY_LOCAL_MACHINE, "SOFTWARE", ACCESS_READ);
RegistryKey passThruSupport = software.openSubKey("PassThruSupport.04.04");
Enumeration vendors = passThruSupport.keyElements();
while (vendors.hasMoreElements()) {
String vendor = (String) vendors.nextElement();
RegistryKey vendorKey = passThruSupport.openSubKey(vendor);
if (!valueExists(vendorKey, "ISO9141", REG_DWORD)) continue;
if (dwordValue(vendorKey, "ISO9141") != 1) continue;
if (!valueExists(vendorKey, "FunctionLibrary", REG_SZ)) continue;
File f = new File(stringValue(vendorKey, "FunctionLibrary"));
if (f.exists()) return f;
}
return null;
} catch (Exception e) {
LOGGER.info("Error determining J2534 library location: " + e.getMessage());
return null;
}
}
private static String stringValue(RegistryKey key, String name) throws RegistryException {
byte[] bytes = valueOf(key, name);
return new String(bytes);
}
private static int dwordValue(RegistryKey key, String name) throws RegistryException {
byte[] bytes = valueOf(key, name);
return asUnsignedInt(bytes);
}
private static byte[] valueOf(RegistryKey key, String name) throws RegistryException {
RegistryValue value = key.getValue(name);
return value.getByteData();
}
public static boolean valueExists(RegistryKey key, String name, int type) {
try {
Enumeration elements = key.valueElements();
while (elements.hasMoreElements()) {
String element = (String) elements.nextElement();
if (!element.equals(name)) continue;
RegistryValue value = key.getValue(element);
return value.getType() == type;
}
return false;
} catch (Exception e) {
return false;
}
}
private static void copy(File from, File to) {
LOGGER.info("Copying: " + from.getAbsolutePath() + " => " + to.getAbsolutePath());
try {
FileReader in = new FileReader(from);
try {
FileWriter out = new FileWriter(to);
try {
int c;
while ((c = in.read()) != -1) out.write(c);
} finally {
out.close();
}
} finally {
in.close();
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
}

View File

@ -19,6 +19,7 @@
package com.romraider.logger.ecu;
import com.centerkey.utils.BareBonesBrowserLaunch;
import com.romraider.ECUEditor;
import com.romraider.Settings;
import static com.romraider.Version.LOGGER_DEFS_URL;
@ -39,7 +40,6 @@ 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.ConfigurationException;
import com.romraider.logger.ecu.exception.PortNotFoundException;
import com.romraider.logger.ecu.external.ExternalDataItem;
import com.romraider.logger.ecu.external.ExternalDataSource;
@ -90,19 +90,18 @@ import com.romraider.util.SettingsManagerImpl;
import com.romraider.util.ThreadUtil;
import static com.romraider.util.ThreadUtil.runAsDaemon;
import static com.romraider.util.ThreadUtil.sleep;
import com.centerkey.utils.BareBonesBrowserLaunch;
import org.apache.log4j.Logger;
import javax.swing.AbstractAction;
import static javax.swing.BorderFactory.createLoweredBevelBorder;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import static javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW;
import javax.swing.JFrame;
import javax.swing.JLabel;
import static javax.swing.JLabel.RIGHT;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import static javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED;
@ -396,9 +395,12 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
}
private void loadLoggerConfig() {
String loggerConfigFilePath = settings.getLoggerDefinitionFilePath();
if (isNullOrEmpty(loggerConfigFilePath)) showMissingConfigDialog();
else {
try {
EcuDataLoader dataLoader = new EcuDataLoaderImpl();
dataLoader.loadConfigFromXml(settings.getLoggerDefinitionFilePath(), settings.getLoggerProtocol(),
dataLoader.loadConfigFromXml(loggerConfigFilePath, settings.getLoggerProtocol(),
settings.getFileLoggingControllerSwitchId(), ecuInit);
List<EcuParameter> ecuParams = dataLoader.getEcuParameters();
addConvertorUpdateListeners(ecuParams);
@ -406,11 +408,14 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
loadEcuSwitches(dataLoader.getEcuSwitches());
initFileLoggingController(dataLoader.getFileLoggingControllerSwitch());
settings.setLoggerConnectionProperties(dataLoader.getConnectionProperties());
} catch (ConfigurationException ce) {
// TODO: is this assumption safe? Could anything else here throw a ConfigurationException?
// assume that the configuration exception is from failure to load logger defs
// no logger definition configured - let user choose to get latest or configure later
Object[] options = { "YES", "NO" };
} catch (Exception e) {
reportError(e);
}
}
}
private void showMissingConfigDialog() {
Object[] options = {"Yes", "No"};
int answer = JOptionPane.showOptionDialog(null,
"Logger definition file not found. Go online to get latest definition file?",
"Configuration Warning",
@ -428,10 +433,6 @@ public final class EcuLogger extends JFrame implements WindowListener, PropertyC
JOptionPane.INFORMATION_MESSAGE);
reportError("No Logger Definition file found");
}
} catch (Exception e) {
reportError(e);
}
}
private void loadLoggerPlugins() {

View File

@ -21,25 +21,25 @@ package com.romraider.util;
import com.romraider.util.exception.NameableNotFoundException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.Vector;
public class NamedSet<E> implements Set<E>, Serializable {
public class NamedSet<T extends Nameable> implements Set<T>, Serializable {
private static final long serialVersionUID = 3700068171618250762L;
Vector<Nameable> objects = new Vector<Nameable>();
private final List<T> objects = new ArrayList<T>();
public void add(Nameable n) {
public boolean add(T n) {
for (int i = 0; i < objects.size(); i++) {
if (objects.get(i).getName().equalsIgnoreCase(n.getName())) {
objects.remove(i);
objects.add(i, n);
return;
return false;
}
}
objects.add(n);
return objects.add(n);
}
public Nameable get(int i) {
@ -47,12 +47,9 @@ public class NamedSet<E> implements Set<E>, Serializable {
}
public Nameable get(String name) throws NameableNotFoundException {
for (int i = 0; i < objects.size(); i++) {
if (objects.get(i).getName().equalsIgnoreCase(name)) {
return objects.get(i);
for (Nameable object : objects) {
if (object.getName().equalsIgnoreCase(name)) return object;
}
}
// Name not found, throw exception
throw new NameableNotFoundException(name);
}
@ -75,7 +72,6 @@ public class NamedSet<E> implements Set<E>, Serializable {
return;
}
}
// Name not found, throw exception
throw new NameableNotFoundException(name);
}
@ -87,19 +83,14 @@ public class NamedSet<E> implements Set<E>, Serializable {
return objects.contains(o);
}
public Iterator<E> iterator() {
return (Iterator<E>) objects.iterator();
public Iterator<T> iterator() {
return objects.iterator();
}
public Object[] toArray() {
return objects.toArray();
}
public boolean add(E o) {
add((Nameable) o);
return true;
}
public boolean remove(Object o) {
return objects.remove(o);
}
@ -108,12 +99,8 @@ public class NamedSet<E> implements Set<E>, Serializable {
return objects.containsAll(c);
}
public boolean addAll(Collection<? extends E> c) {
Iterator<? extends E> it = c.iterator();
while (it.hasNext()) {
add((E) it.next());
}
return true;
public boolean addAll(Collection<? extends T> c) {
return objects.addAll(c);
}
public boolean retainAll(Collection<?> c) {
@ -134,24 +121,21 @@ public class NamedSet<E> implements Set<E>, Serializable {
public String toString() {
StringBuffer output = new StringBuffer();
Iterator<?> it = objects.iterator();
while (it.hasNext()) {
output.append(it.next().toString() + "\n");
}
return output + "";
for (Nameable object : objects) output.append(object).append("\n");
return output.toString();
}
public void move(int src, int dest) {
Nameable obj = objects.get(src);
objects.remove(obj);
objects.insertElementAt(obj, dest);
T t = objects.get(src);
objects.remove(t);
objects.add(dest, t);
}
public void moveBefore(Nameable moving, Nameable anchor) {
public void moveBefore(T moving, T anchor) {
move(objects.indexOf(moving), objects.indexOf(anchor) - 1);
}
public int indexOf(Nameable obj) {
public int indexOf(T obj) {
return objects.indexOf(obj);
}
}