Add sendToLogger parameter (#6699)
This commit is contained in:
parent
a58876edd3
commit
ff59dca8d3
|
@ -1,18 +1,18 @@
|
||||||
package com.rusefi.io;
|
package com.rusefi.io;
|
||||||
|
|
||||||
public interface UpdateOperationCallbacks {
|
public interface UpdateOperationCallbacks {
|
||||||
void log(String message, boolean breakLineOnTextArea);
|
void log(String message, boolean breakLineOnTextArea, boolean sendToLogger);
|
||||||
|
|
||||||
default void logLine(final String message) {
|
default void logLine(final String message) {
|
||||||
log(message, true);
|
log(message, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void append(final String message, final boolean breakLineOnTextArea) {
|
default void append(final String message, final boolean breakLineOnTextArea, final boolean sendToLogger) {
|
||||||
log(message, breakLineOnTextArea);
|
log(message, breakLineOnTextArea, sendToLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void appendLine(final String message) {
|
default void appendLine(final String message) {
|
||||||
append(message, true);
|
append(message, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void done();
|
void done();
|
||||||
|
@ -20,7 +20,7 @@ public interface UpdateOperationCallbacks {
|
||||||
|
|
||||||
class UpdateOperationDummy implements UpdateOperationCallbacks {
|
class UpdateOperationDummy implements UpdateOperationCallbacks {
|
||||||
@Override
|
@Override
|
||||||
public void log(final String message, final boolean breakLineOnTextArea) {
|
public void log(final String message, final boolean breakLineOnTextArea, boolean sendToLogger) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -48,8 +48,10 @@ public class PCanIoStream extends AbstractIoStream {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static PCanIoStream createStream() {
|
public static PCanIoStream createStream() {
|
||||||
return createStream((message, breakLineOnTextArea) -> {
|
return createStream((message, breakLineOnTextArea, sendToLogger) -> {
|
||||||
log.info(message);
|
if (sendToLogger) {
|
||||||
|
log.info(message);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,10 +59,10 @@ public class PCanIoStream extends AbstractIoStream {
|
||||||
PCANBasic can = PCanHelper.create();
|
PCANBasic can = PCanHelper.create();
|
||||||
TPCANStatus status = PCanHelper.init(can);
|
TPCANStatus status = PCanHelper.init(can);
|
||||||
if (status != TPCANStatus.PCAN_ERROR_OK) {
|
if (status != TPCANStatus.PCAN_ERROR_OK) {
|
||||||
statusListener.append("Error initializing PCAN: " + status, true);
|
statusListener.append("Error initializing PCAN: " + status, true, true);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
statusListener.append("Creating PCAN stream...", true);
|
statusListener.append("Creating PCAN stream...", true, true);
|
||||||
return new PCanIoStream(can, statusListener);
|
return new PCanIoStream(can, statusListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +75,7 @@ public class PCanIoStream extends AbstractIoStream {
|
||||||
|
|
||||||
TPCANStatus status = PCanHelper.send(can, isoTpConnector.canId(), payLoad);
|
TPCANStatus status = PCanHelper.send(can, isoTpConnector.canId(), payLoad);
|
||||||
if (status != TPCANStatus.PCAN_ERROR_OK) {
|
if (status != TPCANStatus.PCAN_ERROR_OK) {
|
||||||
statusListener.append("Unable to write the CAN message: " + status, true);
|
statusListener.append("Unable to write the CAN message: " + status, true, true);
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
// log.info("Send OK! length=" + payLoad.length);
|
// log.info("Send OK! length=" + payLoad.length);
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class BinaryProtocolProxy {
|
||||||
clientStream = new TcpIoStream("[[proxy]] ", clientSocket);
|
clientStream = new TcpIoStream("[[proxy]] ", clientSocket);
|
||||||
runProxy(targetEcuSocket, clientStream, clientApplicationActivityListener, USER_IO_TIMEOUT);
|
runProxy(targetEcuSocket, clientStream, clientApplicationActivityListener, USER_IO_TIMEOUT);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
statusConsumer.append("ERROR BinaryProtocolProxy::run " + e, true);
|
statusConsumer.append("ERROR BinaryProtocolProxy::run " + e, true, true);
|
||||||
close(clientStream);
|
close(clientStream);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class BinaryProtocolServer {
|
||||||
public static ServerSocketReference tcpServerSocket(int port, String threadName, CompatibleFunction<Socket, Runnable> socketRunnableFactory, Listener serverSocketCreationCallback, StatusConsumer statusConsumer) throws IOException {
|
public static ServerSocketReference tcpServerSocket(int port, String threadName, CompatibleFunction<Socket, Runnable> socketRunnableFactory, Listener serverSocketCreationCallback, StatusConsumer statusConsumer) throws IOException {
|
||||||
return tcpServerSocket(socketRunnableFactory, port, threadName, serverSocketCreationCallback, p -> {
|
return tcpServerSocket(socketRunnableFactory, port, threadName, serverSocketCreationCallback, p -> {
|
||||||
ServerSocket serverSocket = new ServerSocket(p);
|
ServerSocket serverSocket = new ServerSocket(p);
|
||||||
statusConsumer.append("ServerSocket " + p + " created. Feel free to point TS at IP Address 'localhost' port " + p, true);
|
statusConsumer.append("ServerSocket " + p + " created. Feel free to point TS at IP Address 'localhost' port " + p, true, true);
|
||||||
return serverSocket;
|
return serverSocket;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,13 @@ import static com.devexperts.logging.Logging.getLogging;
|
||||||
public interface StatusConsumer {
|
public interface StatusConsumer {
|
||||||
Logging log = getLogging(StatusConsumer.class);
|
Logging log = getLogging(StatusConsumer.class);
|
||||||
|
|
||||||
StatusConsumer ANONYMOUS = (status, breakLineOnTextArea) -> {
|
StatusConsumer ANONYMOUS = (status, breakLineOnTextArea, sendToLogger) -> {
|
||||||
log.info(status);
|
if (sendToLogger) {
|
||||||
|
log.info(status);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
StatusConsumer VOID = (status, breakLineOnTextArea) -> {
|
StatusConsumer VOID = (status, breakLineOnTextArea, sendToLogger) -> {
|
||||||
};
|
};
|
||||||
|
|
||||||
void append(String status, boolean breakLineOnTextArea);
|
void append(String status, boolean breakLineOnTextArea, boolean sendToLogger);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ public class UpdateStatusWindow extends StatusWindow implements UpdateOperationC
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void log(final String message, final boolean breakLineOnTextArea) {
|
public void log(final String message, final boolean breakLineOnTextArea, boolean sendToLogger) {
|
||||||
append(message, breakLineOnTextArea);
|
append(message, breakLineOnTextArea, sendToLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,9 +15,9 @@ public class CANConnectorStartup {
|
||||||
|
|
||||||
String signature = BinaryProtocol.getSignature(tsStream);
|
String signature = BinaryProtocol.getSignature(tsStream);
|
||||||
if (signature == null) {
|
if (signature == null) {
|
||||||
statusListener.append("Error: no ECU signature from " + tsStream, true);
|
statusListener.append("Error: no ECU signature from " + tsStream, true, true);
|
||||||
} else {
|
} else {
|
||||||
statusListener.append("Got [" + signature + "] ECU signature via " + tsStream, true);
|
statusListener.append("Got [" + signature + "] ECU signature via " + tsStream, true, true);
|
||||||
}
|
}
|
||||||
BinaryProtocolProxy.createProxy(tsStream, TcpConnector.DEFAULT_PORT, BinaryProtocolProxy.ClientApplicationActivityListener.VOID, statusListener);
|
BinaryProtocolProxy.createProxy(tsStream, TcpConnector.DEFAULT_PORT, BinaryProtocolProxy.ClientApplicationActivityListener.VOID, statusListener);
|
||||||
|
|
||||||
|
|
|
@ -56,8 +56,10 @@ public class ConsoleTools {
|
||||||
private static final StatusConsumer statusListener = new StatusConsumer() {
|
private static final StatusConsumer statusListener = new StatusConsumer() {
|
||||||
final Logging log = getLogging(CANConnectorStartup.class);
|
final Logging log = getLogging(CANConnectorStartup.class);
|
||||||
@Override
|
@Override
|
||||||
public void append(final String message, final boolean breakLineOnTextArea) {
|
public void append(final String message, final boolean breakLineOnTextArea, final boolean sendToLogger) {
|
||||||
log.info(message);
|
if (sendToLogger) {
|
||||||
|
log.info(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,10 @@ public class PcanConnectorUI {
|
||||||
JTextArea logTextArea = new JTextArea();
|
JTextArea logTextArea = new JTextArea();
|
||||||
panel.add(logTextArea, BorderLayout.CENTER);
|
panel.add(logTextArea, BorderLayout.CENTER);
|
||||||
|
|
||||||
StatusConsumer statusConsumer = (string, breakLineOnTextArea) -> SwingUtilities.invokeLater(() -> {
|
StatusConsumer statusConsumer = (string, breakLineOnTextArea, sendToLogger) -> SwingUtilities.invokeLater(() -> {
|
||||||
log.info(string);
|
if (sendToLogger) {
|
||||||
|
log.info(string);
|
||||||
|
}
|
||||||
String stringForTextArea = string;
|
String stringForTextArea = string;
|
||||||
if (breakLineOnTextArea) {
|
if (breakLineOnTextArea) {
|
||||||
stringForTextArea += "\r\n";
|
stringForTextArea += "\r\n";
|
||||||
|
@ -40,7 +42,7 @@ public class PcanConnectorUI {
|
||||||
if (stream != null)
|
if (stream != null)
|
||||||
CANConnectorStartup.start(stream, statusConsumer);
|
CANConnectorStartup.start(stream, statusConsumer);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
statusConsumer.append("Error " + e, true);
|
statusConsumer.append("Error " + e, true, true);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,8 @@ public class StatusWindow implements StatusConsumer, UpdateOperationCallbacks {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void log(final String message, final boolean breakLineOnTextArea) {
|
public void log(final String message, final boolean breakLineOnTextArea, final boolean sendToLogger) {
|
||||||
append(message, breakLineOnTextArea);
|
append(message, breakLineOnTextArea, sendToLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -93,11 +93,13 @@ public class StatusWindow implements StatusConsumer, UpdateOperationCallbacks {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void append(final String string, final boolean breakLineOnTextArea) {
|
public void append(final String string, final boolean breakLineOnTextArea, final boolean sendToLogger) {
|
||||||
// todo: check if AWT thread and do not invokeLater if already on AWT thread
|
// todo: check if AWT thread and do not invokeLater if already on AWT thread
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
String s = string.replaceAll(Character.toString((char) 219), "");
|
String s = string.replaceAll(Character.toString((char) 219), "");
|
||||||
log.info(s);
|
if (sendToLogger) {
|
||||||
|
log.info(s);
|
||||||
|
}
|
||||||
String stringForTestArea = s;
|
String stringForTestArea = s;
|
||||||
if (breakLineOnTextArea) {
|
if (breakLineOnTextArea) {
|
||||||
stringForTestArea += "\r\n";
|
stringForTestArea += "\r\n";
|
||||||
|
|
|
@ -8,6 +8,6 @@ import java.io.IOException;
|
||||||
public class PCanIoProxySandbox {
|
public class PCanIoProxySandbox {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
PCanIoStream stream = PCanIoStream.createStream();
|
PCanIoStream stream = PCanIoStream.createStream();
|
||||||
CANConnectorStartup.start(stream, status -> System.out.println("Status: " + status));
|
CANConnectorStartup.start(stream, (status, breakLineOnTextArea, sendToLogger) -> System.out.println("Status: " + status));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue