From 2bbdd5604648cb699ef5c713f778b9baf1b0ea2a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 12 Jun 2019 20:46:31 -0700 Subject: Fix and extend decoder --- .../java/org/traccar/protocol/PluginProtocolDecoder.java | 13 ++++++++++--- .../org/traccar/protocol/PluginProtocolDecoderTest.java | 3 +++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/traccar/protocol/PluginProtocolDecoder.java b/src/main/java/org/traccar/protocol/PluginProtocolDecoder.java index d2bb93962..3f87a774b 100644 --- a/src/main/java/org/traccar/protocol/PluginProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PluginProtocolDecoder.java @@ -34,7 +34,7 @@ public class PluginProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern PATTERN = new PatternBuilder() - .any() + .expression("[^0-9]*") .number("(d+),") // device id .number("(dddd)(dd)(dd)") // date (yyyymmdd) .number("(dd)(dd)(dd),") // time (hhmmss) @@ -44,9 +44,16 @@ public class PluginProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // course .number("(-?d+),") // altitude .number("(-?d+),") // satellites - .number("(d+),") // event + .number("d+,") // type .number("(d+),") // odometer .number("(d+),") // status + .expression("[^,]*,") + .expression("[^,]*,") + .text("0") + .groupBegin() + .text(",+,") + .number("(d+),") // event + .groupEnd("?") .any() .compile(); @@ -76,9 +83,9 @@ public class PluginProtocolDecoder extends BaseProtocolDecoder { position.setAltitude(parser.nextInt()); position.set(Position.KEY_SATELLITES, parser.nextInt()); - position.set(Position.KEY_EVENT, parser.nextInt()); position.set(Position.KEY_ODOMETER, parser.nextInt()); position.set(Position.KEY_STATUS, parser.nextInt()); + position.set(Position.KEY_EVENT, parser.nextInt()); return position; } diff --git a/src/test/java/org/traccar/protocol/PluginProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/PluginProtocolDecoderTest.java index a7cf95618..df102a066 100644 --- a/src/test/java/org/traccar/protocol/PluginProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/PluginProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class PluginProtocolDecoderTest extends ProtocolTest { PluginProtocolDecoder decoder = new PluginProtocolDecoder(null); + verifyPosition(decoder, text( + "$$ALARM801739,20190612121950,28.254067,-25.860494,0,0,0,-1,2,2,12595331,0,0,0,+,22,0,0,0,0,0,,0,0")); + verifyPosition(decoder, text( "$$STATUS801739,20190528143943,28.254086,-25.860665,0,0,0,-1,2,78,11395,0,0,0")); -- cgit v1.2.3