From b1c36134dc14fdbb80ac22306db15280d9b251b5 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 14 Oct 2024 07:13:31 -0700 Subject: [PATCH 01/12] Support GT06 temperature --- .../java/org/traccar/protocol/Gt06ProtocolDecoder.java | 7 ++++++- .../java/org/traccar/protocol/Gt06ProtocolDecoderTest.java | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index 6289b57fc67..16b9889e6df 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -815,8 +815,13 @@ private Object decodeBasic(Channel channel, SocketAddress remoteAddress, ByteBuf position.addAlarm(decodeAlarm(buf.readUnsignedByte(), modelLW)); buf.readUnsignedByte(); // language position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); - buf.readUnsignedByte(); // working mode + int mode = buf.readUnsignedByte(); position.set(Position.KEY_POWER, buf.readUnsignedShort() / 100.0); + buf.readUnsignedByte(); // reserved + buf.readUnsignedShort(); // working time + if (mode == 4) { + position.set(Position.PREFIX_TEMP + 1, buf.readShort() / 10.0); + } } else { if (type == MSG_GPS_LBS_STATUS_5) { position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01); diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 5e28792c720..6d949c237a3 100644 --- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -17,6 +17,10 @@ public void testDecode() throws Exception { verifyNull(decoder, binary( "78780D01086471700328358100093F040D0A")); + verifyAttribute(decoder, binary( + "7878131340b2fa000201040000000000011c00400e550d0a"), + Position.PREFIX_TEMP + 1, 28.4); + verifyAttribute(decoder, binary( "787817360005040002003201010018020192006a015f0324aeaf0d0a"), Position.KEY_BATTERY, 4.02); From d1b9bd2272a190d9c3d852bf4d6a9d9d484a126d Mon Sep 17 00:00:00 2001 From: Kirill Loshmanov Date: Wed, 16 Oct 2024 15:46:25 +0700 Subject: [PATCH 02/12] Add attributes to Wialon forwarder --- src/main/java/org/traccar/MainModule.java | 2 +- .../forward/PositionForwarderWialon.java | 43 +++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index 0df85d614cd..3121beb3181 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -371,7 +371,7 @@ public static PositionForwarder providePositionForwarder( case "kafka" -> new PositionForwarderKafka(config, objectMapper); case "mqtt" -> new PositionForwarderMqtt(config, objectMapper); case "redis" -> new PositionForwarderRedis(config, objectMapper); - case "wialon" -> new PositionForwarderWialon(config, executorService, "1.0"); + case "wialon" -> new PositionForwarderWialon(config, executorService, "1.0", objectMapper); default -> new PositionForwarderUrl(config, client, objectMapper); }; } diff --git a/src/main/java/org/traccar/forward/PositionForwarderWialon.java b/src/main/java/org/traccar/forward/PositionForwarderWialon.java index ac8bfd472d9..3feef1d5aca 100644 --- a/src/main/java/org/traccar/forward/PositionForwarderWialon.java +++ b/src/main/java/org/traccar/forward/PositionForwarderWialon.java @@ -15,11 +15,14 @@ */ package org.traccar.forward; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import org.traccar.config.Config; import org.traccar.config.Keys; import org.traccar.helper.Checksum; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; +import org.json.JSONObject; import java.io.IOException; import java.net.DatagramPacket; @@ -41,9 +44,11 @@ public class PositionForwarderWialon implements PositionForwarder { private final DatagramSocket socket; private final InetAddress address; private final int port; + private final ObjectMapper objectMapper; - public PositionForwarderWialon(Config config, ExecutorService executorService, String version) { + public PositionForwarderWialon(Config config, ExecutorService executorService, String version, ObjectMapper objectMapper) { this.version = version; + this.objectMapper = objectMapper; try { URI url = new URI(config.getString(Keys.FORWARD_URL)); address = InetAddress.getByName(url.getHost()); @@ -72,9 +77,15 @@ public void forward(PositionData positionData, ResultHandler resultHandler) { Position position = positionData.getPosition(); String uniqueId = positionData.getDevice().getUniqueId(); + String attributes = "NA"; + try { + attributes = convertJsonToWialonParams(objectMapper.writeValueAsString(position.getAttributes())); + } catch (JsonProcessingException e) { + resultHandler.onResult(false, e); + } String payload = String.format( - "%s;%02d%.5f;%s;%03d%.5f;%s;%d;%d;%d;NA;NA;NA;NA;;%s;NA", + "%s;%02d%.5f;%s;%03d%.5f;%s;%d;%d;%d;NA;NA;NA;NA;;%s;%s", dateFormat.format(position.getFixTime()), (int) Math.abs(position.getLatitude()), Math.abs(position.getLatitude()) % 1 * 60, @@ -85,7 +96,8 @@ public void forward(PositionData positionData, ResultHandler resultHandler) { (int) UnitsConverter.kphFromKnots(position.getSpeed()), (int) position.getCourse(), (int) position.getAltitude(), - position.getString(Position.KEY_DRIVER_UNIQUE_ID, "NA")); + position.getString(Position.KEY_DRIVER_UNIQUE_ID, "NA"), + attributes); String message; if (version.startsWith("2")) { @@ -108,4 +120,29 @@ public void forward(PositionData positionData, ResultHandler resultHandler) { } } + public static String convertJsonToWialonParams(String jsonString) { + JSONObject jsonObject = new JSONObject(jsonString); + StringBuilder result = new StringBuilder(); + + for (String key : jsonObject.keySet()) { + Object value = jsonObject.get(key); + String type; + + if (value instanceof Integer || value instanceof Long) { + type = "1"; + } else if (value instanceof Double || value instanceof Float) { + type = "2"; + } else { + type = "3"; + } + + if (!result.isEmpty()) { + result.append(","); + } + result.append(key).append(":").append(type).append(":").append(value.toString()); + } + + return result.toString(); + } + } From e246da64fe9a07add70b598e140dcac5687b3094 Mon Sep 17 00:00:00 2001 From: Axel Rieben <26045532+AxelRieben@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:35:29 +0200 Subject: [PATCH 03/12] Add a parameter to configure the httpOnly attribut of the session cookie --- src/main/java/org/traccar/config/Keys.java | 8 ++++++++ src/main/java/org/traccar/web/WebServer.java | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 3da49207eea..08e35b4ec78 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -843,6 +843,14 @@ private Keys() { List.of(KeyType.CONFIG), "max-age=3600,public"); + /** + * Set HttpOnly attribut to the session cookie. + */ + public static final ConfigKey WEB_COOKIE_HTTP_ONLY = new BooleanConfigKey( + "web.cookieHttpOnly", + List.of(KeyType.CONFIG), + false); + /** * Enable TOTP authentication on the server. */ diff --git a/src/main/java/org/traccar/web/WebServer.java b/src/main/java/org/traccar/web/WebServer.java index 6d0dad545ff..aa8bf52d72a 100644 --- a/src/main/java/org/traccar/web/WebServer.java +++ b/src/main/java/org/traccar/web/WebServer.java @@ -217,6 +217,8 @@ private void initSessionConfig(ServletContextHandler servletHandler) { break; } } + + sessionCookieConfig.setHttpOnly(config.getBoolean(Keys.WEB_COOKIE_HTTP_ONLY)); } @Override From a1c96b7bc702d6192898423d209f09f84c6ae732 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 16 Oct 2024 22:28:56 -0700 Subject: [PATCH 04/12] Teltonika FMC650 BLE temperature --- .../java/org/traccar/protocol/TeltonikaProtocolDecoder.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java index 5dc0f325dfc..a494ecb9a7e 100644 --- a/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -243,6 +243,10 @@ private static void register(int id, Set models, BiConsumer p.set(Position.KEY_FUEL_CONSUMPTION, b.readUnsignedShort() * 0.1)); register(113, fmbXXX, (p, b) -> p.set(Position.KEY_BATTERY_LEVEL, b.readUnsignedByte())); register(115, fmbXXX, (p, b) -> p.set("engineTemp", b.readShort() * 0.1)); + register(701, Set.of("FMC640", "FMC650", "FMM640"), (p, b) -> p.set("bleTemp1", b.readShort() * 0.01)); + register(702, Set.of("FMC640", "FMC650", "FMM640"), (p, b) -> p.set("bleTemp2", b.readShort() * 0.01)); + register(703, Set.of("FMC640", "FMC650", "FMM640"), (p, b) -> p.set("bleTemp3", b.readShort() * 0.01)); + register(704, Set.of("FMC640", "FMC650", "FMM640"), (p, b) -> p.set("bleTemp4", b.readShort() * 0.01)); register(179, null, (p, b) -> p.set(Position.PREFIX_OUT + 1, b.readUnsignedByte() > 0)); register(180, null, (p, b) -> p.set(Position.PREFIX_OUT + 2, b.readUnsignedByte() > 0)); register(181, null, (p, b) -> p.set(Position.KEY_PDOP, b.readUnsignedShort() * 0.1)); From ce71f380d7acdb0b2ff85ded4dfd62f19b049d7d Mon Sep 17 00:00:00 2001 From: Kirill Loshmanov Date: Fri, 18 Oct 2024 09:36:58 +0700 Subject: [PATCH 05/12] Add attributes to Wialon forwarder --- src/main/java/org/traccar/MainModule.java | 2 +- .../forward/PositionForwarderWialon.java | 22 +++++-------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index 3121beb3181..0df85d614cd 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -371,7 +371,7 @@ public static PositionForwarder providePositionForwarder( case "kafka" -> new PositionForwarderKafka(config, objectMapper); case "mqtt" -> new PositionForwarderMqtt(config, objectMapper); case "redis" -> new PositionForwarderRedis(config, objectMapper); - case "wialon" -> new PositionForwarderWialon(config, executorService, "1.0", objectMapper); + case "wialon" -> new PositionForwarderWialon(config, executorService, "1.0"); default -> new PositionForwarderUrl(config, client, objectMapper); }; } diff --git a/src/main/java/org/traccar/forward/PositionForwarderWialon.java b/src/main/java/org/traccar/forward/PositionForwarderWialon.java index 3feef1d5aca..1331e7006cc 100644 --- a/src/main/java/org/traccar/forward/PositionForwarderWialon.java +++ b/src/main/java/org/traccar/forward/PositionForwarderWialon.java @@ -15,14 +15,11 @@ */ package org.traccar.forward; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import org.traccar.config.Config; import org.traccar.config.Keys; import org.traccar.helper.Checksum; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; -import org.json.JSONObject; import java.io.IOException; import java.net.DatagramPacket; @@ -34,6 +31,7 @@ import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Map; import java.util.TimeZone; import java.util.concurrent.ExecutorService; @@ -44,11 +42,9 @@ public class PositionForwarderWialon implements PositionForwarder { private final DatagramSocket socket; private final InetAddress address; private final int port; - private final ObjectMapper objectMapper; - public PositionForwarderWialon(Config config, ExecutorService executorService, String version, ObjectMapper objectMapper) { + public PositionForwarderWialon(Config config, ExecutorService executorService, String version) { this.version = version; - this.objectMapper = objectMapper; try { URI url = new URI(config.getString(Keys.FORWARD_URL)); address = InetAddress.getByName(url.getHost()); @@ -77,12 +73,7 @@ public void forward(PositionData positionData, ResultHandler resultHandler) { Position position = positionData.getPosition(); String uniqueId = positionData.getDevice().getUniqueId(); - String attributes = "NA"; - try { - attributes = convertJsonToWialonParams(objectMapper.writeValueAsString(position.getAttributes())); - } catch (JsonProcessingException e) { - resultHandler.onResult(false, e); - } + String attributes = convertJsonToWialonParams(position.getAttributes()); String payload = String.format( "%s;%02d%.5f;%s;%03d%.5f;%s;%d;%d;%d;NA;NA;NA;NA;;%s;%s", @@ -120,12 +111,11 @@ public void forward(PositionData positionData, ResultHandler resultHandler) { } } - public static String convertJsonToWialonParams(String jsonString) { - JSONObject jsonObject = new JSONObject(jsonString); + public static String convertJsonToWialonParams(Map attributes) { StringBuilder result = new StringBuilder(); - for (String key : jsonObject.keySet()) { - Object value = jsonObject.get(key); + for (String key : attributes.keySet()) { + Object value = attributes.get(key); String type; if (value instanceof Integer || value instanceof Long) { From 5fb09612b0efdf268575907d61b5c879afb50de4 Mon Sep 17 00:00:00 2001 From: Kirill Loshmanov Date: Fri, 18 Oct 2024 12:45:59 +0700 Subject: [PATCH 06/12] Add attributes to Wialon forwarder --- .../forward/PositionForwarderWialon.java | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/traccar/forward/PositionForwarderWialon.java b/src/main/java/org/traccar/forward/PositionForwarderWialon.java index 1331e7006cc..1c987a83e22 100644 --- a/src/main/java/org/traccar/forward/PositionForwarderWialon.java +++ b/src/main/java/org/traccar/forward/PositionForwarderWialon.java @@ -34,6 +34,7 @@ import java.util.Map; import java.util.TimeZone; import java.util.concurrent.ExecutorService; +import java.util.stream.Collectors; public class PositionForwarderWialon implements PositionForwarder { @@ -73,7 +74,6 @@ public void forward(PositionData positionData, ResultHandler resultHandler) { Position position = positionData.getPosition(); String uniqueId = positionData.getDevice().getUniqueId(); - String attributes = convertJsonToWialonParams(position.getAttributes()); String payload = String.format( "%s;%02d%.5f;%s;%03d%.5f;%s;%d;%d;%d;NA;NA;NA;NA;;%s;%s", @@ -88,7 +88,7 @@ public void forward(PositionData positionData, ResultHandler resultHandler) { (int) position.getCourse(), (int) position.getAltitude(), position.getString(Position.KEY_DRIVER_UNIQUE_ID, "NA"), - attributes); + formatAttributes(position.getAttributes(), "NA")); String message; if (version.startsWith("2")) { @@ -111,28 +111,22 @@ public void forward(PositionData positionData, ResultHandler resultHandler) { } } - public static String convertJsonToWialonParams(Map attributes) { - StringBuilder result = new StringBuilder(); - - for (String key : attributes.keySet()) { - Object value = attributes.get(key); - String type; - - if (value instanceof Integer || value instanceof Long) { - type = "1"; - } else if (value instanceof Double || value instanceof Float) { - type = "2"; - } else { - type = "3"; - } - - if (!result.isEmpty()) { - result.append(","); - } - result.append(key).append(":").append(type).append(":").append(value.toString()); + public static String formatAttributes(Map attributes, String defaultValue) { + if (attributes.isEmpty()) { + return defaultValue; } - return result.toString(); + return attributes.entrySet().stream() + .map(entry -> { + String key = entry.getKey(); + Object value = entry.getValue(); + + String type = (value instanceof Integer || value instanceof Long) ? "1" : + (value instanceof Double || value instanceof Float) ? "2" : "3"; + + return key + ":" + type + ":" + value.toString(); + }) + .collect(Collectors.joining(",")); } } From bba66a2c306bd7282f5e6d81634f24e6fb3e2c26 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 19 Oct 2024 15:18:48 -0700 Subject: [PATCH 07/12] Device time for engine hours --- src/main/java/org/traccar/handler/EngineHoursHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/handler/EngineHoursHandler.java b/src/main/java/org/traccar/handler/EngineHoursHandler.java index e2d8d580ab4..52d6edf635d 100644 --- a/src/main/java/org/traccar/handler/EngineHoursHandler.java +++ b/src/main/java/org/traccar/handler/EngineHoursHandler.java @@ -36,7 +36,7 @@ public void onPosition(Position position, Callback callback) { if (last != null) { long hours = last.getLong(Position.KEY_HOURS); if (last.getBoolean(Position.KEY_IGNITION) && position.getBoolean(Position.KEY_IGNITION)) { - hours += position.getFixTime().getTime() - last.getFixTime().getTime(); + hours += position.getDeviceTime().getTime() - last.getDeviceTime().getTime(); } if (hours != 0) { position.set(Position.KEY_HOURS, hours); From d41a92fb059f5ce6f9aba37f1a733652d833aca9 Mon Sep 17 00:00:00 2001 From: Kirill Loshmanov Date: Mon, 21 Oct 2024 09:28:14 +0700 Subject: [PATCH 08/12] Add attributes to Wialon forwarder --- .../org/traccar/forward/PositionForwarderWialon.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/traccar/forward/PositionForwarderWialon.java b/src/main/java/org/traccar/forward/PositionForwarderWialon.java index 1c987a83e22..b111e065e1c 100644 --- a/src/main/java/org/traccar/forward/PositionForwarderWialon.java +++ b/src/main/java/org/traccar/forward/PositionForwarderWialon.java @@ -121,8 +121,14 @@ public static String formatAttributes(Map attributes, String def String key = entry.getKey(); Object value = entry.getValue(); - String type = (value instanceof Integer || value instanceof Long) ? "1" : - (value instanceof Double || value instanceof Float) ? "2" : "3"; + String type; + if (value instanceof Integer || value instanceof Long) { + type = "1"; + } else if (value instanceof Double || value instanceof Float) { + type = "2"; + } else { + type = "3"; + } return key + ":" + type + ":" + value.toString(); }) From 94d6750fdd4bfdf0e254537901d1398a3ca7fbe0 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 20 Oct 2024 21:43:22 -0700 Subject: [PATCH 09/12] Simplify attribute formatting --- .../forward/PositionForwarderWialon.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/traccar/forward/PositionForwarderWialon.java b/src/main/java/org/traccar/forward/PositionForwarderWialon.java index b111e065e1c..d4d93469421 100644 --- a/src/main/java/org/traccar/forward/PositionForwarderWialon.java +++ b/src/main/java/org/traccar/forward/PositionForwarderWialon.java @@ -88,7 +88,7 @@ public void forward(PositionData positionData, ResultHandler resultHandler) { (int) position.getCourse(), (int) position.getAltitude(), position.getString(Position.KEY_DRIVER_UNIQUE_ID, "NA"), - formatAttributes(position.getAttributes(), "NA")); + formatAttributes(position.getAttributes())); String message; if (version.startsWith("2")) { @@ -111,26 +111,22 @@ public void forward(PositionData positionData, ResultHandler resultHandler) { } } - public static String formatAttributes(Map attributes, String defaultValue) { + public static String formatAttributes(Map attributes) { if (attributes.isEmpty()) { - return defaultValue; + return "NA"; } - return attributes.entrySet().stream() .map(entry -> { - String key = entry.getKey(); Object value = entry.getValue(); - - String type; - if (value instanceof Integer || value instanceof Long) { - type = "1"; - } else if (value instanceof Double || value instanceof Float) { - type = "2"; + int type; + if (value instanceof Double || value instanceof Float) { + type = 2; + } else if (value instanceof Number) { + type = 1; } else { - type = "3"; + type = 3; } - - return key + ":" + type + ":" + value.toString(); + return entry.getKey() + ":" + type + ":" + value; }) .collect(Collectors.joining(",")); } From d941f59205c8c1bdc44f08f57525da1fa003b085 Mon Sep 17 00:00:00 2001 From: Axel Rieben <26045532+AxelRieben@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:53:00 +0200 Subject: [PATCH 10/12] No longer make the httpOnly attribute of the session cookie configurable --- src/main/java/org/traccar/config/Keys.java | 8 -------- src/main/java/org/traccar/web/WebServer.java | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 08e35b4ec78..3da49207eea 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -843,14 +843,6 @@ private Keys() { List.of(KeyType.CONFIG), "max-age=3600,public"); - /** - * Set HttpOnly attribut to the session cookie. - */ - public static final ConfigKey WEB_COOKIE_HTTP_ONLY = new BooleanConfigKey( - "web.cookieHttpOnly", - List.of(KeyType.CONFIG), - false); - /** * Enable TOTP authentication on the server. */ diff --git a/src/main/java/org/traccar/web/WebServer.java b/src/main/java/org/traccar/web/WebServer.java index aa8bf52d72a..1101a5e9ebe 100644 --- a/src/main/java/org/traccar/web/WebServer.java +++ b/src/main/java/org/traccar/web/WebServer.java @@ -218,7 +218,7 @@ private void initSessionConfig(ServletContextHandler servletHandler) { } } - sessionCookieConfig.setHttpOnly(config.getBoolean(Keys.WEB_COOKIE_HTTP_ONLY)); + sessionCookieConfig.setHttpOnly(true); } @Override From 6438d1ac275affea06b4c39f78db18820d40306e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 26 Oct 2024 10:39:21 -0700 Subject: [PATCH 11/12] Add unit test case --- .../java/org/traccar/protocol/Tr20ProtocolDecoderTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/org/traccar/protocol/Tr20ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Tr20ProtocolDecoderTest.java index 1323691c614..1cb04e37633 100644 --- a/src/test/java/org/traccar/protocol/Tr20ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Tr20ProtocolDecoderTest.java @@ -10,6 +10,9 @@ public void testDecode() throws Exception { var decoder = inject(new Tr20ProtocolDecoder(null)); + verifyPosition(decoder, text( + "%%0561,A,241025160359,N0951.6626W08357.0266,000,025,F0.0,00020000,108,CFG:0.12|")); + verifyPosition(decoder, text( "%%m13,L,221221103115,N1237.2271W00801.9500,000,000,B13.1:F0.0,04020000,253,CFG:133.00|")); From 77e3ac08289679d3f77f92fb73aaec5799c43fe9 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 26 Oct 2024 11:17:40 -0700 Subject: [PATCH 12/12] Jimi IoT VL842 support --- .../traccar/protocol/Gt06ProtocolDecoder.java | 42 +++++++++++++++++-- .../protocol/Gt06ProtocolDecoderTest.java | 6 +++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index 16b9889e6df..300805140c0 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -113,6 +113,7 @@ public Gt06ProtocolDecoder(Protocol protocol) { public static final int MSG_BMS = 0x40; // WD-209 public static final int MSG_MULTIMEDIA = 0x41; // WD-209 public static final int MSG_ALARM = 0x95; // JC100 + public static final int MSG_PERIPHERAL = 0xF2; // VL842 private enum Variant { VXT01, @@ -1371,8 +1372,6 @@ private Object decodeExtended(Channel channel, SocketAddress remoteAddress, Byte if (photo != null) { buf.readBytes(photo, buf.readableBytes() - 3 * 2); if (!photo.isWritable()) { - position = new Position(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); getLastLocation(position, new Date(timestamp)); position.set(Position.KEY_IMAGE, writeMediaFile(deviceSession.getUniqueId(), photo, "jpg")); photos.remove(mediaId).release(); @@ -1387,8 +1386,6 @@ private Object decodeExtended(Channel channel, SocketAddress remoteAddress, Byte } else if (type == MSG_SERIAL) { - position = new Position(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); getLastLocation(position, null); buf.readUnsignedByte(); // external device type code @@ -1403,6 +1400,43 @@ private Object decodeExtended(Channel channel, SocketAddress remoteAddress, Byte return position; + } else if (type == MSG_PERIPHERAL) { + + long timestamp = buf.readUnsignedInt() * 1000; + getLastLocation(position, new Date(timestamp)); + + while (buf.readableBytes() > 6) { + int statusId = buf.readUnsignedShort(); + switch (statusId) { + case 0x000A -> { + int statusLength = buf.readUnsignedShort(); + buf.readUnsignedByte(); // mac address type + position.set("mac", ByteBufUtil.hexDump(buf.readSlice(6))); + int event = buf.readUnsignedByte(); + position.set(Position.KEY_EVENT, event); + int eventData = buf.readUnsignedByte(); + position.set("eventData", event > 0 ? eventData : null); + position.set("dataType", buf.readUnsignedByte()); + position.set("dataDetails", ByteBufUtil.hexDump(buf.readSlice(statusLength - 10))); + } + case 0x000C -> { + buf.readUnsignedByte(); // length + position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); + position.set(Position.KEY_CHARGE, buf.readUnsignedByte() > 0 ? true : null); + position.set("batteryCycles", buf.readUnsignedShort()); + buf.skipBytes(6); + } + default -> { + int statusLength = buf.readUnsignedByte(); + buf.skipBytes(statusLength == 0 ? buf.readUnsignedByte() : statusLength); + } + } + } + + sendResponse(channel, false, type, buf.getShort(buf.writerIndex() - 6), null); + + return position; + } return null; diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 6d949c237a3..e42e6785a5d 100644 --- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -17,6 +17,12 @@ public void testDecode() throws Exception { verifyNull(decoder, binary( "78780D01086471700328358100093F040D0A")); + verifyAttributes(decoder, binary( + "79790016f26718e430000c0a470000000010020000000024bff50d0a")); + + verifyAttributes(decoder, binary( + "79790037f26718e389000b0a0423027aca200c465a60000a001d01c4a82828ccfe0000024254425554544f4e2c412c53233136382c35340016a1eb0d0a")); + verifyAttribute(decoder, binary( "7878131340b2fa000201040000000000011c00400e550d0a"), Position.PREFIX_TEMP + 1, 28.4);