Skip to content

Commit

Permalink
Merge pull request #16 from paulorb/ISSUE-15
Browse files Browse the repository at this point in the history
fix(ISSUE-15): ifGreater not working as expected
  • Loading branch information
paulorb authored Oct 30, 2024
2 parents d108e1c + f67bea6 commit f0a87bf
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/badges/branches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion .github/badges/jacoco.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/main/kotlin/PlcSimulation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PlcSimulation(
memory: PlcMemory,
private val parameters: EnvironmentVariables,
coroutineScope: CoroutineScope
): BaseOperation(parameters,configurationParser.getConfiguredDevice().configuration ) {
): BaseOperation(parameters,configurationParser.getConfiguredDevice().configuration, memory ) {
val linearOperations = LinearOperation()
val csvOperations = CsvOperation()
var traceOperation = TraceOperation(configurationParser.getConfiguredDevice().configuration, memory, parameters)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/operations/AddOperation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.slf4j.LoggerFactory
import java.util.concurrent.CancellationException

class AddOperation(private val configuration: Configuration,private val memory: PlcMemory, environmentVariables: EnvironmentVariables
) : BaseOperation(environmentVariables, configuration) {
) : BaseOperation(environmentVariables, configuration, memory) {

companion object {
val logger = LoggerFactory.getLogger("AddOperation")
Expand Down
48 changes: 46 additions & 2 deletions src/main/kotlin/operations/BaseOperation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package operations

import Configuration
import EnvironmentVariables
import PlcMemory
import Register
import isNumeric
import java.rmi.NotBoundException
import java.util.concurrent.CancellationException

abstract class BaseOperation(
private val parameters: EnvironmentVariables,
private val configuration: Configuration
private val configuration: Configuration,
private val memory: PlcMemory
) {
/**
* processValue convert any variable name used as value to the actual value
Expand All @@ -27,9 +31,49 @@ abstract class BaseOperation(
//value is a symbolic register
var symbolicVariable = configuration.registers.getVarConfiguration(value)
if (symbolicVariable != null) {
return symbolicVariable.value
return resolveSymbolicVariable(symbolicVariable)
}
throw NotBoundException("Invalid value, value is not numeric and also not a parameter nor a symbolic register")
}

fun resolveSymbolicVariable(variable: Register) : String{
when (variable.addressType) {

AddressType.HOLDING_REGISTER -> {
//get the current value
//Mult
//set back the new value

if (variable.datatype == "FLOAT32") {
var currentValue = memory.readHoldingRegister(variable.address.toInt(), 2)
if(currentValue.isEmpty()){
throw CancellationException("Error - Base Operation")
}
val intValue = (( currentValue[1].toInt() shl 16) or (currentValue[0].toInt() and 0xFFFF))
return java.lang.Float.intBitsToFloat(intValue).toString()
} else {
var currentValue = memory.readHoldingRegister(variable.address.toInt(), 1)
if(currentValue.isEmpty()){
throw CancellationException("Error - Base Operation")
}
return currentValue.first().toInt().toString()
}
}
AddressType.INPUT_REGISTER -> {
val currentValue = memory.readInputRegister(variable.address.toInt(), 1)
return currentValue.first().toShort().toString()
}
AddressType.COIL -> {
var currentValue = memory.readCoilStatus(variable.address.toInt(), 2)
if(currentValue.isEmpty()){
throw CancellationException("Error - Base Operation")
}
return currentValue.first().toString()
}

else -> {
throw CancellationException("Error - Base Operation")
}
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/operations/DivOperation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.slf4j.LoggerFactory
import java.util.concurrent.CancellationException

class DivOperation(private val configuration: Configuration,private val memory: PlcMemory, environmentVariables: EnvironmentVariables
) : BaseOperation(environmentVariables, configuration) {
) : BaseOperation(environmentVariables, configuration, memory) {

companion object {
val logger = LoggerFactory.getLogger("DivOperation")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/operations/MultOperation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.slf4j.LoggerFactory
import java.util.concurrent.CancellationException

class MultOperation(private val configuration: Configuration,private val memory: PlcMemory, environmentVariables: EnvironmentVariables
) : BaseOperation(environmentVariables, configuration) {
) : BaseOperation(environmentVariables, configuration, memory) {

companion object {
val logger = LoggerFactory.getLogger("MultOperation")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/operations/SetOperation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import toBooleanFromBinary
import java.util.concurrent.CancellationException

class SetOperation(private val configuration: Configuration,private val memory: PlcMemory, environmentVariables: EnvironmentVariables
) : BaseOperation(environmentVariables, configuration) {
) : BaseOperation(environmentVariables, configuration, memory) {

companion object {
val logger = LoggerFactory.getLogger("SetOperation")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/operations/SubOperation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.util.concurrent.CancellationException


class SubOperation(private val configuration: Configuration,private val memory: PlcMemory, environmentVariables: EnvironmentVariables
) : BaseOperation(environmentVariables, configuration) {
) : BaseOperation(environmentVariables, configuration, memory) {

companion object {
val logger = LoggerFactory.getLogger("SubOperation")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/operations/TraceOperation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.util.concurrent.CancellationException
class TraceOperation(
private val configuration: Configuration, private val memory: PlcMemory, environmentVariables: EnvironmentVariables

) : BaseOperation(environmentVariables, configuration) {
) : BaseOperation(environmentVariables, configuration, memory) {
companion object {
val logger = LoggerFactory.getLogger("TraceOperation")
}
Expand Down

0 comments on commit f0a87bf

Please sign in to comment.