More J2534 updates and a few extra LOGGER.debug statements to assist.

This commit is contained in:
Dale Schultz 2012-05-11 17:47:50 -04:00
parent 6fe30d2c22
commit 0469010046
5 changed files with 43 additions and 17 deletions

View File

@ -89,7 +89,7 @@ public class Settings implements Serializable {
private boolean fastPoll = true;
private double loggerDividerLocation = 400;
private String loggerDebuggingLevel = "info";
private String j2534Device = "op20pt32"; //MONGI432 op20pt32
public Settings() {
//center window by default
@ -492,4 +492,12 @@ public class Settings implements Serializable {
public String getLoggerDebuggingLevel() {
return loggerDebuggingLevel;
}
public void setJ2534Device(String j2534Device) {
this.j2534Device = j2534Device;
}
public String getJ2534Device() {
return j2534Device;
}
}

View File

@ -110,8 +110,7 @@ public final class J2534ConnectionManager implements ConnectionManager {
stopMsgFilter();
disconnectChannel();
closeDevice();
resetHandles();
LOGGER.info("J2534 connection closed");
//resetHandles();
}
private void initJ2534(int baudRate) {
@ -121,7 +120,13 @@ public final class J2534ConnectionManager implements ConnectionManager {
channelId = api.connect(deviceId, Flag.ISO9141_NO_CHECKSUM.getValue(), baudRate);
setConfig(channelId);
msgId = api.startPassMsgFilter(channelId, (byte) 0x00, (byte) 0x00);
LOGGER.debug(String.format(
"J2534 success: deviceId:%d, channelId:%d, msgId:%d",
deviceId, channelId, msgId));
} catch (Exception e) {
LOGGER.debug(String.format(
"J2534 exception: deviceId:%d, channelId:%d, msgId:%d",
deviceId, channelId, msgId));
close();
throw new J2534Exception("J2534 Error opening device: " + e.getMessage(), e);
}
@ -143,7 +148,8 @@ public final class J2534ConnectionManager implements ConnectionManager {
private void stopMsgFilter() {
try {
if (channelId > 0 && msgId > 0) api.stopMsgFilter(channelId, msgId);
api.stopMsgFilter(channelId, msgId);
LOGGER.debug("J2534 stopped message filter:" + msgId);
} catch (Exception e) {
LOGGER.warn("J2534 Error stopping msg filter: " + e.getMessage());
}
@ -151,7 +157,8 @@ public final class J2534ConnectionManager implements ConnectionManager {
private void disconnectChannel() {
try {
if (channelId > 0) api.disconnect(channelId);
api.disconnect(channelId);
LOGGER.debug("J2534 disconnected channel:" + channelId);
} catch (Exception e) {
LOGGER.warn("J2534 Error disconnecting channel: " + e.getMessage());
}
@ -159,15 +166,17 @@ public final class J2534ConnectionManager implements ConnectionManager {
private void closeDevice() {
try {
if (deviceId > 0) api.close(deviceId);
api.close(deviceId);
LOGGER.info("J2534 closed connection to device:" + deviceId);
} catch (Exception e) {
LOGGER.warn("J2534 Error closing device: " + e.getMessage());
}
}
private void resetHandles() {
channelId = 0;
deviceId = 0;
msgId = 0;
}
// private void resetHandles() {
// channelId = -1;
// deviceId = -1;
// msgId = -1;
// api = null;
// }
}

View File

@ -21,6 +21,7 @@ package com.romraider.io.j2534.api;
import java.nio.ByteBuffer;
import com.romraider.Settings;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
@ -32,11 +33,13 @@ import com.sun.jna.ptr.NativeLongByReference;
* JNA Wrapper for Native library <b>J2534 v0404</b><br>
*/
public class J2534_v0404 implements Library {
public static final String JNA_LIBRARY_NAME = "op20pt32";
private static final Settings SETTINGS = new Settings();
public static final String JNA_LIBRARY_NAME =
SETTINGS.getJ2534Device();
public static final NativeLibrary JNA_NATIVE_LIB =
NativeLibrary.getInstance(J2534_v0404.JNA_LIBRARY_NAME);
NativeLibrary.getInstance(J2534_v0404.JNA_LIBRARY_NAME);
static {
Native.register(J2534_v0404.JNA_LIBRARY_NAME);
Native.register(J2534_v0404.JNA_LIBRARY_NAME);
}
public static native NativeLong PassThruOpen(

View File

@ -1319,7 +1319,7 @@ public final class EcuLogger extends AbstractFrame implements MessageListener {
cleanUpUpdateHandlers();
}
} catch (Exception e) {
LOGGER.warn("Error stopping logger", e);
LOGGER.warn("Error stopping logger:", e);
} finally {
saveSettings();
backupCurrentProfile();
@ -1335,12 +1335,18 @@ public final class EcuLogger extends AbstractFrame implements MessageListener {
if (settings.getLoggerParameterListState()) settings.setLoggerDividerLocation(splitPane.getDividerLocation());
settings.setLoggerSelectedTabIndex(tabbedPane.getSelectedIndex());
settings.setLoggerPluginPorts(getPluginPorts(externalDataSources));
new SettingsManagerImpl().save(settings);
try {
new SettingsManagerImpl().save(settings);
LOGGER.debug("Logger settings saved");
} catch (Exception e) {
LOGGER.warn("Error saving logger settings:", e);
}
}
private void backupCurrentProfile() {
try {
saveProfileToFile(getCurrentProfile(), new File(HOME + BACKUP_PROFILE));
LOGGER.debug("Backup profile saved");
} catch (Exception e) {
LOGGER.warn("Error backing up profile", e);
}

View File

@ -64,7 +64,7 @@ public final class SettingsManagerImpl implements SettingsManager {
new File(HOME + "/.RomRaider/").mkdir(); // Creates directory if it does not exist
builder.buildSettings(settings, new File(HOME + SETTINGS_FILE), progress, VERSION);
} catch (Exception e) {
// ignore
throw new RuntimeException(e);
}
}
}