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 /src | |
parent | 9f86b2b1c39fb98cd7ac1f00d0a535b128f158e5 (diff) | |
download | traccar-server-f5f8e079b27d44012dc74d586a1f4ddb9b06db33.tar.gz traccar-server-f5f8e079b27d44012dc74d586a1f4ddb9b06db33.tar.bz2 traccar-server-f5f8e079b27d44012dc74d586a1f4ddb9b06db33.zip |
Implement new Xirgo protocol format
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/protocol/XirgoProtocolDecoder.java | 61 |
1 files changed, 57 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); |