aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol
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
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')
-rw-r--r--src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java39
-rw-r--r--src/main/java/org/traccar/protocol/LaipacProtocolEncoder.java22
2 files changed, 20 insertions, 41 deletions
diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
index c028d78b6..381f497e4 100644
--- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
@@ -26,8 +26,6 @@ import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.model.CellTower;
-import org.traccar.model.Device;
-import org.traccar.model.Command;
import org.traccar.model.Network;
import org.traccar.model.Position;
@@ -123,21 +121,6 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
return event;
}
- private String getDevicePassword(DeviceSession deviceSession) {
-
- String devicePassword = DEFAULT_DEVICE_PASSWORD;
-
- Device device = Context.getIdentityManager().getById(deviceSession.getDeviceId());
- if (device != null) {
- String password = device.getString(Command.KEY_DEVICE_PASSWORD);
- if (password != null) {
- devicePassword = password;
- }
- }
-
- return devicePassword;
- }
-
private void sendEventResponse(
String event, String devicePassword, Channel channel, SocketAddress remoteAddress) {
@@ -247,7 +230,8 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
sendAcknowledge(status, event, checksum, channel, remoteAddress);
- String devicePassword = getDevicePassword(deviceSession);
+ String devicePassword = Context.getIdentityManager()
+ .getDevicePassword(deviceSession.getDeviceId(), DEFAULT_DEVICE_PASSWORD);
sendEventResponse(event, devicePassword, channel, remoteAddress);
}
@@ -260,18 +244,19 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
String sentence = (String) msg;
- Parser parser = new Parser(PATTERN_ECHK, sentence);
- if (parser.matches()) {
- return handleEchk(sentence, parser, channel, remoteAddress);
- }
-
- parser = new Parser(PATTERN_AVRMC, sentence);
- if (parser.matches()) {
- return handleAvrmc(sentence, parser, channel, remoteAddress);
+ if (sentence.startsWith("$ECHK")) {
+ Parser parser = new Parser(PATTERN_ECHK, sentence);
+ if (parser.matches()) {
+ return handleEchk(sentence, parser, channel, remoteAddress);
+ }
+ } else if (sentence.startsWith("$AVRMC")) {
+ Parser parser = new Parser(PATTERN_AVRMC, sentence);
+ if (parser.matches()) {
+ return handleAvrmc(sentence, parser, channel, remoteAddress);
+ }
}
return null;
}
-
}
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;
}