From c5f56b4cb29c7b780394166c971ae9767d6bab89 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 6 Sep 2024 06:43:58 -0700 Subject: [PATCH] Fix Wialon 2.0 UDP decoding --- .../org/traccar/protocol/WialonProtocolDecoder.java | 10 +++++++--- .../traccar/protocol/WialonProtocolDecoderTest.java | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java b/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java index 4d1b34dba..491c5b4dd 100644 --- a/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2022 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 2024 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. @@ -39,6 +39,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern PATTERN_ANY = new PatternBuilder() + .number("d.d;").optional() .expression("([^#]+)?") // imei .text("#") // start byte .expression("([^#]+)") // type @@ -175,12 +176,15 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { String type = parser.next(); String data = parser.next(); + DeviceSession deviceSession; + Position position; + switch (type) { case "L": String[] values = data.split(";"); String imei = values[0].indexOf('.') >= 0 ? values[1] : values[0]; - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); + deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession != null) { sendResponse(channel, remoteAddress, type, 1); } @@ -192,7 +196,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { case "D": case "SD": - Position position = decodePosition(channel, remoteAddress, id, data); + position = decodePosition(channel, remoteAddress, id, data); if (position != null) { sendResponse(channel, remoteAddress, "D", 1); return position; diff --git a/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java index b7c422456..eac3f8aec 100644 --- a/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/WialonProtocolDecoderTest.java @@ -36,7 +36,7 @@ public class WialonProtocolDecoderTest extends ProtocolTest { "#D#101118;061143;0756.0930;N;12338.6403;E;18.223;99.766;-4.000;10;0.800;NA;NA;NA;NA;101_521347:1:521249,101_521126:1:6593598,101_521127:1:774780,101_521072_21.1:1:0,101_521072_21.2:1:71353;F24A")); verifyPosition(decoder, text( - "99999999#D#101118;061143;0756.0930;N;12338.6403;E;18.223;99.766;-4.000;10;0.800;NA;NA;NA;NA;101_521347:1:521249,101_521126:1:6593598,101_521127:1:774780,101_521072_21.1:1:0,101_521072_21.2:1:71353;F24A")); + "2.0;99999999#D#101118;061143;0756.0930;N;12338.6403;E;18.223;99.766;-4.000;10;0.800;NA;NA;NA;NA;101_521347:1:521249,101_521126:1:6593598,101_521127:1:774780,101_521072_21.1:1:0,101_521072_21.2:1:71353;F24A")); verifyPosition(decoder, text( "#D#151216;135910;5321.1466;N;04441.7929;E;87;156;265.000000;12;1.000000;241;NA;NA;NA;odo:2:0.000000,total_fuel:1:430087,can_fls:1:201,can_taho:1:11623,can_mileage:1:140367515")); @@ -82,6 +82,7 @@ public class WialonProtocolDecoderTest extends ProtocolTest { verifyAttribute(decoder, text( "#D#120319;112003;NA;NA;NA;NA;0.000;NA;NA;0;NA;NA;NA;NA;NA;motion:3:false"), "motion", false); + } }