aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/model/Position.java1
-rw-r--r--src/org/traccar/protocol/GoSafeProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/KhdProtocolDecoder.java40
-rw-r--r--test/org/traccar/protocol/KhdProtocolDecoderTest.java3
4 files changed, 36 insertions, 13 deletions
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java
index 3cae4e34b..18e7f7f46 100644
--- a/src/org/traccar/model/Position.java
+++ b/src/org/traccar/model/Position.java
@@ -22,6 +22,7 @@ public class Position extends Message {
public static final String KEY_ORIGINAL = "raw";
public static final String KEY_INDEX = "index";
public static final String KEY_HDOP = "hdop";
+ public static final String KEY_VDOP = "vdop";
public static final String KEY_SATELLITES = "sat"; // in use
public static final String KEY_SATELLITES_VISIBLE = "satVisible";
public static final String KEY_RSSI = "rssi";
diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
index 94d12e989..96f745917 100644
--- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java
+++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
@@ -64,7 +64,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
.number("(d+);") // course
.number("(d+);") // altitude
.number("(d+.d+)") // hdop
- .number("(?:;d+.d+)?") // vdop
+ .number(";(d+.d+)").optional() // vdop
.expression(",?")
.groupEnd()
.groupBegin()
@@ -154,7 +154,8 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
position.setCourse(parser.nextDouble());
position.setAltitude(parser.nextDouble());
- position.set(Position.KEY_HDOP, parser.next());
+ position.set(Position.KEY_HDOP, parser.nextDouble());
+ position.set(Position.KEY_VDOP, parser.nextDouble());
if (parser.hasNext(5)) {
position.setNetwork(new Network(CellTower.from(
diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java
index 0c3d8ee51..1c88a8b9d 100644
--- a/src/org/traccar/protocol/KhdProtocolDecoder.java
+++ b/src/org/traccar/protocol/KhdProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton@traccar.org)
+ * Copyright 2014 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -93,24 +93,42 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(BcdUtil.readCoordinate(buf));
position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4)));
position.setCourse(BcdUtil.readInteger(buf, 4));
+ position.setValid((buf.readUnsignedByte() & 0x80) != 0);
- int flags = buf.readUnsignedByte();
- position.setValid((flags & 0x80) != 0);
+ if (type != MSG_ALARM) {
- if (type == MSG_ALARM) {
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
+ position.set(Position.KEY_STATUS, buf.readUnsignedInt());
+ position.set(Position.KEY_HDOP, buf.readUnsignedByte());
+ position.set(Position.KEY_VDOP, buf.readUnsignedByte());
+ position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- buf.skipBytes(2);
+ buf.skipBytes(5); // other location data
- } else {
+ if (type == MSG_PERIPHERAL) {
- position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
+ buf.readUnsignedShort(); // data length
- buf.skipBytes(4); // status
- buf.skipBytes(8); // other
+ int dataType = buf.readUnsignedByte();
- }
+ buf.readUnsignedByte(); // content length
- // parse extra data
+ switch (dataType) {
+ case 0x01:
+ position.set(Position.KEY_FUEL,
+ buf.readUnsignedByte() * 100 + buf.readUnsignedByte());
+ break;
+ case 0x02:
+ position.set(Position.PREFIX_TEMP + 1,
+ buf.readUnsignedByte() * 100 + buf.readUnsignedByte());
+ break;
+ default:
+ break;
+ }
+
+ }
+
+ }
return position;
diff --git a/test/org/traccar/protocol/KhdProtocolDecoderTest.java b/test/org/traccar/protocol/KhdProtocolDecoderTest.java
index c58600bed..e85695be8 100644
--- a/test/org/traccar/protocol/KhdProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/KhdProtocolDecoderTest.java
@@ -14,6 +14,9 @@ public class KhdProtocolDecoderTest extends ProtocolTest {
"2929b1000605162935b80d"));
verifyPosition(decoder, binary(
+ "2929a3002e1780c663170216203353003060811013839500000114f8000000ffff5000000a00000000000000060102003db70d"));
+
+ verifyPosition(decoder, binary(
"292980002805162935140108074727801129670365336900000103ffff000082fc0000001e78091b000000360d"));
verifyPosition(decoder, binary(