diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2014-03-20 22:34:28 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2014-03-20 22:34:28 +1300 |
commit | c601456e84d2da9200815c07a8686b8f6f13142c (patch) | |
tree | f0f30524725a12947f058c67de4ebfc7f37801e3 /src/org | |
parent | 57a7b6beaade9a51690d0cc89149eca0dea8294a (diff) | |
download | traccar-server-c601456e84d2da9200815c07a8686b8f6f13142c.tar.gz traccar-server-c601456e84d2da9200815c07a8686b8f6f13142c.tar.bz2 traccar-server-c601456e84d2da9200815c07a8686b8f6f13142c.zip |
Fix GT06 timezone issue (fix #604)
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/protocol/Gt06ProtocolDecoder.java | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 351098626..6951b969f 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2014 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ import org.traccar.model.Position; public class Gt06ProtocolDecoder extends BaseProtocolDecoder { private Long deviceId; + private final TimeZone timeZone = TimeZone.getTimeZone("UTC"); public Gt06ProtocolDecoder(ServerManager serverManager) { super(serverManager); @@ -88,7 +89,20 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedByte(); if (type == MSG_LOGIN) { + String imei = readImei(buf); + buf.readUnsignedShort(); // type + + // Timezone offset + if (dataLength > 10) { + int extensionBits = buf.readUnsignedShort(); + int offset = (extensionBits >> 4) * 36000; + if ((extensionBits & 0x8) != 0) { + offset = -offset; + } + timeZone.setRawOffset(offset); + } + try { deviceId = getDataManager().getDeviceByImei(imei).getId(); buf.skipBytes(dataLength - 8); @@ -96,6 +110,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } catch(Exception error) { Log.warning("Unknown device - " + imei); } + } else if (type == MSG_GPS || @@ -109,7 +124,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("gt06"); // Date and time - Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + Calendar time = Calendar.getInstance(timeZone); time.clear(); time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte()); time.set(Calendar.MONTH, buf.readUnsignedByte() - 1); |