From e5c21c80df6310ea29209dc037ba82be5fbf441e Mon Sep 17 00:00:00 2001 From: Sanjeewa Vithanage Date: Fri, 26 Jan 2024 17:03:02 +0200 Subject: analog input voltage decode --- src/main/java/org/traccar/protocol/UproProtocolDecoder.java | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java index ed714e464..debb85365 100644 --- a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java @@ -310,6 +310,11 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { position.set("serial", data.toString(StandardCharsets.US_ASCII).substring(3)); } break; + case 'd': + if (data.readableBytes() > 3) { + position.set(Position.PREFIX_ADC + 1, Integer.parseInt(data.readSlice(5).toString(StandardCharsets.US_ASCII)) * 0.01); + } + break; default: break; } -- cgit v1.2.3 From b82bacce74f38d34cbf16749ca23961eb0f8a919 Mon Sep 17 00:00:00 2001 From: Sanjeewa Vithanage Date: Fri, 26 Jan 2024 17:32:50 +0200 Subject: Line wrapper --- src/main/java/org/traccar/protocol/UproProtocolDecoder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java index debb85365..2f88d803c 100644 --- a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java @@ -312,7 +312,8 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { break; case 'd': if (data.readableBytes() > 3) { - position.set(Position.PREFIX_ADC + 1, Integer.parseInt(data.readSlice(5).toString(StandardCharsets.US_ASCII)) * 0.01); + position.set(Position.PREFIX_ADC + 1, Integer.parseInt(data.readSlice(5). + toString(StandardCharsets.US_ASCII)) * 0.01); } break; default: -- cgit v1.2.3 From 2f49889aa496524b298f764e18f8016e74efab87 Mon Sep 17 00:00:00 2001 From: Sanjeewa Vithanage Date: Sun, 28 Jan 2024 09:28:34 +0200 Subject: fixed with unwanted decimal points ("adc1":12.870000000000001) --- src/main/java/org/traccar/protocol/UproProtocolDecoder.java | 6 ++---- src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java index 2f88d803c..1167f568c 100644 --- a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java @@ -311,10 +311,8 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { } break; case 'd': - if (data.readableBytes() > 3) { - position.set(Position.PREFIX_ADC + 1, Integer.parseInt(data.readSlice(5). - toString(StandardCharsets.US_ASCII)) * 0.01); - } + position.set(Position.PREFIX_ADC + 1, Integer.parseInt(data. + toString(StandardCharsets.US_ASCII))/100.0); break; default: break; diff --git a/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java index ca2944c04..f070c6201 100644 --- a/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java @@ -87,6 +87,10 @@ public class UproProtocolDecoderTest extends ProtocolTest { "*HQ200862312328000001,AD1&A1520441548253003503696640017270124&B0000000000&C00000117&F0000&R2118&N01&V0125&X(J01E0)&K00300&Z000&d01286"), Position.PREFIX_ADC + 1, 12.86); + verifyAttribute(decoder, buffer( + "*HQ200862312328000001,BA&A1520461548253003503696640017270124&B0000000000&C00000117&F0000&R2218&N01&V0125&X(J01E0)&K00300&Z000&d01287"), + Position.PREFIX_ADC + 1, 12.87); + } } -- cgit v1.2.3 From 04a99c14fc2840f78e988d66c150807abae8bf79 Mon Sep 17 00:00:00 2001 From: Sanjeewa Vithanage Date: Mon, 29 Jan 2024 12:11:02 +0200 Subject: fix styling --- src/main/java/org/traccar/protocol/UproProtocolDecoder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java index 1167f568c..915f5adfe 100644 --- a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java @@ -311,8 +311,8 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { } break; case 'd': - position.set(Position.PREFIX_ADC + 1, Integer.parseInt(data. - toString(StandardCharsets.US_ASCII))/100.0); + position.set(Position.PREFIX_ADC + 1, + (Integer.parseInt(data.toString(StandardCharsets.US_ASCII)) / 100.0)); break; default: break; -- cgit v1.2.3