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.

There is a newer version: 0.15.1
Show newest version
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
    )




© 2015 - 2024 Weber Informatics LLC | Privacy Policy