diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-03-17 16:59:51 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-03-17 16:59:51 +1300 |
commit | 8432b3660b7cc40c8734cc00817f176589d9d18e (patch) | |
tree | c3cba32d001839577a505b96b199b1667c3cedee | |
parent | 5adbbcff629056c0d811c9fd22e6a6af82c65ba9 (diff) | |
download | traccar-server-8432b3660b7cc40c8734cc00817f176589d9d18e.tar.gz traccar-server-8432b3660b7cc40c8734cc00817f176589d9d18e.tar.bz2 traccar-server-8432b3660b7cc40c8734cc00817f176589d9d18e.zip |
Extend Meitrack decoder
-rw-r--r-- | src/org/traccar/protocol/MeitrackProtocolDecoder.java | 28 | ||||
-rw-r--r-- | test/org/traccar/protocol/MeitrackProtocolDecoderTest.java | 3 |
2 files changed, 28 insertions, 3 deletions
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 2d8fa9511..cdeef155b 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -69,7 +69,11 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { "(\\p{XDigit}+)?\\|" + // ADC3 "(\\p{XDigit}+)\\|" + // Battery "(\\p{XDigit}+)," + // Power - ".*(\r\n)?"); + "(?:([^,]+)?," + // Event Specific + "[^,]*," + // Reserved + "\\d*," + // Protocol + "(\\p{XDigit}{4})?)?" + // Fuel + ".*\\*\\p{XDigit}{2}(?:\r\n)?"); private Position decodeRegularMessage(Channel channel, ChannelBuffer buf) { @@ -96,7 +100,8 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { } // Event - extendedInfo.set("event", parser.group(index++)); + int event = Integer.valueOf(parser.group(index++)); + extendedInfo.set("event", event); // Coordinates position.setLatitude(Double.valueOf(parser.group(index++))); @@ -155,7 +160,24 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { } extendedInfo.set("battery", Integer.parseInt(parser.group(index++), 16)); extendedInfo.set("power", Integer.parseInt(parser.group(index++), 16)); - + + // Event specific + String data = parser.group(index++); + if (data != null && !data.isEmpty()) { + switch (event) { + case 37: + extendedInfo.set("rfid", data); + break; + } + } + + // Fuel + String fuel = parser.group(index++); + if (fuel != null) { + extendedInfo.set("fuel", + Integer.parseInt(fuel.substring(0, 2), 16) + Integer.parseInt(fuel.substring(2), 16) * 0.01); + } + // Extended info position.setExtendedInfo(extendedInfo.toString()); diff --git a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java index 7d0dc6bc0..f031a5f15 100644 --- a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java @@ -16,6 +16,9 @@ public class MeitrackProtocolDecoderTest { MeitrackProtocolDecoder decoder = new MeitrackProtocolDecoder(new TestDataManager(), null, null); verify(decoder.decode(null, null, ChannelBuffers.copiedBuffer( + "$$I152,013949004569813,AAA,37,54.739468,25.273648,150208173414,A,5,24,0,73,1.5,165,74,3381,246|1|0065|118A,0000,0003|0003|0000|08D4|0002,006380DF,,1,0008*7C", Charset.defaultCharset()))); + + verify(decoder.decode(null, null, ChannelBuffers.copiedBuffer( "$$E141,863071013799553,AAA,35,-1.264521,36.801128,150307132846,A,11,20,0.2,0,5,1767,84045888,36496633,639|02|100E|844,1234,0018|||025D|00CB,*17", Charset.defaultCharset()))); verify(decoder.decode(null, null, ChannelBuffers.copiedBuffer( |