I’m trying to do some bit manipulation in a DSL Rules script.
rule "Test Rule"
when
Item Something changed
then
var int i1 = -2147457441
var int i2 = i1 & 0x0FFFFFFF
// then do something with them...
end
However, the Rules DSL doesn’t appear to like the ‘&’ operator and I get this error:
2021-02-08 18:47:27.988 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'rulefile.rules' has errors, therefore ignoring it: [207,15]: no viable alternative at input 'i1'
The line number refers to the line with the attempted ‘&’ operation.
Does anyone know how I can achieve this in Rules DSL?
The example above with the bitwiseAnd operation on Integer variables works also fine on my setup of OpenHab 3.0.1. However, I fail to adapt this example to apply a bitwise and operation to a received number state.
val Number HvacState = APPEG_Zimmer_Betriebsartstatus_HVAC.state as Number
var Integer HvacMode = HvacState.bitwiseAnd(0x0F)
The result is:
2021-03-21 12:43:00.157 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'knx-1' failed: 'bitwiseAnd' is not a member of 'java.lang.Number'; line 11, column 26, length 25 in knx
I am not familiar with the proper casting of states. When I try to read the state as integer, I receive a different error message…
Does anybody has a hint as how to properly apply bitwise operations onto received number states?
Thank you very much for your hint. Unfortunately, I receive a slightly different error message when applying the suggested change:
[line 38] val HvacState = (APPEG_Bad_Betriebsartstatus_HVAC.state as Number).intvalue
[line 39] var Integer HvacMode = HvacState.bitwiseAnd(0x0F)
The result is:
2021-03-21 14:42:19.480 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'knx-2' failed: 'intvalue' is not a member of 'java.lang.Number'; line 38, column 18, length 59 in knx