aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-07-19 13:15:15 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-07-19 13:15:15 +1200
commitd5640d4a672c0b23bea3a697fc3412fbe7e93350 (patch)
treedb970d388a731082d06b1c30db0fc11e1c4fa6b8
parent9e75f24dc7ddeac4a7059829cd0c24a4f43e988f (diff)
downloadtrackermap-server-d5640d4a672c0b23bea3a697fc3412fbe7e93350.tar.gz
trackermap-server-d5640d4a672c0b23bea3a697fc3412fbe7e93350.tar.bz2
trackermap-server-d5640d4a672c0b23bea3a697fc3412fbe7e93350.zip
Parse battery for Suntech devices
-rw-r--r--src/org/traccar/protocol/SuntechProtocolDecoder.java18
-rw-r--r--test/org/traccar/protocol/SuntechProtocolDecoderTest.java6
2 files changed, 14 insertions, 10 deletions
diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java
index aade44e4f..7ba6020f5 100644
--- a/src/org/traccar/protocol/SuntechProtocolDecoder.java
+++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java
@@ -20,10 +20,7 @@ import java.util.Calendar;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
@@ -35,7 +32,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- static private Pattern pattern = Pattern.compile(
+ private static final Pattern pattern = Pattern.compile(
"S.\\d{3}(?:\\w{3})?;" + // Header
"(?:[^;]+;)?" +
"(\\d{6,});" + // Device ID
@@ -44,10 +41,12 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
"(\\d{4})(\\d{2})(\\d{2});" + // Date (YYYYMMDD)
"(\\d{2}):(\\d{2}):(\\d{2});" + // Time (HH:MM:SS)
"(?:(\\p{XDigit}+);)?" + // Cell
- "([-\\+]\\d{2}.\\d+);" + // Latitude
- "([-\\+]\\d{3}.\\d+);" + // Longitude
- "(\\d{3}.\\d{3});" + // Speed
- "(\\d{3}.\\d{2});" + // Course
+ "([-\\+]\\d{2}\\.\\d+);" + // Latitude
+ "([-\\+]\\d{3}\\.\\d+);" + // Longitude
+ "(\\d{3}\\.\\d{3});" + // Speed
+ "(\\d{3}\\.\\d{2});" + // Course
+ "(?:\\d+;)?" +
+ "(\\d+\\.\\d+)?" + // Battery
".*"); // Full format
@Override
@@ -101,6 +100,9 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
// Course
position.setCourse(Double.valueOf(parser.group(index++)));
+
+ // Battery
+ position.set(Event.KEY_BATTERY, parser.group(index++));
return position;
}
diff --git a/test/org/traccar/protocol/SuntechProtocolDecoderTest.java b/test/org/traccar/protocol/SuntechProtocolDecoderTest.java
index 2fabb541c..f58365e45 100644
--- a/test/org/traccar/protocol/SuntechProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/SuntechProtocolDecoderTest.java
@@ -1,9 +1,8 @@
package org.traccar.protocol;
-import org.traccar.helper.TestIdentityManager;
-import static org.traccar.helper.DecoderVerifier.verify;
import static org.junit.Assert.assertNull;
import org.junit.Test;
+import static org.traccar.helper.DecoderVerifier.verify;
public class SuntechProtocolDecoderTest extends ProtocolDecoderTest {
@@ -43,6 +42,9 @@ public class SuntechProtocolDecoderTest extends ProtocolDecoderTest {
verify(decoder.decode(null, null,
"ST300STT;205027329;03;374;20150108;17:54:42;177b38;-23.566052;-046.477588;000.000;000.00;0;0;0;12.11;000000;1;0312"));
+
+ verify(decoder.decode(null, null,
+ "ST910;Emergency;205283272;500;20150716;19:12:01;-23.659019;-046.695403;000.602;000.00;0;4.2;1;1;02;10820;2fdb090736;724;05;0;2311;255;0;100"));
}