From b2f04a79352a44767d160fd4e85d8c7caf3193d7 Mon Sep 17 00:00:00 2001 From: Florian Roks Date: Mon, 3 Jun 2024 08:39:16 +0200 Subject: [PATCH] add option to change nrc code and interval for sending pending nrc --- build.gradle.kts | 16 ++++++++-------- src/main/kotlin/SimDsl.kt | 22 ++++++++++++++++++++++ src/main/kotlin/SimEcu.kt | 9 +++++---- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 76bda87..c371f33 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ plugins { apply() group = "io.github.doip-sim-ecu" -version = "0.12.0" +version = "0.12.1" repositories { gradlePluginPortal() @@ -113,13 +113,13 @@ publishing { } } -tasks.cyclonedxBom { - setIncludeConfigs(listOf("runtimeClasspath")) - setIncludeLicenseText(false) - outputName.set("sbom") - outputFormat.set("all") - includeBomSerialNumber.set(true) -} +//tasks.cyclonedxBom { +// setIncludeConfigs(listOf("runtimeClasspath")) +// setIncludeLicenseText(false) +// outputName.set("sbom") +// outputFormat.set("all") +// includeBomSerialNumber.set(true) +//} allOpen { annotation("helper.Open") diff --git a/src/main/kotlin/SimDsl.kt b/src/main/kotlin/SimDsl.kt index bf78f16..8c9046d 100644 --- a/src/main/kotlin/SimDsl.kt +++ b/src/main/kotlin/SimDsl.kt @@ -147,6 +147,12 @@ public open class ResponseData( public val pendingFor: Duration? get() = _pendingFor + public val pendingForInterval: Duration? + get() = _pendingForInterval + + public val pendingForNrc: Byte? + get() = _pendingForNrc + public val pendingForCallback: () -> Unit get() = _pendingForCallback @@ -156,6 +162,8 @@ public open class ResponseData( private var _response: ByteArray = ByteArray(0) private var _continueMatching: Boolean = false private var _pendingFor: Duration? = null + private var _pendingForInterval: Duration? = null + private var _pendingForNrc: Byte? = null private var _pendingForCallback: () -> Unit = {} private var _hardResetEntityFor: Duration? = null @@ -262,6 +270,20 @@ public open class ResponseData( _pendingForCallback = callback } + /** + * Overrides the default interval for sending pending NRC + */ + public fun pendingForInterval(duration: Duration) { + _pendingForInterval = duration + } + + /** + * Changes the default busy wait NRC (0x78) to something different + */ + public fun pendingForNrc(nrc: Byte) { + _pendingForNrc = nrc + } + /** * Pretend to hard-reset entity by disconnecting the current, nd not being reachable for duration, * and sending a vam after being reachable again diff --git a/src/main/kotlin/SimEcu.kt b/src/main/kotlin/SimEcu.kt index 667fbc3..94e7ca3 100644 --- a/src/main/kotlin/SimEcu.kt +++ b/src/main/kotlin/SimEcu.kt @@ -119,19 +119,20 @@ public class SimEcu(private val data: EcuData) : SimulatedEcu(data.toEcuConfig() private fun handlePending(request: UdsMessage, responseData: ResponseData) { val pendingFor = responseData.pendingFor ?: return - + val pendingForInterval = responseData.pendingForInterval?.inWholeMilliseconds ?: config.pendingNrcSendInterval.inWholeMilliseconds // this code will send pending nrcs every `config.pendingNrcSendInterval`, until // the pendingFor duration is reached. Afterward the `pendingForCallback` is invoked, // which may again change the final response in ResponseData - val pending = byteArrayOf(0x7f, request.message[0], NrcError.RequestCorrectlyReceivedButResponseIsPending) + val pending = byteArrayOf(0x7f, request.message[0], + responseData.pendingForNrc ?: NrcError.RequestCorrectlyReceivedButResponseIsPending) val end = System.currentTimeMillis() + pendingFor.inWholeMilliseconds while (System.currentTimeMillis() < end) { sendResponse(request, pending) logger.logForRequest(responseData.caller) { "Request for $name: '${request.message.toHexString(limit = 10, limitExceededByteCount = true)}' matched '${responseData.caller}' -> Pending '${pending.toHexString(limit = 10, limitExceededByteCount = true)}'" } - if (end - System.currentTimeMillis() <= config.pendingNrcSendInterval.inWholeMilliseconds) { + if (end - System.currentTimeMillis() <= pendingForInterval) { Thread.sleep(end - System.currentTimeMillis()) } else { - Thread.sleep(config.pendingNrcSendInterval.inWholeMilliseconds) + Thread.sleep(pendingForInterval) } } try {