aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-01-21 16:48:09 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-01-21 16:48:09 +1300
commit39de5581b92a505a19cf1929a52bc562c48c3e2f (patch)
tree0924db688457d2cef28dbfa1b1d6328b19ba6207 /src/org/traccar
parente7c04ee2af5b2bdabc58647c11ec059281dccae0 (diff)
downloadtraccar-server-39de5581b92a505a19cf1929a52bc562c48c3e2f.tar.gz
traccar-server-39de5581b92a505a19cf1929a52bc562c48c3e2f.tar.bz2
traccar-server-39de5581b92a505a19cf1929a52bc562c48c3e2f.zip
Add support for old GoSafe format
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/protocol/GoSafeProtocolDecoder.java73
1 files changed, 59 insertions, 14 deletions
diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
index 810aee3e0..8be462ebf 100644
--- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java
+++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
@@ -41,7 +41,6 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // imei
.number("(dd)(dd)(dd)") // time
.number("(dd)(dd)(dd),") // date
- .optional(2)
.expression("(.*)#?") // data
.compile();
@@ -101,6 +100,23 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
.groupEnd("?")
.compile();
+ private static final Pattern PATTERN_OLD = new PatternBuilder()
+ .text("*GS") // header
+ .number("d+,") // protocol version
+ .number("(d+),") // imei
+ .text("GPS:")
+ .number("(dd)(dd)(dd);") // time
+ .number("d;").optional() // fix type
+ .expression("([AV]);") // validity
+ .number("([NS])(d+.d+);") // latitude
+ .number("([EW])(d+.d+);") // longitude
+ .number("(d+)?;") // speed
+ .number("(d+);") // course
+ .number("(d+.?d*)").optional() // hdop
+ .number("(dd)(dd)(dd)") // date
+ .any()
+ .compile();
+
private Position decodePosition(Parser parser, Date time) {
Position position = new Position();
@@ -148,7 +164,10 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
channel.write("1234");
}
- Parser parser = new Parser(PATTERN, (String) msg);
+ String sentence = (String) msg;
+ Pattern pattern = sentence.startsWith("*GS02") ? PATTERN_OLD : PATTERN;
+
+ Parser parser = new Parser(pattern, (String) msg);
if (!parser.matches()) {
return null;
}
@@ -157,21 +176,47 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Date time = null;
- if (parser.hasNext(6)) {
+ if (pattern == PATTERN_OLD) {
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(getDeviceId());
+
DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt())
- .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
- time = dateBuilder.getDate();
- }
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
- List<Position> positions = new LinkedList<>();
- Parser itemParser = new Parser(PATTERN_ITEM, parser.next());
- while (itemParser.find()) {
- positions.add(decodePosition(itemParser, time));
- }
+ position.setValid(parser.next().equals("A"));
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
+ position.setSpeed(parser.nextDouble());
+ position.setCourse(parser.nextDouble());
+
+ position.set(Event.KEY_HDOP, parser.next());
+
+ dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
- return positions;
+ return position;
+
+ } else {
+
+ Date time = null;
+ if (parser.hasNext(6)) {
+ DateBuilder dateBuilder = new DateBuilder()
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ time = dateBuilder.getDate();
+ }
+
+ List<Position> positions = new LinkedList<>();
+ Parser itemParser = new Parser(PATTERN_ITEM, parser.next());
+ while (itemParser.find()) {
+ positions.add(decodePosition(itemParser, time));
+ }
+
+ return positions;
+
+ }
}
}