aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/YwtProtocolDecoder.java19
-rw-r--r--test/org/traccar/protocol/YwtProtocolDecoderTest.java3
2 files changed, 20 insertions, 2 deletions
diff --git a/src/org/traccar/protocol/YwtProtocolDecoder.java b/src/org/traccar/protocol/YwtProtocolDecoder.java
index e41932177..fd712f100 100644
--- a/src/org/traccar/protocol/YwtProtocolDecoder.java
+++ b/src/org/traccar/protocol/YwtProtocolDecoder.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,7 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder {
super(serverManager);
}
- static private Pattern pattern = Pattern.compile(
+ private static final Pattern pattern = Pattern.compile(
"%(..)," + // Type
"(\\d+):" + // Unit identifier
"\\d+," + // Subtype
@@ -57,6 +57,21 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder {
throws Exception {
String sentence = (String) msg;
+
+ // Synchronization
+ if (sentence.startsWith("%SN") && channel != null) {
+ int start = sentence.indexOf(':');
+ int end = start;
+ for (int i = 0; i < 4; i++) {
+ end = sentence.indexOf(',', end + 1);
+ }
+ if (end == -1) {
+ end = sentence.length();
+ }
+
+ channel.write("%AT+SN=" + sentence.substring(start, end));
+ return null;
+ }
// Parse message
Matcher parser = pattern.matcher(sentence);
diff --git a/test/org/traccar/protocol/YwtProtocolDecoderTest.java b/test/org/traccar/protocol/YwtProtocolDecoderTest.java
index 1ed6ad61c..3f757c9d7 100644
--- a/test/org/traccar/protocol/YwtProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/YwtProtocolDecoderTest.java
@@ -12,6 +12,9 @@ public class YwtProtocolDecoderTest {
YwtProtocolDecoder decoder = new YwtProtocolDecoder(null);
decoder.setDataManager(new TestDataManager());
+
+ assertNull(decoder.decode(null, null,
+ "%SN,0417061042:0,0,140117041203,404"));
verify(decoder.decode(null, null,
"%GP,3000012345:0,090723182813,E114.602345,N22.069725,,30,160,4,0,00,,2794-10FF-46000,3>0-0"));