Teltonika FM4200 - request with few positions - bad sorting

Slawek8 years ago

Hi,
For few weeks I was customizing traccar for my needs based on 3.2 version. I've made many changes but there's one thing that I cannot resolve.
I'm using Teltonika FM4200 tracker. This device sometimes sends few position reports at a time. Sometimes it sends for example 3 positions report in random order in one request (I've set order in device properties but it seems it doesn't work) like this:
2016-01-15 12:41:23
2016-01-15 12:41:25
2016-01-15 12:41:21
I know that they have wrong order because I've checked in logs. As a result, async ajax responses gives me results also in wrong order so when I look at arrow which represents current position of a vehicle, it sometimes jumps to the newest position and suddenly it goes back to previous position because in the meantime, async request with older position comes in.
I think it's some bug with hardware or firmware of Teltonika's device. Despite of that, maybe there's some easy way to fix this in traccar.
Can you give me please some hints where I can find proper place in code for sorting positions which comes from one device request?

I'll appreciate any help, thanks!

Slawek.

Anton Tananaev8 years ago

You can modify ExtendedObjectDecoder class if you want to order positions:

https://github.com/tananaev/traccar/blob/master/src/org/traccar/ExtendedObjectDecoder.java#L45

Slawek8 years ago

I've implemented sorting and handleUpstream method of ExtendedObjectDecoder now looks like this:


            if (decodedMessage instanceof Collection) {
                Collections.sort((List<Comparable>) decodedMessage);
                for (Object o : (Collection) decodedMessage) {
                    Position p = (Position)o;
                    Log.debug(p.getFixTime().toString());
                    Channels.fireMessageReceived(ctx, o, e.getRemoteAddress());
                }
            } else {

and Position class implements Comparable interface:


    public int compareTo(Position o) {
        return this.getFixTime().before(o.getFixTime()) ? -1 : 1;
    }

in logs I can see that sorting works but positions are still sent unsorted:


2016-01-16 14:37:40 DEBUG: Sat Jan 16 14:37:30 CET 2016
2016-01-16 14:37:40 DEBUG: Sat Jan 16 14:37:31 CET 2016
2016-01-16 14:37:40 DEBUG: Sat Jan 16 14:37:32 CET 2016
2016-01-16 14:37:40 DEBUG: Sat Jan 16 14:37:35 CET 2016
2016-01-16 14:37:40  INFO: [59F795DC] id: 3, time: 2016-01-16 14:37:31, lat: 54.54859, lon: 18.50299, speed: 18.4, course: 153.0
2016-01-16 14:37:40  INFO: [59F795DC] id: 3, time: 2016-01-16 14:37:30, lat: 54.54867, lon: 18.50291, speed: 17.8, course: 143.0
2016-01-16 14:37:40  INFO: [59F795DC] id: 3, time: 2016-01-16 14:37:32, lat: 54.54843, lon: 18.50306, speed: 18.9, course: 171.0
2016-01-16 14:37:40  INFO: [59F795DC] id: 3, time: 2016-01-16 14:37:35, lat: 54.54825, lon: 18.50306, speed: 19.4, course: 181.0

maybe it's separate threads related or something?

Anton Tananaev8 years ago

It might be on a separate thread. It's definitely sends message asynchronously. Can't think of any easy solution for this problem.

Slawek8 years ago

Ok, maybe I'll just make a protection on frontend in js so it won't load older positions.

Thanks for your reply.

Anton Tananaev8 years ago
Slawek8 years ago

Yes but I want to make such protection on frontend side in js because async requests from java comes with wrong fix time order so probably in this case I have to correct this on javascript side.

Anton Tananaev8 years ago

Looks like there is some threading issue. I will think about possible solutions, but for now client side filtering sounds like the simplest workaround.