From 815c3de43ee8943fddb916f27317c37a7a806d65 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 19 Jul 2016 15:11:35 +1200 Subject: Move device id to a session --- src/org/traccar/protocol/TaipProtocolDecoder.java | 33 ++++++----------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'src/org/traccar/protocol/TaipProtocolDecoder.java') diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index f44b9bcbe..811db774c 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.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.DateUtil; import org.traccar.helper.Parser; @@ -84,27 +85,6 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { sentence = sentence.substring(beginIndex + 1); } - // Find device identifier - beginIndex = sentence.indexOf(";ID="); - if (beginIndex != -1) { - beginIndex += 4; - int endIndex = sentence.indexOf(';', beginIndex); - if (endIndex == -1) { - endIndex = sentence.length(); - } - - String id = sentence.substring(beginIndex, endIndex); - if (!identify(id, channel, remoteAddress)) { - return null; - } - - if (sendResponse && channel != null) { - channel.write(id); - } - } else { - return null; - } - Parser parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; @@ -112,7 +92,6 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); - position.setDeviceId(getDeviceId()); String week = parser.next(); String day = parser.next(); @@ -157,8 +136,9 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { switch (key) { case "id": - if (!identify(value, channel, remoteAddress)) { - return null; + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value); + if (deviceSession != null) { + position.setDeviceId(deviceSession.getDeviceId()); } if (sendResponse && channel != null) { channel.write(value); @@ -186,7 +166,10 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { } } - return position; + if (position.getDeviceId() != 0) { + return position; + } + return null; } } -- cgit v1.2.3