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 /src | |
parent | 1a86616ca2032fa0c3fee7446a6dc545f4f77451 (diff) | |
download | traccar-server-d6e585d7a989799c31e09578ed20666c9a4054cf.tar.gz traccar-server-d6e585d7a989799c31e09578ed20666c9a4054cf.tar.bz2 traccar-server-d6e585d7a989799c31e09578ed20666c9a4054cf.zip |
Refactor STL060 protocol decoder
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/protocol/Stl060ProtocolDecoder.java | 67 |
1 files changed, 35 insertions, 32 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( |