aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/Gt06ProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-07-19 22:25:12 +1200
committerGitHub <noreply@github.com>2016-07-19 22:25:12 +1200
commit4ebf7c5a6df152af9c23eb9caab2885ff79e448c (patch)
tree3dfcd0b379e71f1fc85b626179a72e14489aeb47 /src/org/traccar/protocol/Gt06ProtocolDecoder.java
parent934371a0af815e18b3d29f350e96be60606de77b (diff)
parent1a0eae22fc58d7241e2c60bb593535a17d6c629b (diff)
downloadtrackermap-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/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;
-
}
}