From d6e77ed7b531bb9b0766dccd251496ba579616ac Mon Sep 17 00:00:00 2001 From: Dale Schultz Date: Wed, 21 Mar 2018 21:49:06 -0400 Subject: [PATCH] Updated tests so developer can select protocol and library on the cmd line --- .../com/romraider/io/j2534/api/TestJ2534.java | 67 +++++++++++++++---- .../io/j2534/api/TestJ2534IsoTp.java | 10 +-- .../romraider/io/j2534/api/TestJ2534OBD.java | 13 +++- 3 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/romraider/io/j2534/api/TestJ2534.java b/src/main/java/com/romraider/io/j2534/api/TestJ2534.java index 49e17451..3d4e3c34 100644 --- a/src/main/java/com/romraider/io/j2534/api/TestJ2534.java +++ b/src/main/java/com/romraider/io/j2534/api/TestJ2534.java @@ -1,6 +1,6 @@ /* * RomRaider Open-Source Tuning, Logging and Reflashing - * Copyright (C) 2006-2012 RomRaider.com + * Copyright (C) 2006-2018 RomRaider.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,24 +32,40 @@ import com.romraider.io.j2534.api.J2534Impl.TxFlags; * an active ECU using the ISO9141 protocol. */ public class TestJ2534 { - private static final J2534 api = new J2534Impl(Protocol.ISO9141, "op20pt32"); + private static String protocol; // Dev to choice SSM or DS2 on cmdline for testing + private static J2534 api; public TestJ2534() { - int deviceId = api.open(); + int deviceId = -1; try { + deviceId = api.open(); version(deviceId); - int channelId = api.connect( - deviceId, Flag.ISO9141_NO_CHECKSUM.getValue(), 4800); + int channelId = -1; + if (protocol.equalsIgnoreCase("ssm")) { + channelId = api.connect( + deviceId, Flag.ISO9141_NO_CHECKSUM.getValue(), 4800); + } + else if (protocol.equalsIgnoreCase("ds2")) { + channelId = api.connect( + deviceId, Flag.ISO9141_NO_CHECKSUM.getValue(), 9600); + } try { setConfig(channelId); getConfig(channelId); - + int msgId = api.startPassMsgFilter(channelId, (byte) 0x00, (byte) 0x00); try { - - byte[] ecuInit = { - (byte) 0x80, (byte) 0x10, (byte) 0xF0, - (byte) 0x01, (byte) 0xBF, (byte) 0x40}; + byte[] ecuInit = null; + if (protocol.equalsIgnoreCase("ssm")) { + ecuInit = new byte[]{ + (byte) 0x80, (byte) 0x10, (byte) 0xF0, + (byte) 0x01, (byte) 0xBF, (byte) 0x40}; + } + else if (protocol.equalsIgnoreCase("ds2")) { + ecuInit = new byte[]{ + (byte) 0x12, (byte) 0x04, (byte) 0x00, + (byte) 0x16}; + } api.writeMsg(channelId, ecuInit, 55L, TxFlags.NO_FLAGS); System.out.println("Request = " + asHex(ecuInit)); @@ -64,7 +80,8 @@ public class TestJ2534 { api.disconnect(channelId); } } finally { - api.close(deviceId); + if (api != null) + api.close(deviceId); } } @@ -79,7 +96,17 @@ public class TestJ2534 { ConfigItem p3Min = new ConfigItem(Config.P3_MIN.getValue(), 0); ConfigItem p4Min = new ConfigItem(Config.P4_MIN.getValue(), 0); ConfigItem loopback = new ConfigItem(Config.LOOPBACK.getValue(), 1); - api.setConfig(channelId, p1Max, p3Min, p4Min, loopback); + ConfigItem parity = null; + ConfigItem databits = null; + if (protocol.equalsIgnoreCase("ssm")) { + parity = new ConfigItem(Config.PARITY.getValue(), 0); + databits = new ConfigItem(Config.DATA_BITS.getValue(), 8); + } + else if (protocol.equalsIgnoreCase("ds2")) { + parity = new ConfigItem(Config.PARITY.getValue(), 2); + databits = new ConfigItem(Config.DATA_BITS.getValue(), 8); + } + api.setConfig(channelId, p1Max, p3Min, p4Min, parity, databits, loopback); } private static void getConfig(int channelId) { @@ -88,7 +115,10 @@ public class TestJ2534 { Config.LOOPBACK.getValue(), Config.P1_MAX.getValue(), Config.P3_MIN.getValue(), - Config.P4_MIN.getValue()); + Config.P4_MIN.getValue(), + Config.P4_MIN.getValue(), + Config.DATA_BITS.getValue(), + Config.LOOPBACK.getValue()); int i = 1; for (ConfigItem item : configs) { System.out.printf("Config item %d: Parameter: %d, value:%d%n", @@ -97,8 +127,17 @@ public class TestJ2534 { } } - public static void main(String args[]){ + public final static void main(String args[]) throws InterruptedException{ initDebugLogging(); + if (args.length < 2) { + System.out.printf("Provide \"library_name\" and \"protocol\" cmdline args."); + return; + } + else { + protocol = args[1].toLowerCase(); // SSM or DS2 + api = new J2534Impl( //op20pt32 MONGI432 /usr/local/lib/j2534.so + Protocol.ISO9141, args[0]); + } TestJ2534 a = new TestJ2534(); } } diff --git a/src/main/java/com/romraider/io/j2534/api/TestJ2534IsoTp.java b/src/main/java/com/romraider/io/j2534/api/TestJ2534IsoTp.java index 8262934d..73dc4662 100644 --- a/src/main/java/com/romraider/io/j2534/api/TestJ2534IsoTp.java +++ b/src/main/java/com/romraider/io/j2534/api/TestJ2534IsoTp.java @@ -1,6 +1,6 @@ /* * RomRaider Open-Source Tuning, Logging and Reflashing - * Copyright (C) 2006-2013 RomRaider.com + * Copyright (C) 2006-2018 RomRaider.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -346,12 +346,12 @@ public final class TestJ2534IsoTp { public final static void main(String args[]) throws InterruptedException{ LogManager.initDebugLogging(); - if (args.length == 0) { //op20pt32 MONGI432 - api = new J2534Impl( - Protocol.ISO15765, "op20pt32"); + if (args.length < 1) { + System.out.printf("Provide \"library_name\" cmdline arg."); + return; } else { - api = new J2534Impl( + api = new J2534Impl( //op20pt32 MONGI432 /usr/local/lib/j2534.so Protocol.ISO15765, args[0]); } diff --git a/src/main/java/com/romraider/io/j2534/api/TestJ2534OBD.java b/src/main/java/com/romraider/io/j2534/api/TestJ2534OBD.java index a8691cc9..a78793f3 100644 --- a/src/main/java/com/romraider/io/j2534/api/TestJ2534OBD.java +++ b/src/main/java/com/romraider/io/j2534/api/TestJ2534OBD.java @@ -1,6 +1,6 @@ /* * RomRaider Open-Source Tuning, Logging and Reflashing - * Copyright (C) 2006-2012 RomRaider.com + * Copyright (C) 2006-2018 RomRaider.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,8 +30,7 @@ import com.romraider.util.LogManager; * an active ECU using the ISO14230 protocol. */ public final class TestJ2534OBD { - private static final J2534 api = new J2534Impl( - Protocol.ISO14230, "op20pt32"); //op20pt32 MONGI432 + private static J2534 api; private static final int LOOPBACK = 0; public TestJ2534OBD() throws InterruptedException { @@ -171,6 +170,14 @@ public final class TestJ2534OBD { public static void main(String args[]) throws InterruptedException{ LogManager.initDebugLogging(); + if (args.length < 1) { + System.out.printf("Provide \"library_name\" cmdline arg."); + return; + } + else { + api = new J2534Impl( //op20pt32 MONGI432 /usr/local/lib/j2534.so + Protocol.ISO14230, args[0]); + } TestJ2534OBD test1 = new TestJ2534OBD(); } }