Purpose of model names in Decoder and Encoder files

Nils Leideck 25 days ago

I noticed that the JT808 Protocol Decoder and the JT808 Protocol Encoder mention specific models or manufacturers in some places.

For example, in the Decoder:

    private static final Set<String> ALARM_MODELS_TAMPER = Set.of("G-360P", "G-508P");
    private static final Set<String> ALARM_MODELS_MOVEMENT = Set.of("AL300", "GL100");
    private static final Set<String> JC_MODELS = Set.of("JC371", "JC181", "JC182", "JC450", "JC451");

and

            if (BitUtil.check(value, 29) || BitUtil.check(value, 30)) {
                if (model == null || !model.equals("VL300")) {
                    position.addAlarm(Position.ALARM_ACCIDENT);
                }
            }

and

        if ("MV810G".equals(model) || "MV710G".equals(model)) {
            position.set(Position.KEY_DOOR, BitUtil.check(status, 16));
        }

and in the Encoder:

    protected Object encodeCommand(Channel channel, Command command) {
...
                case Command.TYPE_CUSTOM:
                    if (model != null && Set.of("AL300", "GL100", "VL300").contains(model)) {
...
                    } else if ("BSJ".equals(model)) {
...
                    } else {
                        return Unpooled.wrappedBuffer(DataConverter.parseHex(command.getString(Command.KEY_DATA)));
                    }

Unfortunately, just looking at the code, I can’t really figure out what this is all about. Out of sheer curiosity, I set the “Model” field in the Traccar GUI for one of my JT808 devices to “BSJ,” and to my surprise, I found that this resolved some command issues with self-encoded commands, because Traccar now encodes the commands on its own. That’s great, but of course it now requires me to assign a “wrong” model to all my devices, so to speak. The actual models are called C5 and C5L from the manufacturer Xchinchun.

Is the simple solution to include these models in the encoder’s code, or have I misunderstood?

-- Cheers, Nils

Anton Tananaev 25 days ago

Yes, we should include models.

Nils Leideck 25 days ago

What would a unit test for this look like? Do you have an example for me?

Anton Tananaev 24 days ago

There are examples in the code.

Nils Leideck 23 days ago

PR created: https://github.com/traccar/traccar/pull/5890

Hope this sufficient.

-- Cheers, Nils