diff options
author | ninioe <ninioe@gmail.com> | 2016-07-19 15:20:15 +0300 |
---|---|---|
committer | ninioe <ninioe@gmail.com> | 2016-07-19 15:20:15 +0300 |
commit | 20f603076210073e122c720e21a3e8999478b11a (patch) | |
tree | 668a50e6c55601c2420bf0f4b986ed0b194c2e32 /src/org/traccar/protocol/CastelProtocolDecoder.java | |
parent | e954e95547d05a34bbd36e3aa5003f4ddaf2ccd0 (diff) | |
parent | 00e2f8a3575855a8b863e245005b8f83b3314bfb (diff) | |
download | trackermap-server-20f603076210073e122c720e21a3e8999478b11a.tar.gz trackermap-server-20f603076210073e122c720e21a3e8999478b11a.tar.bz2 trackermap-server-20f603076210073e122c720e21a3e8999478b11a.zip |
Merge remote-tracking branch 'refs/remotes/tananaev/master'
Diffstat (limited to 'src/org/traccar/protocol/CastelProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/CastelProtocolDecoder.java | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index e379b6f2d..212096018 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.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.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; @@ -52,11 +53,11 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { private static final short MSG_CC_HEARTBEAT = 0x4206; private static final short MSG_CC_HEARTBEAT_RESPONSE = (short) 0x8206; - private Position readPosition(ChannelBuffer buf) { + private Position readPosition(DeviceSession deviceSession, ChannelBuffer buf) { Position position = new Position(); position.setProtocol(getProtocolName()); - position.setDeviceId(getDeviceId()); + position.setDeviceId(deviceSession.getDeviceId()); DateBuilder dateBuilder = new DateBuilder() .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) @@ -148,7 +149,9 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer id = buf.readBytes(20); int type = ChannelBuffers.swapShort(buf.readShort()); - if (!identify(id.toString(StandardCharsets.US_ASCII).trim(), channel, remoteAddress)) { + DeviceSession deviceSession = getDeviceSession( + channel, remoteAddress, id.toString(StandardCharsets.US_ASCII).trim()); + if (deviceSession == null) { return null; } @@ -162,7 +165,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedInt(); // unix time buf.readUnsignedByte(); - return readPosition(buf); + return readPosition(deviceSession, buf); } @@ -205,7 +208,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { List<Position> positions = new LinkedList<>(); for (int i = 0; i < count; i++) { - Position position = readPosition(buf); + Position position = readPosition(deviceSession, buf); position.set(Position.KEY_ODOMETER, odometer); position.set(Position.KEY_STATUS, status); positions.add(position); @@ -217,7 +220,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { } else if (type == MSG_SC_GPS_SLEEP || type == MSG_SC_AGPS_REQUEST) { - return readPosition(buf); + return readPosition(deviceSession, buf); } @@ -233,7 +236,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { List<Position> positions = new LinkedList<>(); for (int i = 0; i < count; i++) { - Position position = readPosition(buf); + Position position = readPosition(deviceSession, buf); position.set(Position.KEY_STATUS, buf.readUnsignedInt()); position.set(Position.KEY_BATTERY, buf.readUnsignedByte()); @@ -255,7 +258,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, remoteAddress, version, id, MSG_CC_LOGIN_RESPONSE, null); - Position position = readPosition(buf); + Position position = readPosition(deviceSession, buf); position.set(Position.KEY_STATUS, buf.readUnsignedInt()); position.set(Position.KEY_BATTERY, buf.readUnsignedByte()); |