diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-04-07 23:03:46 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-04-07 23:37:32 +1200 |
commit | 3b7148075815aa7f6cd650013949934a50a573f7 (patch) | |
tree | 0c5bfe25175f7d0d0c787a43ab9a802361588f3b | |
parent | 1a0ee4171d4f3dbddcbffc65f254fae2bd4632e0 (diff) | |
download | traccar-server-3b7148075815aa7f6cd650013949934a50a573f7.tar.gz traccar-server-3b7148075815aa7f6cd650013949934a50a573f7.tar.bz2 traccar-server-3b7148075815aa7f6cd650013949934a50a573f7.zip |
Optimize minifinder decoder class
-rw-r--r-- | src/org/traccar/protocol/MiniFinderProtocolDecoder.java | 24 | ||||
-rw-r--r-- | test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java | 3 |
2 files changed, 13 insertions, 14 deletions
diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java index db01eaa9f..c7b0aecb2 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java @@ -142,18 +142,12 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; if (sentence.startsWith("!1,")) { - getDeviceSession(channel, remoteAddress, sentence.substring(3, sentence.length())); - return null; } DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); - if (deviceSession == null) { - return null; - } - - if (!sentence.matches("![A-D],.*")) { + if (deviceSession == null || !sentence.matches("![A-D],.*")) { return null; } @@ -161,10 +155,11 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { position.setProtocol(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - String recordType = sentence.substring(1, 2); - position.set(Position.KEY_TYPE, recordType); + String type = sentence.substring(1, 2); + position.set(Position.KEY_TYPE, type); + + if (type.equals("B") || type.equals("D")) { - if (recordType.matches("[BD]")) { Parser parser = new Parser(PATTERN_BD, sentence); if (!parser.matches()) { return null; @@ -175,9 +170,9 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { decodeGPSPrecision(position, parser); return position; - } - if (recordType.matches("C")) { + } else if (type.equals("C")) { + Parser parser = new Parser(PATTERN_C, sentence); if (!parser.matches()) { return null; @@ -187,9 +182,9 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { decodeState(position, parser); return position; - } - if (recordType.matches("A")) { + } else if (type.equals("A")) { + Parser parser = new Parser(PATTERN_A, sentence); if (!parser.matches()) { return null; @@ -198,6 +193,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder { decodeFix(position, parser); return position; + } return null; diff --git a/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java b/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java index 57201670f..4667ab871 100644 --- a/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MiniFinderProtocolDecoderTest.java @@ -20,6 +20,9 @@ public class MiniFinderProtocolDecoderTest extends ProtocolTest { "!1,860719027585011")); verifyPosition(decoder, text( + "!D,07/04/17,05:42:26,-37.588970,145.121231,0,0,0c0001,185.2,92,7,14,1.2")); + + verifyPosition(decoder, text( "!D,28/11/16,00:04:09,42.926067,-85.747589,124,236,140001,179.8,60,11,16,0")); verifyPosition(decoder, text( |