aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-18 10:27:24 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-18 10:27:24 -0700
commit97a189c51817a6b1d7a86aece8a91ff378488799 (patch)
tree9f47127dafa956ae6a8f98c818a9fbcef5432a5b /src/main/java/org/traccar/protocol
parent22bd8bcc80b850dc2308be50cf2886c39b0655da (diff)
downloadtrackermap-server-97a189c51817a6b1d7a86aece8a91ff378488799.tar.gz
trackermap-server-97a189c51817a6b1d7a86aece8a91ff378488799.tar.bz2
trackermap-server-97a189c51817a6b1d7a86aece8a91ff378488799.zip
Refactor attribute lookup
Diffstat (limited to 'src/main/java/org/traccar/protocol')
-rw-r--r--src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java9
-rw-r--r--src/main/java/org/traccar/protocol/H02ProtocolEncoder.java7
-rw-r--r--src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java6
-rw-r--r--src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java6
-rw-r--r--src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java6
-rw-r--r--src/main/java/org/traccar/protocol/T55ProtocolDecoder.java12
-rw-r--r--src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java8
7 files changed, 35 insertions, 19 deletions
diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java
index 569f4a809..e1c17710b 100644
--- a/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java
@@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.traccar.BaseProtocolEncoder;
import org.traccar.Protocol;
+import org.traccar.config.Keys;
import org.traccar.helper.Checksum;
import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Command;
@@ -33,8 +34,8 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder {
private ByteBuf encodeContent(long deviceId, String content) {
- boolean language = getIdentityManager()
- .lookupAttributeBoolean(deviceId, getProtocolName() + ".language", false, false, true);
+ boolean language = AttributeUtil.lookup(
+ getCacheManager(), Keys.PROTOCOL_LANGUAGE.withPrefix(getProtocolName()), deviceId);
ByteBuf buf = Unpooled.buffer();
@@ -66,8 +67,8 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- boolean alternative = getIdentityManager().lookupAttributeBoolean(
- command.getDeviceId(), getProtocolName() + ".alternative", false, false, true);
+ boolean alternative = AttributeUtil.lookup(
+ getCacheManager(), Keys.PROTOCOL_ALTERNATIVE.withPrefix(getProtocolName()), command.getDeviceId());
String password = AttributeUtil.getDevicePassword(
getCacheManager(), command.getDeviceId(), getProtocolName(), "123456");
diff --git a/src/main/java/org/traccar/protocol/H02ProtocolEncoder.java b/src/main/java/org/traccar/protocol/H02ProtocolEncoder.java
index 7fca0f93e..86b8c80d4 100644
--- a/src/main/java/org/traccar/protocol/H02ProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/H02ProtocolEncoder.java
@@ -18,6 +18,8 @@ package org.traccar.protocol;
import org.traccar.Protocol;
import org.traccar.StringProtocolEncoder;
+import org.traccar.config.Keys;
+import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Command;
import java.util.Date;
@@ -58,8 +60,9 @@ public class H02ProtocolEncoder extends StringProtocolEncoder {
return formatCommand(time, uniqueId, "S20", "1", "0");
case Command.TYPE_POSITION_PERIODIC:
String frequency = command.getAttributes().get(Command.KEY_FREQUENCY).toString();
- if (getIdentityManager().lookupAttributeBoolean(
- command.getDeviceId(), getProtocolName() + ".alternative", false, false, true)) {
+ if (AttributeUtil.lookup(
+ getCacheManager(), Keys.PROTOCOL_ALTERNATIVE.withPrefix(getProtocolName()),
+ command.getDeviceId())) {
return formatCommand(time, uniqueId, "D1", frequency);
} else {
return formatCommand(time, uniqueId, "S71", "22", frequency);
diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java
index 82cf03b51..ada7e3fba 100644
--- a/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java
@@ -19,7 +19,9 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.traccar.BaseProtocolEncoder;
import org.traccar.Protocol;
+import org.traccar.config.Keys;
import org.traccar.helper.DataConverter;
+import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Command;
import java.text.SimpleDateFormat;
@@ -34,8 +36,8 @@ public class HuabaoProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- boolean alternative = getIdentityManager().lookupAttributeBoolean(
- command.getDeviceId(), getProtocolName() + ".alternative", false, false, true);
+ boolean alternative = AttributeUtil.lookup(
+ getCacheManager(), Keys.PROTOCOL_ALTERNATIVE.withPrefix(getProtocolName()), command.getDeviceId());
ByteBuf id = Unpooled.wrappedBuffer(
DataConverter.parseHex(getUniqueId(command.getDeviceId())));
diff --git a/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java b/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java
index 7784ab093..21f9f8801 100644
--- a/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java
@@ -19,8 +19,10 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.traccar.BaseProtocolEncoder;
import org.traccar.Protocol;
+import org.traccar.config.Keys;
import org.traccar.helper.Checksum;
import org.traccar.helper.DataConverter;
+import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Command;
import java.nio.charset.StandardCharsets;
@@ -58,8 +60,8 @@ public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- boolean alternative = getIdentityManager().lookupAttributeBoolean(
- command.getDeviceId(), getProtocolName() + ".alternative", false, false, true);
+ boolean alternative = AttributeUtil.lookup(
+ getCacheManager(), Keys.PROTOCOL_ALTERNATIVE.withPrefix(getProtocolName()), command.getDeviceId());
int outputControlMessageType = alternative
? MeiligaoProtocolDecoder.MSG_OUTPUT_CONTROL_1
diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
index 799e14ea2..365dbb35a 100644
--- a/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
@@ -17,7 +17,9 @@ package org.traccar.protocol;
import org.traccar.Protocol;
import org.traccar.StringProtocolEncoder;
+import org.traccar.config.Keys;
import org.traccar.helper.Checksum;
+import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Command;
import java.util.Map;
@@ -41,8 +43,8 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder {
Map<String, Object> attributes = command.getAttributes();
- boolean alternative = getIdentityManager().lookupAttributeBoolean(
- command.getDeviceId(), getProtocolName() + ".alternative", false, false, true);
+ boolean alternative = AttributeUtil.lookup(
+ getCacheManager(), Keys.PROTOCOL_ALTERNATIVE.withPrefix(getProtocolName()), command.getDeviceId());
switch (command.getType()) {
case Command.TYPE_POSITION_SINGLE:
diff --git a/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java b/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java
index 3d892c021..409c7e768 100644
--- a/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java
@@ -17,6 +17,8 @@ package org.traccar.protocol;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.config.Keys;
+import org.traccar.helper.model.AttributeUtil;
import org.traccar.session.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
@@ -128,10 +130,12 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
private Position decodeGprmc(
DeviceSession deviceSession, String sentence, SocketAddress remoteAddress, Channel channel) {
- if (deviceSession != null && channel != null && !(channel instanceof DatagramChannel)
- && getIdentityManager().lookupAttributeBoolean(
- deviceSession.getDeviceId(), getProtocolName() + ".ack", false, false, true)) {
- channel.writeAndFlush(new NetworkMessage("OK1\r\n", remoteAddress));
+ if (deviceSession != null && channel != null && !(channel instanceof DatagramChannel)) {
+ boolean ack = AttributeUtil.lookup(
+ getCacheManager(), Keys.PROTOCOL_ACK.withPrefix(getProtocolName()), deviceSession.getDeviceId());
+ if (ack) {
+ channel.writeAndFlush(new NetworkMessage("OK1\r\n", remoteAddress));
+ }
}
Parser parser = new Parser(PATTERN_GPRMC, sentence);
diff --git a/src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java
index a0e9b199c..e3e1ae961 100644
--- a/src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/Tk103ProtocolEncoder.java
@@ -18,6 +18,8 @@ package org.traccar.protocol;
import org.traccar.Protocol;
import org.traccar.StringProtocolEncoder;
+import org.traccar.config.Keys;
+import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Command;
public class Tk103ProtocolEncoder extends StringProtocolEncoder {
@@ -41,12 +43,12 @@ public class Tk103ProtocolEncoder extends StringProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- boolean alternative = forceAlternative || getIdentityManager().lookupAttributeBoolean(
- command.getDeviceId(), getProtocolName() + ".alternative", false, false, true);
+ boolean alternative = AttributeUtil.lookup(
+ getCacheManager(), Keys.PROTOCOL_ALTERNATIVE.withPrefix(getProtocolName()), command.getDeviceId());
initDevicePassword(command, "123456");
- if (alternative) {
+ if (alternative || forceAlternative) {
switch (command.getType()) {
case Command.TYPE_CUSTOM:
return formatAlt(command, "%s", Command.KEY_DATA);