diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-03-21 23:06:13 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-21 23:06:13 +1300 |
commit | ed8485eb47443a202eeaad79753a2c5a085fce80 (patch) | |
tree | beb695a4addaa4a5fbf6d0006bac56451fe73817 | |
parent | 3449aa51dc8250ba38772b39deb48f1f76be08c1 (diff) | |
parent | 277b14899879e882869552acc7847d63a03effcf (diff) | |
download | trackermap-server-ed8485eb47443a202eeaad79753a2c5a085fce80.tar.gz trackermap-server-ed8485eb47443a202eeaad79753a2c5a085fce80.tar.bz2 trackermap-server-ed8485eb47443a202eeaad79753a2c5a085fce80.zip |
Merge pull request #3810 from kevingoos/master
Added LaipacSFKamel protocol
-rw-r--r-- | src/org/traccar/protocol/LaipacProtocolDecoder.java | 87 | ||||
-rw-r--r-- | test/org/traccar/protocol/LaipacProtocolDecoderTest.java | 25 |
2 files changed, 97 insertions, 15 deletions
diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java index 99189d012..9357123c8 100644 --- a/src/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java @@ -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,8 +47,18 @@ 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 on/off (1 = on, 0 = off) + .number("(d+),") // Analog port 1 + .number("(d+)") // Analog port 2 + .expression(",([0-9a-fA-F]{4})") // Cell 1 - Cell Net Code + .expression("([0-9a-fA-F]{4}),") // Cell 1 - Cell ID Code + .number("(d{3})") // Cell 2 - Country Code + .number("(d{3})") // Cell 2 - Operator Code + .optional(4) + .text("*") .number("(xx)") // checksum .compile(); @@ -79,6 +91,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()); @@ -88,28 +101,72 @@ 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 eventCode = parser.next(); + position.set(Position.KEY_ALARM, decodeAlarm(eventCode)); + position.set(Position.KEY_EVENT, eventCode); + + String batteryVoltage = parser.next(); + batteryVoltage = batteryVoltage.replaceAll("\\.", ""); + position.set(Position.KEY_BATTERY, Double.parseDouble(batteryVoltage) * 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); + + String lac = parser.next(); + String cid = parser.next(); + String mcc = parser.next(); + String mnc = parser.next(); + if (lac != null + && cid != null + && mcc != null + && mnc != null) { + position.setNetwork(new Network(CellTower.from(Integer.parseInt(mcc), Integer.parseInt(mnc), + Integer.parseInt(lac, 16), Long.parseLong(cid, 16)))); + } + String checksum = parser.next(); if (channel != null) { - - if (Character.isLowerCase(status.charAt(0))) { - String response = "$EAVACK," + type + "," + checksum; + if (eventCode.equals("3")) { + channel.write("$AVCFG,00000000,d*31\r\n"); + } else if (eventCode.equals("X") || eventCode.equals("4")) { + channel.write("$AVCFG,00000000,x*2D\r\n"); + } else if (eventCode.equals("Z")) { + channel.write("$AVCFG,00000000,z*2F\r\n"); + } else if (Character.isLowerCase(status.charAt(0))) { + String response = "$EAVACK," + eventCode + "," + checksum; response += Checksum.nmea(response); + 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; } + 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; + } + } } diff --git a/test/org/traccar/protocol/LaipacProtocolDecoderTest.java b/test/org/traccar/protocol/LaipacProtocolDecoderTest.java index 787f33e65..41925040e 100644 --- a/test/org/traccar/protocol/LaipacProtocolDecoderTest.java +++ b/test/org/traccar/protocol/LaipacProtocolDecoderTest.java @@ -95,6 +95,31 @@ public class LaipacProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "$AVRMC,96414215,170046,p,4310.7965,N,07652.0816,E,0.00,0.00,071016,0,4069,98,1,0,0*04")); + verifyPosition(decoder, text( + "$AVRMC,999999999999999,111602,r,5050.1262,N,00419.9660,E,0.00,0.00,120318,0,3843,95,1,0,0,3EE4A617,020610*47")); + + verifyPosition(decoder, text( + "$AVRMC,358174067149865,143456,R,5050.1285,N,00420.0620,E,0.00,309.27,190318,0,3455,119,1,0,0,3EE4A617,020610*54")); + + verifyPosition(decoder, text( + "$AVRMC,999999999999999,084514,r,5050.1314,N,00419.9719,E,0.68,306.39,120318,0,3882,84,1,0,0,3EE4A617,020610*4D")); + + //Alarm button + verifyPosition(decoder, text( + "$AVRMC,358174067149865,142945,R,5050.1254,N,00420.0490,E,0.00,0.00,190318,3,3455,119,1,0,0,3EE4A617,020610*53")); + + //G-Sensor + verifyPosition(decoder, text( + "$AVRMC,358174067149865,143407,R,5050.1254,N,00420.0490,E,0.00,0.00,190318,8,3455,119,1,0,0,3EE4A617,020610*52")); + + //Powered off + verifyPosition(decoder, text( + "$AVRMC,358174067149865,143648,A,5050.1141,N,00420.0525,E,1.24,174.38,190318,H,3455,119,1,0,0,3EE4A617,020610*3E")); + + //No network + verifyPosition(decoder, text( + "$AVRMC,358174067149865,143747,R,5050.1124,N,00420.0542,E,1.34,161.96,190318,a,3416,119,1,0,0*7D")); + } } |