diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-05-07 16:44:27 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-05-07 16:44:27 +1200 |
commit | de56187c1a48b3c4388ff986bd318d4683f2a344 (patch) | |
tree | 9aada33125a5a9b5d9ab935ead33e48ee88b2c35 /src/org/traccar/BaseProtocol.java | |
parent | ff23b231b678536e2d395680c5f9fb0f73e2ddd8 (diff) | |
download | trackermap-server-de56187c1a48b3c4388ff986bd318d4683f2a344.tar.gz trackermap-server-de56187c1a48b3c4388ff986bd318d4683f2a344.tar.bz2 trackermap-server-de56187c1a48b3c4388ff986bd318d4683f2a344.zip |
Implement general custom commands
Diffstat (limited to 'src/org/traccar/BaseProtocol.java')
-rw-r--r-- | src/org/traccar/BaseProtocol.java | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java index 7714f18db..826a290d0 100644 --- a/src/org/traccar/BaseProtocol.java +++ b/src/org/traccar/BaseProtocol.java @@ -15,9 +15,12 @@ */ package org.traccar; +import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.handler.codec.string.StringEncoder; import org.traccar.database.ActiveDevice; import org.traccar.model.Command; +import javax.xml.bind.DatatypeConverter; import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -42,10 +45,19 @@ public abstract class BaseProtocol implements Protocol { @Override public void sendCommand(ActiveDevice activeDevice, Command command) { - if (!supportedCommands.contains(command.getType())) { - throw new RuntimeException("Command " + command.getType() + " is not supported in protocol " + getName()); + if (command.getType().equals(Command.TYPE_CUSTOM)) { + String data = (String) command.getAttributes().get(Command.KEY_DATA); + if (activeDevice.getChannel().getPipeline().get(StringEncoder.class) != null) { + activeDevice.write(data); + } else { + activeDevice.write(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary(data))); + } + } else { + if (!supportedCommands.contains(command.getType())) { + throw new RuntimeException("Command " + command.getType() + " is not supported in protocol " + getName()); + } + activeDevice.write(command); } - activeDevice.write(command); } } |