aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/WialonProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-07-19 22:25:12 +1200
committerGitHub <noreply@github.com>2016-07-19 22:25:12 +1200
commit4ebf7c5a6df152af9c23eb9caab2885ff79e448c (patch)
tree3dfcd0b379e71f1fc85b626179a72e14489aeb47 /src/org/traccar/protocol/WialonProtocolDecoder.java
parent934371a0af815e18b3d29f350e96be60606de77b (diff)
parent1a0eae22fc58d7241e2c60bb593535a17d6c629b (diff)
downloadtrackermap-server-4ebf7c5a6df152af9c23eb9caab2885ff79e448c.tar.gz
trackermap-server-4ebf7c5a6df152af9c23eb9caab2885ff79e448c.tar.bz2
trackermap-server-4ebf7c5a6df152af9c23eb9caab2885ff79e448c.zip
Merge pull request #2127 from tananaev/refactor
Move device id to a session
Diffstat (limited to 'src/org/traccar/protocol/WialonProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/WialonProtocolDecoder.java19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java
index 1de2f9dbf..627b93b1c 100644
--- a/src/org/traccar/protocol/WialonProtocolDecoder.java
+++ b/src/org/traccar/protocol/WialonProtocolDecoder.java
@@ -17,6 +17,7 @@ package org.traccar.protocol;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.DeviceSession;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
@@ -66,16 +67,21 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
}
}
- private Position decodePosition(String substring) {
+ private Position decodePosition(Channel channel, SocketAddress remoteAddress, String substring) {
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
Parser parser = new Parser(PATTERN, substring);
- if (!hasDeviceId() || !parser.matches()) {
+ if (!parser.matches()) {
return null;
}
Position position = new Position();
position.setProtocol(getProtocolName());
- position.setDeviceId(getDeviceId());
+ position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt())
@@ -129,7 +135,8 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
if (sentence.startsWith("#L#")) {
String imei = sentence.substring(3, sentence.indexOf(';'));
- if (identify(imei, channel, remoteAddress)) {
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
+ if (deviceSession != null) {
sendResponse(channel, "#AL#", 1);
}
@@ -140,7 +147,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
} else if (sentence.startsWith("#SD#") || sentence.startsWith("#D#")) {
Position position = decodePosition(
- sentence.substring(sentence.indexOf('#', 1) + 1));
+ channel, remoteAddress, sentence.substring(sentence.indexOf('#', 1) + 1));
if (position != null) {
sendResponse(channel, "#AD#", 1);
@@ -153,7 +160,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
List<Position> positions = new LinkedList<>();
for (String message : messages) {
- Position position = decodePosition(message);
+ Position position = decodePosition(channel, remoteAddress, message);
if (position != null) {
positions.add(position);
}