Computed Attributes; Formula, loops, definitions

Chris4 years ago

Hi,

I'm using Traccar 4.10

My device reports status 4294966271 (dezimal) but I need it on binary. Each bit gives me a differnet spezific state (oil cut off, battery remove, ...).
I've tried to convert the dezimal to binary (with mod operator) bit I can't even get a simple loop to run.
Are there any restrictions at the computed attributes?
Normaly I would write in C++ something like:

while (dezimal) //solange dezimal != 0 ist
{
  rest = dezimal % 2;
  dezimal = dezimal / 2;
  ergebnis = ergebnis + (rest * faktor);
  faktor= faktor * 10;
}
printf ("%i als binaere Zahl: %i\n ", zahl, ergebnis);

What is the coorect way to output a value on jexl?

Regards
Chris

Anton Tananaev4 years ago

Why not just create computed attribute for each specific value that you want to extract and use standard bitmask check?

Chris4 years ago

because traccar gives me a deciamal value over all bits....

eg: 4294966271 instead of 1111 1111 1111 1111 1111 1011 1111 1111

Anton Tananaev4 years ago

How is that relevant? It's an integer and you can apply a mask to it.

Chris4 years ago

I can't follow your idea. How would you do it?
I thought I've to vonvert the dezimal value to binary and only then, I will able to get each value of the 16bits...

Anton Tananaev4 years ago

Computers only operate in binary data. Internally all integers are binary.

Let's say you want to check bit number 2, you can do something like this:

value & 0b100 != 0
Chris4 years ago

Ok, thank you for the idea!
I will try it!!

Chris4 years ago

I've tried some ideas, but non worked
0b100 will not accepted from the parser, only 0x100

Therefor I had to convert the 0b100 to dec (=4) and do the logical AND

my code:

status ? ( status & 4 ) != 0 ? "0" : "1" : null

Type String

Thank you for the idea!

Do you have a donation-link?

Anton Tananaev4 years ago

Here's a donation link:

https://www.traccar.org/donate/

Thanks

Chris4 years ago

Done form eagleeye@c****o.at

Anton Tananaev4 years ago

Thank you!