aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-06-26 21:31:09 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2013-06-26 21:31:09 +1200
commit5ee096fb00acd904bfd30e09aa7dbc91f733426e (patch)
tree75a3f3b5ddbe0ad6e4d2ad0e22ad1fed193f0c21 /src/org/traccar
parent58e657a18a1869b17922bfc990cc0fa645035054 (diff)
downloadtraccar-server-5ee096fb00acd904bfd30e09aa7dbc91f733426e.tar.gz
traccar-server-5ee096fb00acd904bfd30e09aa7dbc91f733426e.tar.bz2
traccar-server-5ee096fb00acd904bfd30e09aa7dbc91f733426e.zip
Finish Atrack decoder
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/protocol/AtrackProtocolDecoder.java135
1 files changed, 67 insertions, 68 deletions
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java
index 43efac542..18af7a123 100644
--- a/src/org/traccar/protocol/AtrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java
@@ -15,15 +15,15 @@
*/
package org.traccar.protocol;
-import java.util.Calendar;
-import java.util.TimeZone;
+import java.nio.charset.Charset;
+import java.util.Date;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
import org.traccar.ServerManager;
import org.traccar.helper.Log;
+import org.traccar.model.ExtendedInfoFormatter;
import org.traccar.model.Position;
public class AtrackProtocolDecoder extends BaseProtocolDecoder {
@@ -57,74 +57,73 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(2); // prefix
buf.readUnsignedShort(); // checksum
buf.readUnsignedShort(); // length
-
- // Zero for location messages
- buf.readByte(); // voltage
- buf.readByte(); // gsm signal
-
- String imei = readImei(buf);
- long index = buf.readUnsignedShort();
- int type = buf.readUnsignedByte();
-
- if (type == MSG_HEARTBEAT) {
- if (channel != null) {
- byte[] response = {0x54, 0x68, 0x1A, 0x0D, 0x0A};
- channel.write(ChannelBuffers.wrappedBuffer(response));
- }
+ buf.readUnsignedShort(); // sequence
+
+ // Create new position
+ Position position = new Position();
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("atrack");
+
+ // Get device id
+ String id = String.valueOf(buf.readLong());
+ try {
+ position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
+ } catch(Exception error) {
+ Log.warning("Unknown device - " + id);
}
- else if (type == MSG_DATA) {
-
- // Create new position
- Position position = new Position();
- position.setId(index);
-
- // Get device id
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
-
- // Date and time
- 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, buf.readUnsignedByte());
- time.set(Calendar.MINUTE, buf.readUnsignedByte());
- time.set(Calendar.SECOND, buf.readUnsignedByte());
- position.setTime(time.getTime());
-
- // Latitude
- double latitude = buf.readUnsignedInt() / (60.0 * 30000.0);
-
- // Longitude
- double longitude = buf.readUnsignedInt() / (60.0 * 30000.0);
-
- // Speed
- position.setSpeed((double) buf.readUnsignedByte());
-
- // Course
- position.setCourse((double) buf.readUnsignedShort());
-
- buf.skipBytes(3); // reserved
-
- // Flags
- long flags = buf.readUnsignedInt();
- position.setValid((flags & 0x1) == 0x1);
- if ((flags & 0x2) == 0) latitude = -latitude;
- if ((flags & 0x4) == 0) longitude = -longitude;
-
- position.setLatitude(latitude);
- position.setLongitude(longitude);
- position.setAltitude(0.0);
-
- return position;
+ // Date and time
+ position.setTime(new Date(buf.readUnsignedInt() * 1000)); // gps time
+ buf.readUnsignedInt(); // rtc time
+ buf.readUnsignedInt(); // send time
+
+ // Coordinates
+ position.setLongitude(buf.readInt() * 0.000001);
+ position.setLatitude(buf.readInt() * 0.000001);
+
+ // Course
+ position.setCourse((double) buf.readUnsignedShort());
+
+ // Report type
+ extendedInfo.set("type", buf.readUnsignedByte());
+
+ // Milage
+ extendedInfo.set("milage", buf.readUnsignedInt() * 0.1);
+
+ // Accuracy
+ extendedInfo.set("hdop", buf.readUnsignedShort() * 0.1);
+
+ // Input
+ extendedInfo.set("input", buf.readUnsignedByte());
+
+ // Speed
+ position.setSpeed(buf.readUnsignedShort() * 0.539957);
+
+ // Output
+ extendedInfo.set("output", buf.readUnsignedByte());
+
+ // ADC
+ extendedInfo.set("adc", buf.readUnsignedShort() * 0.001);
+
+ // Driver
+ int length = 0;
+ while (buf.getByte(buf.readerIndex() + length) != 0) {
+ length += 1;
}
-
- return null;
+ if (length != 0) {
+ extendedInfo.set("driver",
+ buf.toString(buf.readerIndex(), length, Charset.defaultCharset()));
+ buf.skipBytes(length);
+ }
+ buf.readByte();
+
+ // Temperature
+ extendedInfo.set("temperature1", buf.readShort() * 0.1);
+ extendedInfo.set("temperature2", buf.readShort() * 0.1);
+
+ // TODO: text message
+
+ position.setExtendedInfo(extendedInfo.toString());
+ return position;
}
}