aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/Avl301ProtocolDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol/Avl301ProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/Avl301ProtocolDecoder.java38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/org/traccar/protocol/Avl301ProtocolDecoder.java b/src/org/traccar/protocol/Avl301ProtocolDecoder.java
index f0ad97bf8..67ea223fa 100644
--- a/src/org/traccar/protocol/Avl301ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Avl301ProtocolDecoder.java
@@ -16,12 +16,11 @@
package org.traccar.protocol;
import java.net.SocketAddress;
-import java.util.Calendar;
-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;
@@ -60,8 +59,7 @@ public class Avl301ProtocolDecoder 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;
@@ -81,36 +79,25 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder {
} else if (hasDeviceId() && type == MSG_GPS_LBS_STATUS) {
- // Create new position
Position position = new Position();
position.setDeviceId(getDeviceId());
position.setProtocol(getProtocolName());
- // Date and time(6)
- Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- time.clear();
- time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte());
- time.set(Calendar.MONTH, buf.readUnsignedByte() - 1);
- time.set(Calendar.DAY_OF_MONTH, 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());
-
- // GPS length and Satellites count
- int gpsLength = buf.readUnsignedByte();
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
+ .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
+ position.setTime(dateBuilder.getDate());
+
+ int gpsLength = buf.readUnsignedByte(); // gps len and sat
position.set(Event.KEY_SATELLITES, gpsLength & 0xf);
- //Skip Satellite numbers
- buf.skipBytes(1);
+ buf.readUnsignedByte(); // satellites
- // Location
double latitude = buf.readUnsignedInt() / 600000.0;
double longitude = buf.readUnsignedInt() / 600000.0;
- position.setSpeed(buf.readUnsignedByte() * 1.0); // kph?
+ position.setSpeed(buf.readUnsignedByte());
- // Course and flags
- int union = buf.readUnsignedShort();
+ int union = buf.readUnsignedShort(); // course and flags
position.setCourse(union & 0x03FF);
position.setValid((union & 0x1000) != 0);
if ((union & 0x0400) != 0) {
@@ -133,10 +120,11 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder {
int flags = buf.readUnsignedByte();
position.set("acc", (flags & 0x2) != 0);
- // TODO parse other flags
+ // parse other flags
position.set(Event.KEY_POWER, buf.readUnsignedByte());
position.set(Event.KEY_GSM, buf.readUnsignedByte());
+
return position;
}