From 8abf4f011eef72e06dd24720e00ce27350b0b047 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 13 Nov 2018 08:30:09 +1300 Subject: Fix issue with XRB 28 decoder --- src/org/traccar/protocol/Xrb28ProtocolDecoder.java | 13 +++++++------ test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java | 12 +++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/org/traccar/protocol/Xrb28ProtocolDecoder.java b/src/org/traccar/protocol/Xrb28ProtocolDecoder.java index c3af2c4f3..7c382900a 100644 --- a/src/org/traccar/protocol/Xrb28ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xrb28ProtocolDecoder.java @@ -42,7 +42,8 @@ public class Xrb28ProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern PATTERN = new PatternBuilder() - .text("*HBCR,") + .text("*") + .expression("....,") .expression("..,") // vendor .number("d{15},") // imei .expression("..,") // type @@ -67,25 +68,25 @@ public class Xrb28ProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, sentence.substring(10, 26)); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, sentence.substring(8, 24)); if (deviceSession == null) { return null; } - String type = sentence.substring(27, 29); + String type = sentence.substring(25, 27); if (channel != null) { if (type.matches("L0|L1|W0|E1")) { channel.write(new NetworkMessage( - sentence.substring(0, 29) + "#\n", remoteAddress)); + sentence.substring(0, 27) + "#\n", remoteAddress)); } else if (type.equals("R0") && pendingCommand != null) { String command = pendingCommand.equals(Command.TYPE_ALARM_ARM) ? "L1," : "L0,"; channel.write(new NetworkMessage( - sentence.substring(0, 27) + command + sentence.substring(32) + "\n", remoteAddress)); + sentence.substring(0, 25) + command + sentence.substring(30) + "\n", remoteAddress)); pendingCommand = null; } } - Parser parser = new Parser(PATTERN, sentence.substring(2)); + Parser parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; } diff --git a/test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java b/test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java index 441d7b811..eaa28906e 100644 --- a/test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Xrb28ProtocolDecoderTest.java @@ -11,13 +11,19 @@ public class Xrb28ProtocolDecoderTest extends ProtocolTest { Xrb28ProtocolDecoder decoder = new Xrb28ProtocolDecoder(null); verifyNull(decoder, text( - "\u00ff\u00ff*HBCR,OM,123456789123456,Q0,412,80#")); + "*SCOR,OM,863158022988725,H0,0,412,28,80,0#")); verifyNull(decoder, text( - "\u00ff\u00ff*HBCR,OM,123456789123456,R0,0,55,1234,1497689816#")); + "*HBCR,OM,123456789123456,Q0,412,80#")); + + verifyNull(decoder, text( + "*HBCR,OM,123456789123456,R0,0,55,1234,1497689816#")); + + verifyPosition(decoder, text( + "*HBCR,OM,123456789123456,D0,0,124458.00,A,2237.7514,N,11408.6214,E,6,0.21,151216,10,M,A#")); verifyPosition(decoder, text( - "\u00ff\u00ff*HBCR,OM,123456789123456,D0,0,124458.00,A,2237.7514,N,11408.6214,E,6,0.21,151216,10,M,A#")); + "*SCOR,OM,863158022988725,D0,0,124458.00,A,2237.7514,N,11408.6214,E,6,0.21,151216,10,M,A#")); } -- cgit v1.2.3