diff options
author | Christoph Krey <c@ckrey.de> | 2018-04-16 10:45:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-16 10:45:11 +0200 |
commit | 3a602dd133b533cc69d5986d64a00fb3ed670f75 (patch) | |
tree | 97ff753db310a49ae7e53240b1db07fb8475679e /src/org/traccar/protocol/LaipacProtocolDecoder.java | |
parent | 232de5f0daef98f31b28d177d991fdbfa191f195 (diff) | |
parent | 6d4b8df25c7e942b9ad594db9444fe15bcb16be9 (diff) | |
download | trackermap-server-3a602dd133b533cc69d5986d64a00fb3ed670f75.tar.gz trackermap-server-3a602dd133b533cc69d5986d64a00fb3ed670f75.tar.bz2 trackermap-server-3a602dd133b533cc69d5986d64a00fb3ed670f75.zip |
Merge pull request #4 from traccar/master
upgrade to current master
Diffstat (limited to 'src/org/traccar/protocol/LaipacProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/LaipacProtocolDecoder.java | 86 |
1 files changed, 67 insertions, 19 deletions
diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index 32d4ff0e6..bfaff9ec4 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,8 @@ import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; +import org.traccar.model.CellTower; +import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; @@ -45,11 +47,45 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { .number("(d+.d+),") // speed .number("(d+.d+),") // course .number("(dd)(dd)(dd),") // date (ddmmyy) - .expression("(.),") // type - .expression("[^*]+").text("*") + .expression("([abZXTSMHFE86430]),") // event code + .expression("([\\d.]+),") // battery voltage + .number("(d+),") // current mileage + .number("(d),") // gps status + .number("(d+),") // adc1 + .number("(d+)") // adc2 + .number(",(xxxx)") // lac + .number("(xxxx),") // cid + .number("(ddd)") // mcc + .number("(ddd)") // mnc + .optional(4) + .text("*") .number("(xx)") // checksum .compile(); + private String decodeAlarm(String event) { + switch (event) { + case "Z": + return Position.ALARM_LOW_BATTERY; + case "X": + return Position.ALARM_GEOFENCE_ENTER; + case "T": + return Position.ALARM_TAMPERING; + case "H": + return Position.ALARM_POWER_OFF; + case "8": + return Position.ALARM_SHOCK; + case "7": + case "4": + return Position.ALARM_GEOFENCE_EXIT; + case "6": + return Position.ALARM_OVERSPEED; + case "3": + return Position.ALARM_SOS; + default: + return null; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -71,8 +107,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { return null; } - Position position = new Position(); - position.setProtocol(getProtocolName()); + Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); DateBuilder dateBuilder = new DateBuilder() @@ -80,6 +115,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { String status = parser.next(); position.setValid(status.toUpperCase().equals("A")); + position.set(Position.KEY_STATUS, status); position.setLatitude(parser.nextCoordinate()); position.setLongitude(parser.nextCoordinate()); @@ -89,25 +125,37 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); position.setTime(dateBuilder.getDate()); - String type = parser.next(); + String event = parser.next(); + position.set(Position.KEY_ALARM, decodeAlarm(event)); + position.set(Position.KEY_EVENT, event); + position.set(Position.KEY_BATTERY, Double.parseDouble(parser.next().replaceAll("\\.", "")) * 0.001); + position.set(Position.KEY_ODOMETER, parser.nextDouble()); + position.set(Position.KEY_GPS, parser.nextInt()); + position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001); + position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001); + + Integer lac = parser.nextHexInt(); + Integer cid = parser.nextHexInt(); + Integer mcc = parser.nextInt(); + Integer mnc = parser.nextInt(); + if (lac != null && cid != null && mcc != null && mnc != null) { + position.setNetwork(new Network(CellTower.from(mcc, mnc, lac, cid))); + } + String checksum = parser.next(); if (channel != null) { - - if (Character.isLowerCase(status.charAt(0))) { - String response = "$EAVACK," + type + "," + checksum; - response += Checksum.nmea(response); + if (event.equals("3")) { + channel.write("$AVCFG,00000000,d*31\r\n"); + } else if (event.equals("X") || event.equals("4")) { + channel.write("$AVCFG,00000000,x*2D\r\n"); + } else if (event.equals("Z")) { + channel.write("$AVCFG,00000000,z*2F\r\n"); + } else if (Character.isLowerCase(status.charAt(0))) { + String response = "$EAVACK," + event + "," + checksum; + response += Checksum.nmea(response) + "\r\n"; channel.write(response); } - - if (type.equals("S") || type.equals("T")) { - channel.write("$AVCFG,00000000,t*21"); - } else if (type.equals("3")) { - channel.write("$AVCFG,00000000,d*31"); - } else if (type.equals("X") || type.equals("4")) { - channel.write("$AVCFG,00000000,x*2D"); - } - } return position; |