aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java
diff options
context:
space:
mode:
authorEdward Valley <ed.valley@yandex.com>2019-07-10 17:03:25 -0400
committerEdward Valley <ed.valley@yandex.com>2019-07-10 17:03:25 -0400
commit2c604b9c9ee8f996902acfdd60626324a8414d34 (patch)
treedb8a77746ff1b59b846b6806e1019c128803bec1 /src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java
parent11568839d89fa5bf58da0a654248f9b7696ee406 (diff)
downloadtrackermap-server-2c604b9c9ee8f996902acfdd60626324a8414d34.tar.gz
trackermap-server-2c604b9c9ee8f996902acfdd60626324a8414d34.tar.bz2
trackermap-server-2c604b9c9ee8f996902acfdd60626324a8414d34.zip
Changes after third review
Diffstat (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java
index 6f540fa3e..9b99486f7 100644
--- a/src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java
@@ -21,7 +21,11 @@ import org.traccar.helper.Checksum;
public class LaipacProtocolEncoder extends StringProtocolEncoder {
- public LaipacProtocolEncoder() {
+ @Override
+ protected String formatCommand(Command command, String format, String... keys) {
+ String sentence = super.formatCommand(command, "$" + format, keys);
+ sentence += Checksum.nmea(sentence) + "\r\n";
+ return sentence;
}
@Override
@@ -29,30 +33,20 @@ public class LaipacProtocolEncoder extends StringProtocolEncoder {
initDevicePassword(command, LaipacProtocolDecoder.DEFAULT_DEVICE_PASSWORD);
- String commandSentence = null;
-
switch (command.getType()) {
case Command.TYPE_CUSTOM:
- commandSentence = formatCommand(command, "${%s}",
+ return formatCommand(command, "{%s}",
Command.KEY_DATA);
- break;
case Command.TYPE_POSITION_SINGLE:
- commandSentence = formatCommand(command, "$AVREQ,{%s},1",
+ return formatCommand(command, "AVREQ,{%s},1",
Command.KEY_DEVICE_PASSWORD);
- break;
case Command.TYPE_REBOOT_DEVICE:
- commandSentence = formatCommand(command, "$AVRESET,{%s},{%s}",
+ return formatCommand(command, "AVRESET,{%s},{%s}",
Command.KEY_UNIQUE_ID, Command.KEY_DEVICE_PASSWORD);
- break;
default:
break;
}
- if (commandSentence != null) {
- commandSentence += Checksum.nmea(commandSentence) + "\r\n";
- return commandSentence;
- }
-
return null;
}