aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolDecoder.java34
-rw-r--r--test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java3
2 files changed, 24 insertions, 13 deletions
diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
index 7181456fe..9a5cfb134 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.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.
@@ -37,11 +37,13 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
super(serverManager);
}
+ //"134743.003,A,0648.9866,S,10707.5795,E,000.0,000.0,260313"
+
/**
* Regular expressions pattern
*/
static private Pattern pattern = Pattern.compile(
- "(\\d{2})(\\d{2})(\\d{2})\\.(\\d{3})," + // Time (HHMMSS.SSS)
+ "(\\d{2})(\\d{2})(\\d{2})\\.(\\d+)," + // Time (HHMMSS.SSS)
"([AV])," + // Validity
"(\\d{2})(\\d{2}\\.\\d+)," + // Latitude (DDMM.MMMM)
"([NS])," +
@@ -50,8 +52,8 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
"(\\d+.\\d+)," + // Speed
"(\\d+\\.?\\d*)?," + // Course
"(\\d{2})(\\d{2})(\\d{2})" + // Date (DDMMYY)
- "[^\\|]*\\|(\\d+\\.\\d)\\|" + // Dilution of precision
- "(\\d+\\.?\\d*)\\|" + // Altitude
+ "(?:[^\\|]*\\|(\\d+\\.\\d+)\\|" + // Dilution of precision
+ "(\\d+\\.?\\d*)\\|)?" + // Altitude
"([0-9a-fA-F]+)?" + // State
"(?:\\|([0-9a-fA-F]+),([0-9a-fA-F]+))?" + // ADC
"(?:\\|([0-9a-fA-F]+))?" + // Cell
@@ -82,14 +84,11 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
return id;
}
- /**
- * Decode message
- */
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, Object msg)
throws Exception {
-
+
ChannelBuffer buf = (ChannelBuffer) msg;
int command = buf.getUnsignedShort(7);
@@ -113,8 +112,21 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- // Data offset
+ // Payload offset
int offset = 7 + 2;
+
+ // Create new position
+ Position position = new Position();
+ StringBuilder extendedInfo = new StringBuilder("<protocol>meiligao</protocol>");
+
+ // Alarm
+ if (command == 0x9999) {
+ extendedInfo.append("<alarm>");
+ extendedInfo.append(buf.getUnsignedByte(offset));
+ extendedInfo.append("</alarm>");
+ }
+
+ // Data offset
if (command == 0x9955) {
offset += 0;
} else if (command == 0x9016) {
@@ -125,10 +137,6 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- // Create new position
- Position position = new Position();
- StringBuilder extendedInfo = new StringBuilder("<protocol>meiligao</protocol>");
-
// Get device by id
String id = getId(buf);
try {
diff --git a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java
index 6c0a520f5..66ce51b73 100644
--- a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java
@@ -39,6 +39,9 @@ public class MeiligaoProtocolDecoderTest {
byte[] buf8 = {0x59,0x77,0x20,0x37,0x44,0x05,(byte)0x84,(byte)0x99,0x55,0x30,0x32,0x30,0x31,0x31,0x37,0x2E,0x30,0x30,0x30,0x2C,0x41,0x2C,0x34,0x31,0x31,0x37,0x2E,0x39,0x32,0x31,0x32,0x2C,0x4E,0x2C,0x30,0x38,0x31,0x33,0x30,0x2E,0x32,0x30,0x39,0x36,0x2C,0x57,0x2C,0x30,0x2E,0x30,0x30,0x2C,0x33,0x30,0x33,0x2E,0x38,0x35,0x2C,0x32,0x36,0x30,0x32,0x31,0x33,0x7C,0x31,0x2E,0x36,0x7C,0x30,0x30,0x7C,0x30,0x30,0x30,0x30,0x7C,0x30,0x30,0x30,0x30,0x2C,0x30,0x30,0x30,0x30,0x71,(byte)0xCD,0x0D,0x0A};
decoder.decode(null, null, factory.getBuffer(buf8, 0, buf8.length));
+ byte[] buf9 = {0x35,0x11,0x11,0x11,0x11,0x11,0x11,(byte)0x99,0x55,0x31,0x33,0x34,0x37,0x34,0x33,0x2e,0x30,0x30,0x33,0x2c,0x41,0x2c,0x30,0x36,0x34,0x38,0x2e,0x39,0x38,0x36,0x36,0x2c,0x53,0x2c,0x31,0x30,0x37,0x30,0x37,0x2e,0x35,0x37,0x39,0x35,0x2c,0x45,0x2c,0x30,0x30,0x30,0x2e,0x30,0x2c,0x30,0x30,0x30,0x2e,0x30,0x2c,0x32,0x36,0x30,0x33,0x31,0x33,(byte)0xf3,0x15,0x0d,0x0a};
+ assertNotNull(decoder.decode(null, null, factory.getBuffer(buf9, 0, buf9.length)));
+
}
}