diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2013-03-01 21:02:27 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2013-03-01 21:02:27 +1300 |
commit | 352a94ba7c3c9162afb4175e6c49515188544797 (patch) | |
tree | f6dd6730a9e95e4bd9185da72423a37758766792 | |
parent | f78f17199b8f00ac92e1a96c6c8b6981876020a2 (diff) | |
download | trackermap-server-352a94ba7c3c9162afb4175e6c49515188544797.tar.gz trackermap-server-352a94ba7c3c9162afb4175e6c49515188544797.tar.bz2 trackermap-server-352a94ba7c3c9162afb4175e6c49515188544797.zip |
Improve GPS103 date decoding
-rw-r--r-- | src/org/traccar/protocol/Gps103ProtocolDecoder.java | 23 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gps103ProtocolDecoderTest.java | 9 |
2 files changed, 15 insertions, 17 deletions
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 0fa5bb4d2..2e3620179 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2013 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. @@ -26,14 +26,8 @@ import org.traccar.ServerManager; import org.traccar.helper.Log; import org.traccar.model.Position; -/** - * Gps 103 tracker protocol decoder - */ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { - /** - * Initialize - */ public Gps103ProtocolDecoder(ServerManager serverManager) { super(serverManager); } @@ -45,8 +39,8 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { "imei:" + "(\\d+)," + // IMEI "([^,]+)," + // Alarm - "(\\d{2})(\\d{2})(\\d{2})" + // Local Date - "(\\d{2})(\\d{2})," + // Local Time + "(\\d{2})/?(\\d{2})/?(\\d{2})\\s?" + // Local Date + "(\\d{2}):?(\\d{2})," + // Local Time "[^,]*," + "[FL]," + // F - full / L - low "(\\d{2})(\\d{2})(\\d{2})\\.(\\d{3})," + // Time UTC (HHMMSS.SSS) @@ -59,9 +53,6 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { "(\\d+\\.\\d+)?" + // Course ".*"); - /** - * Decode message - */ @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, Object msg) @@ -71,13 +62,17 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { // Send response #1 if (sentence.contains("##")) { - channel.write("LOAD"); + if (channel != null) { + channel.write("LOAD"); + } return null; } // Send response #2 if (sentence.length() == 15 && Character.isDigit(sentence.charAt(0))) { - channel.write("ON"); + if (channel != null) { + channel.write("ON"); + } return null; } diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 24289822a..2e3929b28 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -13,13 +13,16 @@ public class Gps103ProtocolDecoderTest { decoder.setDataManager(new TestDataManager()); // Log on request - //assertNull(decoder.decode(null, null, "##,imei:359586015829802,A")); + assertNull(decoder.decode(null, null, "##,imei:359586015829802,A")); // Heartbeat package - //assertNull(decoder.decode(null, null, "359586015829802")); + assertNull(decoder.decode(null, null, "359586015829802")); // No GPS signal - //assertNull(decoder.decode(null, null, "imei:359586015829802,tracker,000000000,13554900601,L,;")); + assertNull(decoder.decode(null, null, "imei:359586015829802,tracker,000000000,13554900601,L,;")); + + assertNotNull(decoder.decode(null, null, + "imei:359710040656622,tracker,13/02/27 23:40,,F,125952.000,A,3450.9430,S,13828.6753,E,0.00,0")); assertNotNull(decoder.decode(null, null, "imei:353451047570260,tracker,1302110948,,F,144807.000,A,0805.6615,S,07859.9763,W,0.00,,")); |