library.UdsMessage.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-sim-ecu-dsl Show documentation
Show all versions of doip-sim-ecu-dsl Show documentation
This is a kotlin based domain specific language (dsl), to quickly and intuitively write custom DoIP ECU simulations.
package library
import kotlinx.coroutines.*
import java.io.OutputStream
open class UdsMessage(
val sourceAddress: Short,
val targetAddress: Short,
val targetAddressType: Int,
val message: ByteArray,
val output: OutputStream
) {
companion object {
const val PHYSICAL = 0
const val FUNCTIONAL = 1
}
fun respond(data: ByteArray) {
val response = DoipTcpDiagMessage(targetAddress, sourceAddress, data)
runBlocking {
output.writeFully(response.asByteArray)
}
}
}
fun DoipTcpDiagMessage.toUdsMessage(addressType: Int, output: OutputStream): UdsMessage =
UdsMessage(
sourceAddress = this.sourceAddress,
targetAddress = this.targetAddress,
targetAddressType = addressType,
message = this.payload,
output = output
)