All Downloads are FREE. Search and download functionalities are using the official Maven repository.

library.UdsMessage.kt Maven / Gradle / Ivy

Go to download

This is a kotlin based domain specific language (dsl), to quickly and intuitively write custom DoIP ECU simulations.

The newest version!
package library

import io.ktor.utils.io.*
import kotlinx.coroutines.*

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
) {
    public companion object {
        public const val PHYSICAL: Int = 0
        public const val FUNCTIONAL: Int = 1
    }

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

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

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
    )




© 2015 - 2024 Weber Informatics LLC | Privacy Policy