add command to TOPIN Protocol

Antonio Junior7 months ago

Greetings everyone.
I'm trying to implement a command to restart the TOPIN device.
According to the documentation, the information below would be:

0x48 restart the device
The server is sent to the device
Start bit 2byte packet length 1byte protocol number 1byte end bit 2byte
Eg.7878 01 48 0D0A
The device reboots after receiving this instruction

I implemented it as follows:
TopinProtocol.java

        if (!config.getBoolean(Keys.PROTOCOL_DISABLE_COMMANDS.withPrefix(getName()))) {
            setSupportedDataCommands(
                    Command.TYPE_SOS_NUMBER,
                    Command.TYPE_REBOOT_DEVICE
                    );
        }

TopinProtocolDecoder.java

  // ADD NEW COMMANDS

    public static final int MSG_RESTART_DEVICE = 0x48;

TopinProtocolEncoder.java

  switch (command.getType()) {
            case Command.TYPE_SOS_NUMBER:
                content.writeCharSequence(command.getString(Command.KEY_PHONE), StandardCharsets.US_ASCII);
                return encodeContent(TopinProtocolDecoder.MSG_SOS_NUMBER, content);
            case Command.TYPE_REBOOT_DEVICE:
                return encodeContent(TopinProtocolDecoder.MSG_RESTART_DEVICE,content);
            default:
                return null;
        }

I haven't done the tests yet, but could anyone tell me if I'm on the right track? Thanks!

Anton Tananaev7 months ago

You are on the right track.

Antonio Junior7 months ago

Thanks Anton, I'll implement some more and post them here.
To activate and deactivate the LED, I don't quite understand how to do it, could you help me? The documentation says it like this:

0x61 light sensor switch
The server is sent to the device
Start bit 2byte packet length 1byte protocol number 1byte flag bit 1byte end bit 2byte
Eg.7878 02 61 01 0D0A
Mark 01 open light sense, 00 turn off light perception

I saw that the variation would be
 61 01 - on
 61 00 - off

Would the command look like this? If it's not correct, could you help me?

TopinProtocol.java

setSupportedDataCommands(
                    Command.TYPE_SOS_NUMBER,
                    Command.TYPE_REBOOT_DEVICE,
                    Command.TYPE_SET_ENABLE_VIBRATION,
                    Command.TYPE_SET_DISABLE_VIBRATION,
                    Command.TYPE_SET_LED_ON,
                    Command.TYPE_SET_LED_OFF,
                    Command.TYPE_SET_LBS_ON,
                    Command.TYPE_SET_LBS_OFF,
                    Command.TYPE_POSITION_SINGLE

                    );
        }

TopinProtocolDecoder.java

// ADD NEW COMMANDS

    public static final int MSG_RESTART_DEVICE = 0x48;

    public static final int MSG_LED_OFF = 0x6100;

    public static final int MSG_LED_ON = 0x6101;

TopinProtocolEncoder.java

switch (command.getType()) {
            case Command.TYPE_SOS_NUMBER:
                content.writeCharSequence(command.getString(Command.KEY_PHONE), StandardCharsets.US_ASCII);
                return encodeContent(TopinProtocolDecoder.MSG_SOS_NUMBER, content);
            case Command.TYPE_REBOOT_DEVICE:
                return encodeContent(TopinProtocolDecoder.MSG_RESTART_DEVICE,content);
            case Command.TYPE_SET_ENABLE_VIBRATION:
                return encodeContent(TopinProtocolDecoder.MSG_VIBRATION_ON,content);
            case Command.TYPE_SET_DISABLE_VIBRATION:
                return encodeContent(TopinProtocolDecoder.MSG_VIBRATION_OFF,content);
            case Command.TYPE_SET_LED_ON:
                return encodeContent(TopinProtocolDecoder.MSG_LED_ON,content);
            case Command.TYPE_SET_LED_OFF:
                return encodeContent(TopinProtocolDecoder.MSG_LED_OFF,content);
            default:
                return null;
        }
Antonio Junior7 months ago

@Anton, sorry to bother you, could you please help me? I would like to also be able to help the community in the end. grateful!

Anton Tananaev7 months ago

Sorry, but writing code for you is out of scope for my forum support. We do have professional services if you need help with the customization.

Antonio Junior7 months ago

Okay, it wouldn't be for customization. But I understand your position. Thanks!

Anton Tananaev7 months ago

It will be a customization because we don't even have such a standard command in Traccar.

Antonio Junior7 months ago

I'm trying these commands based on the documentation, the tracker is very good for bicycles, the battery lasts well, and it has vibration, LED, lbs functions. But don't worry, I'll try here and who knows, maybe if I can finish it, I can suggest it as a feature issue.

Anton Tananaev7 months ago

To include a new type of command as an official feature in Traccar, we would need at the very least 2 different protocols requiring the same command.

Antonio Junior7 months ago

Hmm I understand, sorry for my lack of understanding. I will try to implement it here.