diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-05-13 15:25:28 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-05-13 15:25:28 +1200 |
commit | f5f8e079b27d44012dc74d586a1f4ddb9b06db33 (patch) | |
tree | 5b83c95f2f3fbcee2488e41303f6a586d5ba731f | |
parent | 9f86b2b1c39fb98cd7ac1f00d0a535b128f158e5 (diff) | |
download | traccar-server-f5f8e079b27d44012dc74d586a1f4ddb9b06db33.tar.gz traccar-server-f5f8e079b27d44012dc74d586a1f4ddb9b06db33.tar.bz2 traccar-server-f5f8e079b27d44012dc74d586a1f4ddb9b06db33.zip |
Implement new Xirgo protocol format
-rw-r--r-- | src/org/traccar/protocol/XirgoProtocolDecoder.java | 61 | ||||
-rw-r--r-- | test/org/traccar/protocol/XirgoProtocolDecoderTest.java | 6 |
2 files changed, 63 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java index 38a14ffcf..debb0657c 100644 --- a/src/org/traccar/protocol/XirgoProtocolDecoder.java +++ b/src/org/traccar/protocol/XirgoProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 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. @@ -25,6 +25,7 @@ import org.traccar.model.Event; import org.traccar.model.Position; import java.net.SocketAddress; +import java.util.regex.Matcher; import java.util.regex.Pattern; public class XirgoProtocolDecoder extends BaseProtocolDecoder { @@ -33,7 +34,11 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private static final Pattern PATTERN = new PatternBuilder() + private boolean newFormat; + + private static final Pattern FIRMWARE = Pattern.compile("\\w{4}-([0-9A-F]{7})"); + + private static final Pattern PATTERN_OLD = new PatternBuilder() .text("$$") .number("(d+),") // imei .number("(d+),") // event @@ -53,11 +58,51 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private static final Pattern PATTERN_NEW = new PatternBuilder() + .text("$$") + .number("(d+),") // imei + .number("(d+),") // event + .number("(dddd)/(dd)/(dd),") // date + .number("(dd):(dd):(dd),") // time + .number("(-?d+.?d*),") // latitude + .number("(-?d+.?d*),") // longitude + .number("(-?d+.?d*),") // altitude + .number("(d+.?d*),") // speed + .number("d+.?d*,") // acceleration + .number("d+.?d*,") // deceleration + .number("d+,") + .number("(d+.?d*),") // course + .number("(d+),") // satellites + .number("(d+.?d*),") // hdop + .number("(d+.?d*),") // odometer + .number("d+.?d*,") // fuel consumption + .number("(d+.d+),") // battery + .number("(d+),") // gsm + .number("(d+),") // gps + .any() + .compile(); + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - Parser parser = new Parser(PATTERN, (String) msg); + String sentence = (String) msg; + + Matcher matcher = FIRMWARE.matcher(sentence); + if (matcher.find()) { + String type = matcher.group(1); + if (type.equals("1137CD1") || type.equals("1137CC1") || type.equals("1137CA3")) { + newFormat = true; + } + } + + Parser parser; + if (newFormat) { + parser = new Parser(PATTERN_NEW, sentence); + } else { + parser = new Parser(PATTERN_OLD, sentence); + } + if (!parser.matches()) { return null; } @@ -85,9 +130,17 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_SATELLITES, parser.next()); position.set(Event.KEY_HDOP, parser.next()); + + if (newFormat) { + position.set(Event.KEY_ODOMETER, parser.next()); + } + position.set(Event.KEY_BATTERY, parser.next()); position.set(Event.KEY_GSM, parser.next()); - position.set(Event.KEY_ODOMETER, parser.next()); + + if (!newFormat) { + position.set(Event.KEY_ODOMETER, parser.next()); + } position.setValid(parser.nextInt() == 1); diff --git a/test/org/traccar/protocol/XirgoProtocolDecoderTest.java b/test/org/traccar/protocol/XirgoProtocolDecoderTest.java index 13cca0a82..0d7087a93 100644 --- a/test/org/traccar/protocol/XirgoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/XirgoProtocolDecoderTest.java @@ -23,6 +23,12 @@ public class XirgoProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "$$357207059646786,4003,2015/05/19,15:55:27,-20.21421,-70.14920,33.6,0.4,0.0,11,0.8,12.9,31,297,1,0,0.0,0.0,0,1,1,1##")); + verifyPosition(decoder, text( + "$$355922060162167,6015,2016/04/21,17:26:52,39.83267,-76.66139,230,0.0,0.0,0.0,779,0,8,1.2,0,0.0,13.0,19,1,1C4BJWDG4GL191009,X0z1-1137CD1,0402,3GATT,0,83.9,-70,-715,738##")); + + verifyPosition(decoder, text( + "$$355922060162167,4002,2016/04/21,17:04:50,39.83253,-76.66102,232,0.0,0.0,0.0,0,0,12,1.2,0,0.0,9.2,15,1,0,0.0,35,-8,1059##")); + } } |