Filter responses packets Teltonika

Peter Flower4 years ago

Hi, how are you? How can I mark as INVALID packets which comes as responses of commands from a Teltonika devices? Packets marked as CODEC_12 exactly, I was trying to do it into: TeltonikaProtocolDecoder.java, but didn't work it. I don't wanna add it into Traccar.

Best Regards
Peter

Anton Tananaev4 years ago

TeltonikaProtocolDecoder is probably the right place.

Peter Flower4 years ago

Hi Anton, thanks for your quick reply. I tried to set inside some if structures but I couldn't.
Is it correct set valid in this way:
Line 639:

} else if (codec == CODEC_12) {
          decodeSerial(channel, remoteAddress, position, buf);
          position.setValid(false);  // LINE ADDED!!!
} else {
          decodeLocation(position, buf, codec);
}
Peter Flower4 years ago

It seems, I did it:

traccar/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java

} else {

            position.set(Position.KEY_TYPE, type);

            int length = buf.readInt();
            if (isPrintable(buf, length)) {
                String data = buf.readSlice(length).toString(StandardCharsets.US_ASCII).trim();
                if (data.startsWith("UUUUww") && data.endsWith("SSS")) {
                    String[] values = data.substring(6, data.length() - 4).split(";");
                    for (int i = 0; i < 8; i++) {
                        position.set("axle" + (i + 1), Double.parseDouble(values[i]));
                    }
                    position.set("loadTruck", Double.parseDouble(values[8]));
                    position.set("loadTrailer", Double.parseDouble(values[9]));
                    position.set("totalTruck", Double.parseDouble(values[10]));
                    position.set("totalTrailer", Double.parseDouble(values[11]));
                } else {
                    position.set(Position.KEY_RESULT, data);
                }
            } else {
                position.set(Position.KEY_RESULT, ByteBufUtil.hexDump(buf.readSlice(length)));
            }
            position.setValid(false);
        }

I have added this line: position.setValid(false);

Anton, please your help, confirming if this is the best part.