aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-11-23 15:36:42 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-11-23 15:36:42 -0800
commit05e44d8cf956f6a0d44497aa0b357036139425dd (patch)
treebbf7d754379c3fe240d86f525102709d94b6ecd9 /src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java
parentca41538149dc6fd549f9c6f7565e3cfd71957d1e (diff)
downloadtrackermap-server-05e44d8cf956f6a0d44497aa0b357036139425dd.tar.gz
trackermap-server-05e44d8cf956f6a0d44497aa0b357036139425dd.tar.bz2
trackermap-server-05e44d8cf956f6a0d44497aa0b357036139425dd.zip
Use correct prefix for commands
Diffstat (limited to 'src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java b/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java
index 55f2c73dd..3b4995110 100644
--- a/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java
@@ -15,6 +15,8 @@
*/
package org.traccar.protocol;
+import io.netty.channel.Channel;
+import org.traccar.BasePipelineFactory;
import org.traccar.StringProtocolEncoder;
import org.traccar.model.Command;
import org.traccar.Protocol;
@@ -25,32 +27,49 @@ public class SuntechProtocolEncoder extends StringProtocolEncoder {
super(protocol);
}
+ private String getPrefix(Channel channel) {
+ String prefix = "SA200CMD";
+ if (channel != null) {
+ SuntechProtocolDecoder protocolDecoder =
+ BasePipelineFactory.getHandler(channel.pipeline(), SuntechProtocolDecoder.class);
+ if (protocolDecoder != null) {
+ String decoderPrefix = protocolDecoder.getPrefix();
+ if (decoderPrefix != null && decoderPrefix.length() > 5) {
+ prefix = decoderPrefix.substring(0, decoderPrefix.length() - 3) + "CMD";
+ }
+ }
+ }
+ return prefix;
+ }
+
@Override
- protected Object encodeCommand(Command command) {
+ protected Object encodeCommand(Channel channel, Command command) {
+
+ String prefix = getPrefix(channel);
switch (command.getType()) {
case Command.TYPE_REBOOT_DEVICE:
- return formatCommand(command, "SA200CMD;%s;02;Reboot\r", Command.KEY_UNIQUE_ID);
+ return formatCommand(command, prefix + ";%s;02;Reboot\r", Command.KEY_UNIQUE_ID);
case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "SA200GTR;%s;02;\r", Command.KEY_UNIQUE_ID);
+ return formatCommand(command, prefix + ";%s;02;\r", Command.KEY_UNIQUE_ID);
case Command.TYPE_OUTPUT_CONTROL:
if (command.getAttributes().containsKey(Command.KEY_DATA)) {
if (command.getAttributes().get(Command.KEY_DATA).equals("1")) {
- return formatCommand(command, "SA200CMD;%s;02;Enable%s\r",
+ return formatCommand(command, prefix + ";%s;02;Enable%s\r",
Command.KEY_UNIQUE_ID, Command.KEY_INDEX);
} else {
- return formatCommand(command, "SA200CMD;%s;02;Disable%s\r",
+ return formatCommand(command, prefix + ";%s;02;Disable%s\r",
Command.KEY_UNIQUE_ID, Command.KEY_INDEX);
}
}
case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, "SA200CMD;%s;02;Enable1\r", Command.KEY_UNIQUE_ID);
+ return formatCommand(command, prefix + ";%s;02;Enable1\r", Command.KEY_UNIQUE_ID);
case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, "SA200CMD;%s;02;Disable1\r", Command.KEY_UNIQUE_ID);
+ return formatCommand(command, prefix + ";%s;02;Disable1\r", Command.KEY_UNIQUE_ID);
case Command.TYPE_ALARM_ARM:
- return formatCommand(command, "SA200CMD;%s;02;Enable2\r", Command.KEY_UNIQUE_ID);
+ return formatCommand(command, prefix + ";%s;02;Enable2\r", Command.KEY_UNIQUE_ID);
case Command.TYPE_ALARM_DISARM:
- return formatCommand(command, "SA200CMD;%s;02;Disable2\r", Command.KEY_UNIQUE_ID);
+ return formatCommand(command, prefix + ";%s;02;Disable2\r", Command.KEY_UNIQUE_ID);
default:
return null;
}