aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-09-02 15:24:21 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-09-02 15:24:21 +1200
commit5cf8952d716419871259ad5a6d4bf8ac98c21efe (patch)
tree90c857e7344bdf34a22563693f43d4e80e82f2a6
parent3223d8ef52518c26aac6dd83b628d8162481fbf8 (diff)
downloadtrackermap-server-5cf8952d716419871259ad5a6d4bf8ac98c21efe.tar.gz
trackermap-server-5cf8952d716419871259ad5a6d4bf8ac98c21efe.tar.bz2
trackermap-server-5cf8952d716419871259ad5a6d4bf8ac98c21efe.zip
Decode H02 alarm status
-rw-r--r--src/org/traccar/model/Event.java1
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java19
-rw-r--r--test/org/traccar/protocol/H02ProtocolDecoderTest.java3
3 files changed, 17 insertions, 6 deletions
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
index 831ae31b3..40ea38e26 100644
--- a/src/org/traccar/model/Event.java
+++ b/src/org/traccar/model/Event.java
@@ -79,6 +79,7 @@ public abstract class Event {
public static final String KEY_IP = "ip";
public static final String KEY_ARCHIVE = "archive";
public static final String KEY_DISTANCE = "distance";
+ public static final String KEY_DOOR = "door";
// Starts with 1 not 0
public static final String PREFIX_TEMP = "temp";
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index 9b58af854..666d868f7 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -27,6 +27,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.helper.BitUtil;
import org.traccar.helper.ChannelBufferTools;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -55,6 +56,14 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
return result;
}
+
+ private void processStatus(Position position, long status) {
+ if (!BitUtil.check(status, 0) || !BitUtil.check(status, 1) || !BitUtil.check(status, 3) || !BitUtil.check(status, 4)) {
+ position.set(Event.KEY_ALARM, true);
+ }
+ position.set(Event.KEY_IGNITION, !BitUtil.check(status, 10));
+ position.set(Event.KEY_STATUS, status);
+ }
private Position decodeBinary(ChannelBuffer buf, Channel channel) {
@@ -95,9 +104,8 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
// Speed and course
position.setSpeed(ChannelBufferTools.readHexInteger(buf, 3));
position.setCourse((buf.readUnsignedByte() & 0x0f) * 100.0 + ChannelBufferTools.readHexInteger(buf, 2));
-
- // Status
- position.set(Event.KEY_STATUS, ChannelBufferTools.readHexString(buf, 8));
+
+ processStatus(position, buf.readUnsignedInt());
return position;
}
@@ -174,9 +182,8 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1);
time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++)));
position.setTime(time.getTime());
-
- // Status
- position.set(Event.KEY_STATUS, parser.group(index++));
+
+ processStatus(position, Long.parseLong(parser.group(index++), 16));
return position;
}
diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
index b7d356ff0..5be78d643 100644
--- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
@@ -82,6 +82,9 @@ public class H02ProtocolDecoderTest extends ProtocolDecoderTest {
"*HQ,8401016597,BASE,152609,0,0,0,0,211014,FFFFFFFF#", Charset.defaultCharset())));
verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
+ "24410600082621532131081504419390060740418306000000fffffbfdff0015060000002c02dc0c000000001f"))));
+
+ verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
"2427051711092133391406135002584900014337822e000000ffffffffff0000"))));
verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(