New plug-in for the AEM X-Wifi Controller. Additional updates:

- Corrected serial connection close() call in all serial plug-ins as exceptions were being thrown
- Changed QueryManager logic to try and deal with duplicate log entries caused by high speed logging, it may still need some work.
This commit is contained in:
Dale Schultz 2012-06-04 01:03:16 -04:00
parent 4fc35be8cc
commit 661a21a0e1
34 changed files with 658 additions and 86 deletions

View File

@ -22,7 +22,11 @@
<classpathentry kind="lib" path="lib/common/cmutimelex.jar"/>
<classpathentry kind="lib" path="lib/common/en_us.jar"/>
<classpathentry kind="lib" path="lib/common/freetts.jar"/>
<classpathentry kind="lib" path="lib/common/RXTXcomm.jar"/>
<classpathentry kind="lib" path="lib/common/RXTXcomm.jar">
<attributes>
<attribute name="javadoc_location" value="http://users.frii.com/jarvi/rxtx/doc/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/windows/jdic_stub.jar"/>
<classpathentry kind="lib" path="lib/common/jdic.jar"/>
<classpathentry kind="lib" path="lib/common/jfreechart-1.0.9.jar"/>

1
plugins/aem.xwifi.plugin Normal file
View File

@ -0,0 +1 @@
datasource.class=com.romraider.logger.external.aem.xwifi.plugin.AemDataSource

View File

@ -66,15 +66,17 @@ public final class ConnectionPropertiesImpl implements ConnectionProperties {
}
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName());
builder.append("[baudRate=").append(baudRate);
builder.append(", dataBits=").append(dataBits);
builder.append(", stopBits=").append(stopBits);
builder.append(", dataBits=").append(dataBits);
builder.append(", parity=").append(parity);
builder.append(", connectTimeout=").append(connectTimeout);
builder.append(", sendTimeout=").append(sendTimeout).append("]");
return builder.toString();
final String properties = String.format(
"%s[baudRate=%d, dataBits=%d, stopBits=%d, parity=%d, " +
"connectTimeout=%d, sendTimeout=%d]",
getClass().getSimpleName(),
getBaudRate(),
getDataBits(),
getStopBits(),
getParity(),
getConnectTimeout(),
getSendTimeout()
);
return properties;
}
}

View File

