Socket can (#4126)
* Linux is asking for SocketCAN ISO-TP console connector #4123 * Linux is asking for SocketCAN ISO-TP console connector #4123 * gradle * Linux is asking for SocketCAN ISO-TP console connector #4123 Co-authored-by: rusefillc <sdfsdfqsf2334234234>
This commit is contained in:
parent
ae807e722a
commit
085d0d4941
|
@ -0,0 +1,18 @@
|
|||
<component name="libraryTable">
|
||||
<library name="javacan-core">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/javacan-core.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/slf4j-api.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/slf4j-simple.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/javacan-core-x86_64.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/JavaCAN-javacan.zip!/JavaCAN-javacan-3.2.0/core-test/src/main/java" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/JavaCAN-javacan.zip!/JavaCAN-javacan-3.2.0/core-test/src/test/java" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/JavaCAN-javacan.zip!/JavaCAN-javacan-3.2.0/core/src/main/java" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/JavaCAN-javacan.zip!/JavaCAN-javacan-3.2.0/epoll-test/src/test/java" />
|
||||
<root url="jar://$PROJECT_DIR$/lib/JavaCAN-javacan.zip!/JavaCAN-javacan-3.2.0/epoll/src/main/java" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
|
@ -0,0 +1,11 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Launcher socketcan_connector" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="com.rusefi.Launcher" />
|
||||
<module name="ui" />
|
||||
<option name="PROGRAM_PARAMETERS" value="elm327_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>
|
|
@ -3,6 +3,7 @@
|
|||
<property name="hw_tests" value="build_hw"/>
|
||||
<property name="jar_file" value="${jar_file_folder}/rusefi_console.jar"/>
|
||||
<property name="server_jar_file" value="${jar_file_folder}/rusefi_server.jar"/>
|
||||
|
||||
<resources id="libs">
|
||||
<string>lib/mockito-all-1.10.19.jar</string>
|
||||
<string>../java_tools/configuration_definition/lib/snakeyaml.jar</string>
|
||||
|
@ -31,8 +32,10 @@
|
|||
<string>lib/miglayout-4.0.jar</string>
|
||||
<string>lib/surfaceplotter-2.0.1.jar</string>
|
||||
<string>../java_tools/configuration_definition/lib/antlr-4.9.3-complete.jar</string>
|
||||
<string>lib/javacan-core.jar</string>
|
||||
</resources>
|
||||
<pathconvert property="lib_list" refid="libs" pathsep=":" />
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="build"/>
|
||||
<delete dir="${hw_tests}"/>
|
||||
|
@ -201,6 +204,10 @@
|
|||
<zipfileset src="lib/jep.jar" includes="**/*.class"/>
|
||||
<zipfileset src="lib/httpclient.jar" includes="**/*.class"/>
|
||||
<zipfileset src="lib/commons-logging.jar" includes="**/*.class"/>
|
||||
<zipfileset src="lib/javacan-core.jar" includes="**/*.class"/>
|
||||
<zipfileset src="lib/javacan-core-x86_64.jar" includes="**/*.class"/>
|
||||
<zipfileset src="lib/slf4j-api.jar" includes="**/*.class"/>
|
||||
<zipfileset src="lib/slf4j-simple.jar" includes="**/*.class"/>
|
||||
<zipfileset src="lib/httpcore.jar" includes="**/*.class"/>
|
||||
<zipfileset src="lib/httpmime.jar" includes="**/*.class"/>
|
||||
<zipfileset src="lib/jaxb-api.jar" includes="**/*.class"/>
|
||||
|
|
|
@ -22,6 +22,7 @@ dependencies {
|
|||
implementation project(':logging')
|
||||
|
||||
implementation group: 'com.fazecast', name: 'jSerialComm', version: '2.9.0'
|
||||
implementation group: 'tel.schich', name: 'javacan-core', version: '3.2.0'
|
||||
implementation group: 'net.jcip', name: 'jcip-annotations', version: '1.0'
|
||||
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
|
||||
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.12'
|
||||
|
|
|
@ -17,5 +17,6 @@
|
|||
<orderEntry type="module" module-name="inifile" exported="" />
|
||||
<orderEntry type="library" name="mockito-all-1.10.19" level="project" />
|
||||
<orderEntry type="module" module-name="logging" exported="" />
|
||||
<orderEntry type="library" name="javacan-core" level="project" />
|
||||
</component>
|
||||
</module>
|
|
@ -0,0 +1,112 @@
|
|||
package com.rusefi.io.stream;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.opensr5.io.DataListener;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.IoStream;
|
||||
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 org.jetbrains.annotations.Nullable;
|
||||
import tel.schich.javacan.CanChannels;
|
||||
import tel.schich.javacan.CanFrame;
|
||||
import tel.schich.javacan.NetworkDevice;
|
||||
import tel.schich.javacan.RawCanChannel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
import static com.rusefi.config.generated.Fields.CAN_ECU_SERIAL_TX_ID;
|
||||
import static tel.schich.javacan.CanFrame.FD_NO_FLAGS;
|
||||
import static tel.schich.javacan.CanSocketOptions.RECV_OWN_MSGS;
|
||||
|
||||
public class SocketCANIoStream extends AbstractIoStream {
|
||||
static Logging log = getLogging(SocketCANIoStream.class);
|
||||
private final IncomingDataBuffer dataBuffer;
|
||||
private final RawCanChannel socket;
|
||||
|
||||
private final IsoTpCanDecoder canDecoder = new IsoTpCanDecoder();
|
||||
|
||||
private final IsoTpConnector isoTpConnector = new IsoTpConnector() {
|
||||
@Override
|
||||
public void sendCanData(byte[] hdr, byte[] data, int dataOffset, int dataLength) {
|
||||
byte[] total = combineArrays(hdr, data, dataOffset, dataLength);
|
||||
|
||||
log.info("-------sendIsoTp " + total.length + " byte(s):");
|
||||
|
||||
log.info("Sending " + IoStream.printHexBinary(total));
|
||||
|
||||
CanFrame packet = CanFrame.create(Fields.CAN_ECU_SERIAL_RX_ID, FD_NO_FLAGS, total);
|
||||
try {
|
||||
socket.write(packet);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData() {
|
||||
}
|
||||
};
|
||||
|
||||
public SocketCANIoStream() {
|
||||
try {
|
||||
NetworkDevice canInterface = NetworkDevice.lookup("can0");
|
||||
socket = CanChannels.newRawChannel();
|
||||
socket.bind(canInterface);
|
||||
|
||||
socket.configureBlocking(true); // we want reader thread to wait for messages
|
||||
socket.setOption(RECV_OWN_MSGS, true);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Error looking up", e);
|
||||
}
|
||||
// buffer could only be created once socket variable is not null due to callback
|
||||
dataBuffer = createDataBuffer("[SocketCAN] ");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SocketCANIoStream create() {
|
||||
return new SocketCANIoStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] bytes) throws IOException {
|
||||
IsoTpConnector.sendStrategy(bytes, isoTpConnector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInputListener(DataListener listener) {
|
||||
Executor threadExecutor = Executors.newSingleThreadExecutor(BinaryProtocolServer.getThreadFactory("SocketCAN reader"));
|
||||
threadExecutor.execute(() -> {
|
||||
while (!isClosed()) {
|
||||
readOnePacket(listener);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void readOnePacket(DataListener listener) {
|
||||
try {
|
||||
CanFrame rx = socket.read();
|
||||
log.info("GOT " + rx);
|
||||
if (rx.getId() != CAN_ECU_SERIAL_TX_ID) {
|
||||
log.info("Skipping non " + CAN_ECU_SERIAL_TX_ID + " packet");
|
||||
return;
|
||||
}
|
||||
byte[] raw = new byte[rx.getDataLength()];
|
||||
rx.getData(raw, 0, raw.length);
|
||||
byte[] decode = canDecoder.decodePacket(raw);
|
||||
listener.onDataArrived(decode);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IncomingDataBuffer getDataBuffer() {
|
||||
return dataBuffer;
|
||||
}
|
||||
}
|
|
@ -3,7 +3,6 @@ package com.rusefi.binaryprotocol.test;
|
|||
import com.devexperts.logging.Logging;
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.serial.AbstractIoStream;
|
||||
import com.rusefi.io.stream.PCanIoStream;
|
||||
|
@ -42,12 +41,9 @@ public class PCanSandbox {
|
|||
*/
|
||||
|
||||
BinaryProtocol bp = new BinaryProtocol(linkManager, tsStream);
|
||||
linkManager.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
boolean response = bp.requestOutputChannels();
|
||||
log.info("requestOutputChannels " + response);
|
||||
}
|
||||
linkManager.submit(() -> {
|
||||
boolean response = bp.requestOutputChannels();
|
||||
log.info("requestOutputChannels " + response);
|
||||
});
|
||||
|
||||
ConfigurationImage ci = SandboxCommon.readImage(tsStream, linkManager);
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package com.rusefi.binaryprotocol.test;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.serial.AbstractIoStream;
|
||||
import com.rusefi.io.stream.SocketCANIoStream;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
|
||||
public class SocketCANSandbox {
|
||||
private static final Logging log = getLogging(PCanSandbox.class);
|
||||
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
AbstractIoStream tsStream = SocketCANIoStream.create();
|
||||
if (tsStream == null)
|
||||
throw new IOException("No SocketCAN");
|
||||
|
||||
/*
|
||||
for (int i = 0; i < 17; i++) {
|
||||
String signature = BinaryProtocol.getSignature(tsStream);
|
||||
System.out.println("Got " + i + " " + signature + " signature via PCAN");
|
||||
if (signature == null || !signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX))
|
||||
throw new IllegalStateException("Unexpected S " + signature);
|
||||
}
|
||||
log.info("****************************************");
|
||||
log.info("****** SocketCAN LOOKS GREAT *********");
|
||||
log.info("****************************************");
|
||||
*/
|
||||
LinkManager linkManager = new LinkManager();
|
||||
/*
|
||||
for (int i = 0; i < 4; i++) {
|
||||
SandboxCommon.verifyCrcNoPending(tsStream, linkManager);
|
||||
}
|
||||
*/
|
||||
|
||||
BinaryProtocol bp = new BinaryProtocol(linkManager, tsStream);
|
||||
linkManager.submit(() -> {
|
||||
boolean response = bp.requestOutputChannels();
|
||||
log.info("requestOutputChannels " + response);
|
||||
});
|
||||
|
||||
ConfigurationImage ci = SandboxCommon.readImage(tsStream, linkManager);
|
||||
log.info("Got ConfigurationImage " + ci);
|
||||
|
||||
// System.out.println("We are done");
|
||||
// System.exit(0);
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -11,9 +11,16 @@
|
|||
<target name="compile">
|
||||
<mkdir dir="build/classes"/>
|
||||
|
||||
<resources id="libs">
|
||||
<string>lib/mockito-all-1.10.19.jar</string>
|
||||
<string>${console_path}/../java_tools/configuration_definition/lib/snakeyaml.jar</string>
|
||||
<string>${console_path}/lib/javacan-core.jar</string>
|
||||
</resources>
|
||||
<pathconvert property="lib_list" refid="libs" pathsep=":" />
|
||||
|
||||
<javac debug="yes"
|
||||
destdir="build/classes"
|
||||
classpath="${console_path}/../java_tools/configuration_definition/lib/snakeyaml.jar:${console_path}/lib/log4j-api-2.13.3.jar:${console_path}/lib/log4j-core-2.13.3.jar:${console_path}/lib/jsr305-2.0.1.jar:${console_path}/lib/jcip-annotations-1.0.jar:${console_path}/lib/annotations.jar:${console_path}/lib/jSerialComm.jar:${console_path}/lib/junit.jar:${console_path}/lib/json-simple-1.1.1.jar:${console_path}/lib/annotations.jar:${launcher_path}/lib/TunerStudioPluginAPI.jar:${console_path}/lib/httpclient.jar:${console_path}/lib/httpmime.jar:${console_path}/lib/httpcore.jar"
|
||||
classpath="${lib_list}:${console_path}/lib/log4j-api-2.13.3.jar:${console_path}/lib/log4j-core-2.13.3.jar:${console_path}/lib/jsr305-2.0.1.jar:${console_path}/lib/jcip-annotations-1.0.jar:${console_path}/lib/annotations.jar:${console_path}/lib/jSerialComm.jar:${console_path}/lib/junit.jar:${console_path}/lib/json-simple-1.1.1.jar:${console_path}/lib/annotations.jar:${launcher_path}/lib/TunerStudioPluginAPI.jar:${console_path}/lib/httpclient.jar:${console_path}/lib/httpmime.jar:${console_path}/lib/httpcore.jar"
|
||||
>
|
||||
<src path="${console_path}/shared_ui/src"/>
|
||||
<src path="${console_path}/autoupdate/src/main/java"/>
|
||||
|
@ -55,6 +62,7 @@
|
|||
<zipfileset src="../../java_console/lib/httpclient.jar" includes="**/*.class"/>
|
||||
<zipfileset src="../../java_console/lib/httpcore.jar" includes="**/*.class"/>
|
||||
<zipfileset src="../../java_console/lib/httpmime.jar" includes="**/*.class"/>
|
||||
<zipfileset src="../../java_console/lib/javacan-core.jar" includes="**/*.class"/>
|
||||
<zipfileset src="../../java_console/lib/json-simple-1.1.1.jar" includes="**/*.class"/>
|
||||
<zipfileset src="../../java_console/lib/jSerialComm.jar" includes="**/*.class **/*.so **/*.dll **/*.jnilib"/>
|
||||
<!-- <zipfileset src="lib/commons-logging.jar" includes="**/*.class"/>-->
|
||||
|
|
Loading…
Reference in New Issue