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.SerialConnectionImpl;
|
||||
import enginuity.logger.ecu.exception.SerialCommunicationException;
|
||||
import static enginuity.util.HexUtil.asHex;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
||||
import static enginuity.util.ThreadUtil.sleep;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class AemConnectionImpl implements AemConnection {
|
||||
private static final Logger LOGGER = Logger.getLogger(AemConnectionImpl.class);
|
||||
private final long sendTimeout;
|
||||
|
@ -21,24 +26,30 @@ public final class AemConnectionImpl implements AemConnection {
|
|||
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() {
|
||||
try {
|
||||
byte[] response = new byte[6];
|
||||
// serialConnection.readStaleData();
|
||||
// long timeout = sendTimeout;
|
||||
// while (serialConnection.available() < response.length) {
|
||||
// sleep(1);
|
||||
// timeout -= 1;
|
||||
// if (timeout < 0) {
|
||||
// byte[] badBytes = new byte[serialConnection.available()];
|
||||
// serialConnection.read(badBytes);
|
||||
// LOGGER.debug("Bad response (read timeout): " + asHex(badBytes));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
serialConnection.read(response);
|
||||
return response;
|
||||
List<Byte> buffer = new ArrayList<Byte>();
|
||||
serialConnection.readStaleData();
|
||||
long start = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - start <= sendTimeout) {
|
||||
byte[] bytes = serialConnection.readAvailable();
|
||||
if (bytes.length > 0) {
|
||||
for (byte b : bytes) {
|
||||
if (b == (byte) 0x0D) {
|
||||
byte[] response = toArray(buffer);
|
||||
LOGGER.trace("AEM UEGO Response: " + asHex(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) {
|
||||
close();
|
||||
throw new SerialCommunicationException(e);
|
||||
|
@ -49,4 +60,12 @@ public final class AemConnectionImpl implements AemConnection {
|
|||
serialConnection.close();
|
||||
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;
|
||||
|
||||
import enginuity.util.HexUtil;
|
||||
import static enginuity.util.HexUtil.asHex;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public final class AemConvertorImpl implements AemConvertor {
|
||||
private static final Logger LOGGER = Logger.getLogger(AemConvertorImpl.class);
|
||||
|
||||
public double convert(byte[] bytes) {
|
||||
// TODO: Finish me!!
|
||||
LOGGER.debug("AEM bytes = " + HexUtil.asHex(bytes));
|
||||
return 0;
|
||||
String value = new String(bytes);
|
||||
double result = convert(value);
|
||||
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();
|
||||
while (serialConnection.available() < response.length) {
|
||||
if (System.currentTimeMillis() - start > sendTimeout) {
|
||||
byte[] badBytes = new byte[serialConnection.available()];
|
||||
serialConnection.read(badBytes);
|
||||
byte[] badBytes = serialConnection.readAvailable();
|
||||
LOGGER.warn("LC-1 Response [read timeout]: " + asHex(badBytes));
|
||||
return badBytes;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue