aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-03-22 01:04:42 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2018-03-22 01:04:42 +1300
commitd2a130b71e9d8064515b16dff865f476a1aadf15 (patch)
tree10fe1be23ec0421e32e94da6a2e34574b939717e /src/org/traccar/protocol
parented8485eb47443a202eeaad79753a2c5a085fce80 (diff)
downloadtrackermap-server-d2a130b71e9d8064515b16dff865f476a1aadf15.tar.gz
trackermap-server-d2a130b71e9d8064515b16dff865f476a1aadf15.tar.bz2
trackermap-server-d2a130b71e9d8064515b16dff865f476a1aadf15.zip
Clean up and refactor Laipac
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/LaipacProtocolDecoder.java102
1 files changed, 47 insertions, 55 deletions
diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java
index 9357123c8..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.
@@ -50,18 +50,42 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
.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
+ .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 {
@@ -101,44 +125,35 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
- 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);
-
+ 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);
- 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))));
+ 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 (eventCode.equals("3")) {
+ if (event.equals("3")) {
channel.write("$AVCFG,00000000,d*31\r\n");
- } else if (eventCode.equals("X") || eventCode.equals("4")) {
+ } else if (event.equals("X") || event.equals("4")) {
channel.write("$AVCFG,00000000,x*2D\r\n");
- } else if (eventCode.equals("Z")) {
+ } else if (event.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";
+ String response = "$EAVACK," + event + "," + checksum;
+ response += Checksum.nmea(response) + "\r\n";
channel.write(response);
}
}
@@ -146,27 +161,4 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
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;
- }
- }
}