Skip to content

Commit

Permalink
feat: Add tester availability uds command
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed Feb 3, 2024
1 parent 5b7b88f commit 5b50c3f
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 20 deletions.
15 changes: 9 additions & 6 deletions src/main/java/org/obd/metrics/api/DefaultWorkflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,27 +208,30 @@ public WorkflowExecutionStatus executeRoutine(@NonNull Query query, @NonNull Ini

commandProducer.pause();

final CommandsBuffer forceResolve = it.forceResolve(CommandsBuffer.class);
final CommandsBuffer commandsBuffer = it.forceResolve(CommandsBuffer.class);
final PidDefinitionRegistry registry = getPidRegistry();

query.getPids().forEach(p -> {
final PidDefinition pid = registry.findBy(p);

if (pid != null) {

// extended diagnosis session
forceResolve.addFirst(UDSConstants.UDS_EXTENDED_SESSION);

// can request id
init.getHeaders()
.stream()
.filter(w -> w.getMode().equals(pid.deductMode()))
.findFirst()
.ifPresent( id ->
forceResolve.addFirst(new ATCommand("SH" + id.getHeader()))
commandsBuffer.addFirst(new ATCommand("SH" + id.getHeader()))
);

// extended diagnosis session
commandsBuffer.addFirst(UDSConstants.UDS_EXTENDED_SESSION);
// tester availability
commandsBuffer.addFirst(UDSConstants.UDS_TESTER_AVAILIBILITY);

// routine
forceResolve.addFirst(new ObdCommand(pid.getPid()));
commandsBuffer.addFirst(new ObdCommand(pid.getPid()));
}
});
commandProducer.resume();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/obd/metrics/api/UDSConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@NoArgsConstructor(access = AccessLevel.PRIVATE)
final class UDSConstants {
static ObdCommand UDS_TESTER_AVAILIBILITY = new ObdCommand("3E00");
static ObdCommand UDS_EXTENDED_SESSION = new ObdCommand("10 03");
static ObdCommand UDS_DEFAULT_SESSION = new ObdCommand("10 01");
}
18 changes: 16 additions & 2 deletions src/main/resources/giulia_2.0_gme.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,30 @@
"mode": "22",
"pid": "2F509203FF",
"description": "Cooling Fan request\nSTART",
"successCode": "54"
"successCode": "6F5"
},
{

"id": "10001",
"mode": "22",
"pid": "2F509203",
"description": "Cooling Fan Request\nSTOP",
"successCode": "54"
"successCode": "6F5"
},

{

"id": "10002",
"mode": "22",
"pid": "2F55720308",
"description":"Turn dashboard illumination on",
"successCode": "6F557203",
"overrides" : {
"canMode": "123",
"batchEnabled": false
}
}

],


