diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-02-10 08:24:14 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-10 08:24:14 +1300 |
commit | e1bd30161e842b61e395e932ec9251a326025ad8 (patch) | |
tree | fc142d1f296623186e55ef0cd51df4219fa8dbc1 /src/org/traccar/protocol/Gt06ProtocolDecoder.java | |
parent | 96e45b5a990182ddc4b878e48d93d301d014427a (diff) | |
parent | 267c6e1651b6e0e91dd7c3463f86de929d7bc73c (diff) | |
download | trackermap-server-e1bd30161e842b61e395e932ec9251a326025ad8.tar.gz trackermap-server-e1bd30161e842b61e395e932ec9251a326025ad8.tar.bz2 trackermap-server-e1bd30161e842b61e395e932ec9251a326025ad8.zip |
Merge pull request #3765 from Abyss777/device_timezone
Unified Device timezone handling
Diffstat (limited to 'src/org/traccar/protocol/Gt06ProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/Gt06ProtocolDecoder.java | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 4173b4d5b..3e5ebc8c5 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,18 +44,10 @@ import java.util.regex.Pattern; public class Gt06ProtocolDecoder extends BaseProtocolDecoder { - private boolean forceTimeZone = false; - private final TimeZone timeZone = TimeZone.getTimeZone("UTC"); - private final Map<Integer, ChannelBuffer> photos = new HashMap<>(); public Gt06ProtocolDecoder(Gt06Protocol protocol) { super(protocol); - - if (Context.getConfig().hasKey(getProtocolName() + ".timezone")) { - forceTimeZone = true; - timeZone.setRawOffset(Context.getConfig().getInteger(getProtocolName() + ".timezone") * 1000); - } } public static final int MSG_LOGIN = 0x01; @@ -202,9 +194,9 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, false, MSG_X1_PHOTO_DATA, 0, content); } - private boolean decodeGps(Position position, ChannelBuffer buf, boolean hasLength) { + private boolean decodeGps(Position position, ChannelBuffer buf, boolean hasLength, TimeZone timezone) { - DateBuilder dateBuilder = new DateBuilder(timeZone) + DateBuilder dateBuilder = new DateBuilder(timezone) .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); position.setTime(dateBuilder.getDate()); @@ -387,6 +379,9 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { if (deviceSession == null) { return null; } + if (deviceSession.getTimeZone() == null) { + deviceSession.setTimeZone(getTimeZone(deviceSession.getDeviceId())); + } } if (type == MSG_LOGIN) { @@ -394,6 +389,11 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1); buf.readUnsignedShort(); // type + deviceSession = getDeviceSession(channel, remoteAddress, imei); + if (deviceSession != null && deviceSession.getTimeZone() == null) { + deviceSession.setTimeZone(getTimeZone(deviceSession.getDeviceId())); + } + if (dataLength > 10) { int extensionBits = buf.readUnsignedShort(); int hours = (extensionBits >> 4) / 100; @@ -402,12 +402,17 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { if ((extensionBits & 0x8) != 0) { offset = -offset; } - if (!forceTimeZone) { - timeZone.setRawOffset(offset * 1000); + if (deviceSession != null) { + TimeZone timeZone = deviceSession.getTimeZone(); + if (timeZone.getRawOffset() == 0) { + timeZone.setRawOffset(offset * 1000); + deviceSession.setTimeZone(timeZone); + } } + } - if (getDeviceSession(channel, remoteAddress, imei) != null) { + if (deviceSession != null) { sendResponse(channel, false, type, buf.getShort(buf.writerIndex() - 6), null); } @@ -455,7 +460,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedInt(); // data and alarm - decodeGps(position, buf, false); + decodeGps(position, buf, false, deviceSession.getTimeZone()); buf.readUnsignedShort(); // terminal info @@ -543,7 +548,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { boolean longFormat = type == MSG_LBS_2 || type == MSG_WIFI_3; - DateBuilder dateBuilder = new DateBuilder(timeZone) + DateBuilder dateBuilder = new DateBuilder(deviceSession.getTimeZone()) .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); @@ -589,7 +594,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } else if (isSupported(type)) { if (hasGps(type)) { - decodeGps(position, buf, false); + decodeGps(position, buf, false, deviceSession.getTimeZone()); } else { getLastLocation(position, null); } @@ -642,6 +647,10 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return null; } + if (deviceSession.getTimeZone() == null) { + deviceSession.setTimeZone(getTimeZone(deviceSession.getDeviceId())); + } + Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); @@ -711,7 +720,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } else if (type == MSG_AZ735_GPS || type == MSG_AZ735_ALARM) { - if (!decodeGps(position, buf, true)) { + if (!decodeGps(position, buf, true, deviceSession.getTimeZone())) { getLastLocation(position, position.getDeviceTime()); } |