@ -35,6 +35,7 @@ import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import static gnu.io.SerialPort.FLOWCONTROL_NONE;
import static java.lang.System.currentTimeMillis;
import gnu.io.UnsupportedCommOperationException;
import org.apache.log4j.Logger;
import static org.apache.log4j.Logger.getLogger;
@ -60,6 +61,7 @@ public final class SerialConnectionImpl implements SerialConnection {
os = new BufferedOutputStream(serialPort.getOutputStream());
is = new BufferedInputStream(serialPort.getInputStream());
reader = new BufferedReader(new InputStreamReader(is));
LOGGER.info("Serial connection initialised: " + connectionProperties);
} catch (Exception e) {
close();
throw new NotConnectedException(e);
@ -123,14 +125,18 @@ public final class SerialConnectionImpl implements SerialConnection {
public void readStaleData() {
if (available() <= 0) return;
byte[] staleBytes = readAvailable();
LOGGER.debug("Stale data read: " + asHex(staleBytes));
final long end = currentTimeMillis() + 100L;
do {
byte[] staleBytes = readAvailable();
LOGGER.debug("Stale data read: " + asHex(staleBytes));
sleep(2);
} while ( (available() > 0)
&& (currentTimeMillis() <= end));
}
public void close() {
if (os != null) {
try {
readStaleData();
os.close();
} catch (IOException e) {
LOGGER.error("Error closing output stream", e);
@ -138,6 +144,7 @@ public final class SerialConnectionImpl implements SerialConnection {
}
if (reader != null) {
try {
//readStaleData();
reader.close();
} catch (IOException e) {
LOGGER.error("Error closing input stream reader", e);
@ -145,6 +152,7 @@ public final class SerialConnectionImpl implements SerialConnection {
}
if (is != null) {
try {
//readStaleData();
is.close();
} catch (IOException e) {
LOGGER.error("Error closing input stream", e);

View File

@ -38,17 +38,18 @@ public final class SerialConnectionManager implements ConnectionManager {
private final SerialConnection connection;
private final ConnectionProperties connectionProperties;
private byte[] lastResponse;
private long timeout;
private final long timeout;
private long readTimeout;
public SerialConnectionManager(String portName, ConnectionProperties connectionProperties) {
checkNotNullOrEmpty(portName, "portName");
checkNotNull(connectionProperties, "connectionProperties");
this.connectionProperties = connectionProperties;
timeout = (long)connectionProperties.getConnectTimeout();
readTimeout = timeout;
// Use TestSerialConnection for testing!!
connection = new SerialConnectionImpl(portName, connectionProperties);
// connection = new TestSerialConnection2(portName, connectionProperties);
LOGGER.info("Serial connection initialised");
}
// Send request and wait for response with known length
@ -67,13 +68,14 @@ public final class SerialConnectionManager implements ConnectionManager {
}
while (connection.available() < response.length) {
sleep(1);
timeout -= 1;
if (timeout <= 0) {
readTimeout -= 1;
if (readTimeout <= 0) {
byte[] badBytes = connection.readAvailable();
LOGGER.debug("SSM Bad read response (read timeout): " + asHex(badBytes));
return; // this will reinitialize the connection
}
}
readTimeout = timeout;
connection.read(response);
if (pollState.getCurrentState() == 1){

View File

@ -73,4 +73,17 @@ public final class PollingStateImpl implements PollingState {
public void setFastPoll(boolean state) {
fastPoll = state;
}
public String toString() {
final String state = String.format(
"Polling State [isFastPoll=%s, CurrentState=%d, LastState=%d, " +
"isNewQuery=%s, isLastQuery=%s]",
isFastPoll(),
getCurrentState(),
getLastState(),
isNewQuery(),
isLastQuery()
);
return state;
}
}

View File

@ -24,6 +24,7 @@ import static com.romraider.logger.ecu.definition.EcuDataType.EXTERNAL;
import static com.romraider.util.ParamChecker.checkNotNull;
import static com.romraider.util.ThreadUtil.runAsDaemon;
import static com.romraider.util.ThreadUtil.sleep;
import static java.lang.System.currentTimeMillis;
import static java.util.Collections.synchronizedList;
import static java.util.Collections.synchronizedMap;
@ -54,6 +55,7 @@ import com.romraider.logger.ecu.ui.MessageListener;
import com.romraider.logger.ecu.ui.StatusChangeListener;
import com.romraider.logger.ecu.ui.handler.DataUpdateHandler;
import com.romraider.logger.ecu.ui.handler.file.FileLoggerControllerSwitchMonitor;
import com.romraider.logger.ecu.ui.handler.file.FileUpdateHandlerImpl;
public final class QueryManagerImpl implements QueryManager {
private static final Logger LOGGER = Logger.getLogger(QueryManagerImpl.class);
@ -64,6 +66,8 @@ public final class QueryManagerImpl implements QueryManager {
private final Map<String, Query> addList = new HashMap<String, Query>();
private final List<String> removeList = new ArrayList<String>();
private static final PollingState pollState = new PollingStateImpl();
private static final String ECU = "ECU";
private static final String TCU = "TCU";
private final Settings settings;
private final EcuInitCallback ecuInitCallback;
private final MessageListener messageListener;
@ -149,12 +153,12 @@ public final class QueryManagerImpl implements QueryManager {
}
private boolean doEcuInit(byte id) {
String target = "";
String target = null;
if (id == 0x10){
target = "ECU";
target = ECU;
}
if (id == 0x18){
target = "TCU";
target = TCU;
}
try {
@ -187,12 +191,12 @@ public final class QueryManagerImpl implements QueryManager {
}
private void runLogger(byte id) {
String target = "";
String target = null;
if (id == 0x10){
target = "ECU";
target = ECU;
}
if (id == 0x18){
target = "TCU";
target = TCU;
}
TransmissionManager txManager = new TransmissionManagerImpl(settings);
long start = System.currentTimeMillis();
@ -204,43 +208,64 @@ public final class QueryManagerImpl implements QueryManager {
pollState.setFastPoll(settings.isFastPoll());
updateQueryList();
if (queryMap.isEmpty()) {
if (pollState.isLastQuery()) endEcuQueries(txManager);
if (pollState.isLastQuery() && pollState.getCurrentState() == 0) {
endEcuQueries(txManager);
pollState.setLastState(0);
}
start = System.currentTimeMillis();
count = 0;
messageListener.reportMessage("Select parameters to be logged...");
sleep(1000L);
} else {
sendEcuQueries(txManager);
final long end = currentTimeMillis() + 1L; // update once every 1msec
final List<EcuQuery> ecuQueries = filterEcuQueries(queryMap.values());
if (!ecuQueries.isEmpty()) {
sendEcuQueries(txManager);
if (!pollState.isFastPoll() && lastPollState) {
endEcuQueries(txManager);
}
if (pollState.isFastPoll()) {
if (pollState.getCurrentState() == 0 && pollState.isNewQuery()) {
pollState.setCurrentState(1);
pollState.setNewQuery(false);
}
if (pollState.getCurrentState() == 0 && !pollState.isNewQuery()) {
pollState.setCurrentState(1);
}
if (pollState.getCurrentState() == 1 && pollState.isNewQuery()) {
pollState.setCurrentState(0);
pollState.setLastState(1);
pollState.setNewQuery(false);
}
if (pollState.getCurrentState() == 1 && !pollState.isNewQuery()) {
pollState.setLastState(1);
}
pollState.setLastQuery(true);
}
else {
pollState.setCurrentState(0);
pollState.setLastState(0);
pollState.setNewQuery(false);
}
lastPollState = pollState.isFastPoll();
}
else {
if (pollState.isLastQuery() && pollState.getLastState() == 1) {
endEcuQueries(txManager);
pollState.setLastState(0);
pollState.setCurrentState(0);
pollState.setNewQuery(true);
}
}
sendExternalQueries();
// waiting until at least 1msec has passed since last query set
while (currentTimeMillis() < end) {
sleep(1L);
}
handleQueryResponse();
count++;
messageListener.reportMessage("Querying " + target + "...");
messageListener.reportStats(buildStatsMessage(start, count));
if (!pollState.isFastPoll() && lastPollState) endEcuQueries(txManager);
if (pollState.isFastPoll()) {
if (pollState.getCurrentState() == 0 && pollState.isNewQuery()) {
pollState.setCurrentState(1);
pollState.setNewQuery(false);
}
if (pollState.getCurrentState() == 0 && !pollState.isNewQuery()) {
pollState.setCurrentState(1);
}
if (pollState.getCurrentState() == 1 && pollState.isNewQuery()) {
pollState.setCurrentState(0);
pollState.setLastState(1);
pollState.setNewQuery(false);
}
if (pollState.getCurrentState() == 1 && !pollState.isNewQuery()) {
pollState.setLastState(1);
}
pollState.setLastQuery(true);
}
else {
pollState.setCurrentState(0);
pollState.setLastState(0);
pollState.setNewQuery(false);
}
lastPollState = pollState.isFastPoll();
}
}
} catch (Exception e) {
@ -253,15 +278,15 @@ public final class QueryManagerImpl implements QueryManager {
}
private void sendEcuQueries(TransmissionManager txManager) {
List<EcuQuery> ecuQueries = filterEcuQueries(queryMap.values());
if (fileLoggerQuery != null &&
settings.isFileLoggingControllerSwitchActive())
ecuQueries.add(fileLoggerQuery);
txManager.sendQueries(ecuQueries, pollState);
final List<EcuQuery> ecuQueries = filterEcuQueries(queryMap.values());
if (fileLoggerQuery != null
&& settings.isFileLoggingControllerSwitchActive())
ecuQueries.add(fileLoggerQuery);
txManager.sendQueries(ecuQueries, pollState);
}
private void sendExternalQueries() {
List<ExternalQuery> externalQueries =
final List<ExternalQuery> externalQueries =
filterExternalQueries(queryMap.values());
for (ExternalQuery externalQuery : externalQueries) {
//FIXME: This is a hack!!
@ -271,7 +296,7 @@ public final class QueryManagerImpl implements QueryManager {
}
private void endEcuQueries(TransmissionManager txManager) {
txManager.endQueries();
txManager.endQueries();
pollState.setLastQuery(false);
}
@ -288,8 +313,8 @@ public final class QueryManagerImpl implements QueryManager {
}
private Response buildResponse(Collection<Query> queries) {
Response response = new ResponseImpl();
for (Query query : queries) {
final Response response = new ResponseImpl();
for (final Query query : queries) {
response.setDataValue(query.getLoggerData(), query.getResponse());
}
return response;

View File

@ -42,7 +42,7 @@ public class ResponseImpl implements Response {
}
public double getDataValue(LoggerData data) {
Double value = dataValues.get(data);
final Double value = dataValues.get(data);
return value == null ? ZERO : value;
}

View File

@ -49,4 +49,19 @@ public final class AemConnectionProperties implements ConnectionProperties {
public int getSendTimeout() {
return 500;
}
public String toString() {
String properties = String.format(
"%s[baudRate=%d, dataBits=%d, stopBits=%d, parity=%d, " +
"connectTimeout=%d, sendTimeout=%d]",
getClass().getSimpleName(),
getBaudRate(),
getDataBits(),
getStopBits(),
getParity(),
getConnectTimeout(),
getSendTimeout()
);
return properties;
}
}

View File

@ -42,10 +42,11 @@ public final class AemRunner implements Stoppable {
public void run() {
try {
while (!stop) {
String response = connection.readLine();
final String response = connection.readLine();
LOGGER.trace("AEM UEGO AFR Response: " + response);
if (!isNullOrEmpty(response)) dataItem.setData(parseDouble(response));
}
connection.close();
} catch (Throwable t) {
LOGGER.error("Error occurred", t);
} finally {
@ -55,12 +56,13 @@ public final class AemRunner implements Stoppable {
public void stop() {
stop = true;
connection.close();
}
private double parseDouble(String value) {
try {
return Double.parseDouble(value);
final String[] substr = value.split("\t");
final double result = Double.parseDouble(substr[0]);
return result;
} catch (Exception e) {
return 0.0;
}

View File

@ -0,0 +1,67 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 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.logger.external.aem.xwifi.io;
import com.romraider.io.connection.ConnectionProperties;
public final class AemConnectionProperties implements ConnectionProperties {
public int getBaudRate() {
return 115200;
}
public void setBaudRate(int b) {
}
public int getDataBits() {
return 8;
}
public int getStopBits() {
return 1;
}
public int getParity() {
return 0;
}
public int getConnectTimeout() {
return 2000;
}
public int getSendTimeout() {
return 500;
}
public String toString() {
final String properties = String.format(
"%s[baudRate=%d, dataBits=%d, stopBits=%d, parity=%d, " +
"connectTimeout=%d, sendTimeout=%d]",
getClass().getSimpleName(),
getBaudRate(),
getDataBits(),
getStopBits(),
getParity(),
getConnectTimeout(),
getSendTimeout()
);
return properties;
}
}

View File

@ -0,0 +1,77 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 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.logger.external.aem.xwifi.io;
import com.romraider.io.connection.ConnectionProperties;
import com.romraider.io.serial.connection.SerialConnection;
import com.romraider.io.serial.connection.SerialConnectionImpl;
import com.romraider.logger.external.core.Stoppable;
import com.romraider.logger.external.aem.xwifi.plugin.AemDataItem;
import com.romraider.logger.external.aem.xwifi.plugin.AemSensorType;
import static com.romraider.util.ParamChecker.isNullOrEmpty;
import org.apache.log4j.Logger;
import static org.apache.log4j.Logger.getLogger;
import java.util.Map;
public final class AemRunner implements Stoppable {
private static final Logger LOGGER = getLogger(AemRunner.class);
private static final ConnectionProperties CONNECTION_PROPS = new AemConnectionProperties();
private final Map<AemSensorType, AemDataItem> dataItems;
private final SerialConnection connection;
private boolean stop;
public AemRunner(final String port, final Map<AemSensorType, AemDataItem> dataItems) {
this.connection = new SerialConnectionImpl(port, CONNECTION_PROPS);
this.dataItems = dataItems;
}
public void run() {
try {
while (!stop) {
final String response = connection.readLine();
if (isNullOrEmpty(response)) continue;
LOGGER.trace("AEM X-Wifi Response: " + response);
final String[] values = response.split(",");
for (int i = 0; i < values.length; i++) {
final AemDataItem dataItem = dataItems.get(AemSensorType.valueOf(i));
if (dataItem != null) dataItem.setData(parseDouble(values[i]));
}
}
connection.close();
} catch (Throwable t) {
LOGGER.error("AEM X-Wifi read error occurred", t);
} finally {
connection.close();
}
}
public void stop() {
stop = true;
}
private double parseDouble(final String value) {
try {
final double result = Double.parseDouble(value);
return result;
} catch (Exception e) {
return 0.0;
}
}
}

View File

@ -0,0 +1,60 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 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.logger.external.aem.xwifi.plugin;
import static com.romraider.logger.external.core.ExternalDataConvertorLoader.loadConvertors;
import com.romraider.logger.ecu.definition.EcuDataConvertor;
import com.romraider.logger.external.core.DataListener;
import com.romraider.logger.external.core.ExternalDataItem;
import com.romraider.logger.external.core.ExternalSensorConversions;
public final class AemDataItem implements ExternalDataItem, DataListener {
private EcuDataConvertor[] convertors;
private final String name;
private double data;
public AemDataItem(final String name, final ExternalSensorConversions... convertorList) {
super();
this.name = name;
convertors = new EcuDataConvertor[convertorList.length];
convertors = loadConvertors(this, convertors, convertorList);
}
public String getName() {
return "AEM X-Wifi " + name;
}
public String getDescription() {
return "AEM X-Wifi " + name + " data";
}
public double getData() {
return data;
}
public void setData(double data) {
this.data = data;
}
public EcuDataConvertor[] getConvertors() {
return convertors;
}
}

View File

@ -0,0 +1,98 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 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.logger.external.aem.xwifi.plugin;
import static com.romraider.logger.external.aem.xwifi.plugin.AemSensorType.EGT1;
import static com.romraider.logger.external.aem.xwifi.plugin.AemSensorType.EGT2;
import static com.romraider.logger.external.aem.xwifi.plugin.AemSensorType.UEGO;
import static com.romraider.logger.external.core.SensorConversionsLambda.AFR_146;
import static com.romraider.logger.external.core.SensorConversionsLambda.AFR_147;
import static com.romraider.logger.external.core.SensorConversionsLambda.AFR_155;
import static com.romraider.logger.external.core.SensorConversionsLambda.AFR_172;
import static com.romraider.logger.external.core.SensorConversionsLambda.AFR_34;
import static com.romraider.logger.external.core.SensorConversionsLambda.AFR_64;
import static com.romraider.logger.external.core.SensorConversionsLambda.AFR_90;
import static com.romraider.logger.external.core.SensorConversionsLambda.LAMBDA;
import static com.romraider.logger.external.core.SensorConversionsOther.EXHAUST_DEG_F;
import static com.romraider.logger.external.core.SensorConversionsOther.EXHAUST_DEG_F2C;
import static com.romraider.util.ThreadUtil.runAsDaemon;
import static java.util.Collections.unmodifiableList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.Action;
import com.romraider.logger.ecu.EcuLogger;
import com.romraider.logger.external.aem.xwifi.io.AemRunner;
import com.romraider.logger.external.core.ExternalDataItem;
import com.romraider.logger.external.core.ExternalDataSource;
public final class AemDataSource implements ExternalDataSource {
private final Map<AemSensorType, AemDataItem> dataItems = new HashMap<AemSensorType, AemDataItem>();
private AemRunner runner;
private String port;
{
dataItems.put(UEGO, new AemDataItem("Wideband", AFR_147, LAMBDA, AFR_90, AFR_146, AFR_64, AFR_155, AFR_172, AFR_34));
dataItems.put(EGT1, new AemDataItem("EGT 1", EXHAUST_DEG_F, EXHAUST_DEG_F2C));
dataItems.put(EGT2, new AemDataItem("EGT 2", EXHAUST_DEG_F, EXHAUST_DEG_F2C));
}
public String getId() {
return getClass().getName();
}
public String getName() {
return "AEM X-Wifi Controller";
}
public String getVersion() {
return "0.01";
}
public List<? extends ExternalDataItem> getDataItems() {
return unmodifiableList(new ArrayList<AemDataItem>(dataItems.values()));
}
public Action getMenuAction(final EcuLogger logger) {
return null;
}
public void setPort(final String port) {
this.port = port;
}
public String getPort() {
return port;
}
public void connect() {
runner = new AemRunner(port, dataItems);
runAsDaemon(runner);
}
public void disconnect() {
if (runner != null) runner.stop();
}
}

View File

@ -0,0 +1,72 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 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.logger.external.aem.xwifi.plugin;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
/**
* Enum class representing the AEM X-Wifi sensor types available with methods to
* translate the mnemonic and numerical values.
*/
public enum AemSensorType {
UEGO(0),
EGT1(1),
EGT2(2),
UNDEFINED(-1); // Returned when no match is found for get()
private static final Map<Integer, AemSensorType> lookup
= new HashMap<Integer, AemSensorType>();
static {
for(AemSensorType s : EnumSet.allOf(AemSensorType.class))
lookup.put(s.getValue(), s);
}
private final int value;
private AemSensorType(int value) {
this.value = value;
}
/**
* Get the numeric value associated with the <b>AemSensorType</b>
* mnemonic string.
* @return numeric value.
*/
public int getValue() {
return value;
}
/**
* Get the <b>AemSensorType</b> mnemonic mapped to the numeric
* value or UNDEFINED if value is undefined.
* @param value - numeric value to be translated.
* @return the <b>AemSensorType</b> mnemonic mapped to the numeric
* value or UNDEFINED if value is undefined.
*/
public static AemSensorType valueOf(int value) {
if (lookup.containsKey(value)) {
return lookup.get(value);
}
else return UNDEFINED;
}
}

View File

@ -49,4 +49,19 @@ public final class AemConnectionProperties implements ConnectionProperties {
public int getSendTimeout() {
return 500;
}
public String toString() {
final String properties = String.format(
"%s[baudRate=%d, dataBits=%d, stopBits=%d, parity=%d, " +
"connectTimeout=%d, sendTimeout=%d]",
getClass().getSimpleName(),
getBaudRate(),
getDataBits(),
getStopBits(),
getParity(),
getConnectTimeout(),
getSendTimeout()
);
return properties;
}
}

View File

@ -30,6 +30,7 @@ import static org.apache.log4j.Logger.getLogger;
public final class AemRunner implements Stoppable {
private static final Logger LOGGER = getLogger(AemRunner.class);
private static final AemConnectionProperties CONNECTION_PROPS = new AemConnectionProperties();
private static final String TAB = "\t";
private final SerialConnection connection;
private final AemDataItem dataItem;
private boolean stop;
@ -42,10 +43,11 @@ public final class AemRunner implements Stoppable {
public void run() {
try {
while (!stop) {
String response = connection.readLine();
final String response = connection.readLine();
LOGGER.trace("AEM UEGO Lambda Response: " + response);
if (!isNullOrEmpty(response)) dataItem.setData(parseString(response));
}
connection.close();
} catch (Throwable t) {
LOGGER.error("Error occurred", t);
} finally {
@ -55,7 +57,6 @@ public final class AemRunner implements Stoppable {
public void stop() {
stop = true;
connection.close();
}
/*
@ -68,13 +69,14 @@ public final class AemRunner implements Stoppable {
* terminated with a carriage return and line feed. This should
* work for either case.
*/
private double parseString(String value){
try{
String[] substr = value.split("\t");
return Double.parseDouble(substr[0]);
}
catch (Exception e){
return 0.0;
}
}
private double parseString(String value){
try{
final String[] substr = value.split(TAB);
final double result = Double.parseDouble(substr[0]);
return result;
}
catch (Exception e){
return 0.0;
}
}
}

View File

@ -101,8 +101,8 @@ public final class GenericDataSourceManager implements ExternalDataSource {
}
private void reconnect(String port) {
dataSource.setPort(port);
doDisconnect();
dataSource.setPort(port);
doConnect();
}
}

View File

@ -49,4 +49,19 @@ public final class NawConnectionProperties implements ConnectionProperties {
public int getSendTimeout() {
return 500;
}
public String toString() {
final String properties = String.format(
"%s[baudRate=%d, dataBits=%d, stopBits=%d, parity=%d, " +
"connectTimeout=%d, sendTimeout=%d]",
getClass().getSimpleName(),
getBaudRate(),
getDataBits(),
getStopBits(),
getParity(),
getConnectTimeout(),
getSendTimeout()
);
return properties;
}
}

View File

@ -40,9 +40,10 @@ public final class NawRunner implements Stoppable {
try {
while (!stop) {
connection.write(NAW_PROMPT);
byte[] buffer = connection.readBytes();
final byte[] buffer = connection.readBytes();
listener.setBytes(buffer);
}
connection.close();
} catch (Throwable t) {
LOGGER.error("Error occurred", t);
} finally {
@ -52,6 +53,5 @@ public final class NawRunner implements Stoppable {
public void stop() {
stop = true;
connection.close();
}
}

View File

@ -50,4 +50,19 @@ public final class InnovateConnectionProperties implements ConnectionProperties
// innovate specifies 82 but this isn't enough...
return 200;
}
public String toString() {
final String properties = String.format(
"%s[baudRate=%d, dataBits=%d, stopBits=%d, parity=%d, " +
"connectTimeout=%d, sendTimeout=%d]",
getClass().getSimpleName(),
getBaudRate(),
getDataBits(),
getStopBits(),
getParity(),
getConnectTimeout(),
getSendTimeout()
);
return properties;
}
}

View File

@ -83,6 +83,7 @@ public final class InnovateRunner implements Stoppable {
LOGGER.trace("Innovate discarded: " + asHex(b0));
}
}
connection.close();
} catch (Throwable t) {
LOGGER.error("Error occurred", t);
} finally {
@ -92,7 +93,6 @@ public final class InnovateRunner implements Stoppable {
public void stop() {
stop = true;
connection.close();
}
private void process(byte[] bytes) {

View File

@ -49,4 +49,19 @@ public final class MrfConnectionProperties implements ConnectionProperties {
public int getSendTimeout() {
return 500;
}
}
public String toString() {
final String properties = String.format(
"%s[baudRate=%d, dataBits=%d, stopBits=%d, parity=%d, " +
"connectTimeout=%d, sendTimeout=%d]",
getClass().getSimpleName(),
getBaudRate(),
getDataBits(),
getStopBits(),
getParity(),
getConnectTimeout(),
getSendTimeout()
);
return properties;
}
}

View File

@ -54,6 +54,7 @@ public final class MrfRunner implements Stoppable {
if (dataItem != null) dataItem.setData(parseDouble(values[i]));
}
}
connection.close();
} catch (Throwable t) {
LOGGER.error("Error occurred", t);
} finally {
@ -63,7 +64,6 @@ public final class MrfRunner implements Stoppable {
public void stop() {
stop = true;
connection.close();
}
private double parseDouble(String value) {

View File

@ -49,4 +49,19 @@ public final class PlxConnectionProperties implements ConnectionProperties {
public int getSendTimeout() {
return 500;
}
}
public String toString() {
final String properties = String.format(
"%s[baudRate=%d, dataBits=%d, stopBits=%d, parity=%d, " +
"connectTimeout=%d, sendTimeout=%d]",
getClass().getSimpleName(),
getBaudRate(),
getDataBits(),
getStopBits(),
getParity(),
getConnectTimeout(),
getSendTimeout()
);
return properties;
}
}

View File

@ -53,6 +53,7 @@ public final class PlxRunner implements Stoppable {
item.setRaw(response.value);
}
}
connection.close();
} catch (Throwable t) {
LOGGER.error("Error occurred", t);
} finally {
@ -62,7 +63,6 @@ public final class PlxRunner implements Stoppable {
public void stop() {
stop = true;
connection.close();
}
private boolean isValid(PlxResponse response) {

View File

@ -49,4 +49,19 @@ public final class TEConnectionProperties implements ConnectionProperties {
public int getSendTimeout() {
return 500;
}
public String toString() {
final String properties = String.format(
"%s[baudRate=%d, dataBits=%d, stopBits=%d, parity=%d, " +
"connectTimeout=%d, sendTimeout=%d]",
getClass().getSimpleName(),
getBaudRate(),
getDataBits(),
getStopBits(),
getParity(),
getConnectTimeout(),
getSendTimeout()
);
return properties;
}
}

View File

@ -171,6 +171,7 @@ public final class TERunner implements Stoppable {
packetStarted = false;
}
}
connection.close();
}
catch (Throwable t) {
LOGGER.error("Error occurred", t);
@ -182,6 +183,5 @@ public final class TERunner implements Stoppable {
public void stop() {
stop = true;
connection.close();
}
}

View File

@ -48,4 +48,19 @@ public final class TxsConnectionProperties implements ConnectionProperties {
public int getSendTimeout() {
return 500;
}
public String toString() {
final String properties = String.format(
"%s[baudRate=%d, dataBits=%d, stopBits=%d, parity=%d, " +
"connectTimeout=%d, sendTimeout=%d]",
getClass().getSimpleName(),
getBaudRate(),
getDataBits(),
getStopBits(),
getParity(),
getConnectTimeout(),
getSendTimeout()
);
return properties;
}
}

View File

@ -97,6 +97,7 @@ public final class TxsRunner implements Stoppable{
//Set Data Item Values
SetDataItemValues(values);
}
connection.close();
}
catch (Throwable t) {
LOGGER.error("Error occurred", t);
@ -108,7 +109,6 @@ public final class TxsRunner implements Stoppable{
public void stop() {
stop = true;
connection.close();
}
private String[] SplitUtecString(String value) {

View File

@ -49,4 +49,19 @@ public final class ZT2ConnectionProperties implements ConnectionProperties {
public int getSendTimeout() {
return 500;
}
public String toString() {
final String properties = String.format(
"%s[baudRate=%d, dataBits=%d, stopBits=%d, parity=%d, " +
"connectTimeout=%d, sendTimeout=%d]",
getClass().getSimpleName(),
getBaudRate(),
getDataBits(),
getStopBits(),
getParity(),
getConnectTimeout(),
getSendTimeout()
);
return properties;
}
}

View File

@ -123,6 +123,7 @@ public final class ZT2Runner implements Stoppable {
packetStarted = false;
}
}
connection.close();
} catch (Throwable t) {
LOGGER.error("ZT2 error occurred", t);
} finally {
@ -132,6 +133,5 @@ public final class ZT2Runner implements Stoppable {
public void stop() {
stop = true;
connection.close();
}
}

View File

@ -53,6 +53,7 @@
<file src="plugins/aem.plugin" targetdir="$INSTALL_PATH/plugins"/>
<file src="plugins/aem2.plugin" targetdir="$INSTALL_PATH/plugins"/>
<file src="plugins/aem.xwifi.plugin" targetdir="$INSTALL_PATH/plugins"/>
<file src="plugins/fourteenpoint7.plugin" targetdir="$INSTALL_PATH/plugins"/>
<file src="plugins/innovate.plugin" targetdir="$INSTALL_PATH/plugins"/>
<file src="plugins/mrf.plugin" targetdir="$INSTALL_PATH/plugins"/>
@ -68,6 +69,7 @@
<include name="plugins/**"/>
<exclude name="plugins/aem.plugin"/>
<exclude name="plugins/aem2.plugin"/>
<exclude name="plugins/aem.xwifi.plugin"/>
<exclude name="plugins/fourteenpoint7.plugin"/>
<exclude name="plugins/innovate.plugin"/>
<exclude name="plugins/mrf.plugin"/>

View File

@ -54,6 +54,7 @@
<file src="plugins/aem.plugin" targetdir="$INSTALL_PATH/plugins"/>
<file src="plugins/aem2.plugin" targetdir="$INSTALL_PATH/plugins"/>
<file src="plugins/aem.xwifi.plugin" targetdir="$INSTALL_PATH/plugins"/>
<file src="plugins/fourteenpoint7.plugin" targetdir="$INSTALL_PATH/plugins"/>
<file src="plugins/innovate.plugin" targetdir="$INSTALL_PATH/plugins"/>
<file src="plugins/lm2_mts.plugin" targetdir="$INSTALL_PATH/plugins"/>
@ -70,6 +71,7 @@
<include name="plugins/**"/>
<exclude name="plugins/aem.plugin"/>
<exclude name="plugins/aem2.plugin"/>
<exclude name="plugins/aem.xwifi.plugin"/>
<exclude name="plugins/fourteenpoint7.plugin"/>
<exclude name="plugins/innovate.plugin"/>
<exclude name="plugins/lm2_mts.plugin"/>