Expand Down
74 changes: 73 additions & 1 deletion src/test/java/org/obd/metrics/api/WorkflowRoutineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ public void successFlowTest() throws IOException, InterruptedException {
.contains("ATSHDA10F1");

Assertions.assertThat(connection.recordedQueries())
.contains("10 03");
.contains(UDSConstants.UDS_EXTENDED_SESSION.getQuery());

Assertions.assertThat(connection.recordedQueries())
.contains("10 03");

Assertions.assertThat(connection.recordedQueries())
.contains("2F509203FF");

Expand All @@ -103,6 +106,75 @@ public void successFlowTest() throws IOException, InterruptedException {
Assertions.assertThat(workflow.isRunning()).isFalse();
}

@Test
public void canRequestIdOverrideTest() throws IOException, InterruptedException {

// Create an instance of DataCollector that receives the OBD Metrics
DataCollector collector = new DataCollector();

SimpleLifecycle lifecycle = new SimpleLifecycle();

// Obtain the Workflow instance for mode 01
Workflow workflow = SimpleWorkflowFactory.getWorkflow(lifecycle, collector, "giulia_2.0_gme.json");

// Query for specified PID's like: Engine coolant temperature
Query query1 = Query.builder()
.pid(6015l) // Oil temp
.pid(6008l) // Coolant
.pid(6007l) // IAT
.build();
// Create an instance of mock connection with additional commands and replies
MockAdapterConnection connection = MockAdapterConnection.builder()
.requestResponse("22 194F 1003 1935 2", "00B0:62194F2E65101:0348193548")
.requestResponse("2F509203FF", "OK").build();

final Adjustments optional = getAdjustements();

WorkflowExecutionStatus status = workflow.start(connection,query1, optional);
Assertions.assertThat(status).isEqualTo(WorkflowExecutionStatus.STARTED);

WorkflowFinalizer.waitUntilRunning(workflow);
Assertions.assertThat(workflow.isRunning()).isTrue();


final Init init = Init.builder()
.delayAfterInit(0)
.header(Header.builder().mode("123").header("DA60F1").build())
.header(Header.builder().mode("22").header("DA10F1").build())
.header(Header.builder().mode("01").header("DB33F1").build())
.header(Header.builder().mode("556").header("DA1AF1").build())
.header(Header.builder().mode("555").header("DA18F1").build())
.protocol(Protocol.CAN_29)
.sequence(DefaultCommandGroup.INIT).build();

status = workflow.executeRoutine(Query.builder().pid(10002L).build(), init);
Assertions.assertThat(status).isEqualTo(WorkflowExecutionStatus.ROUTINE_EXECUTED);

// Starting the workflow completion job, it will end workflow after some period
// of time (helper method)
WorkflowFinalizer.finalize(workflow);

// Ensure batch commands were sent out

Assertions.assertThat(connection.recordedQueries())
.contains("ATSHDA60F1");

Assertions.assertThat(connection.recordedQueries())
.contains(UDSConstants.UDS_EXTENDED_SESSION.getQuery());

Assertions.assertThat(connection.recordedQueries())
.contains("10 03");

Assertions.assertThat(connection.recordedQueries())
.contains("2F55720308");

// Ensure we receive AT commands
Assertions.assertThat(collector.findATResetCommand()).isNotNull();

// Workflow is not running
Assertions.assertThat(workflow.isRunning()).isFalse();
}


@Test
public void noIDsProvidedTest() throws IOException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.util.concurrent.ExecutionException;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.obd.metrics.api.model.AdaptiveTimeoutPolicy;
import org.obd.metrics.api.model.Adjustments;
Expand All @@ -36,27 +37,79 @@
public class Raw_2_0_GME_IntegrationTest extends RawIntegrationRunner {

@Test
public void mode_01_tests() throws IOException, InterruptedException, ExecutionException {
public void routineFanTest() throws IOException, InterruptedException, ExecutionException {

final Pids pids = Pids.builder()
.resource(Thread.currentThread().getContextClassLoader().getResource("mode01.json")).build();
.resource(Thread.currentThread().getContextClassLoader().getResource("giulia_2.0_gme.json")).build();

final CommandsBuffer buffer = CommandsBuffer.instance();
buffer.addFirst(new ATCommand("Z")); // reset
buffer.addLast(new ATCommand("L0")); // line feed off
buffer.addLast(new ATCommand("H0"));
buffer.addLast(new ATCommand("E0"));
buffer.addLast(new ATCommand("SPB"));
// buffer.addLast(new ATCommand("S0"));
// buffer.addLast(new ATCommand("AL"));
// buffer.addLast(new ATCommand("CP18"));
// buffer.addLast(new ATCommand("AT1"));
// buffer.addLast(new ATCommand("ST99"));

for (int i=0; i<50; i++) {
buffer.addLast(new ObdCommand("STPX H:18DB33F1, D:01 15 0C 04 06 11 0E, R:4"));
}

buffer.addLast(new ATCommand("CRA18DAF"));
buffer.addLast(new ATCommand("SHDA10F1"));
buffer.addLast(new ObdCommand("10 03"));

//2F509203FF
//7F2F13
buffer.addLast(new ObdCommand("3E00"));//7F2F11
buffer.addLast(new ObdCommand("2F509203FF"));//7F2F11

buffer.addLast(new QuitCommand());

final Adjustments optional = Adjustments.builder()
.debugEnabled(Boolean.TRUE)
.adaptiveTimeoutPolicy(
AdaptiveTimeoutPolicy
.builder()
.enabled(Boolean.TRUE)
.checkInterval(10)
.commandFrequency(6)
.build())
.producerPolicy(ProducerPolicy
.builder()
.priorityQueueEnabled(Boolean.TRUE).build())
.cachePolicy(CachePolicy
.builder()
.resultCacheEnabled(Boolean.FALSE).build())
.batchPolicy(BatchPolicy.builder().enabled(Boolean.TRUE).build())
.build();

runBtTest(pids, buffer, optional);
}


@Test
public void dashboardIlluminationTest() throws IOException, InterruptedException, ExecutionException {

final Pids pids = Pids.builder()
.resource(Thread.currentThread().getContextClassLoader().getResource("giulia_2.0_gme.json")).build();

final CommandsBuffer buffer = CommandsBuffer.instance();
buffer.addFirst(new ATCommand("Z")); // reset
buffer.addLast(new ATCommand("L0")); // line feed off
buffer.addLast(new ATCommand("H0"));
buffer.addLast(new ATCommand("E0"));
buffer.addLast(new ATCommand("SPB"));

// buffer.addLast(new ATCommand("CRA18DAF160"));
buffer.addLast(new ATCommand("SHDA60F1"));
buffer.addLast(new ObdCommand("10 01"));
buffer.addLast(new ObdCommand("3E00"));

buffer.addLast(new ObdCommand("10 03"));

buffer.addLast(new ObdCommand("2F55720308"));//6F557203 7F2F7F

// buffer.addLast(new ObdCommand("2F55720304"));//6F557203
// buffer.addLast(new ObdCommand("2F55720302"));
// buffer.addLast(new ObdCommand("2F55720300"));
// buffer.addLast(new ObdCommand("2F557200"));
//

buffer.addLast(new QuitCommand());

final Adjustments optional = Adjustments.builder()
Expand All @@ -82,6 +135,7 @@ public void mode_01_tests() throws IOException, InterruptedException, ExecutionE


@Test
@Disabled
public void mode_22_tests() throws IOException, InterruptedException, ExecutionException {

final Pids pids = Pids.builder()
Expand Down

0 comments on commit 5b50c3f

Please sign in to comment.