aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorSergey Kostin <7er@inbox.ru>2019-08-06 11:41:10 +0300
committerSergey Kostin <7er@inbox.ru>2019-08-06 11:41:10 +0300
commitcf6493b331dc59753090e7977d29f8d145b241d2 (patch)
tree0cdea63b22dc7fb3d47f4e4ddb4b8c65b9049584 /src/main
parent9f2f1e1b524151aeb9e1d21e67f7de2b1597fabc (diff)
downloadtrackermap-server-cf6493b331dc59753090e7977d29f8d145b241d2.tar.gz
trackermap-server-cf6493b331dc59753090e7977d29f8d145b241d2.tar.bz2
trackermap-server-cf6493b331dc59753090e7977d29f8d145b241d2.zip
code review edits
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/BaseProtocolDecoder.java4
-rw-r--r--src/main/java/org/traccar/protocol/EgtsProtocolDecoder.java34
2 files changed, 17 insertions, 21 deletions
diff --git a/src/main/java/org/traccar/BaseProtocolDecoder.java b/src/main/java/org/traccar/BaseProtocolDecoder.java
index 02c2cc3ed..9dbe78c9d 100644
--- a/src/main/java/org/traccar/BaseProtocolDecoder.java
+++ b/src/main/java/org/traccar/BaseProtocolDecoder.java
@@ -146,8 +146,8 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
return getDeviceSession(channel, remoteAddress, false, uniqueIds);
}
- public DeviceSession getDeviceSession(Channel channel, SocketAddress remoteAddress, boolean ignoreCache,
- String... uniqueIds) {
+ public DeviceSession getDeviceSession(
+ Channel channel, SocketAddress remoteAddress, boolean ignoreCache, String... uniqueIds) {
if (channel != null && BasePipelineFactory.getHandler(channel.pipeline(), HttpRequestDecoder.class) != null
|| ignoreCache
|| config.getBoolean("decoder.ignoreSessionCache")) {
diff --git a/src/main/java/org/traccar/protocol/EgtsProtocolDecoder.java b/src/main/java/org/traccar/protocol/EgtsProtocolDecoder.java
index 75f32f1bb..4c2781963 100644
--- a/src/main/java/org/traccar/protocol/EgtsProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/EgtsProtocolDecoder.java
@@ -43,7 +43,7 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private boolean useOidAsDeviceId = true;
+ private boolean useObjectIdAsDeviceId = true;
public static final int PT_RESPONSE = 0;
public static final int PT_APPDATA = 1;
@@ -136,12 +136,11 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(headerLength);
if (packetType == PT_RESPONSE) {
- // some retranslator systems do send response on response packets - just skip them
return null;
}
int frameDataEnd = buf.readerIndex() + frameDataLength;
- long oid = 0L;
+ long objectId = 0L;
while (buf.readerIndex() < frameDataEnd) {
int length = buf.readUnsignedShortLE();
@@ -149,7 +148,7 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder {
int recordFlags = buf.readUnsignedByte();
if (BitUtil.check(recordFlags, 0)) {
- oid = buf.readUnsignedIntLE(); // object id
+ objectId = buf.readUnsignedIntLE();
}
if (BitUtil.check(recordFlags, 1)) {
@@ -180,7 +179,7 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder {
int end = buf.readUnsignedShortLE() + buf.readerIndex();
if (type == MSG_TERM_IDENTITY) {
- useOidAsDeviceId = false;
+ useObjectIdAsDeviceId = false;
buf.readUnsignedIntLE(); // object id
int flags = buf.readUnsignedByte();
@@ -189,14 +188,12 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedShortLE(); // home dispatcher identifier
}
if (BitUtil.check(flags, 1)) {
- String imei = buf.readSlice(15).toString(StandardCharsets.US_ASCII).trim();
- LOGGER.trace("[{}] Using IMEI1 as deviceId: {}", channel == null ? "" : channel.id(), imei);
- getDeviceSession(channel, remoteAddress, imei);
+ getDeviceSession(
+ channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII).trim());
}
if (BitUtil.check(flags, 2)) {
- String imei = buf.readSlice(16).toString(StandardCharsets.US_ASCII).trim();
- LOGGER.trace("[{}] Using IMEI2 as deviceId: {}", channel == null ? "" : channel.id(), imei);
- getDeviceSession(channel, remoteAddress, imei);
+ getDeviceSession(
+ channel, remoteAddress, buf.readSlice(16).toString(StandardCharsets.US_ASCII).trim());
}
if (BitUtil.check(flags, 3)) {
buf.skipBytes(3); // language identifier
@@ -208,9 +205,8 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedShortLE(); // buffer size
}
if (BitUtil.check(flags, 7)) {
- String imei = buf.readSlice(15).toString(StandardCharsets.US_ASCII).trim();
- LOGGER.trace("[{}] Using IMEI7 as deviceId: {}", channel == null ? "" : channel.id(), imei);
- getDeviceSession(channel, remoteAddress, imei);
+ getDeviceSession(
+ channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII).trim());
}
response = Unpooled.buffer();
@@ -274,15 +270,15 @@ public class EgtsProtocolDecoder extends BaseProtocolDecoder {
buf.readerIndex(end);
}
- if (serviceType == SERVICE_TELEDATA && position.getFixTime() != null) {
- if (useOidAsDeviceId && oid != 0L) {
- LOGGER.debug("[{}] Using OID as deviceId: {}", channel == null ? "" : channel.id(), oid);
- deviceSession = getDeviceSession(channel, remoteAddress, true, String.valueOf(oid));
+ if (serviceType == SERVICE_TELEDATA && position.getValid()) {
+ if (useObjectIdAsDeviceId && objectId != 0L) {
+ LOGGER.debug("[{}] Using objectId as deviceId: {}", channel == null ? "" : channel.id(), objectId);
+ deviceSession = getDeviceSession(channel, remoteAddress, true, String.valueOf(objectId));
if (deviceSession != null) {
position.setDeviceId(deviceSession.getDeviceId());
}
}
- if (position.getDeviceId() != 0L) {
+ if (deviceSession != null) {
positions.add(position);
}
}