diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-12 13:49:59 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-12 13:49:59 +1200 |
commit | 69a4af1c2b419fd7cc6356bcc2bf760969a73f95 (patch) | |
tree | 4192ef221be88b024d96422e274836f4c6b33922 /src/org/traccar/protocol/L100ProtocolDecoder.java | |
parent | 1dc1e06cfd4b7b23775984a254723b2d06b4f1dd (diff) | |
parent | 86ad45c63c9a9e9bee59a8cc621416e1396f9c89 (diff) | |
download | trackermap-server-69a4af1c2b419fd7cc6356bcc2bf760969a73f95.tar.gz trackermap-server-69a4af1c2b419fd7cc6356bcc2bf760969a73f95.tar.bz2 trackermap-server-69a4af1c2b419fd7cc6356bcc2bf760969a73f95.zip |
Merge branch 'master' into netty4
# Conflicts:
# src/org/traccar/protocol/AquilaProtocolDecoder.java
# src/org/traccar/protocol/L100FrameDecoder.java
Diffstat (limited to 'src/org/traccar/protocol/L100ProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/L100ProtocolDecoder.java | 109 |
1 files changed, 107 insertions, 2 deletions
diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java index ad93baf67..7c652c95a 100644 --- a/src/org/traccar/protocol/L100ProtocolDecoder.java +++ b/src/org/traccar/protocol/L100ProtocolDecoder.java @@ -18,6 +18,7 @@ package org.traccar.protocol; import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; @@ -66,23 +67,59 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder { .text("ATL") .compile(); + private static final Pattern PATTERN_OBD = new PatternBuilder() + .expression("[LH],") // archive + .text("ATL,") + .number("(d{15}),") // imei + .number("(d+),") // type + .number("(d+),") // index + .groupBegin() + .number("(dd)(dd)(dd),") // time (hhmmss) + .number("(dd)(dd)(dd),") // date (ddmmyy) + .expression("([AV]),") // validity + .number("(d+.d+);([NS]),") // latitude + .number("(d+.d+);([EW]),") // longitude + .number("(d+),") // speed + .number("(d+),") // course + .number("(d+.d+),") // odometer + .number("(d+.d+),") // battery + .number("(d+),") // rssi + .number("(d+),") // mcc + .number("(d+),") // mnc + .number("(d+),") // lac + .number("(x+),") // cid + .number("#(d)(d)(d)(d),") // status + .number("(d),") // overspeed + .text("ATL,") + .groupEnd("?") + .compile(); + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { String sentence = (String) msg; + if (sentence.startsWith("L") || sentence.startsWith("H")) { + return decodeObd(channel, remoteAddress, sentence); + } else { + return decodeNormal(channel, remoteAddress, sentence); + } + } + + private Object decodeNormal(Channel channel, SocketAddress remoteAddress, String sentence) { + Parser parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; } - Position position = new Position(getProtocolName()); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); if (deviceSession == null) { return null; } + + Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); DateBuilder dateBuilder = new DateBuilder() @@ -112,4 +149,72 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder { return position; } + private Object decodeObd(Channel channel, SocketAddress remoteAddress, String sentence) { + + Parser parser = new Parser(PATTERN_OBD, sentence); + if (!parser.matches()) { + return null; + } + + String imei = parser.next(); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); + if (deviceSession == null) { + return null; + } + + int type = parser.nextInt(); + int index = parser.nextInt(); + + if (type == 1) { + if (channel != null) { + String response = "@" + imei + ",00," + index + ","; + response += "*" + (char) Checksum.xor(response); + channel.write(response, remoteAddress); + } + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY)); + position.setValid(parser.next().equals("A")); + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM)); + position.setSpeed(parser.nextInt()); + position.setCourse(parser.nextInt()); + + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); + position.set(Position.KEY_BATTERY, parser.nextDouble()); + + int rssi = parser.nextInt(); + position.setNetwork(new Network(CellTower.from( + parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextHexInt(), rssi))); + + position.set(Position.KEY_IGNITION, parser.nextInt() == 1); + parser.next(); // reserved + + switch (parser.nextInt()) { + case 0: + position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); + break; + case 2: + position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); + break; + case 1: + position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); + break; + default: + break; + } + + position.set(Position.KEY_CHARGE, parser.nextInt() == 1); + + if (parser.nextInt() == 1) { + position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); + } + + return position; + } + } |