aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/Gt06ProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-07-19 15:11:35 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2016-07-19 15:11:35 +1200
commit815c3de43ee8943fddb916f27317c37a7a806d65 (patch)
treea38e4f6bf80c35ccc83ae9d4c4d3d88e0d837b00 /src/org/traccar/protocol/Gt06ProtocolDecoder.java
parent4054777eac379ce07560c44901ada659aad062ba (diff)
downloadtrackermap-server-815c3de43ee8943fddb916f27317c37a7a806d65.tar.gz
trackermap-server-815c3de43ee8943fddb916f27317c37a7a806d65.tar.bz2
trackermap-server-815c3de43ee8943fddb916f27317c37a7a806d65.zip
Move device id to a session
Diffstat (limited to 'src/org/traccar/protocol/Gt06ProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolDecoder.java44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
index 57e2d64b7..f89d20fce 100644
--- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -20,6 +20,7 @@ import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
+import org.traccar.DeviceSession;
import org.traccar.helper.BitUtil;
import org.traccar.helper.Checksum;
import org.traccar.helper.DateBuilder;
@@ -175,7 +176,6 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
int length = buf.readUnsignedByte();
int dataLength = length - 5;
-
int type = buf.readUnsignedByte();
if (type == MSG_LOGIN) {
@@ -197,17 +197,23 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
}
}
- if (identify(imei, channel, remoteAddress)) {
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
+ if (deviceSession != null) {
buf.skipBytes(buf.readableBytes() - 6);
sendResponse(channel, type, buf.readUnsignedShort());
}
- } else if (hasDeviceId()) {
+ } else {
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
if (type == MSG_STRING) {
Position position = new Position();
- position.setDeviceId(getDeviceId());
+ position.setDeviceId(deviceSession.getDeviceId());
position.setProtocol(getProtocolName());
getLastLocation(position, null);
@@ -228,7 +234,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
} else if (isSupported(type)) {
Position position = new Position();
- position.setDeviceId(getDeviceId());
+ position.setDeviceId(deviceSession.getDeviceId());
position.setProtocol(getProtocolName());
if (hasGps(type)) {
@@ -271,39 +277,31 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
} else if (header == 0x7979) {
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
+
buf.readUnsignedShort(); // length
int type = buf.readUnsignedByte();
if (type == MSG_INFO) {
int subType = buf.readUnsignedByte();
- if (subType == 0x00) {
+ Position position = new Position();
+ position.setDeviceId(deviceSession.getDeviceId());
+ position.setProtocol(getProtocolName());
- Position position = new Position();
- position.setDeviceId(getDeviceId());
- position.setProtocol(getProtocolName());
-
- getLastLocation(position, null);
+ getLastLocation(position, null);
+ if (subType == 0x00) {
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
-
return position;
-
} else if (subType == 0x05) {
-
- Position position = new Position();
- position.setDeviceId(getDeviceId());
- position.setProtocol(getProtocolName());
-
- getLastLocation(position, null);
-
int flags = buf.readUnsignedByte();
-
position.set("door", BitUtil.check(flags, 0));
position.set(Position.PREFIX_IO + 1, BitUtil.check(flags, 2));
-
return position;
-
}
}