Your expression returns int
value. You should return boolean
with something like this:
status ? (status & 0x0800 > 0) : false
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?
Brackets missing:
status ? ((status & 0x0800) > 0) : false
status ? ((status & 0x0800) > 0) : false
The above expression always returns false.
It means that status doesn't have bit that you are expecting.
It is set, I'm sure of it
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.
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.
It means that value is a string, so you need to convert it to integer first.
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
andign 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.
You can try something like this to convert string to int:
new("java.lang.Integer", 0).parseInt(status, 16)
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
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(";java.lang.Integer";, 0).parseInt(status, 16) &amp; 0x0400) &gt; 0) : false
traccar seems to be substituting the " for " and this throws an error when testing
Don't modify it once you created computed attribute.
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?