diff options
Diffstat (limited to 'src/org/traccar/protocol/AutoFonProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/AutoFonProtocolDecoder.java | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java index 1da024e0b..9356e2cd7 100644 --- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java @@ -16,14 +16,13 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; import java.util.LinkedList; import java.util.List; -import java.util.TimeZone; 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.helper.DateBuilder; import org.traccar.model.Event; import org.traccar.model.Position; @@ -45,7 +44,6 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { private Position decodePosition(ChannelBuffer buf, boolean history) { - // Create new position Position position = new Position(); position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); @@ -61,7 +59,6 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_BATTERY, buf.readUnsignedByte()); buf.skipBytes(6); // time - // Timers if (!history) { for (int i = 0; i < 2; i++) { buf.skipBytes(5); // time @@ -77,23 +74,15 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedShort(); // lac buf.readUnsignedShort(); // cid - // GPS status int valid = buf.readUnsignedByte(); position.setValid((valid & 0xc0) != 0); position.set(Event.KEY_SATELLITES, valid & 0x3f); - // Date and time - Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte()); - time.set(Calendar.MONTH, buf.readUnsignedByte() - 1); - time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte()); - time.set(Calendar.HOUR_OF_DAY, buf.readUnsignedByte()); - time.set(Calendar.MINUTE, buf.readUnsignedByte()); - time.set(Calendar.SECOND, buf.readUnsignedByte()); - position.setTime(time.getTime()); - - // Location + DateBuilder dateBuilder = new DateBuilder() + .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) + .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); + position.setTime(dateBuilder.getDate()); + position.setLatitude(convertCoordinate(buf.readInt())); position.setLongitude(convertCoordinate(buf.readInt())); position.setAltitude(buf.readShort()); @@ -109,8 +98,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { @Override protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) - throws Exception { + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ChannelBuffer buf = (ChannelBuffer) msg; @@ -126,7 +114,6 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { return null; } - // Send response if (channel != null) { channel.write(ChannelBuffers.wrappedBuffer(new byte[] {buf.readByte()})); } |