Skip to content

Commit

Permalink
feat: Switch diagnosis session to extended when executing routine
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed Feb 1, 2024
1 parent e653daf commit 9ccd0a9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/main/java/org/obd/metrics/api/DefaultWorkflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
@Slf4j
final class DefaultWorkflow implements Workflow {


private transient Future<?> tasks;

@Getter
Expand Down Expand Up @@ -185,7 +186,7 @@ public void stop(boolean gracefulStop) {
public WorkflowExecutionStatus executeRoutine(@NonNull Query query, @NonNull Init init,
@NonNull Adjustments adjustments) {

log.info("[Routine] Updating running workflow with new query");
log.info("[Routine] Executing routine");
log.info("[Routine] Selected PID's: {}", query.getPids());
log.info("[Routine] Protocol: {}, headers: {}",init.getProtocol(), init.getHeaders());
log.info("[Routine] Debug: {}", adjustments.isDebugEnabled());
Expand All @@ -204,7 +205,8 @@ public WorkflowExecutionStatus executeRoutine(@NonNull Query query, @NonNull Ini
if (pid != null) {
final Optional<Header> findFirst = init.getHeaders().stream().filter(w -> w.getMode().equals(pid.findMode())).findFirst();

forceResolve.addFirst(new ObdCommand("10 03"));
// extended diagnosis session
forceResolve.addFirst(UdsConstants.UDS_EXTENDED_SESSION);

if (findFirst.isPresent()) {
forceResolve.addFirst(new ATCommand("SH" + findFirst.get().getHeader()));
Expand Down Expand Up @@ -247,8 +249,12 @@ public WorkflowExecutionStatus updateQuery(@NonNull Query query, @NonNull Init i
diagnostics.rate().reset();
commandProducer.pause();

it.forceResolve(CommandsBuffer.class).clear();

final CommandsBuffer buffer = it.forceResolve(CommandsBuffer.class);
buffer.clear();

// defult diagnosis session
buffer.addFirst(UdsConstants.UDS_DEFAULT_SESSION);

commandProducer.updateSettings(adjustments, getCommandsSupplier(init, adjustments, query), diagnostics,
init);

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/obd/metrics/api/UdsConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.obd.metrics.api;

import org.obd.metrics.command.obd.ObdCommand;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
final class UdsConstants {
static ObdCommand UDS_EXTENDED_SESSION = new ObdCommand("10 03");
static ObdCommand UDS_DEFAULT_SESSION = new ObdCommand("10 01");
}
5 changes: 2 additions & 3 deletions src/test/java/org/obd/metrics/api/WorkflowRoutineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
import org.obd.metrics.api.model.BatchPolicy;
import org.obd.metrics.api.model.CachePolicy;
import org.obd.metrics.api.model.Init;
import org.obd.metrics.api.model.ProducerPolicy;
import org.obd.metrics.api.model.Query;
import org.obd.metrics.api.model.Init.Header;
import org.obd.metrics.api.model.Init.Protocol;
import org.obd.metrics.api.model.ProducerPolicy;
import org.obd.metrics.api.model.Query;
import org.obd.metrics.command.group.DefaultCommandGroup;
import org.obd.metrics.connection.MockAdapterConnection;
import org.obd.metrics.pid.PidDefinition;

public class WorkflowRoutineTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,16 @@ public void canHeaderChangeTest(boolean batchEnabled, String adapterGivenRespons
// switching CAN header to mode 555
boolean changeCanAferUpdate = false;
for (int i=0; i<6; i++) {
changeCanAferUpdate = recordedQueries.pop().equals("ATSHDA18F1");
changeCanAferUpdate = recordedQueries.pop().equals("10 01");
if (changeCanAferUpdate) {
break;
}
}
Assertions.assertThat(changeCanAferUpdate).isTrue().describedAs("Did not found: ATSHDA18F1");
Assertions.assertThat(changeCanAferUpdate).isTrue().describedAs("Did not found: 10 01");


Assertions.assertThat(recordedQueries.pop()).isEqualTo("ATSHDA18F1");

Assertions.assertThat(recordedQueries.pop()).isEqualTo(batchEnabled ? "22 04FE" : "2204FE");
Assertions.assertThat(recordedQueries.pop()).isEqualTo(batchEnabled ? "22 04FE" : "2204FE");

Expand Down

0 comments on commit 9ccd0a9

Please sign in to comment.