Skip to content

Commit

Permalink
bugfix gateways not having defined properties
Browse files Browse the repository at this point in the history
  • Loading branch information
froks committed Jan 26, 2022
1 parent ffd19d9 commit a4efbe8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
42 changes: 31 additions & 11 deletions doip-sim-ecu-dsl/src/main/kotlin/SimDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -233,23 +233,34 @@ fun MutableList<RequestMatcher>.removeByName(name: String): RequestMatcher? {

data class ResetHandler(val name: String?, val handler: (SimEcu) -> Unit)

open class RequestsData(val name: String, requests: List<RequestMatcher> = emptyList(), resetHandler: List<ResetHandler> = emptyList()) {
open class RequestsData(
val name: String,
/**
* List of all defined requests in the order they were defined
* Return a nrc when no request could be matched
*/
val requests: MutableList<RequestMatcher> = mutableListOf(*requests.toTypedArray())

val resetHandler: MutableList<ResetHandler> = mutableListOf(*resetHandler.toTypedArray())

var nrcOnNoMatch: Boolean = true,
requests: List<RequestMatcher> = emptyList(),
resetHandler: List<ResetHandler> = emptyList(),
/**
* Maximum length of data converted into a hex-string for incoming requests
*/
var requestRegexMatchBytes: Int = 10
var requestRegexMatchBytes: Int = 10,

/**
* Map of Request SID to number of ack response byte count
*/
var ackBytesLengthMap: Map<Byte, Int> = mapOf()
var ackBytesLengthMap: Map<Byte, Int> = mapOf(),
) {
/**
* List of all defined requests in the order they were defined
*/
val requests: MutableList<RequestMatcher> = mutableListOf(*requests.toTypedArray())

/**
* List of defined reset handlers
*/
val resetHandler: MutableList<ResetHandler> = mutableListOf(*resetHandler.toTypedArray())


private fun regexifyRequestHex(requestHex: String) =
Regex(
Expand Down Expand Up @@ -320,10 +331,19 @@ open class EcuData(
name: String,
var physicalAddress: Int = 0,
var functionalAddress: Int = 0,
var nrcOnNoMatch: Boolean = true,
nrcOnNoMatch: Boolean = true,
requests: List<RequestMatcher> = emptyList(),
resetHandler: List<ResetHandler> = emptyList()
) : RequestsData(name, requests, resetHandler)
resetHandler: List<ResetHandler> = emptyList(),
requestRegexMatchBytes: Int = 10,
ackBytesLengthMap: Map<Byte, Int> = mapOf(),
) : RequestsData(
name = name,
nrcOnNoMatch = nrcOnNoMatch,
requests = requests,
resetHandler = resetHandler,
requestRegexMatchBytes = requestRegexMatchBytes,
ackBytesLengthMap = ackBytesLengthMap,
)

val gateways: MutableList<GatewayData> = mutableListOf()
val gatewayInstances: MutableList<SimGateway> = mutableListOf()
Expand Down
4 changes: 4 additions & 0 deletions doip-sim-ecu-dsl/src/main/kotlin/SimGateway.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class SimGateway(private val data: GatewayData) : StandardGateway(data.toGateway
physicalAddress = data.logicalAddress,
functionalAddress = data.functionalAddress,
requests = data.requests,
nrcOnNoMatch = data.nrcOnNoMatch,
resetHandler = data.resetHandler,
requestRegexMatchBytes = data.requestRegexMatchBytes,
ackBytesLengthMap = data.ackBytesLengthMap,
)
return SimEcu(ecu)
}
Expand Down

0 comments on commit a4efbe8

Please sign in to comment.