rusEFI console ISO-TP via PCAN #3667

WOW, YES!!!
This commit is contained in:
rusefillc 2021-12-08 19:01:44 -05:00
parent 574d09e29e
commit f65907a192
7 changed files with 63 additions and 29 deletions

View File

@ -29,7 +29,8 @@ All notable user-facing or behavior-altering changes will be documented in this
## Added
- Improved vehicle speed sensor configuration: now uses real physical constants about tires, gear ratio, sensor, etc.
- Improved priming logic. Now includes a table of priming fuel mass vs. engine temperature, in addition to a delay before priming to allow fuel pressure to build.
- Improved priming logic. Now includes a table of priming fuel mass vs. engine temperature, in addition to a delay before priming to allow fuel pressure to build. #3674
- ISO-TP connector in firmware & ISO-TP to TCP/IP bridge in rusEFI console #3667
### Fixed
- Faster engine sync + startup on engines with crank-speed primary trigger

View File

@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Launcher pcan_connector" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="com.rusefi.Launcher" />
<module name="ui" />
<option name="PROGRAM_PARAMETERS" value="pcan_connector" />
<option name="VM_PARAMETERS" value="-Dini_file_path=../firmware/tunerstudio -Dshow_etb_pane=true -Dhigh_speed_logger_rpm=10000" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

View File

@ -1,4 +1,4 @@
package com.rusefi.binaryprotocol.test;
package com.rusefi.io.stream;
import com.opensr5.io.DataListener;
import com.rusefi.binaryprotocol.IncomingDataBuffer;
@ -8,9 +8,8 @@ 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 peak.can.basic.PCANBasic;
import peak.can.basic.TPCANMsg;
import peak.can.basic.TPCANStatus;
import org.jetbrains.annotations.Nullable;
import peak.can.basic.*;
import java.io.IOException;
import java.util.concurrent.Executor;
@ -19,6 +18,7 @@ import java.util.concurrent.Executors;
import static peak.can.basic.TPCANMessageType.PCAN_MESSAGE_STANDARD;
public class PCanIoStream extends AbstractIoStream {
public static final TPCANHandle CHANNEL = TPCANHandle.PCAN_USBBUS1;
private final IncomingDataBuffer dataBuffer;
private final PCANBasic can;
private final IsoTpCanDecoder canDecoder = new IsoTpCanDecoder() {
@ -47,10 +47,23 @@ public class PCanIoStream extends AbstractIoStream {
}
};
@Nullable
public static PCanIoStream getPCANIoStream() {
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) {
System.err.println("Error initializing PCAN: " + status);
return null;
}
System.out.println("Hello PCAN!");
return new PCanIoStream(can);
}
private void sendCanPacket(byte[] payLoad) {
TPCANMsg msg = new TPCANMsg(Fields.CAN_ECU_SERIAL_RX_ID, PCAN_MESSAGE_STANDARD.getValue(),
(byte) payLoad.length, payLoad);
TPCANStatus status = can.Write(PCanSandbox.CHANNEL, msg);
TPCANStatus status = can.Write(CHANNEL, msg);
if (status != TPCANStatus.PCAN_ERROR_OK) {
System.out.println("Unable to write the CAN message: " + status);
System.exit(0);
@ -84,7 +97,7 @@ public class PCanIoStream extends AbstractIoStream {
public void readOnePacket() {
// todo: can we reuse instance?
TPCANMsg rx = new TPCANMsg();
TPCANStatus status = can.Read(PCanSandbox.CHANNEL, rx, null);
TPCANStatus status = can.Read(CHANNEL, rx, null);
if (status == TPCANStatus.PCAN_ERROR_OK) {
System.out.println(rx + " id=" + rx.getID() + " len=" + rx.getLength() + ": " + IoStream.printByteArray(rx.getData()));
byte[] decode = canDecoder.decodePacket(rx.getData());

View File

@ -1,13 +1,8 @@
package com.rusefi.binaryprotocol.test;
import com.opensr5.ConfigurationImage;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.binaryprotocol.BinaryProtocolState;
import com.rusefi.config.generated.Fields;
import com.rusefi.io.ConnectionStateListener;
import com.rusefi.io.LinkManager;
import com.rusefi.io.serial.StreamConnector;
import peak.can.basic.*;
import com.rusefi.io.stream.PCanIoStream;
import java.io.IOException;
@ -16,19 +11,10 @@ import java.io.IOException;
*/
public class PCanSandbox {
public static final TPCANHandle CHANNEL = TPCANHandle.PCAN_USBBUS1;
public static void main(String[] args) throws IOException, InterruptedException {
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) {
System.out.println("Error initializing PCAN: " + status);
return;
}
System.out.println("Hello PCAN " + can);
PCanIoStream tsStream = new PCanIoStream(can);
PCanIoStream tsStream = PCanIoStream.getPCANIoStream();
if (tsStream == null)
throw new IOException("No PCAN");
/*
for (int i = 0; i < 17; i++) {
@ -42,11 +28,15 @@ public class PCanSandbox {
System.out.println("****************************************");
*/
LinkManager linkManager = new LinkManager();
SandboxCommon.verifyCrcNoPending(tsStream, linkManager);
/*
for (int i = 0; i < 4; i++) {
SandboxCommon.verifyCrcNoPending(tsStream, linkManager);
}
*/
ConfigurationImage ci = SandboxCommon.readImage(tsStream, linkManager);
System.exit(0);
// System.out.println("We are done");
// System.exit(0);
}
}

View File

@ -6,7 +6,7 @@ import java.net.URL;
import java.util.concurrent.atomic.AtomicReference;
public class rusEFIVersion {
public static final int CONSOLE_VERSION = 20211206;
public static final int CONSOLE_VERSION = 20211208;
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
public static long classBuildTimeMillis() {

View File

@ -66,6 +66,7 @@ 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 -> PCANConnectorStartup.start(), "Connect your rusEFI ECU using ELM327 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.");

View File

@ -0,0 +1,18 @@
package com.rusefi.tools;
import com.rusefi.io.stream.PCanIoStream;
import com.rusefi.io.tcp.BinaryProtocolProxy;
import com.rusefi.io.tcp.TcpConnector;
import java.io.IOException;
public class PCANConnectorStartup {
public static void start() throws IOException {
PCanIoStream tsStream = PCanIoStream.getPCANIoStream();
if (tsStream == null)
throw new IOException("No PCAN");
BinaryProtocolProxy.createProxy(tsStream, TcpConnector.DEFAULT_PORT, BinaryProtocolProxy.ClientApplicationActivityListener.VOID);
}
}