diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-07-19 22:25:12 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-19 22:25:12 +1200 |
commit | 4ebf7c5a6df152af9c23eb9caab2885ff79e448c (patch) | |
tree | 3dfcd0b379e71f1fc85b626179a72e14489aeb47 /src/org/traccar/protocol/GranitProtocolDecoder.java | |
parent | 934371a0af815e18b3d29f350e96be60606de77b (diff) | |
parent | 1a0eae22fc58d7241e2c60bb593535a17d6c629b (diff) | |
download | trackermap-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/GranitProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/GranitProtocolDecoder.java | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/org/traccar/protocol/GranitProtocolDecoder.java b/src/org/traccar/protocol/GranitProtocolDecoder.java index 7432961b0..0c7ea4d1d 100644 --- a/src/org/traccar/protocol/GranitProtocolDecoder.java +++ b/src/org/traccar/protocol/GranitProtocolDecoder.java @@ -19,6 +19,7 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; import org.traccar.helper.Checksum; import org.traccar.helper.StringFinder; @@ -136,11 +137,13 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { int indexTilde = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("~")); - if (hasDeviceId() && indexTilde == -1) { + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + + if (deviceSession != null && indexTilde == -1) { String bufString = buf.toString(StandardCharsets.US_ASCII); Position position = new Position(); position.setProtocol(getProtocolName()); - position.setDeviceId(getDeviceId()); + position.setDeviceId(deviceSession.getDeviceId()); position.setTime(new Date()); getLastLocation(position, new Date()); @@ -155,9 +158,11 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { String header = buf.readBytes(HEADER_LENGTH).toString(StandardCharsets.US_ASCII); if (header.equals("+RRCB~")) { + buf.skipBytes(2); //binary length 26 int deviceId = buf.readUnsignedShort(); - if (!identify(String.valueOf(deviceId), channel, remoteAddress)) { + deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(deviceId)); + if (deviceSession == null) { return null; } long unixTime = buf.readUnsignedInt(); @@ -166,7 +171,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { } Position position = new Position(); position.setProtocol(getProtocolName()); - position.setDeviceId(getDeviceId()); + position.setDeviceId(deviceSession.getDeviceId()); position.setTime(new Date(unixTime * 1000)); @@ -174,9 +179,11 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { return position; } else if (header.equals("+DDAT~")) { + buf.skipBytes(2); //binary length int deviceId = buf.readUnsignedShort(); - if (!identify(String.valueOf(deviceId), channel, remoteAddress)) { + deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(deviceId)); + if (deviceSession == null) { return null; } byte format = buf.readByte(); @@ -197,7 +204,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { if (buf.getUnsignedByte(buf.readerIndex()) != 0xFE) { Position position = new Position(); position.setProtocol(getProtocolName()); - position.setDeviceId(getDeviceId()); + position.setDeviceId(deviceSession.getDeviceId()); position.setTime(new Date((unixTime + i * timeIncrement) * 1000)); decodeStructure(buf, position); positions.add(position); @@ -208,7 +215,10 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(2); // increment } return positions; + } + return null; } + } |