logging improvement
This commit is contained in:
parent
9b3b27c37e
commit
4b9157d804
|
@ -25,8 +25,6 @@ import static com.devexperts.logging.Logging.getLogging;
|
||||||
* 5/11/2015.
|
* 5/11/2015.
|
||||||
*/
|
*/
|
||||||
public interface IoStream extends WriteStream, Closeable, StreamStatistics {
|
public interface IoStream extends WriteStream, Closeable, StreamStatistics {
|
||||||
Logging log = getLogging(IoStream.class);
|
|
||||||
|
|
||||||
static String printHexBinary(byte[] data) {
|
static String printHexBinary(byte[] data) {
|
||||||
if (data == null)
|
if (data == null)
|
||||||
return "(null)";
|
return "(null)";
|
||||||
|
|
|
@ -12,7 +12,7 @@ public abstract class IsoTpConnector {
|
||||||
public static void sendStrategy(byte[] bytes, IsoTpConnector connector) {
|
public static void sendStrategy(byte[] bytes, IsoTpConnector connector) {
|
||||||
log.info("-------sendBytesToCan " + bytes.length + " byte(s):");
|
log.info("-------sendBytesToCan " + bytes.length + " byte(s):");
|
||||||
|
|
||||||
System.out.println(IoStream.printHexBinary(bytes));
|
log.info(IoStream.printHexBinary(bytes));
|
||||||
|
|
||||||
|
|
||||||
// 1 frame
|
// 1 frame
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.rusefi.io.serial;
|
package com.rusefi.io.serial;
|
||||||
|
|
||||||
|
import com.devexperts.logging.Logging;
|
||||||
import com.fazecast.jSerialComm.SerialPort;
|
import com.fazecast.jSerialComm.SerialPort;
|
||||||
import com.fazecast.jSerialComm.SerialPortDataListener;
|
import com.fazecast.jSerialComm.SerialPortDataListener;
|
||||||
import com.fazecast.jSerialComm.SerialPortEvent;
|
import com.fazecast.jSerialComm.SerialPortEvent;
|
||||||
|
@ -8,7 +9,11 @@ import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||||
import com.rusefi.io.IoStream;
|
import com.rusefi.io.IoStream;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import static com.devexperts.logging.Logging.getLogging;
|
||||||
|
|
||||||
public class SerialIoStream extends AbstractIoStream {
|
public class SerialIoStream extends AbstractIoStream {
|
||||||
|
static Logging log = getLogging(SerialIoStream.class);
|
||||||
|
|
||||||
protected final SerialPort sp;
|
protected final SerialPort sp;
|
||||||
protected final String port;
|
protected final String port;
|
||||||
private boolean withListener;
|
private boolean withListener;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.rusefi.io.stream;
|
package com.rusefi.io.stream;
|
||||||
|
|
||||||
|
import com.devexperts.logging.Logging;
|
||||||
import com.opensr5.io.DataListener;
|
import com.opensr5.io.DataListener;
|
||||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||||
import com.rusefi.config.generated.Fields;
|
import com.rusefi.config.generated.Fields;
|
||||||
|
@ -15,9 +16,12 @@ import java.io.IOException;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import static com.devexperts.logging.Logging.getLogging;
|
||||||
import static peak.can.basic.TPCANMessageType.PCAN_MESSAGE_STANDARD;
|
import static peak.can.basic.TPCANMessageType.PCAN_MESSAGE_STANDARD;
|
||||||
|
|
||||||
public class PCanIoStream extends AbstractIoStream {
|
public class PCanIoStream extends AbstractIoStream {
|
||||||
|
static Logging log = getLogging(PCanIoStream.class);
|
||||||
|
|
||||||
public static final TPCANHandle CHANNEL = TPCANHandle.PCAN_USBBUS1;
|
public static final TPCANHandle CHANNEL = TPCANHandle.PCAN_USBBUS1;
|
||||||
private final IncomingDataBuffer dataBuffer;
|
private final IncomingDataBuffer dataBuffer;
|
||||||
private final PCANBasic can;
|
private final PCANBasic can;
|
||||||
|
@ -37,7 +41,7 @@ public class PCanIoStream extends AbstractIoStream {
|
||||||
|
|
||||||
log.info("-------sendIsoTp " + total.length + " byte(s):");
|
log.info("-------sendIsoTp " + total.length + " byte(s):");
|
||||||
|
|
||||||
log.info(IoStream.printHexBinary(total));
|
log.info("Sending " + IoStream.printHexBinary(total));
|
||||||
|
|
||||||
sendCanPacket(total);
|
sendCanPacket(total);
|
||||||
}
|
}
|
||||||
|
@ -56,7 +60,7 @@ public class PCanIoStream extends AbstractIoStream {
|
||||||
log.info("Error initializing PCAN: " + status);
|
log.info("Error initializing PCAN: " + status);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
System.out.println("Hello PCAN!");
|
log.info("Hello PCAN!");
|
||||||
return new PCanIoStream(can);
|
return new PCanIoStream(can);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,13 +103,13 @@ public class PCanIoStream extends AbstractIoStream {
|
||||||
TPCANMsg rx = new TPCANMsg();
|
TPCANMsg rx = new TPCANMsg();
|
||||||
TPCANStatus status = can.Read(CHANNEL, rx, null);
|
TPCANStatus status = can.Read(CHANNEL, rx, null);
|
||||||
if (status == TPCANStatus.PCAN_ERROR_OK) {
|
if (status == TPCANStatus.PCAN_ERROR_OK) {
|
||||||
log.info(rx + " id=" + rx.getID() + " len=" + rx.getLength() + ": " + IoStream.printByteArray(rx.getData()));
|
log.info("Got [" + rx + "] id=" + rx.getID() + " len=" + rx.getLength() + ": " + IoStream.printByteArray(rx.getData()));
|
||||||
byte[] decode = canDecoder.decodePacket(rx.getData());
|
byte[] decode = canDecoder.decodePacket(rx.getData());
|
||||||
listener.onDataArrived(decode);
|
listener.onDataArrived(decode);
|
||||||
|
|
||||||
// System.out.println("Decoded " + IoStream.printByteArray(decode));
|
// log.info("Decoded " + IoStream.printByteArray(decode));
|
||||||
} else {
|
} else {
|
||||||
// System.out.println(new Date() + ": Receive " + status);
|
// log.info("Receive " + status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.rusefi.binaryprotocol.test;
|
package com.rusefi.binaryprotocol.test;
|
||||||
|
|
||||||
|
import com.devexperts.logging.Logging;
|
||||||
import com.opensr5.ConfigurationImage;
|
import com.opensr5.ConfigurationImage;
|
||||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||||
import com.rusefi.binaryprotocol.BinaryProtocolState;
|
import com.rusefi.binaryprotocol.BinaryProtocolState;
|
||||||
|
@ -16,7 +17,11 @@ import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import static com.devexperts.logging.Logging.getLogging;
|
||||||
|
|
||||||
public class SandboxCommon {
|
public class SandboxCommon {
|
||||||
|
private static final Logging log = getLogging(SandboxCommon.class);
|
||||||
|
|
||||||
static ConfigurationImage readImage(IoStream tsStream, LinkManager linkManager) throws InterruptedException {
|
static ConfigurationImage readImage(IoStream tsStream, LinkManager linkManager) throws InterruptedException {
|
||||||
AtomicReference<ConfigurationImage> configurationImageAtomicReference = new AtomicReference<>();
|
AtomicReference<ConfigurationImage> configurationImageAtomicReference = new AtomicReference<>();
|
||||||
CountDownLatch imageLatch = new CountDownLatch(1);
|
CountDownLatch imageLatch = new CountDownLatch(1);
|
||||||
|
@ -26,11 +31,11 @@ public class SandboxCommon {
|
||||||
streamConnector.connectAndReadConfiguration(new BinaryProtocol.Arguments(false), new ConnectionStateListener() {
|
streamConnector.connectAndReadConfiguration(new BinaryProtocol.Arguments(false), new ConnectionStateListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionEstablished() {
|
public void onConnectionEstablished() {
|
||||||
System.out.println("onConnectionEstablished");
|
log.info("onConnectionEstablished");
|
||||||
|
|
||||||
BinaryProtocol currentStreamState = linkManager.getCurrentStreamState();
|
BinaryProtocol currentStreamState = linkManager.getCurrentStreamState();
|
||||||
if (currentStreamState == null) {
|
if (currentStreamState == null) {
|
||||||
System.out.println("No BinaryProtocol");
|
log.info("No BinaryProtocol");
|
||||||
} else {
|
} else {
|
||||||
BinaryProtocolState binaryProtocolState = currentStreamState.getBinaryProtocolState();
|
BinaryProtocolState binaryProtocolState = currentStreamState.getBinaryProtocolState();
|
||||||
ConfigurationImage ci = binaryProtocolState.getControllerConfiguration();
|
ConfigurationImage ci = binaryProtocolState.getControllerConfiguration();
|
||||||
|
@ -41,13 +46,13 @@ public class SandboxCommon {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionFailed() {
|
public void onConnectionFailed() {
|
||||||
System.out.println("onConnectionFailed");
|
log.info("onConnectionFailed");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
imageLatch.await(1, TimeUnit.MINUTES);
|
imageLatch.await(1, TimeUnit.MINUTES);
|
||||||
ConfigurationImage ci = configurationImageAtomicReference.get();
|
ConfigurationImage ci = configurationImageAtomicReference.get();
|
||||||
System.out.println("Got ConfigurationImage " + ci + ", " + ci.getSize());
|
log.info("Got ConfigurationImage " + ci + ", " + ci.getSize());
|
||||||
return ci;
|
return ci;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +60,7 @@ public class SandboxCommon {
|
||||||
BinaryProtocol bp = new BinaryProtocol(linkManager, tsStream);
|
BinaryProtocol bp = new BinaryProtocol(linkManager, tsStream);
|
||||||
linkManager.COMMUNICATION_EXECUTOR.submit(() -> {
|
linkManager.COMMUNICATION_EXECUTOR.submit(() -> {
|
||||||
if (tsStream.getDataBuffer().dropPending() != 0)
|
if (tsStream.getDataBuffer().dropPending() != 0)
|
||||||
System.out.println("ERROR Extra data before CRC");
|
log.info("ERROR Extra data before CRC");
|
||||||
bp.getCrcFromController(Fields.TOTAL_CONFIG_SIZE);
|
bp.getCrcFromController(Fields.TOTAL_CONFIG_SIZE);
|
||||||
// bp.getCrcFromController(Fields.TOTAL_CONFIG_SIZE);
|
// bp.getCrcFromController(Fields.TOTAL_CONFIG_SIZE);
|
||||||
// bp.getCrcFromController(Fields.TOTAL_CONFIG_SIZE);
|
// bp.getCrcFromController(Fields.TOTAL_CONFIG_SIZE);
|
||||||
|
@ -66,7 +71,7 @@ public class SandboxCommon {
|
||||||
|
|
||||||
static void verifySignature(IoStream tsStream, String prefix, String suffix) throws IOException {
|
static void verifySignature(IoStream tsStream, String prefix, String suffix) throws IOException {
|
||||||
String signature = BinaryProtocol.getSignature(tsStream);
|
String signature = BinaryProtocol.getSignature(tsStream);
|
||||||
System.out.println(prefix + "Got " + signature + " signature via " + suffix);
|
log.info(prefix + "Got " + signature + " signature via " + suffix);
|
||||||
if (signature == null || !signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX))
|
if (signature == null || !signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX))
|
||||||
throw new IllegalStateException("Unexpected S " + signature);
|
throw new IllegalStateException("Unexpected S " + signature);
|
||||||
}
|
}
|
||||||
|
@ -78,7 +83,7 @@ public class SandboxCommon {
|
||||||
byte[] fResponse = new byte[3];
|
byte[] fResponse = new byte[3];
|
||||||
dataBuffer.waitForBytes("hello", System.currentTimeMillis(), fResponse.length);
|
dataBuffer.waitForBytes("hello", System.currentTimeMillis(), fResponse.length);
|
||||||
dataBuffer.getData(fResponse);
|
dataBuffer.getData(fResponse);
|
||||||
System.out.println(prefix + " Got F response " + IoStream.printByteArray(fResponse));
|
log.info(prefix + " Got F response " + IoStream.printByteArray(fResponse));
|
||||||
if (fResponse[0] != '0' || fResponse[1] != '0' || fResponse[2] != '1')
|
if (fResponse[0] != '0' || fResponse[1] != '0' || fResponse[2] != '1')
|
||||||
throw new IllegalStateException("Unexpected TS_COMMAND_F response " + Arrays.toString(fResponse));
|
throw new IllegalStateException("Unexpected TS_COMMAND_F response " + Arrays.toString(fResponse));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue