aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/BaseProtocol.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/BaseProtocol.java')
-rw-r--r--src/org/traccar/BaseProtocol.java18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java
index c77e61a81..446f57d65 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.Collection;
import java.util.HashSet;
@@ -48,10 +51,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);
}
}