aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
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
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')
-rw-r--r--src/org/traccar/protocol/AutoFonProtocolDecoder.java17
-rw-r--r--src/org/traccar/protocol/Avl301ProtocolDecoder.java38
-rw-r--r--src/org/traccar/protocol/CellocatorProtocolDecoder.java27
-rw-r--r--src/org/traccar/protocol/GatorProtocolDecoder.java38
-rw-r--r--src/org/traccar/protocol/KhdProtocolDecoder.java38
-rw-r--r--src/org/traccar/protocol/M2mProtocolDecoder.java36
6 files changed, 65 insertions, 129 deletions
diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
index c0c3aaf08..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;
@@ -79,15 +78,10 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
position.setValid((valid & 0xc0) != 0);
position.set(Event.KEY_SATELLITES, valid & 0x3f);
- 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());
+ 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()));
@@ -120,7 +114,6 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- // Send response
if (channel != null) {
channel.write(ChannelBuffers.wrappedBuffer(new byte[] {buf.readByte()}));
}
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;
}
diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
index 5517e703b..27c94c6ba 100644
--- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
@@ -17,12 +17,11 @@ package org.traccar.protocol;
import java.net.SocketAddress;
import java.nio.ByteOrder;
-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.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -70,8 +69,7 @@ public class CellocatorProtocolDecoder 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;
@@ -84,15 +82,13 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
}
byte packetNumber = buf.readByte();
- // Send reply
sendReply(channel, deviceUniqueId, packetNumber);
- // Parse location
if (type == MSG_CLIENT_STATUS) {
+
Position position = new Position();
position.setProtocol(getProtocolName());
- // Device identifier
if (!identify(String.valueOf(deviceUniqueId), channel)) {
return null;
}
@@ -102,7 +98,6 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // software version
buf.readUnsignedByte(); // protocol version
- // Status
position.set(Event.KEY_STATUS, buf.getUnsignedByte(buf.readerIndex()) & 0x0f);
int operator = (buf.readUnsignedByte() & 0xf0) << 4;
@@ -128,23 +123,17 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
position.setValid(buf.readUnsignedByte() >= 3); // satellites
- // Location data
position.setLongitude(buf.readInt() / Math.PI * 180 / 100000000);
position.setLatitude(buf.readInt() / Math.PI * 180 / 100000000.0);
position.setAltitude(buf.readInt() * 0.01);
position.setSpeed(UnitsConverter.knotsFromMps(buf.readInt() * 0.01));
position.setCourse(buf.readUnsignedShort() / Math.PI * 180.0 / 1000.0);
- // Time
- Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- time.clear();
- time.set(Calendar.SECOND, buf.readUnsignedByte());
- time.set(Calendar.MINUTE, buf.readUnsignedByte());
- time.set(Calendar.HOUR_OF_DAY, buf.readUnsignedByte());
- time.set(Calendar.DAY_OF_MONTH, buf.readUnsignedByte());
- time.set(Calendar.MONTH, buf.readUnsignedByte() - 1);
- time.set(Calendar.YEAR, buf.readUnsignedShort());
- position.setTime(time.getTime());
+ DateBuilder dateBuilder = new DateBuilder()
+ .setTimeReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
+ .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedShort());
+ position.setTime(dateBuilder.getDate());
+
return position;
}
diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java
index 2bf10b14c..aad771099 100644
--- a/src/org/traccar/protocol/GatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/GatorProtocolDecoder.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.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.ChannelBufferTools;
+import org.traccar.helper.DateBuilder;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -57,8 +56,7 @@ public class GatorProtocolDecoder 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,42 +79,30 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder {
}
position.setDeviceId(getDeviceId());
- // Date and time
- Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- time.clear();
- time.set(Calendar.YEAR, 2000 + ChannelBufferTools.readHexInteger(buf, 2));
- time.set(Calendar.MONTH, ChannelBufferTools.readHexInteger(buf, 2) - 1);
- time.set(Calendar.DAY_OF_MONTH, ChannelBufferTools.readHexInteger(buf, 2));
- time.set(Calendar.HOUR_OF_DAY, ChannelBufferTools.readHexInteger(buf, 2));
- time.set(Calendar.MINUTE, ChannelBufferTools.readHexInteger(buf, 2));
- time.set(Calendar.SECOND, ChannelBufferTools.readHexInteger(buf, 2));
- position.setTime(time.getTime());
-
- // Location
+ DateBuilder dateBuilder = new DateBuilder()
+ .setYear(ChannelBufferTools.readHexInteger(buf, 2))
+ .setMonth(ChannelBufferTools.readHexInteger(buf, 2))
+ .setDay(ChannelBufferTools.readHexInteger(buf, 2))
+ .setHour(ChannelBufferTools.readHexInteger(buf, 2))
+ .setMinute(ChannelBufferTools.readHexInteger(buf, 2))
+ .setSecond(ChannelBufferTools.readHexInteger(buf, 2));
+ position.setTime(dateBuilder.getDate());
+
position.setLatitude(ChannelBufferTools.readCoordinate(buf));
position.setLongitude(ChannelBufferTools.readCoordinate(buf));
position.setSpeed(UnitsConverter.knotsFromKph(ChannelBufferTools.readHexInteger(buf, 4)));
position.setCourse(ChannelBufferTools.readHexInteger(buf, 4));
- // Flags
int flags = buf.readUnsignedByte();
position.setValid((flags & 0x80) != 0);
position.set(Event.KEY_SATELLITES, flags & 0x0f);
- // Status
position.set(Event.KEY_STATUS, buf.readUnsignedByte());
-
- // Key switch
position.set("key", buf.readUnsignedByte());
-
- // Oil
position.set("oil", buf.readUnsignedShort() / 10.0);
-
- // Power
position.set(Event.KEY_POWER, buf.readUnsignedByte() + buf.readUnsignedByte() / 100.0);
-
- // Odometer
position.set(Event.KEY_ODOMETER, buf.readUnsignedInt());
+
return position;
}
diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java
index 1ae192bf5..f6083be70 100644
--- a/src/org/traccar/protocol/KhdProtocolDecoder.java
+++ b/src/org/traccar/protocol/KhdProtocolDecoder.java
@@ -16,14 +16,13 @@
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.ChannelBufferTools;
import org.traccar.helper.Checksum;
+import org.traccar.helper.DateBuilder;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -60,8 +59,7 @@ public class KhdProtocolDecoder 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;
@@ -72,34 +70,28 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
if (type == MSG_ON_DEMAND || type == MSG_POSITION_UPLOAD || type == MSG_POSITION_REUPLOAD
|| type == MSG_ALARM || type == MSG_REPLY || type == MSG_PERIPHERAL) {
- // Create new position
Position position = new Position();
position.setProtocol(getProtocolName());
- // Device identification
if (!identify(readSerialNumber(buf), channel)) {
return null;
}
position.setDeviceId(getDeviceId());
- // Date and time
- Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
- time.clear();
- time.set(Calendar.YEAR, 2000 + ChannelBufferTools.readHexInteger(buf, 2));
- time.set(Calendar.MONTH, ChannelBufferTools.readHexInteger(buf, 2) - 1);
- time.set(Calendar.DAY_OF_MONTH, ChannelBufferTools.readHexInteger(buf, 2));
- time.set(Calendar.HOUR_OF_DAY, ChannelBufferTools.readHexInteger(buf, 2));
- time.set(Calendar.MINUTE, ChannelBufferTools.readHexInteger(buf, 2));
- time.set(Calendar.SECOND, ChannelBufferTools.readHexInteger(buf, 2));
- position.setTime(time.getTime());
-
- // Location
+ DateBuilder dateBuilder = new DateBuilder()
+ .setYear(ChannelBufferTools.readHexInteger(buf, 2))
+ .setMonth(ChannelBufferTools.readHexInteger(buf, 2))
+ .setDay(ChannelBufferTools.readHexInteger(buf, 2))
+ .setHour(ChannelBufferTools.readHexInteger(buf, 2))
+ .setMinute(ChannelBufferTools.readHexInteger(buf, 2))
+ .setSecond(ChannelBufferTools.readHexInteger(buf, 2));
+ position.setTime(dateBuilder.getDate());
+
position.setLatitude(ChannelBufferTools.readCoordinate(buf));
position.setLongitude(ChannelBufferTools.readCoordinate(buf));
position.setSpeed(UnitsConverter.knotsFromKph(ChannelBufferTools.readHexInteger(buf, 4)));
position.setCourse(ChannelBufferTools.readHexInteger(buf, 4));
- // Flags
int flags = buf.readUnsignedByte();
position.setValid((flags & 0x80) != 0);
@@ -109,14 +101,10 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
} else {
- // Odometer
position.set(Event.KEY_ODOMETER, buf.readUnsignedMedium());
- // Status
- buf.skipBytes(4);
-
- // Other
- buf.skipBytes(8);
+ buf.skipBytes(4); // status
+ buf.skipBytes(8); // other
}
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;
}