aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-10-23 22:34:53 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-10-23 22:34:53 +1300
commit1928609c0f6e6cd78a4788a7d3fe2f37f32ead33 (patch)
treeaa2847d3cbb9e60705be4d5c682c38b5fb9b8457
parent30ebfa7d6b683fcec586233fa5c68a966c2841ad (diff)
downloadtrackermap-server-1928609c0f6e6cd78a4788a7d3fe2f37f32ead33.tar.gz
trackermap-server-1928609c0f6e6cd78a4788a7d3fe2f37f32ead33.tar.bz2
trackermap-server-1928609c0f6e6cd78a4788a7d3fe2f37f32ead33.zip
Improve H02 decoders
-rw-r--r--src/org/traccar/protocol/H02FrameDecoder.java6
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java10
-rw-r--r--test/org/traccar/protocol/H02ProtocolDecoderTest.java9
3 files changed, 20 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java
index ef28e9986..82e3201f7 100644
--- a/src/org/traccar/protocol/H02FrameDecoder.java
+++ b/src/org/traccar/protocol/H02FrameDecoder.java
@@ -33,6 +33,12 @@ public class H02FrameDecoder extends FrameDecoder {
ChannelBuffer buf) throws Exception {
String marker = buf.toString(buf.readerIndex(), 1, Charset.defaultCharset());
+
+ while ((marker.equals(" ") || marker.equals("\r") || marker.equals("\n")) && buf.readableBytes() > 0) {
+ buf.skipBytes(1);
+ marker = buf.toString(buf.readerIndex(), 1, Charset.defaultCharset());
+ }
+
if (marker.equals("*")) {
// Return text message
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index 463c0af27..cc59eea9d 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -106,19 +106,19 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- static private Pattern pattern = Pattern.compile(
+ private static final Pattern pattern = Pattern.compile(
"\\*..," + // Manufacturer
"(\\d+)," + // IMEI
"V\\d," + // Version?
".*" +
"(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS)
"([AV])," + // Validity
- "(\\d+)(\\d{2}.\\d{4})," + // Latitude (DDMM.MMMM)
+ "(\\d+)(\\d{2}.\\d+)," + // Latitude (DDMM.MMMM)
"([NS])," +
- "(\\d+)(\\d{2}.\\d{4})," + // Longitude (DDMM.MMMM)
+ "(\\d+)(\\d{2}.\\d+)," + // Longitude (DDMM.MMMM)
"([EW])," +
- "(\\d+.\\d+)," + // Speed
- "(\\d+.\\d+)?," + // Course
+ "(\\d+.?\\d*)," + // Speed
+ "(\\d+.?\\d*)?," + // Course
"(\\d{2})(\\d{2})(\\d{2})," + // Date (DDMMYY)
"(\\p{XDigit}{8})" + // Status
".*");
diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
index b5d71be18..3b4233752 100644
--- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
@@ -63,6 +63,15 @@ public class H02ProtocolDecoderTest {
assertNotNull(decoder.decode(null, null, ChannelBuffers.copiedBuffer(
"*TH,2020916012,V4,S1,OK,pass_word,130305,050316,A,2212.8745,N,11346.6574,E,14.28,028,220902,FFFFFBFD#", Charset.defaultCharset())));
+ assertNotNull(decoder.decode(null, null, ChannelBuffers.copiedBuffer(
+ "*HQ,353588020068342,V1,062840,A,5241.1249,N,954.9490,E,0.00,0.00,231013,ffffffff,000106,000002,000203,004c87,24#", Charset.defaultCharset())));
+
+ assertNotNull(decoder.decode(null, null, ChannelBuffers.copiedBuffer(
+ "*HQ,353505220903211,V1,075228,A,5227.5039,N,01032.8443,E,0.00,0,231013,FFFBFFFF,106,14, 201,2173#", Charset.defaultCharset())));
+
+ assertNotNull(decoder.decode(null, null, ChannelBuffers.copiedBuffer(
+ "*HQ,353505220903211,V1,140817,A,5239.3538,N,01003.5292,E,21.03,312,221013,FFFBFFFF,106,14, 203,1cd#", Charset.defaultCharset())));
+
int[] buf1 = {0x24,0x27,0x05,0x17,0x11,0x09,0x21,0x33,0x39,0x14,0x06,0x13,0x50,0x02,0x58,0x49,0x00,0x01,0x43,0x37,0x82,0x2e,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0x00,0x00};
assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertArray(buf1))));