Computed Attributes - Help with testing the ignition status of Meiligao devices

John H. Ward, Jr. 8 years ago

Hello all,

From what I understand from the examples in the Traccar documentation pages regarding Computed Attributes this should work, it does not, at least not with the Meiligao device I'm working with...

Ignition
status ? (status & 0x0800) : false
boolean

I have also tried....

Ignition
status ? (status & 2048) : false
boolean

Which does not work either. What am I doing wrong?

Anton Tananaev 8 years ago

Your expression returns int value. You should return boolean with something like this:

status ? (status & 0x0800 > 0) : false
John H. Ward, Jr. 8 years ago

The expression...

status ? (status & 0x0800 > 0) : false

errors and returns this....

"Error
Invalid parameter or constraints violation

java.lang.Long cannot be cast to java.lang.Boolean - ClassCastException (AttributeResource:57 < ...)"

I think "status" is a string, no?

Anton Tananaev 8 years ago

Brackets missing:

status ? ((status & 0x0800) > 0) : false
John H. Ward, Jr. 8 years ago

status ? ((status & 0x0800) > 0) : false

The above expression always returns false.

Anton Tananaev 8 years ago

It means that status doesn't have bit that you are expecting.

John H. Ward, Jr. 8 years ago

It is set, I'm sure of it

John H. Ward, Jr. 8 years ago

It looks like status is stored as a string in MeiligaoProtocolDecoder.java

Changing the code at around line 256 to store it in flags as an integer seems to have fixed it.

jaimzj 8 years ago

is this change to store status in flags as integer already done in the code?

I am trying get Ignition status from 'status' using computed attribute however it returns the following error.

'For input string: "0A00" - NumberFormatException (... < ComputedAttributesHandler:86 < AttributeResource:51 < ...)'

Any help would be highly appreciated.

Anton Tananaev 8 years ago

It means that value is a string, so you need to convert it to integer first.

jaimzj 8 years ago

Hello Anton,

I tried taking hints from this post https://www.traccar.org/forums/topic/doubt-with-computed-attributes-protocol-suntech/ on converting strings to integer, however i kept getting errors for jexel.

the status value is as following

ign of status value 0201 = 0000 0010 0000 0001
and
ign on status value OA01 = 0000 1010 0000 0001

and from this post i took the computted attribute example status ? ((status & 0x0800) > 0) : false

and tried this status ? (((new ("java.lang.Integer", status)) & 0x0800) > 0) : false also tried few other approach, but i am surely making some mistake,

could you please help me on this again.

Anton Tananaev 8 years ago

You can try something like this to convert string to int:

new("java.lang.Integer", 0).parseInt(status, 16)
jaimzj 8 years ago

Thanks Anton,

Sharing in-case it comes of use to any other user in the future. the computed attribute that worked for me for Meiligao Protocol device to detect ignition status.

status ? ((new("java.lang.Integer", 0).parseInt(status, 16) & 0x0800) > 0) : false
Jamie S 7 years ago

hi
I am also trying to get ignition status working with meitrack T366 as it doesnt appear automatically
when i try add computed attribute as above, i can click test without saving it and it returns 'false' as id expect but as soon as i save it and then go back and view it, it shows and error and the string is changed to status ? ((new(&#34;;java.lang.Integer&#34;;, 0).parseInt(status, 16) &amp;amp; 0x0400) &amp;gt; 0) : false

traccar seems to be substituting the " for &#34 and this throws an error when testing

Anton Tananaev 7 years ago

Don't modify it once you created computed attribute.