From 86511cd68d968c15db66ddfbe831a34be13e8ba1 Mon Sep 17 00:00:00 2001 From: edvalley <52469633+edvalley@users.noreply.github.com> Date: Thu, 25 May 2023 19:58:07 -0400 Subject: Acknowledge mileage alert and decode third input status --- .../traccar/protocol/LaipacProtocolDecoder.java | 29 +++++++++++++++------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index e9570ee11..ede4650b8 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -110,17 +110,25 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { private String decodeEvent(String event, Position position) { - if (event.length() == 1) { - char inputStatus = event.charAt(0); - if (inputStatus >= 'A' && inputStatus <= 'D') { - int inputStatusInt = inputStatus - 'A'; - position.set(Position.PREFIX_IN + 1, inputStatusInt & 1); - position.set(Position.PREFIX_IN + 2, inputStatusInt & 2); - return null; - } + if (event.length() != 1) + return event; + + int inputStatusInt = 0; + char inputStatus = event.charAt(0); + + if (inputStatus >= 'A' && inputStatus <= 'D') { + inputStatusInt = inputStatus - 'A'; + } else if(inputStatus >= 'O' && inputStatus <= 'R') { + inputStatusInt = inputStatus - 'O' + 4; + } else { + return event; } - return event; + position.set(Position.PREFIX_IN + 1, inputStatusInt & 1); + position.set(Position.PREFIX_IN + 2, inputStatusInt & 2); + position.set(Position.PREFIX_IN + 3, inputStatusInt & 4); + + return null; } private void sendEventResponse( @@ -132,6 +140,9 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { case "3": responseCode = "d"; break; + case "M": + responseCode = "m"; + break; case "S": case "T": responseCode = "t"; -- cgit v1.2.3 From 03b9409f05c2edef2c1f52dde8bedc2f43184a50 Mon Sep 17 00:00:00 2001 From: edvalley <52469633+edvalley@users.noreply.github.com> Date: Thu, 25 May 2023 20:03:35 -0400 Subject: Fix style check violation --- src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index ede4650b8..5b9629ff3 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -118,7 +118,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { if (inputStatus >= 'A' && inputStatus <= 'D') { inputStatusInt = inputStatus - 'A'; - } else if(inputStatus >= 'O' && inputStatus <= 'R') { + } else if (inputStatus >= 'O' && inputStatus <= 'R') { inputStatusInt = inputStatus - 'O' + 4; } else { return event; -- cgit v1.2.3 From 6c3b33275e2d8310011c38ed1bc292546e15cae9 Mon Sep 17 00:00:00 2001 From: edvalley <52469633+edvalley@users.noreply.github.com> Date: Thu, 25 May 2023 20:06:59 -0400 Subject: Fix style check violation --- src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index 5b9629ff3..3b654db0c 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -110,8 +110,9 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { private String decodeEvent(String event, Position position) { - if (event.length() != 1) + if (event.length() != 1) { return event; + } int inputStatusInt = 0; char inputStatus = event.charAt(0); -- cgit v1.2.3 From c12f74fea206191877d4a727547bfdb0c9b938cc Mon Sep 17 00:00:00 2001 From: edvalley <52469633+edvalley@users.noreply.github.com> Date: Fri, 7 Jul 2023 08:08:48 -0400 Subject: Keep same structure as before --- .../traccar/protocol/LaipacProtocolDecoder.java | 39 +++++++++++----------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index 3b654db0c..dbac159b3 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -110,26 +110,25 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { private String decodeEvent(String event, Position position) { - if (event.length() != 1) { - return event; - } - - int inputStatusInt = 0; - char inputStatus = event.charAt(0); - - if (inputStatus >= 'A' && inputStatus <= 'D') { - inputStatusInt = inputStatus - 'A'; - } else if (inputStatus >= 'O' && inputStatus <= 'R') { - inputStatusInt = inputStatus - 'O' + 4; - } else { - return event; - } - - position.set(Position.PREFIX_IN + 1, inputStatusInt & 1); - position.set(Position.PREFIX_IN + 2, inputStatusInt & 2); - position.set(Position.PREFIX_IN + 3, inputStatusInt & 4); - - return null; + if (event.length() == 1) { + char inputStatus = event.charAt(0); + if (inputStatus >= 'A' && inputStatus <= 'D') { + int inputStatusInt = inputStatus - 'A'; + position.set(Position.PREFIX_IN + 1, inputStatusInt & 1); + position.set(Position.PREFIX_IN + 2, inputStatusInt & 2); + position.set(Position.PREFIX_IN + 3, 0); + return null; + } else if (inputStatus >= 'O' && inputStatus <= 'R') { + int inputStatusInt = inputStatus - 'O'; + position.set(Position.PREFIX_IN + 1, inputStatusInt & 1); + position.set(Position.PREFIX_IN + 2, inputStatusInt & 2); + position.set(Position.PREFIX_IN + 3, 1); + return null; + } + } + + return event; + } private void sendEventResponse( -- cgit v1.2.3 From 83cb4c11d740a3645a5b9a5dafbc13b245c89a07 Mon Sep 17 00:00:00 2001 From: edvalley <52469633+edvalley@users.noreply.github.com> Date: Fri, 7 Jul 2023 08:16:03 -0400 Subject: Change tabs to spaces --- .../org/traccar/protocol/LaipacProtocolDecoder.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index dbac159b3..2237dcebc 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -111,23 +111,23 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { private String decodeEvent(String event, Position position) { if (event.length() == 1) { - char inputStatus = event.charAt(0); - if (inputStatus >= 'A' && inputStatus <= 'D') { - int inputStatusInt = inputStatus - 'A'; - position.set(Position.PREFIX_IN + 1, inputStatusInt & 1); - position.set(Position.PREFIX_IN + 2, inputStatusInt & 2); + char inputStatus = event.charAt(0); + if (inputStatus >= 'A' && inputStatus <= 'D') { + int inputStatusInt = inputStatus - 'A'; + position.set(Position.PREFIX_IN + 1, inputStatusInt & 1); + position.set(Position.PREFIX_IN + 2, inputStatusInt & 2); position.set(Position.PREFIX_IN + 3, 0); - return null; - } else if (inputStatus >= 'O' && inputStatus <= 'R') { + return null; + } else if (inputStatus >= 'O' && inputStatus <= 'R') { int inputStatusInt = inputStatus - 'O'; position.set(Position.PREFIX_IN + 1, inputStatusInt & 1); - position.set(Position.PREFIX_IN + 2, inputStatusInt & 2); + position.set(Position.PREFIX_IN + 2, inputStatusInt & 2); position.set(Position.PREFIX_IN + 3, 1); return null; } - } + } - return event; + return event; } -- cgit v1.2.3 From eb7c310a6337328f73c33cb8f0e222dc286925f1 Mon Sep 17 00:00:00 2001 From: edvalley <52469633+edvalley@users.noreply.github.com> Date: Fri, 7 Jul 2023 08:21:01 -0400 Subject: Remove trailing spaces --- src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index 2237dcebc..60a9365c5 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -126,9 +126,9 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { return null; } } - + return event; - + } private void sendEventResponse( -- cgit v1.2.3 From 19e00af6d0c7b666841b181438e401bb8e7415ff Mon Sep 17 00:00:00 2001 From: edvalley <52469633+edvalley@users.noreply.github.com> Date: Fri, 7 Jul 2023 23:24:23 -0400 Subject: Use BitUtil instead of logical bitwise AND operator --- src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index 60a9365c5..c2146c22d 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -28,6 +28,7 @@ import org.traccar.helper.PatternBuilder; import org.traccar.model.CellTower; import org.traccar.model.Network; import org.traccar.model.Position; +import org.traccar.helper.BitUtil; import java.net.SocketAddress; import java.util.regex.Pattern; @@ -114,14 +115,14 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { char inputStatus = event.charAt(0); if (inputStatus >= 'A' && inputStatus <= 'D') { int inputStatusInt = inputStatus - 'A'; - position.set(Position.PREFIX_IN + 1, inputStatusInt & 1); - position.set(Position.PREFIX_IN + 2, inputStatusInt & 2); + position.set(Position.PREFIX_IN + 1, BitUtil.check(inputStatusInt, 0)); + position.set(Position.PREFIX_IN + 2, BitUtil.check(inputStatusInt, 1)); position.set(Position.PREFIX_IN + 3, 0); return null; } else if (inputStatus >= 'O' && inputStatus <= 'R') { int inputStatusInt = inputStatus - 'O'; - position.set(Position.PREFIX_IN + 1, inputStatusInt & 1); - position.set(Position.PREFIX_IN + 2, inputStatusInt & 2); + position.set(Position.PREFIX_IN + 1, BitUtil.check(inputStatusInt, 0)); + position.set(Position.PREFIX_IN + 2, BitUtil.check(inputStatusInt, 1)); position.set(Position.PREFIX_IN + 3, 1); return null; } -- cgit v1.2.3 From 536888fd7e64f00ca9693ea9b41624360949c8ab Mon Sep 17 00:00:00 2001 From: edvalley <52469633+edvalley@users.noreply.github.com> Date: Sun, 9 Jul 2023 14:01:12 -0400 Subject: Conditionally set digital input 3 and analog input 2 according to device model --- .../traccar/protocol/LaipacProtocolDecoder.java | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index c2146c22d..df0f1e2ed 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -113,17 +113,22 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { 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, BitUtil.check(inputStatusInt, 0)); - position.set(Position.PREFIX_IN + 2, BitUtil.check(inputStatusInt, 1)); - position.set(Position.PREFIX_IN + 3, 0); + 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") { + position.set(Position.PREFIX_IN + 3, false); + } return null; } else if (inputStatus >= 'O' && inputStatus <= 'R') { int inputStatusInt = inputStatus - 'O'; - position.set(Position.PREFIX_IN + 1, BitUtil.check(inputStatusInt, 0)); - position.set(Position.PREFIX_IN + 2, BitUtil.check(inputStatusInt, 1)); - position.set(Position.PREFIX_IN + 3, 1); + 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") { + position.set(Position.PREFIX_IN + 3, true); + } return null; } } @@ -247,7 +252,11 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { 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); - position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001); + + String deviceModel = device.getModel(); + if (deviceModel == "AVL110" || deviceModel == "AVL120") { + position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001); + } Integer lac = parser.nextHexInt(); Integer cid = parser.nextHexInt(); -- cgit v1.2.3 From 67f05acaa4e72db3576418a150ebbe53971309bf Mon Sep 17 00:00:00 2001 From: edvalley <52469633+edvalley@users.noreply.github.com> Date: Sun, 9 Jul 2023 14:34:32 -0400 Subject: Fix some errors --- .../traccar/protocol/LaipacProtocolDecoder.java | 29 +++++++++++++--------- 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') 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); } -- cgit v1.2.3 From e63b6bd4868f367c581db40997f741d00587b3b2 Mon Sep 17 00:00:00 2001 From: edvalley <52469633+edvalley@users.noreply.github.com> Date: Sun, 9 Jul 2023 14:37:30 -0400 Subject: Fix more errors --- src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index 5218cfc16..e3409c85a 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -28,6 +28,7 @@ import org.traccar.helper.PatternBuilder; import org.traccar.model.CellTower; import org.traccar.model.Network; import org.traccar.model.Position; +import org.traccar.model.Device; import org.traccar.helper.BitUtil; import java.net.SocketAddress; -- cgit v1.2.3 From 7ade92a97f41951aecfbb9de720780cf5232e2c1 Mon Sep 17 00:00:00 2001 From: edvalley <52469633+edvalley@users.noreply.github.com> Date: Sun, 9 Jul 2023 16:06:18 -0400 Subject: Fix more errors --- src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index e3409c85a..f0753cb5c 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -220,22 +220,21 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { return null; } - String deviceId = parser.next(); - DeviceSession deviceSession = - getDeviceSession(channel, remoteAddress, deviceId); + getDeviceSession(channel, remoteAddress, parser.next()); if (deviceSession == null) { return null; } String deviceModel = null; - Device device = getCacheManager().getObject(Device.class, deviceId); + Device device = getCacheManager().getObject(Device.class, deviceSession.getDeviceId()); if (device != null) { deviceModel = device.getModel(); } Position position = new Position(getProtocolName()); - position.setDeviceId(deviceId); + + position.setDeviceId(deviceSession.getDeviceId()); DateBuilder dateBuilder = new DateBuilder() .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)); @@ -281,7 +280,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { sendAcknowledge(status, event, checksum, channel, remoteAddress); String devicePassword = AttributeUtil.getDevicePassword( - getCacheManager(), deviceId, getProtocolName(), DEFAULT_DEVICE_PASSWORD); + getCacheManager(), deviceSession.getDeviceId(), getProtocolName(), DEFAULT_DEVICE_PASSWORD); sendEventResponse(event, devicePassword, channel, remoteAddress); } -- cgit v1.2.3 From 779486a30483f7ab9c2c0f4c39c6a4e14319b330 Mon Sep 17 00:00:00 2001 From: Edward Valley Date: Sun, 9 Jul 2023 17:07:35 -0400 Subject: Fix more errors --- src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index f0753cb5c..de039a2fd 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -231,6 +231,9 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { if (device != null) { deviceModel = device.getModel(); } + if (deviceModel == null) { + deviceModel = ""; + } Position position = new Position(getProtocolName()); @@ -261,6 +264,8 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { if ("AVL110".equals(deviceModel) || "AVL120".equals(deviceModel)) { position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001); + } else { + parser.next(); } Integer lac = parser.nextHexInt(); -- cgit v1.2.3 From 97240fd579c2d01f43a5b7ba1f9b16bad19085f2 Mon Sep 17 00:00:00 2001 From: Edward Valley Date: Sun, 9 Jul 2023 17:11:55 -0400 Subject: Remove unneded code --- src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index de039a2fd..6a5b67669 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -231,9 +231,6 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { if (device != null) { deviceModel = device.getModel(); } - if (deviceModel == null) { - deviceModel = ""; - } Position position = new Position(getProtocolName()); -- cgit v1.2.3 From 60522a68d292541c44efa3736967f471d4347a50 Mon Sep 17 00:00:00 2001 From: Edward Valley Date: Sun, 9 Jul 2023 18:04:33 -0400 Subject: Follow refactor suggestion --- .../java/org/traccar/protocol/LaipacProtocolDecoder.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java index 6a5b67669..5745909c7 100644 --- a/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java @@ -110,7 +110,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { } } - private String decodeEvent(String event, Position position, String deviceModel) { + private String decodeEvent(String event, Position position, String model) { if (event.length() == 1) { char inputStatus = event.charAt(0); @@ -118,7 +118,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { 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 ("SF-Lite".equals(deviceModel)) { + if ("SF-Lite".equals(model)) { position.set(Position.PREFIX_IN + 3, false); } return null; @@ -126,7 +126,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 ("SF-Lite".equals(deviceModel)) { + if ("SF-Lite".equals(model)) { position.set(Position.PREFIX_IN + 3, true); } return null; @@ -226,11 +226,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder { return null; } - String deviceModel = null; - Device device = getCacheManager().getObject(Device.class, deviceSession.getDeviceId()); - if (device != null) { - deviceModel = device.getModel(); - } + String model = getCacheManager().getObject(Device.class, deviceSession.getDeviceId()).getModel(); Position position = new Position(getProtocolName()); @@ -253,13 +249,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, deviceModel)); + position.set(Position.KEY_EVENT, decodeEvent(event, position, model)); 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); - if ("AVL110".equals(deviceModel) || "AVL120".equals(deviceModel)) { + if ("AVL110".equals(model) || "AVL120".equals(model)) { position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001); } else { parser.next(); -- cgit v1.2.3