aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/GoSafeProtocolDecoder.java22
-rw-r--r--test/org/traccar/protocol/GoSafeProtocolDecoderTest.java6
2 files changed, 18 insertions, 10 deletions
diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
index 2fb7522d3..810aee3e0 100644
--- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java
+++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -41,11 +41,12 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // imei
.number("(dd)(dd)(dd)") // time
.number("(dd)(dd)(dd),") // date
+ .optional(2)
.expression("(.*)#?") // data
.compile();
private static final Pattern PATTERN_ITEM = new PatternBuilder()
- .number("(x+)?,") // event
+ .number("(x+)?,").optional() // event
.groupBegin()
.text("SYS:")
.expression("[^,]*,")
@@ -105,7 +106,10 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(getDeviceId());
- position.setTime(time);
+
+ if (time != null) {
+ position.setTime(time);
+ }
position.set(Event.KEY_EVENT, parser.next());
@@ -153,14 +157,18 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt())
- .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ 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, dateBuilder.getDate()));
+ positions.add(decodePosition(itemParser, time));
}
return positions;
diff --git a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java
index e4f20f6ba..8569fcae8 100644
--- a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java
@@ -10,11 +10,11 @@ public class GoSafeProtocolDecoderTest extends ProtocolTest {
GoSafeProtocolDecoder decoder = new GoSafeProtocolDecoder(new GoSafeProtocol());
- verifyNothing(decoder, text(
- "*GS02,358696043774648"));
+ /*verifyPositions(decoder, text(
+ "*GS02,358696043774648,GPS:230040;A;S1.166829;E36.934287;0;0;170116,STT:20;0,MGR:32755204,ADC:0;11.2;1;28.3;2;4.1,GFS:0;0"));*/
verifyNothing(decoder, text(
- "*GS02,358696043774648,GPS:230040;A;S1.166829;E36.934287;0;0;170116,STT:20;0,MGR:32755204,ADC:0;11.2;1;28.3;2;4.1,GFS:0;0"));
+ "*GS02,358696043774648"));
verifyPositions(decoder, text(
"*GS16,351535058709775,100356130215,,SYS:G79W;V1.06;V1.0.2,GPS:A;6;N24.802700;E46.616828;0;0;684;1.35,COT:60,ADC:4.31;0.10,DTT:20000;;0;0;0;1"));