From 989956915085944d6d5ac550020a7a854c68b541 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 18 Sep 2016 19:09:28 +1200 Subject: Allow to switch GT06 command format --- src/org/traccar/protocol/Gt06ProtocolEncoder.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/org/traccar/protocol/Gt06ProtocolEncoder.java index 3ef9b1313..e478424f9 100644 --- a/src/org/traccar/protocol/Gt06ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,11 @@ package org.traccar.protocol; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.traccar.BaseProtocolEncoder; +import org.traccar.Context; import org.traccar.helper.Checksum; import org.traccar.helper.Log; import org.traccar.model.Command; +import org.traccar.model.Device; import java.nio.charset.StandardCharsets; @@ -54,11 +56,19 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { @Override protected Object encodeCommand(Command command) { + boolean alternative; + Device device = Context.getIdentityManager().getDeviceById(command.getDeviceId()); + if (device.getAttributes().containsKey("gt06.alternative")) { + alternative = Boolean.parseBoolean((String) device.getAttributes().get("gt06.alternative")); + } else { + alternative = Context.getConfig().getBoolean("gt06.alternative"); + } + switch (command.getType()) { case Command.TYPE_ENGINE_STOP: - return encodeContent("Relay,1#"); + return encodeContent(alternative ? "DYD,123456#\r\n" : "Relay,1#"); case Command.TYPE_ENGINE_RESUME: - return encodeContent("Relay,0#"); + return encodeContent(alternative ? "HFYD,123456#\r\n" : "Relay,0#"); default: Log.warning(new UnsupportedOperationException(command.getType())); break; -- cgit v1.2.3