mirror of https://github.com/rusefi/RomRaider.git
updated aem and lc-1 plugins
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@732 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
7b843df3b6
commit
ff3705939e
|
@ -4,10 +4,15 @@ import enginuity.io.connection.ConnectionProperties;
|
||||||
import enginuity.io.connection.SerialConnection;
|
import enginuity.io.connection.SerialConnection;
|
||||||
import enginuity.io.connection.SerialConnectionImpl;
|
import enginuity.io.connection.SerialConnectionImpl;
|
||||||
import enginuity.logger.ecu.exception.SerialCommunicationException;
|
import enginuity.logger.ecu.exception.SerialCommunicationException;
|
||||||
|
import static enginuity.util.HexUtil.asHex;
|
||||||
import static enginuity.util.ParamChecker.checkNotNull;
|
import static enginuity.util.ParamChecker.checkNotNull;
|
||||||
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
||||||
|
import static enginuity.util.ThreadUtil.sleep;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public final class AemConnectionImpl implements AemConnection {
|
public final class AemConnectionImpl implements AemConnection {
|
||||||
private static final Logger LOGGER = Logger.getLogger(AemConnectionImpl.class);
|
private static final Logger LOGGER = Logger.getLogger(AemConnectionImpl.class);
|
||||||
private final long sendTimeout;
|
private final long sendTimeout;
|
||||||
|
@ -21,24 +26,30 @@ public final class AemConnectionImpl implements AemConnection {
|
||||||
LOGGER.info("AEM connected");
|
LOGGER.info("AEM connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Update this for AEM...same as lc1 atm which won't work
|
//TODO: This a guess!!...untested!!
|
||||||
public byte[] read() {
|
public byte[] read() {
|
||||||
try {
|
try {
|
||||||
byte[] response = new byte[6];
|
List<Byte> buffer = new ArrayList<Byte>();
|
||||||
// serialConnection.readStaleData();
|
serialConnection.readStaleData();
|
||||||
// long timeout = sendTimeout;
|
long start = System.currentTimeMillis();
|
||||||
// while (serialConnection.available() < response.length) {
|
while (System.currentTimeMillis() - start <= sendTimeout) {
|
||||||
// sleep(1);
|
byte[] bytes = serialConnection.readAvailable();
|
||||||
// timeout -= 1;
|
if (bytes.length > 0) {
|
||||||
// if (timeout < 0) {
|
for (byte b : bytes) {
|
||||||
// byte[] badBytes = new byte[serialConnection.available()];
|
if (b == (byte) 0x0D) {
|
||||||
// serialConnection.read(badBytes);
|
byte[] response = toArray(buffer);
|
||||||
// LOGGER.debug("Bad response (read timeout): " + asHex(badBytes));
|
LOGGER.trace("AEM UEGO Response: " + asHex(response));
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
serialConnection.read(response);
|
|
||||||
return response;
|
return response;
|
||||||
|
} else {
|
||||||
|
buffer.add(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
byte[] badBytes = toArray(buffer);
|
||||||
|
LOGGER.warn("AEM UEGO Response [read timeout]: " + asHex(badBytes));
|
||||||
|
return badBytes;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
close();
|
close();
|
||||||
throw new SerialCommunicationException(e);
|
throw new SerialCommunicationException(e);
|
||||||
|
@ -49,4 +60,12 @@ public final class AemConnectionImpl implements AemConnection {
|
||||||
serialConnection.close();
|
serialConnection.close();
|
||||||
LOGGER.info("AEM disconnected");
|
LOGGER.info("AEM disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private byte[] toArray(List<Byte> buffer) {
|
||||||
|
byte[] result = new byte[buffer.size()];
|
||||||
|
for (int j = 0; j < buffer.size(); j++) {
|
||||||
|
result[j] = buffer.get(j);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,24 @@
|
||||||
package enginuity.logger.aem.plugin;
|
package enginuity.logger.aem.plugin;
|
||||||
|
|
||||||
import enginuity.util.HexUtil;
|
import static enginuity.util.HexUtil.asHex;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
public final class AemConvertorImpl implements AemConvertor {
|
public final class AemConvertorImpl implements AemConvertor {
|
||||||
private static final Logger LOGGER = Logger.getLogger(AemConvertorImpl.class);
|
private static final Logger LOGGER = Logger.getLogger(AemConvertorImpl.class);
|
||||||
|
|
||||||
public double convert(byte[] bytes) {
|
public double convert(byte[] bytes) {
|
||||||
// TODO: Finish me!!
|
String value = new String(bytes);
|
||||||
LOGGER.debug("AEM bytes = " + HexUtil.asHex(bytes));
|
double result = convert(value);
|
||||||
return 0;
|
LOGGER.debug("Converting AEM response: " + asHex(bytes) + " --> \"" + value + "\" --> " + result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double convert(String value) {
|
||||||
|
try {
|
||||||
|
return Double.valueOf(value);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
LOGGER.error("Error converting AEM response to double: \"" + value + "\"", e);
|
||||||
|
return -1.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,7 @@ public final class Lc1Connection implements InnovateConnection {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
while (serialConnection.available() < response.length) {
|
while (serialConnection.available() < response.length) {
|
||||||
if (System.currentTimeMillis() - start > sendTimeout) {
|
if (System.currentTimeMillis() - start > sendTimeout) {
|
||||||
byte[] badBytes = new byte[serialConnection.available()];
|
byte[] badBytes = serialConnection.readAvailable();
|
||||||
serialConnection.read(badBytes);
|
|
||||||
LOGGER.warn("LC-1 Response [read timeout]: " + asHex(badBytes));
|
LOGGER.warn("LC-1 Response [read timeout]: " + asHex(badBytes));
|
||||||
return badBytes;
|
return badBytes;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue