diff options
-rw-r--r-- | src/org/traccar/protocol/Gt06ProtocolDecoder.java | 19 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gt06ProtocolDecoderTest.java | 24 |
2 files changed, 30 insertions, 13 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); diff --git a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 45ba85563..23fd29f39 100644 --- a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -2,7 +2,6 @@ package org.traccar.protocol; import org.traccar.helper.TestDataManager; import org.jboss.netty.buffer.ChannelBuffers; -import static org.traccar.helper.DecoderVerifier.verify; import static org.junit.Assert.assertNull; import org.junit.Test; import org.traccar.helper.ChannelBufferTools; @@ -16,32 +15,35 @@ public class Gt06ProtocolDecoderTest { Gt06ProtocolDecoder decoder = new Gt06ProtocolDecoder(null); decoder.setDataManager(new TestDataManager()); - int[] buf1 = {0x78,0x78,0x11,0x01,0x01,0x23,0x45,0x67,(byte)0x89,0x01,0x23,0x45,0x10,0x0B,0x32,0x01,0x00,0x01,0x71,(byte)0x93,0x0D,0x0A}; + int[] buf1 = {0x78,0x78,0x11,0x01,0x01,0x23,0x45,0x67,0x89,0x01,0x23,0x45,0x10,0x0B,0x32,0x01,0x00,0x01,0x71,0x93,0x0D,0x0A}; assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(buf1)))); - int[] buf2 = {0x78,0x78,0x1F,0x12,0x0B,0x08,0x1D,0x11,0x2E,0x10,(byte)0xCC,0x02,0x7A,(byte)0xC7,(byte)0xEB,0x0C,0x46,0x58,0x49,0x00,0x14,(byte)0x8F,0x01,(byte)0xCC,0x00,0x28,0x7D,0x00,0x1F,(byte)0xB8,0x00,0x03,(byte)0x80,(byte)0x81,0x0D,0x0A}; + int[] buf2 = {0x78,0x78,0x1F,0x12,0x0B,0x08,0x1D,0x11,0x2E,0x10,0xCC,0x02,0x7A,0xC7,0xEB,0x0C,0x46,0x58,0x49,0x00,0x14,0x8F,0x01,0xCC,0x00,0x28,0x7D,0x00,0x1F,0xB8,0x00,0x03,0x80,0x81,0x0D,0x0A}; verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(buf2)))); - int[] buf3 = {0x78,0x78,0x0D,0x01,0x08,0x64,0x71,0x70,0x03,0x28,0x35,(byte)0x81,0x00,0x09,0x3F,0x04,0x0D,0x0A}; + int[] buf3 = {0x78,0x78,0x0D,0x01,0x08,0x64,0x71,0x70,0x03,0x28,0x35,0x81,0x00,0x09,0x3F,0x04,0x0D,0x0A}; assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(buf3)))); - int[] buf4 = {0x78,0x78,0x0D,0x01,0x01,0x23,0x45,0x67,(byte)0x89,0x01,0x23,0x45,0x00,0x01,(byte)0x8C,(byte)0xDD,0x0D,0x0A}; + int[] buf4 = {0x78,0x78,0x0D,0x01,0x01,0x23,0x45,0x67,0x89,0x01,0x23,0x45,0x00,0x01,0x8C,0xDD,0x0D,0x0A}; assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(buf4)))); - int[] buf5 = {0x78,0x78,0x0d,0x01,0x03,0x53,0x41,(byte)0x90,0x36,0x06,0x60,0x61,0x00,0x03,(byte)0xc3,(byte)0xdf,0x0d,0x0a}; + int[] buf5 = {0x78,0x78,0x0d,0x01,0x03,0x53,0x41,0x90,0x36,0x06,0x60,0x61,0x00,0x03,0xc3,0xdf,0x0d,0x0a}; assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(buf5)))); - int[] buf6 = {0x78,0x78,0x19,0x10,0x0B,0x03,0x1A,0x0B,0x1B,0x31,(byte)0xCC,0x02,0x7A,(byte)0xC7,(byte)0xFD,0x0C,0x46,0x57,(byte)0xBF,0x01,0x15,0x21,0x00,0x01,0x00,0x1C,(byte)0xC6,0x07,0x0D,0x0A}; + int[] buf6 = {0x78,0x78,0x19,0x10,0x0B,0x03,0x1A,0x0B,0x1B,0x31,0xCC,0x02,0x7A,0xC7,0xFD,0x0C,0x46,0x57,0xBF,0x01,0x15,0x21,0x00,0x01,0x00,0x1C,0xC6,0x07,0x0D,0x0A}; verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(buf6)))); - int[] buf7 = {78,0x78,0x21,0x12,0x0C,0x01,0x0C,0x0F,0x15,0x1F,(byte)0xCF,0x02,0x7A,(byte)0xC8,(byte)0x84,0x0C,0x46,0x57,(byte)0xEC,0x00,0x14,0x00,0x01,(byte)0xCC,0x00,0x28,0x7D,0x00,0x1F,0x72,0x00,0x01,0x00,0x0F,0x53,(byte)0xA0,0x0D,0x0A}; + int[] buf7 = {78,0x78,0x21,0x12,0x0C,0x01,0x0C,0x0F,0x15,0x1F,0xCF,0x02,0x7A,0xC8,0x84,0x0C,0x46,0x57,0xEC,0x00,0x14,0x00,0x01,0xCC,0x00,0x28,0x7D,0x00,0x1F,0x72,0x00,0x01,0x00,0x0F,0x53,0xA0,0x0D,0x0A}; verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(buf7)))); - int[] buf8 = {0x78,0x78,0x25,0x16,0x0B,0x05,0x1B,0x09,0x35,0x23,(byte)0xCF,0x02,0x7A,(byte)0xC8,0x36,0x0C,0x46,0x57,(byte)0xB3,0x00,0x14,0x00,0x09,0x01,(byte)0xCC,0x00,0x26,0x6A,0x00,0x1E,0x17,0x40,0x05,0x04,0x00,0x02,0x00,0x08,(byte)0xD7,(byte)0xB1,0x0D,0x0A}; + int[] buf8 = {0x78,0x78,0x25,0x16,0x0B,0x05,0x1B,0x09,0x35,0x23,0xCF,0x02,0x7A,0xC8,0x36,0x0C,0x46,0x57,0xB3,0x00,0x14,0x00,0x09,0x01,0xCC,0x00,0x26,0x6A,0x00,0x1E,0x17,0x40,0x05,0x04,0x00,0x02,0x00,0x08,0xD7,0xB1,0x0D,0x0A}; verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(buf8)))); + + int[] buf9 = {0x78,0x78,0x11,0x01,0x08,0x64,0x71,0x70,0x03,0x66,0x44,0x67,0x10,0x0f,0x19,0x0a,0x00,0x02,0xc6,0xd2,0x0d,0x0a}; + assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(buf9)))); - int[] buf9 = {0x78,0x78,0x19,0x10,0x0e,0x01,0x09,0x03,0x23,0x0e,0xc8,0x03,0xae,0x32,0xa6,0x06,0x53,0xcd,0xed,0x00,0x18,0x00,0x00,0x02,0x00,0x72,0xfe,0xb7,0x0d,0x0a}; - verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(buf9)))); + int[] buf10 = {0x78,0x78,0x19,0x10,0x0e,0x01,0x09,0x03,0x23,0x0e,0xc8,0x03,0xae,0x32,0xa6,0x06,0x53,0xcd,0xed,0x00,0x18,0x00,0x00,0x02,0x00,0x72,0xfe,0xb7,0x0d,0x0a}; + verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(buf10)))); } |