Bitwise Computed attribute calculation error

James4 years ago

Hi,
I'm trying to use a computed attribute to display the status of of a BLE sensor for a teltonika FMB device. Most of the time this works, but I am getting periods where it errors.

The teltonika spec says:

MAG Mode data Example:
IO ID[331] Length[ 2]: 00 02 BLE Custom 1
00 02 - 0000 0000 0000 0010 (15 Bits Movement Counter: Attached/Detached Counter 1 time; 1 bit State
of Sensor: Current State 0, Detached)

So in short, the last (lsb) bit is what shows the status of the sensor.

I figured that I should be able to achieve this with the following computed attribute (spaces added for clarity):

io331 ? ( io331 & 0x00000001 ) == 0 ? "open" : "closed" : null

Most of the time this works fine, but it seems that when the counter gets to a certain point I get the following error:

error - For input string: "001b" - NumberFormatException (... < ComputedAttributesHandler:102 < *:113 < BaseDataHandler:27 < ... < *:29 < ... < *:29 < ... < *:29 < ... < GeocoderHandler:90 < ...)

If I and 001b & 00000001 I get 1, which is what I would expect as the sensor is closed, but this seems to error (as above)

Any suggestions would be appreciated.

Anton Tananaev4 years ago

It should not be a string in the first place. Why is it not a number?

James4 years ago

You mean like this?
io331 ? ( io331 & 0x00000001 ) == 0 ? 0 : 1 : null

Anton Tananaev4 years ago

No, I'm talking about the attribute io331.

James4 years ago

It's a hex value - it seems to work when the value is represented by numbers (eg 0044) but not when it isn't (eg 001b)

Anton Tananaev4 years ago

But it should not be a string in the first place. It should be an integer.

James4 years ago

Ok, so is it a bug then?

James4 years ago

The Teltonika spec from here: https://wiki.teltonika-gps.com/view/FMB_AVL_ID


Property ID In AVL Packet	Property Name	Bytes	Type	Value Range	Multiplier	Units	Description	HW Support	Parameter Group
331	BLE Sensor 1	Variable	HEX	0	256	-	-	Raw data of BLE sensor	Devices: [Expand]	Permanent I/O elements
Anton Tananaev4 years ago

I see. Looks like it's raw HEX data. You should parse it first and convert into an integer. Something like Integer.parseInt(io331, 16).

James4 years ago

Perfect, thank you I'll give it a go.

I did suspect it would be something like that, but it's trying to search for the right thing... I was looking for cast.

Will try the above and report back.

Thanks again

James4 years ago

this errors...

org.traccar.handler.ComputedAttributesHandler.computeAttribute@102![16,35]: 'io331? (Integer.parseInt(io331, 16) & 0x00000001) == 0? 0 : 1 : null;' attempting to call method on null - JexlException (... < ComputedAttributesHandler:102 < AttributeResource:57 < ...)
James4 years ago

Got it sorted in the end here's the final computed attribute:

io331 ? ( new("java.lang.Integer", 0).parseInt(io331, 16) & 0x00000001 ) == 0 ? "open" : "closed" : null
Sharipov3 years ago
http://localhost:8082/api/reports/summary?type=allEvents&page=1&start=0&limit=25&from=2021-03-08T19:00:00.000Z&to=2021-03-09T19:00:00.000Z&deviceId=52,49,44&daily=false

return For input string: "52,49,44" - NumberFormatException (...)

Anton Tananaev3 years ago

Sharipov you are completely off-topic here.