diff options
author | Kevin Goos <kevin.goos@infrabel.be> | 2018-03-16 12:13:02 +0100 |
---|---|---|
committer | Kevin Goos <kevin.goos@infrabel.be> | 2018-03-16 12:13:02 +0100 |
commit | 901c331745c8aed5593ca80f3faff5ee4d06d2a8 (patch) | |
tree | 644232982eb111a0a50dea802a57c30784eb7832 | |
parent | 9c13bf44cd83c3d2489b763a6c5af6d04d26ad48 (diff) | |
download | trackermap-server-901c331745c8aed5593ca80f3faff5ee4d06d2a8.tar.gz trackermap-server-901c331745c8aed5593ca80f3faff5ee4d06d2a8.tar.bz2 trackermap-server-901c331745c8aed5593ca80f3faff5ee4d06d2a8.zip |
Added null check
-rw-r--r-- | src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java | 3 | ||||
-rw-r--r-- | test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java | 6 |
2 files changed, 5 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java index 0d3995144..dc169c668 100644 --- a/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacSFKamelProtocolDecoder.java @@ -118,8 +118,9 @@ public class LaipacSFKamelProtocolDecoder extends BaseProtocolDecoder { checksum = parser.next(); } + String result = sentence.replaceAll("^\\$(.*)\\*[0-9a-fA-F]{2}$", "$1"); - if (Integer.parseInt(checksum, 16) != Checksum.xor(result)) + if (checksum == null || Integer.parseInt(checksum, 16) != Checksum.xor(result)) { return null; } diff --git a/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java b/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java index 05de5dcbe..69c4243ab 100644 --- a/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java +++ b/test/org/traccar/protocol/LaipacSFKamelProtocolDecoderTest.java @@ -2,6 +2,7 @@ package org.traccar.protocol; import org.junit.Test; import org.traccar.ProtocolTest; +import org.traccar.helper.Checksum; public class LaipacSFKamelProtocolDecoderTest extends ProtocolTest { @@ -11,7 +12,7 @@ public class LaipacSFKamelProtocolDecoderTest extends ProtocolTest { LaipacSFKamelProtocolDecoder decoder = new LaipacSFKamelProtocolDecoder(new LaipacSFKamelProtocol()); verifyPosition(decoder, text( - "$AVRMC,358174067149865,084514,r,5050.1314,N,00419.9719,E,0.68,306.39,120318,0,3882,84,1,0,0,3EE4A617,020610*4E")); + "$AVRMC,999999999999999,084514,r,5050.1314,N,00419.9719,E,0.68,306.39,120318,0,3882,84,1,0,0,3EE4A617,020610*4D")); verifyNull(decoder, text( "$AVSYS,99999999,V1.50,SN0000103,32768*15")); @@ -29,7 +30,6 @@ public class LaipacSFKamelProtocolDecoderTest extends ProtocolTest { "$ECHK,MSG00002,0*5E")); verifyPosition(decoder, text( - "$AVRMC,358174067149865,111602,r,5050.1262,N,00419.9660,E,0.00,0.00,120318,0,3843,95,1,0,0,3EE4A617,020610*44")); + "$AVRMC,999999999999999,111602,r,5050.1262,N,00419.9660,E,0.00,0.00,120318,0,3843,95,1,0,0,3EE4A617,020610*47")); } - } |