From 92fa5f43ccf7471c3afa7c18bbef868ba76afd35 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 18 Oct 2018 14:30:42 +1300 Subject: More flexible match for GPS103 --- src/org/traccar/protocol/Gps103ProtocolDecoder.java | 6 +++--- test/org/traccar/protocol/Gps103ProtocolDecoderTest.java | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 36060f841..4ef14b29b 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -276,11 +276,11 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; - if (sentence.contains("##")) { + if (sentence.contains("imei:") && sentence.length() <= 25) { if (channel != null) { channel.writeAndFlush(new NetworkMessage("LOAD", remoteAddress)); - Matcher matcher = Pattern.compile("##,imei:(\\d+),A").matcher(sentence); - if (matcher.matches()) { + Matcher matcher = Pattern.compile("imei:(\\d+),").matcher(sentence); + if (matcher.find()) { getDeviceSession(channel, remoteAddress, matcher.group(1)); } } diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 6e1612655..26fada1d9 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class Gps103ProtocolDecoderTest extends ProtocolTest { Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(null); + verifyNull(decoder, text( + "imei:123451234512345,L,")); + verifyAttributes(decoder, text( "imei:868683027758113,OBD,180905200218,,,,0,0,0.39%,70,9.41%,494,0.00,P0137,P0430,,;")); -- cgit v1.2.3