diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-05 15:16:24 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-05 15:16:24 +1300 |
commit | d6e585d7a989799c31e09578ed20666c9a4054cf (patch) | |
tree | 40acf21487e40197b3051d131c1468785d2fc4c2 | |
parent | 1a86616ca2032fa0c3fee7446a6dc545f4f77451 (diff) | |
download | traccar-server-d6e585d7a989799c31e09578ed20666c9a4054cf.tar.gz traccar-server-d6e585d7a989799c31e09578ed20666c9a4054cf.tar.bz2 traccar-server-d6e585d7a989799c31e09578ed20666c9a4054cf.zip |
Refactor STL060 protocol decoder
-rw-r--r-- | src/org/traccar/protocol/Stl060ProtocolDecoder.java | 67 | ||||
-rw-r--r-- | test/org/traccar/protocol/Stl060ProtocolDecoderTest.java | 5 |
2 files changed, 38 insertions, 34 deletions
diff --git a/src/org/traccar/protocol/Stl060ProtocolDecoder.java b/src/org/traccar/protocol/Stl060ProtocolDecoder.java index b5b972982..b583aee66 100644 --- a/src/org/traccar/protocol/Stl060ProtocolDecoder.java +++ b/src/org/traccar/protocol/Stl060ProtocolDecoder.java @@ -21,6 +21,7 @@ import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; +import org.traccar.helper.PatternBuilder; import org.traccar.model.Event; import org.traccar.model.Position; @@ -30,38 +31,40 @@ public class Stl060ProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private static final Pattern PATTERN = Pattern.compile( - ".*\\$1," + - "(\\d+)," + // IMEI - "D001," + // Type - "[^,]*," + // Vehicle - "(\\d{2})/(\\d{2})/(\\d{2})," + // Date - "(\\d{2}):(\\d{2}):(\\d{2})," + // Time - "(\\d{2})(\\d{2})\\.?(\\d+)([NS])," + // Latitude - "(\\d{3})(\\d{2})\\.?(\\d+)([EW])," + // Longitude - "(\\d+\\.?\\d*)," + // Speed - "(\\d+\\.?\\d*)," + // Course - - "(?:(\\d+)," + // Odometer - "(\\d+)," + // Ignition - "(\\d+)," + // DI1 - "(\\d+)," + // DI2 - "(\\d+),|" + // Fuel - - "([01])," + // Charging - "([01])," + // Ignition - "0,0," + // Reserved - "(\\d+)," + // DI - "([^,]+)," + // RFID - "(\\d+)," + // Odometer - "(\\d+)," + // Temperature - "(\\d+)," + // Fuel - "([01])," + // Accelerometer - "([01])," + // DO1 - "([01]),)" + // DO2 - - "([AV])" + // Validity - ".*"); + private static final Pattern PATTERN = new PatternBuilder() + .any() + .text("$1,") + .number("(d+),") // imei + .text("D001,") // type + .expression("[^,]*,") // vehicle + .number("(dd)/(dd)/(dd),") // date + .number("(dd):(dd):(dd),") // time + .number("(dd)(dd).?(d+)([NS]),") // latitude + .number("(ddd)(dd).?(d+)([EW]),") // longitude + .number("(d+.?d*),") // speed + .number("(d+.?d*),") // course + .groupBegin() + .number("(d+),") // odometer + .number("(d+),") // Ignition + .number("(d+),") // di1 + .number("(d+),") // di2 + .number("(d+),") // fuel + .or() + .expression("([01]),") // charging + .expression("([01]),") // ignition + .expression("0,0,") // reserved + .number("(d+),") // di + .expression("([^,]+),") // rfid + .number("(d+),") // odometer + .number("(d+),") // temperature + .number("(d+),") // fuel + .expression("([01]),") // accelerometer + .expression("([01]),") // do1 + .expression("([01]),") // do2 + .groupEnd() + .expression("([AV])") // validity + .any() + .compile(); @Override protected Object decode( diff --git a/test/org/traccar/protocol/Stl060ProtocolDecoderTest.java b/test/org/traccar/protocol/Stl060ProtocolDecoderTest.java index f167f983a..3af99374d 100644 --- a/test/org/traccar/protocol/Stl060ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Stl060ProtocolDecoderTest.java @@ -11,8 +11,9 @@ public class Stl060ProtocolDecoderTest extends ProtocolDecoderTest { Stl060ProtocolDecoder decoder = new Stl060ProtocolDecoder(new Stl060Protocol()); verifyPosition(decoder, text( - "$1,357804048043099,D001,AP29AW0963,23/02/14,14:06:54,17248488N,078342226E,0.08,193.12,1,1,1,1,1,A")); - + "$1,357804048043099,D001,AP29AW0963,23/02/14,14:06:54,17248488N,078342226E,0.08,193.12,1,1,1,1,1,A"), + position("2014-02-23 14:06:54.000", true, 17.41415, 78.57038)); + verifyPosition(decoder, text( "$1,357804048043099,D001,AP29AW0963,12/05/14,07:39:57,1724.8564N,07834.2199E,0.00,302.84,1,1,1,1,1,A")); |