aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-01-26 11:44:09 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2014-01-26 11:44:09 +1300
commit8e0a29c68f76d5514bb74b77537d90cd64e76ea3 (patch)
tree49bca47c934e1574f848e3322a0b150c9e663343
parent4889e57de4b9bf88b56e1b75b7940bfd25ccae07 (diff)
downloadtrackermap-server-8e0a29c68f76d5514bb74b77537d90cd64e76ea3.tar.gz
trackermap-server-8e0a29c68f76d5514bb74b77537d90cd64e76ea3.tar.bz2
trackermap-server-8e0a29c68f76d5514bb74b77537d90cd64e76ea3.zip
Improve Gotop regex pattern
-rw-r--r--src/org/traccar/protocol/GotopProtocolDecoder.java16
-rw-r--r--test/org/traccar/protocol/GotopProtocolDecoderTest.java5
2 files changed, 16 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/GotopProtocolDecoder.java b/src/org/traccar/protocol/GotopProtocolDecoder.java
index 09385d884..23b2773c7 100644
--- a/src/org/traccar/protocol/GotopProtocolDecoder.java
+++ b/src/org/traccar/protocol/GotopProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,7 +33,8 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder {
super(serverManager);
}
- static private Pattern pattern = Pattern.compile(
+ //353327020412763,CMD-F,V,DATE:140125,TIME:183636,LAT:51.6384466N,LOT:000.2863866E,Speed:000.0,61-19,
+ private static final Pattern pattern = Pattern.compile(
"(\\d+)," + // IMEI
"[^,]+," + // Type
"([AV])," + // Validity
@@ -43,7 +44,7 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder {
"LOT:(\\d+.\\d+)([EW])," + // Longitude
"Speed:(\\d+.\\d+)," + // Speed
"([^,]+)," + // Status
- "(\\d+)" + // Course
+ "(\\d+)?" + // Course
".*");
@Override
@@ -73,7 +74,7 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder {
}
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@@ -106,7 +107,12 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder {
extendedInfo.set("status", parser.group(index++));
// Course
- position.setCourse(Double.valueOf(parser.group(index++)));
+ String course = parser.group(index++);
+ if (course != null) {
+ position.setCourse(Double.valueOf(course));
+ } else {
+ position.setCourse(0.0);
+ }
position.setExtendedInfo(extendedInfo.toString());
return position;
diff --git a/test/org/traccar/protocol/GotopProtocolDecoderTest.java b/test/org/traccar/protocol/GotopProtocolDecoderTest.java
index bc0253e83..d0e290b61 100644
--- a/test/org/traccar/protocol/GotopProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/GotopProtocolDecoderTest.java
@@ -14,6 +14,8 @@ public class GotopProtocolDecoderTest {
decoder.setDataManager(new TestDataManager());
assertNull(decoder.decode(null, null, ""));
+
+ assertNull(decoder.decode(null, null, "353327020412763,CMD-X"));
verify(decoder.decode(null, null,
"013226009991924,CMD-T,A,DATE:130802,TIME:153721,LAT:25.9757433S,LOT:028.1087816E,Speed:000.0,X-X-X-X-81-26,000,65501-00A0-4B8E"));
@@ -24,6 +26,9 @@ public class GotopProtocolDecoderTest {
verify(decoder.decode(null, null,
"353327020115804,CMD-T,A,DATE:090329,TIME:223252,LAT:22.7634066N,LOT:114.3964783E,Speed:000.0,1-1-0-84-20,000"));
+ verify(decoder.decode(null, null,
+ "353327020412763,CMD-F,V,DATE:140125,TIME:183636,LAT:51.6384466N,LOT:000.2863866E,Speed:000.0,61-19,"));
+
}
}