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/AutoFonProtocolDecoder.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/AutoFonProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/AutoFonProtocolDecoder.java | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java index b80fd6bcb..dd0f54af0 100644 --- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java @@ -20,6 +20,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.DateBuilder; import org.traccar.model.Position; @@ -57,11 +58,11 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { } } - private Position decodePosition(ChannelBuffer buf, boolean history) { + private Position decodePosition(DeviceSession deviceSession, ChannelBuffer buf, boolean history) { Position position = new Position(); position.setProtocol(getProtocolName()); - position.setDeviceId(getDeviceId()); + position.setDeviceId(deviceSession.getDeviceId()); if (!history) { buf.readUnsignedByte(); // interval @@ -127,20 +128,27 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { } String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1); - if (!identify(imei, channel, remoteAddress)) { - return null; - } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); - if (channel != null) { + if (deviceSession != null && channel != null) { ChannelBuffer response = ChannelBuffers.dynamicBuffer(); response.writeBytes("resp_crc=".getBytes(StandardCharsets.US_ASCII)); response.writeByte(buf.getByte(buf.writerIndex() - 1)); channel.write(response); } - } else if (type == MSG_LOCATION) { + return null; + + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null) { + return null; + } + + if (type == MSG_LOCATION) { - return decodePosition(buf, false); + return decodePosition(deviceSession, buf, false); } else if (type == MSG_HISTORY) { @@ -149,7 +157,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { List<Position> positions = new LinkedList<>(); for (int i = 0; i < count; i++) { - positions.add(decodePosition(buf, true)); + positions.add(decodePosition(deviceSession, buf, true)); } return positions; @@ -158,7 +166,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); - position.setDeviceId(getDeviceId()); + position.setDeviceId(deviceSession.getDeviceId()); short status = buf.readUnsignedByte(); position.set(Position.KEY_ALARM, BitUtil.check(status, 7)); |