diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java | 30 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/Tk103ProtocolDecoderTest.java | 4 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java index 325d2ebeb..1a45fbf75 100644 --- a/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -131,6 +131,14 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private static final Pattern PATTERN_VIN = new PatternBuilder() + .text("(") + .number("(d+)") // device id + .expression("BV00") // command + .expression("(.{17})") // vin + .text(")") + .compile(); + private String decodeAlarm(int value) { switch (value) { case 1: @@ -370,7 +378,27 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_RESULT, parser.next()); return position; + } + + private Position decodeVin(Channel channel, SocketAddress remoteAddress, String sentence) { + Parser parser = new Parser(PATTERN_VIN, sentence); + if (!parser.matches()) { + return null; + } + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, null); + + position.set(Position.KEY_VIN, parser.next()); + + return position; } @Override @@ -398,6 +426,8 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { return decodeCommandResult(channel, remoteAddress, sentence); } else if (sentence.contains("DW5")) { return decodeLbsWifi(channel, remoteAddress, sentence); + } else if (sentence.contains("BV00")) { + return decodeVin(channel, remoteAddress, sentence); } Parser parser = new Parser(PATTERN, sentence); diff --git a/src/test/java/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Tk103ProtocolDecoderTest.java index 48a72447c..422f99a73 100644 --- a/src/test/java/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -12,6 +12,10 @@ public class Tk103ProtocolDecoderTest extends ProtocolTest { Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(null); verifyAttribute(decoder, text( + "(027023361470BV005J6RW2H53HL066029)"), + Position.KEY_VIN, "5J6RW2H53HL066029"); + + verifyAttribute(decoder, text( "(044027395704BQ81,ALARM,1,164,151101A2238.5237N11349.4571E0.7031241010.0000,00000000)"), Position.KEY_ALARM, Position.ALARM_OVERSPEED); |