aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/helper/Parser.java5
-rw-r--r--src/org/traccar/protocol/VisiontekProtocolDecoder.java35
-rw-r--r--test/org/traccar/protocol/VisiontekProtocolDecoderTest.java10
3 files changed, 32 insertions, 18 deletions
diff --git a/src/org/traccar/helper/Parser.java b/src/org/traccar/helper/Parser.java
index f70fe2e89..bda7d6366 100644
--- a/src/org/traccar/helper/Parser.java
+++ b/src/org/traccar/helper/Parser.java
@@ -87,6 +87,7 @@ public class Parser {
}
public enum CoordinateFormat {
+ DEG_HEM,
DEG_MIN_HEM,
DEG_MIN_MIN_HEM,
HEM_DEG,
@@ -99,6 +100,10 @@ public class Parser {
String hemisphere;
switch (format) {
+ case DEG_HEM:
+ coordinate = nextDouble();
+ hemisphere = next();
+ break;
case DEG_MIN_MIN_HEM:
coordinate = nextInt();
coordinate += Double.parseDouble(next() + '.' + next()) / 60;
diff --git a/src/org/traccar/protocol/VisiontekProtocolDecoder.java b/src/org/traccar/protocol/VisiontekProtocolDecoder.java
index 0dce4954d..31e9ff069 100644
--- a/src/org/traccar/protocol/VisiontekProtocolDecoder.java
+++ b/src/org/traccar/protocol/VisiontekProtocolDecoder.java
@@ -22,10 +22,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
+import org.traccar.helper.*;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -41,13 +38,17 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),").optional() // imei
.number("(dd),(dd),(dd),") // date
.number("(dd),(dd),(dd),") // time
- .number("(dd)(dd).?(dddd)") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd).?(dddd)") // longitude
- .expression("([EW]),")
+ .groupBegin()
+ .number("(dd)(dd).?(d+)([NS]),") // latitude
+ .number("(ddd)(dd).?(d+)([EW]),") // longitude
+ .or()
+ .number("(dd.d+)([NS]),") // latitude
+ .number("(ddd.d+)([EW]),") // longitude
+ .groupEnd()
.number("(d+.?d+),") // speed
.number("(d+),") // course
.groupBegin()
+ .groupBegin()
.number("(d+),") // altitude
.number("(d+),") // satellites
.groupEnd("?")
@@ -60,8 +61,10 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder {
.number("(d),") // external battery status
.number("(d+),") // gsm
.groupEnd("?")
- .expression("([AV]),?") // validity
- .number("(d+)?") // rfid
+ .groupEnd("?")
+ .any()
+ .expression("([AV])") // validity
+ .number(",(d{10})").optional() // rfid
.any()
.compile();
@@ -79,7 +82,7 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder {
String id = parser.next();
String imei = parser.next();
- if (!identify(id, channel, null, false) && !identify(imei, channel)) {
+ if (!identify(id, channel, null, false) && (imei == null || !identify(imei, channel))) {
return null;
}
position.setDeviceId(getDeviceId());
@@ -89,8 +92,14 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder {
.setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
position.setTime(dateBuilder.getDate());
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM));
+ if (parser.hasNext(8)) {
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM));
+ }
+ if (parser.hasNext(4)) {
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ }
position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(
parser.next().replace(".", "")) / 10));
diff --git a/test/org/traccar/protocol/VisiontekProtocolDecoderTest.java b/test/org/traccar/protocol/VisiontekProtocolDecoderTest.java
index 3a31d3c28..8b817f618 100644
--- a/test/org/traccar/protocol/VisiontekProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/VisiontekProtocolDecoderTest.java
@@ -10,14 +10,14 @@ public class VisiontekProtocolDecoderTest extends ProtocolDecoderTest {
VisiontekProtocolDecoder decoder = new VisiontekProtocolDecoder(new VisiontekProtocol());
- /*verifyPosition(decoder, text(
+ verifyPosition(decoder, text(
"$1,VMC,358072044271838,26,10,15,10,43,20,17.066418N,080.395667E,000.0,285,00.8,0074,6390,0,0,0,0,0,0,0,0,00.00,00.00,00,00,0000,12.7,4.0,24,10,0000000000000,A,0"));
- verifyPosition(decoder, text(
- "$1,VMC,358072044271838,25,10,15,09,19,40,00.0000000,000.0000000,000.0,000,00.0,0000,6070,0,0,0,0,0,0,0,0,00.00,00.00,00,00,0000,12.5,4.0,99,00,0000000000000,V,0"));*/
+ verifyNothing(decoder, text(
+ "$1,VMC,358072044271838,25,10,15,09,19,40,00.0000000,000.0000000,000.0,000,00.0,0000,6070,0,0,0,0,0,0,0,0,00.00,00.00,00,00,0000,12.5,4.0,99,00,0000000000000,V,0"));
- //verifyPosition(decoder, text(
- // "$1,AP116,05,06,15,11,48,32,1725.0460N,07824.5289E,0617,07,0,030,2091,0,0,0,1,1,1,1,20,00.0000,00.3820,00.0000,VAJRA V1.00,A#"));
+ verifyPosition(decoder, text(
+ "$1,AP116,05,06,15,11,48,32,1725.0460N,07824.5289E,0617,07,0,030,2091,0,0,0,1,1,1,1,20,00.0000,00.3820,00.0000,VAJRA V1.00,A"));
verifyPosition(decoder, text(
"$1,AP09BU9397,861785006462448,20,06,14,15,03,28,17267339N,078279407E,060.0,073,0550,11,0,1,0,0,1,1,26,A,0000000000"),