aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/GranitProtocolEncoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol/GranitProtocolEncoder.java')
-rw-r--r--src/org/traccar/protocol/GranitProtocolEncoder.java29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/org/traccar/protocol/GranitProtocolEncoder.java b/src/org/traccar/protocol/GranitProtocolEncoder.java
index bde267ee6..6345ff971 100644
--- a/src/org/traccar/protocol/GranitProtocolEncoder.java
+++ b/src/org/traccar/protocol/GranitProtocolEncoder.java
@@ -20,36 +20,29 @@ import java.nio.charset.StandardCharsets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.traccar.BaseProtocolEncoder;
-import org.traccar.helper.Log;
import org.traccar.model.Command;
public class GranitProtocolEncoder extends BaseProtocolEncoder {
- @Override
- protected Object encodeCommand(Command command) {
- String commandString = "";
+ private ByteBuf encodeCommand(String commandString) {
+ ByteBuf buffer = Unpooled.buffer();
+ buffer.writeBytes(commandString.getBytes(StandardCharsets.US_ASCII));
+ GranitProtocolDecoder.appendChecksum(buffer, commandString.length());
+ return buffer;
+ }
+ @Override
+ protected Object encodeCommand(Command command) {
switch (command.getType()) {
case Command.TYPE_IDENTIFICATION:
- commandString = "BB+IDNT";
- break;
+ return encodeCommand("BB+IDNT");
case Command.TYPE_REBOOT_DEVICE:
- commandString = "BB+RESET";
- break;
+ return encodeCommand("BB+RESET");
case Command.TYPE_POSITION_SINGLE:
- commandString = "BB+RRCD";
- break;
+ return encodeCommand("BB+RRCD");
default:
- Log.warning(new UnsupportedOperationException(command.getType()));
return null;
}
- if (!commandString.isEmpty()) {
- ByteBuf commandBuf = Unpooled.buffer();
- commandBuf.writeBytes(commandString.getBytes(StandardCharsets.US_ASCII));
- GranitProtocolDecoder.appendChecksum(commandBuf, commandString.length());
- return commandBuf;
- }
- return null;
}
}