diff options
Diffstat (limited to 'src/main/java/org/traccar/protocol')
8 files changed, 11 insertions, 26 deletions
diff --git a/src/main/java/org/traccar/protocol/DualcamProtocolDecoder.java b/src/main/java/org/traccar/protocol/DualcamProtocolDecoder.java index 75cd52384..411e2b9d7 100644 --- a/src/main/java/org/traccar/protocol/DualcamProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/DualcamProtocolDecoder.java @@ -19,7 +19,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; -import org.traccar.model.Device; import org.traccar.session.DeviceSession; import org.traccar.NetworkMessage; import org.traccar.Protocol; @@ -77,7 +76,7 @@ public class DualcamProtocolDecoder extends BaseProtocolDecoder { deviceSession = getDeviceSession(channel, remoteAddress, uniqueId); long settings = buf.readUnsignedInt(); if (channel != null && deviceSession != null) { - model = getCacheManager().getObject(Device.class, deviceSession.getDeviceId()).getModel(); + model = getDeviceModel(deviceSession); ByteBuf response = Unpooled.buffer(); if (BitUtil.check(settings, 25)) { response.writeShort(MSG_PATH_REQUEST); diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java index dc5dd446f..fd6bb8451 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolEncoder.java @@ -23,7 +23,6 @@ import org.traccar.config.Keys; import org.traccar.helper.Checksum; import org.traccar.helper.model.AttributeUtil; import org.traccar.model.Command; -import org.traccar.model.Device; import java.nio.charset.StandardCharsets; @@ -74,11 +73,11 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { String password = AttributeUtil.getDevicePassword( getCacheManager(), command.getDeviceId(), getProtocolName(), "123456"); - Device device = getCacheManager().getObject(Device.class, command.getDeviceId()); + String model = getDeviceModel(command.getDeviceId()); switch (command.getType()) { case Command.TYPE_ENGINE_STOP: - if ("G109".equals(device.getModel())) { + if ("G109".equals(model)) { return encodeContent(command.getDeviceId(), "DYD#"); } else if (alternative) { return encodeContent(command.getDeviceId(), "DYD," + password + "#"); @@ -86,7 +85,7 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { return encodeContent(command.getDeviceId(), "Relay,1#"); } case Command.TYPE_ENGINE_RESUME: - if ("G109".equals(device.getModel())) { + if ("G109".equals(model)) { return encodeContent(command.getDeviceId(), "HFYD#"); } else if (alternative) { return encodeContent(command.getDeviceId(), "HFYD," + password + "#"); diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index 5745909c7..343d42e09 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -28,7 +28,6 @@ import org.traccar.helper.PatternBuilder; import org.traccar.model.CellTower; import org.traccar.model.Network; import org.traccar.model.Position; -import org.traccar.model.Device; import org.traccar.helper.BitUtil; import java.net.SocketAddress; @@ -226,7 +225,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { return null; } - String model = getCacheManager().getObject(Device.class, deviceSession.getDeviceId()).getModel(); + String model = getDeviceModel(deviceSession); Position position = new Position(getProtocolName()); diff --git a/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java b/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java index 5859d91ce..6d3b4f7e9 100644 --- a/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java @@ -24,7 +24,6 @@ import org.traccar.helper.Checksum; import org.traccar.helper.DataConverter; import org.traccar.helper.model.AttributeUtil; import org.traccar.model.Command; -import org.traccar.model.Device; import java.nio.charset.StandardCharsets; import java.util.Set; @@ -64,7 +63,7 @@ public class MeiligaoProtocolEncoder extends BaseProtocolEncoder { int outputCount; int outputType; - String model = getCacheManager().getObject(Device.class, deviceId).getModel(); + String model = getDeviceModel(deviceId); if (model != null && Set.of("TK510", "GT08", "TK208", "TK228", "MT05").contains(model)) { outputCount = 5; diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java index 965c8ee0d..88b6380a5 100644 --- a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -20,7 +20,6 @@ import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; -import org.traccar.model.Device; import org.traccar.session.DeviceSession; import org.traccar.NetworkMessage; import org.traccar.Protocol; @@ -38,6 +37,7 @@ import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.LinkedList; import java.util.List; +import java.util.Objects; import java.util.regex.Pattern; public class MeitrackProtocolDecoder extends BaseProtocolDecoder { @@ -206,11 +206,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_ADC + i, parser.nextHexInt()); } - String model = getCacheManager().getObject(Device.class, deviceSession.getDeviceId()).getModel(); - if (model == null) { - model = ""; - } - switch (model.toUpperCase()) { + switch (Objects.requireNonNullElse(getDeviceModel(deviceSession), "").toUpperCase()) { case "MVT340": case "MVT380": position.set(Position.KEY_BATTERY, parser.nextHexInt() * 3.0 * 2.0 / 1024.0); diff --git a/src/main/java/org/traccar/protocol/Minifinder2ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Minifinder2ProtocolEncoder.java index 72ac9db4e..6e330a4dd 100644 --- a/src/main/java/org/traccar/protocol/Minifinder2ProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/Minifinder2ProtocolEncoder.java @@ -21,7 +21,6 @@ import org.traccar.BaseProtocolEncoder; import org.traccar.Protocol; import org.traccar.helper.Checksum; import org.traccar.model.Command; -import org.traccar.model.Device; import java.nio.charset.StandardCharsets; @@ -55,8 +54,7 @@ public class Minifinder2ProtocolEncoder extends BaseProtocolEncoder { content.writeByte(0xF0); // type } - Device device = getCacheManager().getObject(Device.class, command.getDeviceId()); - if ("Nano".equalsIgnoreCase(device.getModel())) { + if ("Nano".equalsIgnoreCase(getDeviceModel(command.getDeviceId()))) { ByteBuf content = Unpooled.buffer(); if (command.getType().equals(Command.TYPE_FIRMWARE_UPDATE)) { String url = command.getString(Command.KEY_DATA); diff --git a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java index 9380d2327..e0dfab9b2 100644 --- a/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/SigfoxProtocolDecoder.java @@ -23,7 +23,6 @@ import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpResponseStatus; import org.traccar.BaseHttpProtocolDecoder; import org.traccar.helper.BufferUtil; -import org.traccar.model.Device; import org.traccar.session.DeviceSession; import org.traccar.Protocol; import org.traccar.helper.BitUtil; @@ -155,12 +154,10 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder { } else if (jsonContains(json, "data")) { - String model = getCacheManager().getObject(Device.class, deviceSession.getDeviceId()).getModel(); - ByteBuf buf = Unpooled.wrappedBuffer(DataConverter.parseHex(json.getString("data"))); try { int header = buf.readUnsignedByte(); - if ("Amber".equals(model)) { + if ("Amber".equals(getDeviceModel(deviceSession))) { int flags = buf.readUnsignedByte(); position.set(Position.KEY_MOTION, BitUtil.check(flags, 1)); diff --git a/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java index 2f0874797..6197c6c13 100644 --- a/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -21,7 +21,6 @@ import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.helper.BufferUtil; -import org.traccar.model.Device; import org.traccar.session.DeviceSession; import org.traccar.NetworkMessage; import org.traccar.Protocol; @@ -654,7 +653,6 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (deviceSession == null) { return null; } - String model = getCacheManager().getObject(Device.class, deviceSession.getDeviceId()).getModel(); for (int i = 0; i < count; i++) { Position position = new Position(getProtocolName()); @@ -680,7 +678,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } else if (codec == CODEC_12) { decodeSerial(channel, remoteAddress, deviceSession, position, buf); } else { - decodeLocation(position, buf, codec, model); + decodeLocation(position, buf, codec, getDeviceModel(deviceSession)); } if (!position.getOutdated() || !position.getAttributes().isEmpty()) { |