Skip to content

Commit

Permalink
respond to function requests with the physical address
Browse files Browse the repository at this point in the history
  • Loading branch information
froks committed Jun 27, 2024
1 parent e58e6d5 commit f2c51d3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {
apply<NexusReleasePlugin>()

group = "io.github.doip-sim-ecu"
version = "0.12.2"
version = "0.13.0"

repositories {
gradlePluginPortal()
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/SimDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public class RequestMessage(udsMessage: UdsMessage, public val isBusy: Boolean)
udsMessage.sourceAddress,
udsMessage.targetAddress,
udsMessage.targetAddressType,
udsMessage.targetAddressPhysical,
udsMessage.message,
udsMessage.output
)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/library/DoipEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public abstract class DoipEntity<out T : SimulatedEcu>(
runBlocking {
MDC.put("ecu", ecu.name)
launch(MDCContext()) {
onIncomingUdsMessage(diagMessage.toUdsMessage(UdsMessage.PHYSICAL, output))
onIncomingUdsMessage(diagMessage.toUdsMessage(UdsMessage.PHYSICAL, output, ecu.config.logicalAddress))
}
}
// Exit if the target ecu was found by physical
Expand All @@ -191,7 +191,7 @@ public abstract class DoipEntity<out T : SimulatedEcu>(
runBlocking {
MDC.put("ecu", it.name)
launch(MDCContext()) {
it.onIncomingUdsMessage(diagMessage.toUdsMessage(UdsMessage.FUNCTIONAL, output))
it.onIncomingUdsMessage(diagMessage.toUdsMessage(UdsMessage.FUNCTIONAL, output, it.config.logicalAddress))
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/library/UdsMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public open class UdsMessage(
public val sourceAddress: Short,
public val targetAddress: Short,
public val targetAddressType: Int,
public val targetAddressPhysical: Short,
public val message: ByteArray,
public val output: ByteWriteChannel
) {
Expand All @@ -16,19 +17,20 @@ public open class UdsMessage(
}

public fun respond(data: ByteArray) {
val response = DoipTcpDiagMessage(targetAddress, sourceAddress, data)
val response = DoipTcpDiagMessage(targetAddressPhysical, sourceAddress, data)

runBlocking {
output.writeFully(response.asByteArray)
}
}
}

public fun DoipTcpDiagMessage.toUdsMessage(addressType: Int, output: ByteWriteChannel): UdsMessage =
public fun DoipTcpDiagMessage.toUdsMessage(addressType: Int, output: ByteWriteChannel, targetAddressPhysical: Short): UdsMessage =
UdsMessage(
sourceAddress = this.sourceAddress,
targetAddress = this.targetAddress,
targetAddressType = addressType,
targetAddressPhysical = targetAddressPhysical,
message = this.payload,
output = output
)
1 change: 1 addition & 0 deletions src/test/kotlin/SimDslTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class SimDslTest {
0x1,
0x2,
UdsMessage.PHYSICAL,
0x2,
byteArrayOf(0x22, 0x10, 0x20),
Mockito.mock(ByteWriteChannel::class.java)
)
Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/SimEcuTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ class SimEcuTest {
sourceAddress = sourceAddress,
targetAddress = targetAddress,
targetAddressType = targetAddressType,
targetAddressPhysical = targetAddress,
message = data,
output = Mockito.mock(ByteWriteChannel::class.java)
)
Expand Down

0 comments on commit f2c51d3

Please sign in to comment.