diff options
Diffstat (limited to 'src/org/traccar/protocol/M2mProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/M2mProtocolDecoder.java | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/src/org/traccar/protocol/M2mProtocolDecoder.java b/src/org/traccar/protocol/M2mProtocolDecoder.java index 6e57b5766..d60303601 100644 --- a/src/org/traccar/protocol/M2mProtocolDecoder.java +++ b/src/org/traccar/protocol/M2mProtocolDecoder.java @@ -16,13 +16,12 @@ 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.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.DateBuilder; import org.traccar.model.Event; import org.traccar.model.Position; @@ -36,8 +35,7 @@ public class M2mProtocolDecoder 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; @@ -53,7 +51,6 @@ public class M2mProtocolDecoder extends BaseProtocolDecoder { firstPacket = false; - // Read IMEI StringBuilder imei = new StringBuilder(); for (int i = 0; i < 8; i++) { int b = buf.readByte(); @@ -63,28 +60,23 @@ public class M2mProtocolDecoder extends BaseProtocolDecoder { imei.append(b % 10); } - // Identification identify(imei.toString(), channel); } else if (hasDeviceId()) { - // Create new position Position position = new Position(); position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); - // Date and time - Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte() & 0x3f); - time.set(Calendar.MONTH, (buf.readUnsignedByte() & 0x3f) - 1); - time.set(Calendar.YEAR, 2000 + buf.readUnsignedByte()); - time.set(Calendar.HOUR_OF_DAY, buf.readUnsignedByte() & 0x3f); - time.set(Calendar.MINUTE, buf.readUnsignedByte() & 0x7f); - time.set(Calendar.SECOND, buf.readUnsignedByte() & 0x7f); - position.setTime(time.getTime()); - - // Location + DateBuilder dateBuilder = new DateBuilder() + .setDay(buf.readUnsignedByte() & 0x3f) + .setMonth(buf.readUnsignedByte() & 0x3f) + .setYear(buf.readUnsignedByte()) + .setHour(buf.readUnsignedByte() & 0x3f) + .setMinute(buf.readUnsignedByte() & 0x7f) + .setSecond(buf.readUnsignedByte() & 0x7f); + position.setTime(dateBuilder.getDate()); + int degrees = buf.readUnsignedByte(); double latitude = buf.readUnsignedByte(); latitude += buf.readUnsignedByte() / 100.0; @@ -108,19 +100,19 @@ public class M2mProtocolDecoder extends BaseProtocolDecoder { latitude = -latitude; } + position.setValid(true); position.setLatitude(latitude); position.setLongitude(longitude); position.setSpeed(buf.readUnsignedByte()); - // Satellites int satellites = buf.readUnsignedByte(); if (satellites == 0) { return null; // cell information } position.set(Event.KEY_SATELLITES, satellites); - position.setValid(true); - // TODO decode everything else + // decode other data + return position; } |