aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/ProgressProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2012-12-17 22:57:05 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2012-12-17 22:57:05 +1300
commit34923934e0ee7d707aa9ffef2712942115236472 (patch)
tree1e213cce9e4544421cb0196dc8c4df5bcf98e9f7 /src/org/traccar/protocol/ProgressProtocolDecoder.java
parent1cde955eb9e506ec3a4cf4b3829d88b798d45175 (diff)
downloadtrackermap-server-34923934e0ee7d707aa9ffef2712942115236472.tar.gz
trackermap-server-34923934e0ee7d707aa9ffef2712942115236472.tar.bz2
trackermap-server-34923934e0ee7d707aa9ffef2712942115236472.zip
Improved progress decoder
Diffstat (limited to 'src/org/traccar/protocol/ProgressProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/ProgressProtocolDecoder.java51
1 files changed, 42 insertions, 9 deletions
diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java
index 0494b339f..64aca8157 100644
--- a/src/org/traccar/protocol/ProgressProtocolDecoder.java
+++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java
@@ -15,9 +15,9 @@
*/
package org.traccar.protocol;
+import java.nio.charset.Charset;
import java.util.Calendar;
import java.util.TimeZone;
-import java.nio.charset.Charset;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
@@ -60,6 +60,7 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder {
/**
* Decode message
*/
+ @Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, Object msg)
throws Exception {
@@ -74,22 +75,24 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder {
length = buf.readUnsignedShort();
buf.skipBytes(length);
length = buf.readUnsignedShort();
+ buf.skipBytes(length);
+ length = buf.readUnsignedShort();
String imei = buf.readBytes(length).toString(Charset.defaultCharset());
try {
deviceId = getDataManager().getDeviceByImei(imei).getId();
} catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ Log.warning("Unknown device - " + imei + " (id - " + id + ")");
}
}
// Position
- else if (type == MSG_POINT || type == MSG_ALARM) {
+ else if (deviceId != 0 && (type == MSG_POINT || type == MSG_ALARM)) {
Position position = new Position();
StringBuilder extendedInfo = new StringBuilder("<protocol>progress</protocol>");
position.setDeviceId(deviceId);
// Message index
- buf.readUnsignedInt();
+ position.setId(buf.readUnsignedInt());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@@ -114,9 +117,11 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder {
// Satellites
int satellitesNumber = buf.readUnsignedByte();
- extendedInfo.append("<sat>");
+ extendedInfo.append("<satellites>");
extendedInfo.append(satellitesNumber);
- extendedInfo.append("</sat>");
+ extendedInfo.append("</satellites>");
+
+ // Validity
position.setValid(satellitesNumber >= 3); // TODO: probably wrong
// Cell signal
@@ -124,10 +129,35 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder {
extendedInfo.append(buf.readUnsignedByte());
extendedInfo.append("</gsm>");
- // TODO: process other data
+ // Milage
+ extendedInfo.append("<milage>");
+ extendedInfo.append(buf.readUnsignedInt());
+ extendedInfo.append("</milage>");
+
+ long extraFlags = buf.readLong();
+
+ // Analog inputs
+ if ((extraFlags & 0x1) == 0x1) {
+ int count = buf.readUnsignedShort();
+ for (int i = 1; i <= count; i++) {
+ extendedInfo.append("<adc").append(i).append(">");
+ extendedInfo.append(buf.readUnsignedShort());
+ extendedInfo.append("</adc").append(i).append(">");
+ }
+
+ }
- // Extended info
- position.setExtendedInfo(extendedInfo.toString());
+ // CAN adapter
+ if ((extraFlags & 0x2) == 0x2) {
+ int size = buf.readUnsignedShort();
+ buf.skipBytes(size);
+ }
+
+ // Passenger sensor
+ if ((extraFlags & 0x4) == 0x4) {
+ int size = buf.readUnsignedShort();
+ buf.skipBytes(size);
+ }
// Send response for alarm message
if (type == MSG_ALARM) {
@@ -137,6 +167,9 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder {
extendedInfo.append("<alarm>true</alarm>");
}
+ // Extended info
+ position.setExtendedInfo(extendedInfo.toString());
+
return position;
}