mirror of https://github.com/rusefi/rusefi.git
expanding status API
This commit is contained in:
parent
c6f0b92883
commit
7035cc93e5
|
@ -9,6 +9,7 @@ import com.rusefi.io.can.IsoTpCanDecoder;
|
|||
import com.rusefi.io.can.IsoTpConnector;
|
||||
import com.rusefi.io.serial.AbstractIoStream;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
import com.rusefi.ui.StatusConsumer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import peak.can.basic.*;
|
||||
|
||||
|
@ -26,6 +27,7 @@ public class PCanIoStream extends AbstractIoStream {
|
|||
public static final TPCANHandle CHANNEL = TPCANHandle.PCAN_USBBUS1;
|
||||
private final IncomingDataBuffer dataBuffer = createDataBuffer("[PCAN] ");
|
||||
private final PCANBasic can;
|
||||
private final StatusConsumer statusListener;
|
||||
private final IsoTpCanDecoder canDecoder = new IsoTpCanDecoder() {
|
||||
@Override
|
||||
protected void onTpFirstFrame() {
|
||||
|
@ -48,15 +50,19 @@ public class PCanIoStream extends AbstractIoStream {
|
|||
|
||||
@Nullable
|
||||
public static PCanIoStream createStream() {
|
||||
return createStream(message -> log.info(message));
|
||||
}
|
||||
|
||||
public static PCanIoStream createStream(StatusConsumer statusListener) {
|
||||
PCANBasic can = new PCANBasic();
|
||||
can.initializeAPI();
|
||||
TPCANStatus status = can.Initialize(CHANNEL, TPCANBaudrate.PCAN_BAUD_500K, TPCANType.PCAN_TYPE_NONE, 0, (short) 0);
|
||||
if (status != TPCANStatus.PCAN_ERROR_OK) {
|
||||
log.info("Error initializing PCAN: " + status);
|
||||
statusListener.append("Error initializing PCAN: " + status);
|
||||
return null;
|
||||
}
|
||||
log.info("Hello PCAN!");
|
||||
return new PCanIoStream(can);
|
||||
statusListener.append("Hello PCAN!");
|
||||
return new PCanIoStream(can, statusListener);
|
||||
}
|
||||
|
||||
private void sendCanPacket(byte[] payLoad) {
|
||||
|
@ -70,14 +76,15 @@ public class PCanIoStream extends AbstractIoStream {
|
|||
(byte) payLoad.length, payLoad);
|
||||
TPCANStatus status = can.Write(CHANNEL, msg);
|
||||
if (status != TPCANStatus.PCAN_ERROR_OK) {
|
||||
log.info("Unable to write the CAN message: " + status);
|
||||
statusListener.append("Unable to write the CAN message: " + status);
|
||||
System.exit(0);
|
||||
}
|
||||
// log.info("Send OK! length=" + payLoad.length);
|
||||
}
|
||||
|
||||
public PCanIoStream(PCANBasic can) {
|
||||
private PCanIoStream(PCANBasic can, StatusConsumer statusListener) {
|
||||
this.can = can;
|
||||
this.statusListener = statusListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,24 +1,20 @@
|
|||
package com.rusefi.tools;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.io.serial.AbstractIoStream;
|
||||
import com.rusefi.io.tcp.BinaryProtocolProxy;
|
||||
import com.rusefi.io.tcp.TcpConnector;
|
||||
import com.rusefi.ui.StatusConsumer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
|
||||
public class CANConnectorStartup {
|
||||
private static final Logging log = getLogging(CANConnectorStartup.class);
|
||||
|
||||
public static void start(AbstractIoStream tsStream) throws IOException {
|
||||
public static void start(AbstractIoStream tsStream, StatusConsumer statusListener) throws IOException {
|
||||
if (tsStream == null)
|
||||
throw new IOException("Failed to initialise connector");
|
||||
|
||||
String signature = BinaryProtocol.getSignature(tsStream);
|
||||
log.info("Got [" + signature + "] signature via " + tsStream);
|
||||
statusListener.append("Got [" + signature + "] signature via " + tsStream);
|
||||
|
||||
BinaryProtocolProxy.createProxy(tsStream, TcpConnector.DEFAULT_PORT, BinaryProtocolProxy.ClientApplicationActivityListener.VOID);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.tools;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.opensr5.ini.IniFileModel;
|
||||
import com.opensr5.io.ConfigurationImageFile;
|
||||
|
@ -27,6 +28,7 @@ import com.rusefi.proxy.client.LocalApplicationProxy;
|
|||
import com.rusefi.tools.online.Online;
|
||||
import com.rusefi.tune.xml.Msq;
|
||||
import com.rusefi.ui.AuthTokenPanel;
|
||||
import com.rusefi.ui.StatusConsumer;
|
||||
import com.rusefi.ui.light.LightweightGUI;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -38,6 +40,7 @@ import java.util.Map;
|
|||
import java.util.TreeMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
import static com.rusefi.binaryprotocol.BinaryProtocol.sleep;
|
||||
import static com.rusefi.binaryprotocol.IoHelper.getCrc32;
|
||||
|
||||
|
@ -48,6 +51,14 @@ public class ConsoleTools {
|
|||
|
||||
private static final Map<String, String> toolsHelp = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
private static final StatusConsumer statusListener = new StatusConsumer() {
|
||||
final Logging log = getLogging(CANConnectorStartup.class);
|
||||
@Override
|
||||
public void append(String message) {
|
||||
log.info(message);
|
||||
}
|
||||
};
|
||||
|
||||
static {
|
||||
registerTool("help", args -> printTools(), "Print this help.");
|
||||
registerTool("headless", ConsoleTools::runHeadless, "Connect to rusEFI controller and start saving logs.");
|
||||
|
@ -63,9 +74,13 @@ public class ConsoleTools {
|
|||
registerTool("network_connector", strings -> NetworkConnectorStartup.start(), "Connect your rusEFI ECU to rusEFI Online");
|
||||
registerTool("network_authenticator", strings -> LocalApplicationProxy.start(), "rusEFI Online Authenticator");
|
||||
registerTool("elm327_connector", strings -> Elm327ConnectorStartup.start(), "Connect your rusEFI ECU using ELM327 CAN-bus adapter");
|
||||
registerTool("pcan_connector", strings -> CANConnectorStartup.start(PCanIoStream.createStream()), "Connect your rusEFI ECU using PCAN CAN-bus adapter");
|
||||
registerTool("pcan_connector", strings -> {
|
||||
|
||||
PCanIoStream stream = PCanIoStream.createStream();
|
||||
CANConnectorStartup.start(stream, statusListener);
|
||||
}, "Connect your rusEFI ECU using PCAN CAN-bus adapter");
|
||||
if (!FileLog.isWindows()) {
|
||||
registerTool("socketcan_connector", strings -> CANConnectorStartup.start(SocketCANIoStream.create()), "Connect your rusEFI ECU using SocketCAN CAN-bus adapter");
|
||||
registerTool("socketcan_connector", strings -> CANConnectorStartup.start(SocketCANIoStream.create(), statusListener), "Connect your rusEFI ECU using SocketCAN CAN-bus adapter");
|
||||
}
|
||||
registerTool("print_auth_token", args -> printAuthToken(), "Print current rusEFI Online authentication token.");
|
||||
registerTool("print_vehicle_token", args -> printVehicleToken(), "Prints vehicle access token.");
|
||||
|
|
Loading…
Reference in New Issue