diff options
Diffstat (limited to 'src/org/traccar/protocol/Mta6ProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/Mta6ProtocolDecoder.java | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java index 86b191b0b..4fb7d0ecd 100644 --- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java +++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java @@ -17,7 +17,7 @@ package org.traccar.protocol; import java.nio.charset.Charset; import java.net.SocketAddress; -import java.util.Calendar; +import java.util.Calendar; import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -38,7 +38,7 @@ import org.traccar.model.Event; import org.traccar.model.Position; public class Mta6ProtocolDecoder extends BaseProtocolDecoder { - + private final boolean simple; public Mta6ProtocolDecoder(Protocol protocol, boolean simple) { @@ -51,7 +51,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE); channel.write(response); } - + private void sendResponse(Channel channel, short packetId, short packetCount) { HttpResponse response = new DefaultHttpResponse( HttpVersion.HTTP_1_1, HttpResponseStatus.OK); @@ -61,15 +61,15 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { end.writeByte(packetId); end.writeByte(packetCount); end.writeByte(0); - + response.setContent(ChannelBuffers.wrappedBuffer(begin, end)); channel.write(response); } - + private static class FloatReader { - + private int previousFloat; - + public float readFloat(ChannelBuffer buf) { switch (buf.getUnsignedByte(buf.readerIndex()) >> 6) { @@ -88,13 +88,13 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { } return Float.intBitsToFloat(previousFloat); } - + } - + private static class TimeReader extends FloatReader { - + private long weekNumber; - + public Date readTime(ChannelBuffer buf) { long weekTime = (long) (readFloat(buf) * 1000); if (weekNumber == 0) { @@ -110,16 +110,16 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { return new Date(offset + weekNumber * 7 * 24 * 60 * 60 * 1000 + weekTime); } - + } private List<Position> parseFormatA(ChannelBuffer buf) { List<Position> positions = new LinkedList<>(); - + FloatReader latitudeReader = new FloatReader(); FloatReader longitudeReader = new FloatReader(); TimeReader timeReader = new TimeReader(); - + try { while (buf.readable()) { Position position = new Position(); @@ -196,7 +196,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { } } catch (IndexOutOfBoundsException error) { } - + return positions; } @@ -270,17 +270,17 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { position.setValid(satellites >= 3); position.set(Event.KEY_SATELLITES, satellites); } - + // TODO: process other data return position; } - + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - + HttpRequest request = (HttpRequest) msg; ChannelBuffer buf = request.getContent(); @@ -295,7 +295,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { } buf.skipBytes(uniqueId.length()); buf.skipBytes("&bin=".length()); - + // Read header short packetId = buf.readUnsignedByte(); short offset = buf.readUnsignedByte(); // dataOffset @@ -303,13 +303,13 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // reserved short parameters = buf.readUnsignedByte(); // TODO: handle timezone buf.skipBytes(offset - 5); - + // Send response if (channel != null) { sendContinue(channel); sendResponse(channel, packetId, packetCount); } - + // Parse data if (packetId == 0x31 || packetId == 0x32 || packetId == 0x36) { if (simple) { |