Computed attribute byte to ascii

Nikolay a year ago

Hello,
I'm trying to make a computed attribute that converts from byte to ASCII.
I have io1014 with a byte value of 66, which in ASCII is "B"

I tried the following things:
io1014 ? chr(io1014) : null

io1014 ? chr(io1014.toInt()) : null

io1014 ? String.fromCharCode(io1014.toInt()) : null

io1014 ? ${chr(io1014.toInt())} : null

io1014 ? ${chr(io1014)} : null

The errors I get are:

unsolvable function/method 'chr(Byte)' - Method

unsolvable function/method 'chr(object)' - Method

Or it just stays 66

Anton Tananaeva year ago

Expressions are based on Java language.

Nikolay a year ago

I'm not sure I understood.

In java I would do the following.

byte io1014 = (byte) 66
int digit = (io1014 & 0xFF);
char needed = (char) digit

or

char needed = (char) (io1014 & 0xFF)

or

Expression

io1014 ? (char) (io1014 & 0xFF) : null

which will result in this :)

org.traccar.handler.ComputedAttributesHandler.computeAttribute:119@1:12 variable 'char' is undefined - Variable (ComputedAttributesHandler:120 < AttributeResource:63 < ...)
Anton Tananaeva year ago

Maybe you can have something like this:

new("java.lang.Character", io1014).toString()