diff options
-rw-r--r-- | src/org/traccar/protocol/LaipacProtocolDecoder.java | 16 | ||||
-rw-r--r-- | test/org/traccar/protocol/LaipacProtocolDecoderTest.java | 36 |
2 files changed, 43 insertions, 9 deletions
diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index ac0356991..a62a50e51 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,11 +34,11 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { super(serverManager); } - static private Pattern pattern = Pattern.compile( + private static final Pattern pattern = Pattern.compile( "\\$AVRMC," + - "(\\d+)," + // Identifier + "([^,]+)," + // Identifier "(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS) - "([AVavr])," + // Validity + "([AVRavr])," + // Validity "(\\d{2})(\\d{2}\\.\\d+)," + // Latitude (DDMM.MMMM) "([NS])," + "(\\d{3})(\\d{2}\\.\\d+)," + // Longitude (DDDMM.MMMM) @@ -58,10 +58,8 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; // Heartbeat - if (sentence.startsWith("$ECHK")) { - if (channel != null) { - channel.write(sentence + "\r\n"); - } + if (sentence.startsWith("$ECHK") && channel != null) { + channel.write(sentence + "\r\n"); return null; } @@ -93,7 +91,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { // Validity String status = parser.group(index++); - position.setValid(status.compareToIgnoreCase("A") == 0 ? true : false); + position.setValid(status.compareToIgnoreCase("A") == 0); // Latitude Double latitude = Double.valueOf(parser.group(index++)); diff --git a/test/org/traccar/protocol/LaipacProtocolDecoderTest.java b/test/org/traccar/protocol/LaipacProtocolDecoderTest.java index f6bdf5d9e..4facc64fa 100644 --- a/test/org/traccar/protocol/LaipacProtocolDecoderTest.java +++ b/test/org/traccar/protocol/LaipacProtocolDecoderTest.java @@ -16,6 +16,12 @@ public class LaipacProtocolDecoderTest { assertNull(decoder.decode(null, null, "$AVSYS,99999999,V1.50,SN0000103,32768*15")); assertNull(decoder.decode(null, null, "$ECHK,99999999,0*35")); + + assertNull(decoder.decode(null, null, "$AVSYS,MSG00002,14406,7046811160,64*1A")); + + assertNull(decoder.decode(null, null, "$EAVSYS,MSG00002,8931086013104404999,,Owner,0x52014406*76")); + + assertNull(decoder.decode(null, null, "$ECHK,MSG00002,0*5E")); verify(decoder.decode(null, null, "$AVRMC,99999999,164339,A,4351.0542,N,07923.5445,W,0.29,78.66,180703,0,3.727,17,1,0,0*37")); @@ -44,6 +50,36 @@ public class LaipacProtocolDecoderTest { verify(decoder.decode(null, null, "$AVRMC,99999999,164339,A,4351.0542,N,07923.5445,W,0.29,78.66,180703,4,3.727,17,1,0,0*33")); + verify(decoder.decode(null, null, + "$AVRMC,MSG00002,003016,v,0000.0000,N,00000.0000,E,0.00,0.00,200614,0,3804,167,1,0,0,0D7AB913,020408*23")); + + verify(decoder.decode(null, null, + "$AVRMC,MSG00002,003049,V,0000.0000,N,00000.0000,E,0.00,0.00,200614,H,3804,167,1,0,0,0D7AB913,020408*71")); + + verify(decoder.decode(null, null, + "$AVRMC,MSG00002,041942,V,0000.0000,N,00000.0000,E,0.00,0.00,200614,H,4115,167,1,0,0*0E")); + + verify(decoder.decode(null, null, + "$AVRMC,MSG00002,043703,V,0000.0000,N,00000.0000,E,0.00,0.00,200614,H,4115,167,1,0,0*07")); + + verify(decoder.decode(null, null, + "$AVRMC,MSG00002,043750,V,0000.0000,N,00000.0000,E,0.00,0.00,200614,H,4115,167,1,0,0*01")); + + verify(decoder.decode(null, null, + "$AVRMC,MSG00002,124022,V,0000.0000,N,00000.0000,E,0.00,0.00,240614,3,4076,167,1,0,0,0D7AB913,020408*0D")); + + verify(decoder.decode(null, null, + "$AVRMC,MSG00002,124058,A,5053.0447,N,00557.8549,E,0.45,65.06,240614,0,4037,167,1,0,0,0D7AB913,020408*26")); + + verify(decoder.decode(null, null, + "$AVRMC,MSG00002,124144,A,5053.0450,N,00557.8544,E,0.00,65.06,240614,3,4076,167,1,0,0,0D7AB913,020408*26")); + + verify(decoder.decode(null, null, + "$AVRMC,MSG00002,125142,R,5053.0442,N,00557.8694,E,1.21,40.90,240614,0,4037,167,1,0,0,0D7AB913,020408*33")); + + verify(decoder.decode(null, null, + "$AVRMC,MSG00002,125517,R,5053.0442,N,00557.8694,E,0.00,0.00,240614,H,4076,167,1,0,0,0D7AB913,020408*75")); + } } |