From 2005fd55347816cf4a86b66ae97bc245f53f0bcd Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 6 Jul 2024 19:47:06 -0700 Subject: Update switch statements --- .../org/traccar/protocol/H02ProtocolDecoder.java | 35 ++++++++++------------ 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'src/main/java/org/traccar/protocol/H02ProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java b/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java index 2ad4f644b..38c063b52 100644 --- a/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java @@ -598,7 +598,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { String marker = buf.toString(0, 1, StandardCharsets.US_ASCII); switch (marker) { - case "*": + case "*" -> { String sentence = buf.toString(StandardCharsets.US_ASCII).trim(); int typeStart = sentence.indexOf(',', sentence.indexOf(',') + 1) + 1; int typeEnd = sentence.indexOf(',', typeStart); @@ -607,33 +607,30 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { } if (typeEnd > 0) { String type = sentence.substring(typeStart, typeEnd); - switch (type) { - case "V0": - case "HTBT": + return switch (type) { + case "V0", "HTBT" -> { if (channel != null) { String response = sentence.substring(0, typeEnd) + "#"; channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } - return decodeHeartbeat(sentence, channel, remoteAddress); - case "NBR": - return decodeLbs(sentence, channel, remoteAddress); - case "LINK": - return decodeLink(sentence, channel, remoteAddress); - case "V3": - return decodeV3(sentence, channel, remoteAddress); - case "VP1": - return decodeVp1(sentence, channel, remoteAddress); - default: - return decodeText(sentence, channel, remoteAddress); - } + yield decodeHeartbeat(sentence, channel, remoteAddress); + } + case "NBR" -> decodeLbs(sentence, channel, remoteAddress); + case "LINK" -> decodeLink(sentence, channel, remoteAddress); + case "V3" -> decodeV3(sentence, channel, remoteAddress); + case "VP1" -> decodeVp1(sentence, channel, remoteAddress); + default -> decodeText(sentence, channel, remoteAddress); + }; } else { return null; } - case "$": + } + case "$" -> { return decodeBinary(buf, channel, remoteAddress); - case "X": - default: + } + default -> { return null; + } } } -- cgit v1.2.3 From 864872b2df3e26c94d3a5826f4df504de3cf6c62 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 7 Jul 2024 06:51:42 -0700 Subject: Invalid ST-901L-4G coordinates --- .../org/traccar/protocol/H02ProtocolDecoder.java | 20 ++++++++++++++------ .../org/traccar/protocol/H02ProtocolDecoderTest.java | 3 +++ 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'src/main/java/org/traccar/protocol/H02ProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java b/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java index 38c063b52..ed6460e97 100644 --- a/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java @@ -350,24 +350,32 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { position.setValid(true); } + double latitude = 0; if (parser.hasNext(3)) { - position.setLatitude(parser.nextCoordinate()); + latitude = parser.nextCoordinate(); } if (parser.hasNext(3)) { - position.setLatitude(parser.nextCoordinate()); + latitude = parser.nextCoordinate(); } if (parser.hasNext(4)) { - position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM)); + latitude = parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM); + } + if (latitude != 99 + 99.9999 / 60) { + position.setLatitude(latitude); } + double longitude = 0; if (parser.hasNext(3)) { - position.setLongitude(parser.nextCoordinate()); + longitude = parser.nextCoordinate(); } if (parser.hasNext(3)) { - position.setLongitude(parser.nextCoordinate()); + longitude = parser.nextCoordinate(); } if (parser.hasNext(4)) { - position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM)); + longitude = parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM); + } + if (longitude != 999 + 99.9999 / 60) { + position.setLongitude(longitude); } position.setSpeed(parser.nextDouble(0)); diff --git a/src/test/java/org/traccar/protocol/H02ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/H02ProtocolDecoderTest.java index a63488960..05a362cb0 100644 --- a/src/test/java/org/traccar/protocol/H02ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/H02ProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class H02ProtocolDecoderTest extends ProtocolTest { var decoder = inject(new H02ProtocolDecoder(null)); + verifyPosition(decoder, buffer( + "*HQ,8888888888,V1,083600,V,9999.9999,N,99999.9999,E,000.00,000,070724,FFFFDFFF,231,03,10,196354#")); + verifyPosition(decoder, buffer( "*HQ,3177718238,V6,002926,V,3514.4088,N,9733.2842,W,0.00,0.00,151222,FFF7FBFF,310,260,32936,13641,8944501311217563382F,#")); -- cgit v1.2.3 From b48e4a456f0e44a91d563a8d5b42295e131ebdaf Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 8 Jul 2024 05:44:23 -0700 Subject: Revert "Invalid ST-901L-4G coordinates" This reverts commit 864872b2df3e26c94d3a5826f4df504de3cf6c62. --- .../org/traccar/protocol/H02ProtocolDecoder.java | 20 ++++++-------------- .../org/traccar/protocol/H02ProtocolDecoderTest.java | 3 --- 2 files changed, 6 insertions(+), 17 deletions(-) (limited to 'src/main/java/org/traccar/protocol/H02ProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java b/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java index ed6460e97..38c063b52 100644 --- a/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java @@ -350,32 +350,24 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { position.setValid(true); } - double latitude = 0; if (parser.hasNext(3)) { - latitude = parser.nextCoordinate(); + position.setLatitude(parser.nextCoordinate()); } if (parser.hasNext(3)) { - latitude = parser.nextCoordinate(); + position.setLatitude(parser.nextCoordinate()); } if (parser.hasNext(4)) { - latitude = parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM); - } - if (latitude != 99 + 99.9999 / 60) { - position.setLatitude(latitude); + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM)); } - double longitude = 0; if (parser.hasNext(3)) { - longitude = parser.nextCoordinate(); + position.setLongitude(parser.nextCoordinate()); } if (parser.hasNext(3)) { - longitude = parser.nextCoordinate(); + position.setLongitude(parser.nextCoordinate()); } if (parser.hasNext(4)) { - longitude = parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM); - } - if (longitude != 999 + 99.9999 / 60) { - position.setLongitude(longitude); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM)); } position.setSpeed(parser.nextDouble(0)); diff --git a/src/test/java/org/traccar/protocol/H02ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/H02ProtocolDecoderTest.java index 05a362cb0..a63488960 100644 --- a/src/test/java/org/traccar/protocol/H02ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/H02ProtocolDecoderTest.java @@ -11,9 +11,6 @@ public class H02ProtocolDecoderTest extends ProtocolTest { var decoder = inject(new H02ProtocolDecoder(null)); - verifyPosition(decoder, buffer( - "*HQ,8888888888,V1,083600,V,9999.9999,N,99999.9999,E,000.00,000,070724,FFFFDFFF,231,03,10,196354#")); - verifyPosition(decoder, buffer( "*HQ,3177718238,V6,002926,V,3514.4088,N,9733.2842,W,0.00,0.00,151222,FFF7FBFF,310,260,32936,13641,8944501311217563382F,#")); -- cgit v1.2.3