aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
index df0f1e2ed..5218cfc16 100644
--- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java
@@ -109,16 +109,15 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
}
}
- private String decodeEvent(String event, Position position) {
+ private String decodeEvent(String event, Position position, String deviceModel) {
if (event.length() == 1) {
char inputStatus = event.charAt(0);
- String deviceModel = device.getModel();
if (inputStatus >= 'A' && inputStatus <= 'D') {
int inputStatusInt = inputStatus - 'A';
position.set(Position.PREFIX_IN + 1, (boolean) BitUtil.check(inputStatusInt, 0));
position.set(Position.PREFIX_IN + 2, (boolean) BitUtil.check(inputStatusInt, 1));
- if (deviceModel == "SF-Lite") {
+ if ("SF-Lite".equals(deviceModel)) {
position.set(Position.PREFIX_IN + 3, false);
}
return null;
@@ -126,7 +125,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
int inputStatusInt = inputStatus - 'O';
position.set(Position.PREFIX_IN + 1, (boolean) BitUtil.check(inputStatusInt, 0));
position.set(Position.PREFIX_IN + 2, (boolean) BitUtil.check(inputStatusInt, 1));
- if (deviceModel == "SF-Lite") {
+ if ("SF-Lite".equals(deviceModel)) {
position.set(Position.PREFIX_IN + 3, true);
}
return null;
@@ -220,15 +219,22 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ String deviceId = parser.next();
+
DeviceSession deviceSession =
- getDeviceSession(channel, remoteAddress, parser.next());
+ getDeviceSession(channel, remoteAddress, deviceId);
if (deviceSession == null) {
return null;
}
- Position position = new Position(getProtocolName());
+ String deviceModel = null;
+ Device device = getCacheManager().getObject(Device.class, deviceId);
+ if (device != null) {
+ deviceModel = device.getModel();
+ }
- position.setDeviceId(deviceSession.getDeviceId());
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceId);
DateBuilder dateBuilder = new DateBuilder()
.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
@@ -247,14 +253,13 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
String event = parser.next();
position.set(Position.KEY_ALARM, decodeAlarm(event));
- position.set(Position.KEY_EVENT, decodeEvent(event, position));
+ position.set(Position.KEY_EVENT, decodeEvent(event, position, deviceModel));
position.set(Position.KEY_BATTERY, Double.parseDouble(parser.next().replaceAll("\\.", "")) * 0.001);
position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
position.set(Position.KEY_GPS, parser.nextInt());
position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001);
-
- String deviceModel = device.getModel();
- if (deviceModel == "AVL110" || deviceModel == "AVL120") {
+
+ if ("AVL110".equals(deviceModel) || "AVL120".equals(deviceModel)) {
position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001);
}
@@ -275,7 +280,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
sendAcknowledge(status, event, checksum, channel, remoteAddress);
String devicePassword = AttributeUtil.getDevicePassword(
- getCacheManager(), deviceSession.getDeviceId(), getProtocolName(), DEFAULT_DEVICE_PASSWORD);
+ getCacheManager(), deviceId, getProtocolName(), DEFAULT_DEVICE_PASSWORD);
sendEventResponse(event, devicePassword, channel, remoteAddress);
}