From 0064dec35205fba7b1c8e6c1c0553407688055a8 Mon Sep 17 00:00:00 2001 From: Edward Valley Date: Wed, 10 Jul 2019 18:11:13 -0400 Subject: Changes after fourth review --- .../traccar/protocol/LaipacProtocolDecoder.java | 31 +++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index 381f497e4..3eecf58a3 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -167,8 +167,13 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { } - private Object handleEchk( - String sentence, Parser parser, Channel channel, SocketAddress remoteAddress) { + private Object decodeEchk( + String sentence, Channel channel, SocketAddress remoteAddress) { + + Parser parser = new Parser(PATTERN_ECHK, sentence); + if (!parser.matches()) { + return null; + } if (channel != null) { channel.writeAndFlush(new NetworkMessage(sentence + "\r\n", remoteAddress)); @@ -177,8 +182,13 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { return null; } - protected Object handleAvrmc( - String sentence, Parser parser, Channel channel, SocketAddress remoteAddress) { + protected Object decodeAvrmc( + String sentence, Channel channel, SocketAddress remoteAddress) { + + Parser parser = new Parser(PATTERN_AVRMC, sentence); + if (!parser.matches()) { + return null; + } DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); @@ -245,15 +255,10 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; if (sentence.startsWith("$ECHK")) { - Parser parser = new Parser(PATTERN_ECHK, sentence); - if (parser.matches()) { - return handleEchk(sentence, parser, channel, remoteAddress); - } - } else if (sentence.startsWith("$AVRMC")) { - Parser parser = new Parser(PATTERN_AVRMC, sentence); - if (parser.matches()) { - return handleAvrmc(sentence, parser, channel, remoteAddress); - } + return decodeEchk(sentence, channel, remoteAddress); + } + if (sentence.startsWith("$AVRMC")) { + return decodeAvrmc(sentence, channel, remoteAddress); } return null; -- cgit v1.2.3