Skip to content

Commit

Permalink
Merge pull request #14 from paulorb/MultDivOperation
Browse files Browse the repository at this point in the history
feat(ISSUE-13): Add support for Mult, Div, IfLess and ifGreater
  • Loading branch information
paulorb authored Sep 10, 2024
2 parents bbd7cae + 30705e4 commit 8a73fbf
Show file tree
Hide file tree
Showing 8 changed files with 532 additions and 3 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.
30 changes: 30 additions & 0 deletions docs/getting-started/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,36 @@ Supported registers: **HOLDING_REGISTER**, **INPUT_REGISTER**
*For **INPUT_REGISTER** type *FLOAT32* is not supported!*


## Mult
Mult (as the name implies) multiplies a certain value of a variable, like the example below:

```xml
<mult symbol="MOTOR_SPEED1">1.12</mult>
```

Both **symbol** and **value** are mandatory fields. **value** can be of type *FLOAT32* , *INT16* which must
follow the same type of the specified **symbol** definition.

Supported registers: **HOLDING_REGISTER**, **INPUT_REGISTER**

*For **INPUT_REGISTER** type *FLOAT32* is not supported!*


## Div
Div (as the name implies) divides a certain value of a variable, like the example below:

```xml
<div symbol="MOTOR_SPEED1">1.12</div>
```

Both **symbol** and **value** are mandatory fields. **value** can be of type *FLOAT32* , *INT16* which must
follow the same type of the specified **symbol** definition.

Supported registers: **HOLDING_REGISTER**, **INPUT_REGISTER**

*For **INPUT_REGISTER** type *FLOAT32* is not supported!*


## Random
Random generates new random values each time it executes

Expand Down
13 changes: 13 additions & 0 deletions examples/configuration_simulation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,20 @@
<set symbol="RPM_MOTOR">100</set>
<set symbol="MOTOR_SPEED1">100.5</set>
<random symbol="TEMPERATURE1" valueMin="-50.0" valueMax="10.0"/>
<trace symbol="TEMPERATURE1" />
<delay>500</delay>
<set symbol="RPM">60</set>
<set symbol="MOTOR_SPEED1">190.5</set>
<mult symbol="MOTOR_SPEED1">2.5</mult>
<trace symbol="MOTOR_SPEED1" />
<ifGreater symbol="MOTOR_SPEED1" value="470.0">
<trace symbol="MOTOR_SPEED1" />
</ifGreater>
<div symbol="MOTOR_SPEED1">3.5</div>
<ifLess symbol="MOTOR_SPEED1" value="470.0">
<trace symbol="MOTOR_SPEED1" />
</ifLess>
<trace symbol="MOTOR_SPEED1" />
<ifEqual symbol="RPM_MOTOR1" value="1">
<set symbol="RPM_MOTOR1">777</set>
<ifEqual symbol="RPM_MOTOR1" value="777">
Expand All @@ -74,9 +85,11 @@
</ifEqual>
<linear symbol="TEMPERATURE_MOTOR1" a="3" b="2" startX="0" endX="12" replay="true" step="1.5"/>
<linear symbol="TEMPERATURE_MOTOR2" a="3" b="2" startX="12" endX="0" replay="true" step="1.5"/>
<trace symbol="TEMPERATURE_MOTOR2" />
<csv symbol="TEMPERATURE_MOTOR3" file="test_data.csv" column="1" replay="true"/>
<csv symbol="TEMPERATURE_MOTOR4" file="test_data.csv" column="2" step="2" startRow="2" endRow="5" replay="true"/>
<set symbol="RELAYON">1</set>
<trace symbol="RELAYON" />
<set symbol="RELAY_STATUS">1</set>
<trace symbol="RPM_MOTOR" />
<set symbol="RPM_MOTOR">400</set>
Expand Down
59 changes: 58 additions & 1 deletion src/main/kotlin/ConfigurationParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ConfigurationParser {
}
private fun load(): Device? {
try {
val context = JAXBContext.newInstance(Device::class.java, Set::class.java, Random::class.java, Delay::class.java, Linear::class.java, Add::class.java, Sub::class.java, Csv::class.java, IfEqual::class.java, Parameters::class.java, Parameter::class.java, Trace::class.java)
val context = JAXBContext.newInstance(Device::class.java, Set::class.java, Random::class.java, Delay::class.java, Linear::class.java, Add::class.java, Sub::class.java, Csv::class.java, IfEqual::class.java, Parameters::class.java, Parameter::class.java, Trace::class.java, Mult::class.java, Div::class.java, IfGreater::class.java, IfLess::class.java)
val unmarshaller = context.createUnmarshaller()
return if(fileName.isEmpty() ) {
val reader = StringReader(this::class.java.classLoader.getResource("configuration.xml")!!.readText())
Expand Down Expand Up @@ -97,6 +97,40 @@ data class IfEqual(
constructor() : this("","",mutableListOf())
}

//<ifGreater symbol="TEMP" value="12.4">
// <sub symbol="MOTOR_SPEED1">12</sub>
// any other operation ...
//</ifGreater>
@XmlRootElement(name="ifGreater")
data class IfGreater(
@field:XmlAttribute(required = true)
val symbol: String,
@field:XmlAttribute(required = true)
val value: String,
@XmlAnyElement(lax = true)
var randomElements: List<Any>
){
constructor() : this("","",mutableListOf())
}

//<ifLess symbol="TEMP" value="12.4">
// <sub symbol="MOTOR_SPEED1">12</sub>
// any other operation ...
//</ifLess>
@XmlRootElement(name="ifLess")
data class IfLess(
@field:XmlAttribute(required = true)
val symbol: String,
@field:XmlAttribute(required = true)
val value: String,
@XmlAnyElement(lax = true)
var randomElements: List<Any>
){
constructor() : this("","",mutableListOf())
}



//<csv symbol="TEMPERATURE_MOTOR4" file="test.csv" column="0" step="2" startRow="2" endRow="100" replay="true"/>
@XmlRootElement(name="csv")
data class Csv(
Expand Down Expand Up @@ -173,6 +207,29 @@ data class Add(
constructor(): this("", "0")
}

//<mult symbol="MOTOR_SPEED1">RPM_MOTOR1</mult>
@XmlRootElement(name="mult")
data class Mult(
@field:XmlAttribute(required = true)
val symbol: String,
@field:XmlValue
val value: String,
){
constructor(): this("", "0")
}

//<div symbol="MOTOR_SPEED1">RPM_MOTOR1</div>
@XmlRootElement(name="div")
data class Div(
@field:XmlAttribute(required = true)
val symbol: String,
@field:XmlValue
val value: String,
){
constructor(): this("", "0")
}


//<delay>100</delay>
@XmlRootElement(name="delay")
data class Delay(
Expand Down
Loading

0 comments on commit 8a73fbf

Please sign in to comment.