Hi,
what is the best way to convert this string into a HEX?
40.255.240.136.131.23.04.78.
I do want to have a string-result like this:
28FFF3B39017052C
or maybe the 28 FF F3 B3 90 17 05 2C
Regards
Hi,
what is the best way to convert this string into a HEX?
40.255.240.136.131.23.04.78.
I do want to have a string-result like this:
28FFF3B39017052C
or maybe the 28 FF F3 B3 90 17 05 2C
Regards
DSL rules fragment
val String rawdata = "40.255.240.136.131.23.04.78"
val chunks = rawdata.split("\\.") // escape stop char
val StringBuilder sb = new StringBuilder
chunks.forEach(b | sb.append(Integer::toHexString(Integer::parseInt(b)).toUpperCase + " "))
logInfo("test", "output " + sb)
2020-07-13 02:29:03.256 [INFO ] [.eclipse.smarthome.model.script.test] - output 28 FF F0 88 83 17 4 4E
Nice, it is working well, but how ca I get a leading Zero if b < 10?
Some suggestions here (It’s b< 16 you are interested in)
i’d try the .format()
method.
Using a big X in there will replace the toUpperCase
as well.
Why did I get this Error?
Configuration model 'wind.rules' has errors, therefore ignoring it: [70,4]: no viable alternative at input 'var' [76,3]: mismatched input ')' expecting 'end'
Part of Rule
val StringBuilder adr_hex_01 = new StringBuilder
temp_adr_01.split("\\.").forEach
(b |
var val_int = Integer::parseInt(b)
if (val_int < 16)
{
adr_hex_01.append("0")
}
adr_hex_01.append(Integer::toHexString(val_int).toUpperCase)
)
You need to use curly braces to denote your multi-line code, like you do with if()
temp_adr_01.split("\\.").forEach
(b | {
var val_int = Integer::parseInt(b)
...
}
Great, thanks a lot.
Got this error message, why?
val wind_dir_inv = transform("JSONPATH", "$.variables.sb", res)
val wind_spd_inv = transform("JSONPATH", "$.variables.sc", res)
val wind_dir_inv_grad = wind_dir_inv * 22.5
val wind_spd_inv_msec = wind_spd_inv / 10
error msg:
Error during the execution of rule 'rule_get_status': Unknown variable or command '*'; line 231, column 27, length 19
The transform returns a string. Variable wind_dir_inv is a string.
Variable wind_dir_inv is a string. The rules parser does not understand what you mean by '*'
here, because you cannot multiply a string.
You already know how to parse a string into a Number.