aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/GranitProtocolDecoder.java
diff options
context:
space:
mode:
authorninioe <ninioe@gmail.com>2016-07-19 15:20:15 +0300
committerninioe <ninioe@gmail.com>2016-07-19 15:20:15 +0300
commit20f603076210073e122c720e21a3e8999478b11a (patch)
tree668a50e6c55601c2420bf0f4b986ed0b194c2e32 /src/org/traccar/protocol/GranitProtocolDecoder.java
parente954e95547d05a34bbd36e3aa5003f4ddaf2ccd0 (diff)
parent00e2f8a3575855a8b863e245005b8f83b3314bfb (diff)
downloadtrackermap-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/GranitProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/GranitProtocolDecoder.java22
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;
}
+
}