diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/protocol/StartekProtocolDecoder.java | 32 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/StartekProtocolDecoderTest.java | 4 |
2 files changed, 35 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java b/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java index 68fc511aa..aae764993 100644 --- a/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java @@ -41,6 +41,11 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder { .expression(".") // index .number("d+,") // length .number("(d+),") // imei + .expression("(.+)") // content + .number("xx") // checksum + .compile(); + + private static final Pattern PATTERN_POSITION = new PatternBuilder() .number("xxx,") // command .number("(d+),") // event .expression("([^,]+)?,") // event data @@ -75,7 +80,6 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder { .expression("([^,]+)?") // temperature .groupEnd("?") .groupEnd("?") - .number("xx") // checksum .compile(); private String decodeAlarm(int value) { @@ -108,6 +112,32 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder { return null; } + String content = parser.next(); + if (content.length() < 100) { + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + position.set(Position.KEY_RESULT, content); + + return position; + + } else { + + return decodePosition(deviceSession, content); + + } + } + + protected Object decodePosition(DeviceSession deviceSession, String content) throws Exception { + + Parser parser = new Parser(PATTERN_POSITION, content); + if (!parser.matches()) { + return null; + } + Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); diff --git a/src/test/java/org/traccar/protocol/StartekProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/StartekProtocolDecoderTest.java index 81f2f8f69..e85672326 100644 --- a/src/test/java/org/traccar/protocol/StartekProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/StartekProtocolDecoderTest.java @@ -11,6 +11,10 @@ public class StartekProtocolDecoderTest extends ProtocolTest { var decoder = new StartekProtocolDecoder(null); + verifyAttribute(decoder, text( + "&&:23,860262050015424,129,OKA2"), + Position.KEY_RESULT, "129,OK"); + verifyPosition(decoder, text( "&&o125,861157040554384,000,0,,210702235150,A,27.263505,153.037061,11,1.2,0,0,31,5125,505|1|7032|8C89802,20,0000002D,00,00,01E2|019DF0")); |