Skip to content

Commit

Permalink
Fix #283 - Handle additional padding data
Browse files Browse the repository at this point in the history
  • Loading branch information
fr3ts0n committed Nov 24, 2024
1 parent 148674e commit 7bf7133
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 6 deletions.
4 changes: 2 additions & 2 deletions androbd/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
// SDK 25 to allow background service mechanism for plugins
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 25
versionCode 20612
versionName 'V2.6.12'
versionCode 20613
versionName 'V2.6.13'

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
28 changes: 25 additions & 3 deletions library/src/main/java/com/fr3ts0n/ecu/prot/obd/ElmProt.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ public class ElmProt
* custom ELM initialisation commands
*/
private final Vector<String> customInitCommands = new Vector<String>();

/**
* last detected message counter ID
*/
private int lastMsgId = 0;

/**
* ELM protocol ID's
*/
Expand Down Expand Up @@ -918,7 +922,7 @@ else if (adrLen == 10)
return (result);
}

// is this a multy-line response
// is this a multi-line response
int idx = bufferStr.indexOf(':');

// .. or a ISO multi line response with format SVC PID MSGID DATA...
Expand All @@ -932,7 +936,25 @@ else if (adrLen == 10)
{
// Use header on 1st response, cut from continuation messages
int msgId = Integer.valueOf(bufferStr.substring(4,6),0x10);
idx = msgId <= 1 ? 0 : 5; // index of last digit message id
if(msgId <= 1)
{
// 1st response line
idx = 0;
lastMsgId = msgId;
}
else if (msgId == (lastMsgId + 1))
{
// continuation line
idx = 5;
lastMsgId = msgId;
}
else
{
// NOT a ISO multi line message
idx = -1;
// cut additional (padding) byte
bufferStr = bufferStr.substring(0,buffer.length-2);
}
}
}

Expand Down
60 changes: 60 additions & 0 deletions library/src/test/java/com/fr3ts0n/ecu/prot/obd/ElmProtTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,66 @@ void handleTelegram_NoMessageCount()
// assertEquals(1, prot.getNextSupportedPid());
}

/**
* PID message with trailing padding response bytes
* - either from Adapter, or from vehicle OBD?
* @Verifies AndrOBD/#283
*/
@Test
void handleTelegram_Clio2023_Data()
{
prot.setService(ObdProt.OBD_SVC_DATA);
// PID message without optional message counter
prot.handleTelegram("4100BE3EA817AA".toCharArray());
// ensure, trailing padding bytes are detected and cut off
// BE3EA817 -> PID's 1,3,4,5,6,7 ... set
assertEquals(1, prot.getNextSupportedPid());
assertEquals(3, prot.getNextSupportedPid());
assertEquals(4, prot.getNextSupportedPid());
assertEquals(5, prot.getNextSupportedPid());
assertEquals(6, prot.getNextSupportedPid());
assertEquals(7, prot.getNextSupportedPid());
assertEquals(11, prot.getNextSupportedPid());
assertEquals(12, prot.getNextSupportedPid());
assertEquals(13, prot.getNextSupportedPid());
assertEquals(14, prot.getNextSupportedPid());
assertEquals(15, prot.getNextSupportedPid());
assertEquals(17, prot.getNextSupportedPid());
assertEquals(19, prot.getNextSupportedPid());
assertEquals(21, prot.getNextSupportedPid());
assertEquals(28, prot.getNextSupportedPid());
assertEquals(30, prot.getNextSupportedPid());
assertEquals(31, prot.getNextSupportedPid());
// PIDs repeat again
// assertEquals(1, prot.getNextSupportedPid());
}

/**
* PID message with trailing padding response bytes
* - either from Adapter, or from vehicle OBD?
* @Verifies AndrOBD/#283
*/
@Test
void handleTelegram_Clio2023_VehicleInfo()
{
prot.setService(ObdProt.OBD_SVC_VEH_INFO);
// PID message without optional message counter
prot.handleTelegram("490055430280AA".toCharArray());
// ensure, trailing padding bytes are detected and cut off
// 55430280 -> PID's 2,4,6,8 ... set
assertEquals(2, prot.getNextSupportedPid());
assertEquals(4, prot.getNextSupportedPid());
assertEquals(6, prot.getNextSupportedPid());
assertEquals(8, prot.getNextSupportedPid());
assertEquals(10, prot.getNextSupportedPid());
assertEquals(15, prot.getNextSupportedPid());
assertEquals(16, prot.getNextSupportedPid());
assertEquals(23, prot.getNextSupportedPid());
assertEquals(25, prot.getNextSupportedPid());
// PIDs repeat again
// assertEquals(1, prot.getNextSupportedPid());
}

@Test
void handleTelegram_Vin_ISO_Multiline()
{
Expand Down
2 changes: 1 addition & 1 deletion plugin

0 comments on commit 7bf7133

Please sign in to comment.