library.DoipUdpMessageHandler.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.
The newest version!
package library
import io.ktor.network.sockets.*
import io.ktor.utils.io.core.*
import kotlinx.coroutines.channels.SendChannel
import org.slf4j.Logger
import org.slf4j.LoggerFactory
public interface DoipUdpMessageHandler {
private companion object {
val logger: Logger = LoggerFactory.getLogger(DoipUdpMessageHandler::class.java)
}
public suspend fun handleUdpMessage(
sendChannel: SendChannel,
sourceAddress: SocketAddress,
message: DoipUdpMessage
) {
logger.traceIf { "> handleUdpMessage $message" }
when (message) {
is DoipUdpHeaderNegAck -> {
handleUdpHeaderNegAck(sendChannel, sourceAddress, message)
}
is DoipUdpVehicleInformationRequest -> {
handleUdpVehicleInformationRequest(sendChannel, sourceAddress, message)
}
is DoipUdpVehicleInformationRequestWithEid -> {
handleUdpVehicleInformationRequestWithEid(sendChannel, sourceAddress, message)
}
is DoipUdpVehicleInformationRequestWithVIN -> {
handleUdpVehicleInformationRequestWithVIN(sendChannel, sourceAddress, message)
}
is DoipUdpVehicleAnnouncementMessage -> {
handleUdpVehicleAnnouncementMessage(sendChannel, sourceAddress, message)
}
is DoipUdpEntityStatusRequest -> {
handleUdpEntityStatusRequest(sendChannel, sourceAddress, message)
}
is DoipUdpEntityStatusResponse -> {
handleUdpEntityStatusResponse(sendChannel, sourceAddress, message)
}
is DoipUdpDiagnosticPowerModeRequest -> {
handleUdpDiagnosticPowerModeRequest(sendChannel, sourceAddress, message)
}
is DoipUdpDiagnosticPowerModeResponse -> {
handleUdpDiagnosticPowerModeResponse(sendChannel, sourceAddress, message)
}
else -> {
handleUnknownDoipUdpMessage(sendChannel, sourceAddress, message)
}
}
}
public suspend fun handleUdpHeaderNegAck(
sendChannel: SendChannel,
sourceAddress: SocketAddress,
message: DoipUdpHeaderNegAck
) {
logger.traceIf { "> handleUdpHeaderNegAck $message" }
}
public suspend fun handleUdpVehicleInformationRequest(
sendChannel: SendChannel,
sourceAddress: SocketAddress,
message: DoipUdpVehicleInformationRequest
) {
logger.traceIf { "> handleUdpVehicleInformationRequest $message" }
}
public suspend fun handleUdpVehicleInformationRequestWithEid(
sendChannel: SendChannel,
sourceAddress: SocketAddress,
message: DoipUdpVehicleInformationRequestWithEid
) {
logger.traceIf { "> handleUdpVehicleInformationRequestWithEid $message" }
}
public suspend fun handleUdpVehicleInformationRequestWithVIN(
sendChannel: SendChannel,
sourceAddress: SocketAddress,
message: DoipUdpVehicleInformationRequestWithVIN
) {
logger.traceIf { "> handleUdpVehicleInformationRequestWithVIN $message" }
}
public suspend fun handleUdpVehicleAnnouncementMessage(
sendChannel: SendChannel,
sourceAddress: SocketAddress,
message: DoipUdpVehicleAnnouncementMessage
) {
logger.traceIf { "> handleUdpVehicleAnnouncementMessage $message" }
}
public suspend fun handleUdpEntityStatusRequest(
sendChannel: SendChannel,
sourceAddress: SocketAddress,
message: DoipUdpEntityStatusRequest
) {
logger.traceIf { "> handleUdpEntityStatusRequest $message" }
}
public suspend fun handleUdpEntityStatusResponse(
sendChannel: SendChannel,
sourceAddress: SocketAddress,
message: DoipUdpEntityStatusResponse
) {
logger.traceIf { "> handleUdpEntityStatusResponse $message" }
}
public suspend fun handleUdpDiagnosticPowerModeRequest(
sendChannel: SendChannel,
sourceAddress: SocketAddress,
message: DoipUdpDiagnosticPowerModeRequest
) {
logger.traceIf { "> handleUdpDiagnosticPowerModeRequest $message" }
}
public suspend fun handleUdpDiagnosticPowerModeResponse(
sendChannel: SendChannel,
sourceAddress: SocketAddress,
message: DoipUdpDiagnosticPowerModeResponse
) {
logger.traceIf { "> handleUdpDiagnosticPowerModeResponse $message" }
}
public suspend fun handleUnknownDoipUdpMessage(
sendChannel: SendChannel,
sourceAddress: SocketAddress,
message: DoipUdpMessage
) {
logger.traceIf { "> handleUnknownDoipUdpMessage $message" }
}
public suspend fun respondHeaderNegAck(
sendChannel: SendChannel,
address: SocketAddress,
code: Byte
) {
logger.traceIf { "> respondHeaderNegAck $code" }
sendChannel.send(
Datagram(
packet = ByteReadPacket(DoipUdpHeaderNegAck(code).asByteArray),
address = address
)
)
}
}