From bba38f9078a1c1455730daf80d76587cf21228cc Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 17 Jul 2019 08:14:43 -0700 Subject: Fix event decoding --- src/main/java/org/traccar/protocol/GoSafeProtocolDecoder.java | 4 ++-- src/test/java/org/traccar/protocol/GoSafeProtocolDecoderTest.java | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/main/java/org/traccar/protocol/GoSafeProtocolDecoder.java index 8164a016d..c4b29850d 100644 --- a/src/main/java/org/traccar/protocol/GoSafeProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GoSafeProtocolDecoder.java @@ -184,8 +184,8 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { for (; index < fragments.length; index += 1) { if (!fragments[index].isEmpty()) { - if (Character.isDigit(fragments[index].charAt(0))) { - position.set(Position.KEY_EVENT, Integer.parseInt(fragments[index])); + if (fragments[index].matches("\\p{XDigit}+")) { + position.set(Position.KEY_EVENT, Integer.parseInt(fragments[index], 16)); } else { decodeFragment(position, fragments[index]); } diff --git a/src/test/java/org/traccar/protocol/GoSafeProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/GoSafeProtocolDecoderTest.java index 4fbfa6fc1..9a3f61274 100644 --- a/src/test/java/org/traccar/protocol/GoSafeProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/GoSafeProtocolDecoderTest.java @@ -2,6 +2,7 @@ package org.traccar.protocol; import org.junit.Test; import org.traccar.ProtocolTest; +import org.traccar.model.Position; public class GoSafeProtocolDecoderTest extends ProtocolTest { @@ -10,8 +11,9 @@ public class GoSafeProtocolDecoderTest extends ProtocolTest { GoSafeProtocolDecoder decoder = new GoSafeProtocolDecoder(null); - verifyPositions(decoder, text( - "*GS06,860078024206844,075029250619,,SYS:G3SC;V3.37;V1.1.8,GPS:A;10;N3.009522;E101.512320;5;137;31;0.69,COT:27376703,ADC:25.81;4.28;2.60,DTT:5004;E1;0;0;0;3$075031250619,,SYS:G3SC;V3.37;V1.1.8,GPS:A;9;N3.009488;E101.512344;6;145;31;0.76,COT:27376703,ADC:25.58;4.25;2.28,DTT:5004;E1;0;0;0;3$075033250619,,SYS:G3SC;V3.37;V1.1.8,GPS:A;10;N3.009459;E101.512360;5;152;31;0.69,COT:27376722,ADC:25.78;4.29;2.30,DTT:5004;E1;0;0;0;3#")); + verifyAttribute(decoder, text( + "*GS06,359568052580548,091946150719,1C,SYS:G3C;V1.40;V1.0.4,GPS:A;5;S25.750200;E28.204858;0;0;1337;1.68,COT:,ADC:13.12;4.06,DTT:4004;C6;0;0;10000000;0$091948150719,,SYS:G3C;V1.40;V1.0.4,GPS:A;5;S25.750200;E28.204858;0;0;1337;1.68,COT:,ADC:12.96;4.06,DTT:4004;C6;0;0;0;1#"), + Position.KEY_EVENT, 0x1C); verifyPositions(decoder, text( "*GS06,860078024226974,101437211218,,SYS:G3SC;V3.36;V1.1.8,GPS:A;7;N3.052302;E101.787216;16;137;48;1.58,COT:4261733103,ADC:22.86;0.58;0.01,DTT:4004;E1;0;0;0;3$101439211218,,SYS:G3SC;V3.36;V1.1.8,GPS:A;8;N3.052265;E101.787200;12;152;46;1.31,COT:4261733103,ADC:22.98;0.58;0.01,DTT:4004;E1;0;0;0;3$101441211218,,SYS:G3SC;V3.36;V1.1.8,GPS:A;8;N3.052247;E101.787232;8;131;46;1.34,COT:4261733103,ADC:23.13;0.58;0.01,DTT:4004;E1;0;0;0;3$101510211218,,SYS:G3SC;V3.36;V1.1.8,GPS:A;8;N3.052150;E101.787152;0;131;40;0.97,COT:4261733160,ADC:22.88;0.58;0.01,DTT:4000;E1;0;0;0;1$101540211218,,SYS:G3SC;V3.36;V1.1.8,GPS:A;7;N3.052150;E101.787152;0;131;40;0.97,COT:4261733160,ADC:22.91;0.58;0.00,DTT:4000;E1;0;0;0;1#")); -- cgit v1.2.3