aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/M2mProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-11-07 17:33:12 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-11-07 17:33:12 +1300
commit912e63f296c6e4b7ec6e56768b55904e461dd07c (patch)
tree785c651b3a7ba6cf2a47b8ba15c4e1fe7b69cb74 /src/org/traccar/protocol/M2mProtocolDecoder.java
parent08df8bea6809065f1d1e7d1298e2634d7427894b (diff)
downloadtrackermap-server-912e63f296c6e4b7ec6e56768b55904e461dd07c.tar.gz
trackermap-server-912e63f296c6e4b7ec6e56768b55904e461dd07c.tar.bz2
trackermap-server-912e63f296c6e4b7ec6e56768b55904e461dd07c.zip
Replace Calendar with DateBuilder
Diffstat (limited to 'src/org/traccar/protocol/M2mProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/M2mProtocolDecoder.java36
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;
}