From bf3770fad4ceb7aeab4f1e686c3a49f3b1aa1592 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 3 Jun 2024 07:27:30 -0700 Subject: Decode beacon battery data --- src/test/java/org/traccar/protocol/TeltonikaProtocolDecoderTest.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/test/java/org') diff --git a/src/test/java/org/traccar/protocol/TeltonikaProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/TeltonikaProtocolDecoderTest.java index 2a8ff87b6..d8e480f25 100644 --- a/src/test/java/org/traccar/protocol/TeltonikaProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/TeltonikaProtocolDecoderTest.java @@ -15,6 +15,10 @@ public class TeltonikaProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "000F313233343536373839303132333435")); + verifyAttribute(decoder, binary( + "00000000000000768e010000018fdc4b27cb015b3e33ceefa529030009013f0e0000022400010000000000000000000102240049010f0001c60106babbf36300550202806d0f0001ca01063456555565690202806b0f0001d10106467975425450020280690b0001c90106fa54ba8d00550b0001cf0106cabbf36300550100005455"), + "tag1Voltage", 3090); + verifyPositions(decoder, binary( "00000000000000728e010000018b23dd796300fbf7263c24f9e11a0000000000000002240001000000000000000000010224004501210001e50110cde39f7e42bb55aa788e4a29ed650055020ab70a8f264c6000ffff6b210001b00110f89b907e42bb55aaa3463b29ed650055020ab708bb2600ae0500096c01000051d4")); -- cgit v1.2.3 From 5fe720929ba2ab9928bb6fa950f369ce85451698 Mon Sep 17 00:00:00 2001 From: jcardus Date: Tue, 11 Jun 2024 03:23:33 +0100 Subject: Update Gl200TextProtocolDecoderTest.java --- .../java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/test/java/org') diff --git a/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java index 925a0da1c..b208f13b6 100644 --- a/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java @@ -513,6 +513,12 @@ public class Gl200TextProtocolDecoderTest extends ProtocolTest { verifyAttributes(decoder, buffer( "+RESP:GTCAN,8020050605,867488060270575,,00,1,FFFFFFFF,8LBETF3W4N0001613,,,22.54,0,,,,,,,7.84,4.61,3.24,3.33,,8080,,,00,0.00,0.00,1,14,14,2371,0,001FFFFF,,,,,,,,,7158,9998,0,7.84,0.00,0.00,558,,,,,,,C0,,,,,0,0.0,346,2848.5,-78.592371,-0.968132,20240202083437,0740,0002,526C,00AE7907,00,20240202083440,3F6D$")); + verifyAttribute(decoder, buffer( + "+BUFF:GTIGN,6E0202,868589060169789,ra79,379,1,0.0,105,532.2,-70.616413,-33.393457,20240610201712,0730,0001,333A,00CFA301,01,11,,0.0,20240610201713,3AE2$"), + Position.KEY_IGNITION, true); + verifyAttribute(decoder, buffer( + "+RESP:GTIGF,6E0202,868589060169789,ra79,145,1,0.0,83,532.2,-70.616413,-33.393457,20240610201937,0730,0001,333A,00CFA301,01,12,,0.0,20240610201938,3AE9$"), + Position.KEY_IGNITION, false); } } -- cgit v1.2.3 From 4f01875e3f48510427dabca966eb35c18ec33004 Mon Sep 17 00:00:00 2001 From: jcardus Date: Tue, 11 Jun 2024 04:42:41 +0100 Subject: Update Gl200TextProtocolDecoderTest.java fix formatting --- src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/test/java/org') diff --git a/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java index b208f13b6..406a447ab 100644 --- a/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java @@ -514,10 +514,11 @@ public class Gl200TextProtocolDecoderTest extends ProtocolTest { "+RESP:GTCAN,8020050605,867488060270575,,00,1,FFFFFFFF,8LBETF3W4N0001613,,,22.54,0,,,,,,,7.84,4.61,3.24,3.33,,8080,,,00,0.00,0.00,1,14,14,2371,0,001FFFFF,,,,,,,,,7158,9998,0,7.84,0.00,0.00,558,,,,,,,C0,,,,,0,0.0,346,2848.5,-78.592371,-0.968132,20240202083437,0740,0002,526C,00AE7907,00,20240202083440,3F6D$")); verifyAttribute(decoder, buffer( - "+BUFF:GTIGN,6E0202,868589060169789,ra79,379,1,0.0,105,532.2,-70.616413,-33.393457,20240610201712,0730,0001,333A,00CFA301,01,11,,0.0,20240610201713,3AE2$"), + "+BUFF:GTIGN,6E0202,868589060169789,ra79,379,1,0.0,105,532.2,-70.616413,-33.393457,20240610201712,0730,0001,333A,00CFA301,01,11,,0.0,20240610201713,3AE2$"), Position.KEY_IGNITION, true); + verifyAttribute(decoder, buffer( - "+RESP:GTIGF,6E0202,868589060169789,ra79,145,1,0.0,83,532.2,-70.616413,-33.393457,20240610201937,0730,0001,333A,00CFA301,01,12,,0.0,20240610201938,3AE9$"), + "+RESP:GTIGF,6E0202,868589060169789,ra79,145,1,0.0,83,532.2,-70.616413,-33.393457,20240610201937,0730,0001,333A,00CFA301,01,12,,0.0,20240610201938,3AE9$"), Position.KEY_IGNITION, false); } -- cgit v1.2.3 From bc65eb120807b7c899d3fd95fbb6684934bfa3ef Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 15 Jun 2024 06:53:13 -0700 Subject: Support GT06 RFID card --- src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java | 13 ++++++++++++- .../java/org/traccar/protocol/Gt06ProtocolDecoderTest.java | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index a1a9c3773..0c23f42d3 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -65,6 +65,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_STRING = 0x15; public static final int MSG_GPS_LBS_STATUS_1 = 0x16; public static final int MSG_WIFI = 0x17; + public static final int MSG_GPS_LBS_RFID = 0x17; public static final int MSG_GPS_LBS_STATUS_2 = 0x26; public static final int MSG_GPS_LBS_STATUS_3 = 0x27; public static final int MSG_LBS_MULTIPLE_1 = 0x28; @@ -125,6 +126,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { JC400, SL4X, SEEWORLD, + RFID, } private Variant variant; @@ -175,6 +177,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { case MSG_GPS_PHONE: case MSG_GPS_LBS_EXTEND: case MSG_GPS_LBS_7: + case MSG_GPS_LBS_RFID: case MSG_FENCE_SINGLE: case MSG_FENCE_MULTI: return true; @@ -197,6 +200,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { case MSG_GPS_LBS_STATUS_3: case MSG_GPS_LBS_STATUS_4: case MSG_GPS_LBS_7: + case MSG_GPS_LBS_RFID: case MSG_FENCE_SINGLE: case MSG_FENCE_MULTI: case MSG_LBS_ALARM: @@ -602,7 +606,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return null; - } else if (type == MSG_WIFI || type == MSG_WIFI_2 || type == MSG_WIFI_4) { + } else if ((type == MSG_WIFI && variant != Variant.RFID) || type == MSG_WIFI_2 || type == MSG_WIFI_4) { ByteBuf time = buf.readSlice(6); DateBuilder dateBuilder = new DateBuilder() @@ -945,6 +949,11 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } } + if (type == MSG_GPS_LBS_RFID) { + buf.readUnsignedByte(); // validity + position.set(Position.KEY_DRIVER_UNIQUE_ID, ByteBufUtil.hexDump(buf.readSlice(8))); + } + if (buf.readableBytes() == 3 + 6 || buf.readableBytes() == 3 + 4 + 6) { position.set(Position.KEY_IGNITION, buf.readUnsignedByte() > 0); buf.readUnsignedByte(); // upload mode @@ -1492,6 +1501,8 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { variant = Variant.SEEWORLD; } else if (header == 0x7878 && type == MSG_GPS_LBS_STATUS_1 && length == 0x26) { variant = Variant.SEEWORLD; + } else if (header == 0x7878 && type == MSG_GPS_LBS_RFID && length == 0x28) { + variant = Variant.RFID; } else { variant = Variant.STANDARD; } diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 05a33cc72..962bcb5c8 100644 --- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -17,6 +17,10 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "78780D01086471700328358100093F040D0A")); + verifyAttribute(decoder, binary( + "7878281718060e021831c6026e8acc0c361b1000140001cc00286d000f4dbf0000012ca7e001000004b2630d0a"), + Position.KEY_DRIVER_UNIQUE_ID, "0000012ca7e00100"); + verifyAttribute(decoder, binary( "78782732180214123324ca0162bdf0041f45d900190b0a02d4000bc5270000ec025206040202005e07e10d0a"), Position.KEY_ALARM, Position.ALARM_POWER_CUT); -- cgit v1.2.3 From d4e4a4a00c04d2a848d1f1f8d58724202d578ea6 Mon Sep 17 00:00:00 2001 From: Matjaž Črnko Date: Sat, 15 Jun 2024 21:09:18 +0200 Subject: Photon Geocoder --- src/main/java/org/traccar/MainModule.java | 4 ++ .../java/org/traccar/geocoder/PhotonGeocoder.java | 75 ++++++++++++++++++++++ .../java/org/traccar/geocoder/GeocoderTest.java | 7 ++ 3 files changed, 86 insertions(+) create mode 100644 src/main/java/org/traccar/geocoder/PhotonGeocoder.java (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index 66238ab44..5df8015d9 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -68,6 +68,7 @@ import org.traccar.geocoder.OpenCageGeocoder; import org.traccar.geocoder.PositionStackGeocoder; import org.traccar.geocoder.PlusCodesGeocoder; import org.traccar.geocoder.TomTomGeocoder; +import org.traccar.geocoder.PhotonGeocoder; import org.traccar.geolocation.GeolocationProvider; import org.traccar.geolocation.GoogleGeolocationProvider; import org.traccar.geolocation.OpenCellIdGeolocationProvider; @@ -261,6 +262,9 @@ public class MainModule extends AbstractModule { case "geoapify": geocoder = new GeoapifyGeocoder(client, key, language, cacheSize, addressFormat); break; + case "photon": + geocoder = new PhotonGeocoder(client, url, key, language, cacheSize, addressFormat); + break; default: geocoder = new GoogleGeocoder(client, key, language, cacheSize, addressFormat); break; diff --git a/src/main/java/org/traccar/geocoder/PhotonGeocoder.java b/src/main/java/org/traccar/geocoder/PhotonGeocoder.java new file mode 100644 index 000000000..898c04afd --- /dev/null +++ b/src/main/java/org/traccar/geocoder/PhotonGeocoder.java @@ -0,0 +1,75 @@ +/* + * Copyright 2014 - 2024 Anton Tananaev (anton@traccar.org) + * Copyright 2024 - 2024 Matjaž Črnko (m.crnko@txt.i) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.geocoder; + +import jakarta.json.JsonArray; +import jakarta.json.JsonObject; +import jakarta.ws.rs.client.Client; + +public class PhotonGeocoder extends JsonGeocoder { + + private static String formatUrl(String url, String key, String language) { + if (url == null) { + url = "https://photon.komoot.io/reverse"; + } + url += "?lat=%f&lon=%f"; + if (language != null) { + url += "&lang=" + language; + } + return url; + } + + public PhotonGeocoder( + Client client, String url, String key, String language, int cacheSize, AddressFormat addressFormat) { + super(client, formatUrl(url, key, language), cacheSize, addressFormat); + } + + @Override + public Address parseAddress(JsonObject json) { + JsonArray features = json.getJsonArray("features"); + if (!features.isEmpty()) { + Address address = new Address(); + JsonObject properties = features.getJsonObject(0).getJsonObject("properties"); + + if (properties.containsKey("housenumber")) { + address.setHouse(properties.getString("housenumber")); + } + if (properties.containsKey("street")) { + address.setStreet(properties.getString("street")); + } + if (properties.containsKey("city")) { + address.setSettlement(properties.getString("city")); + } + if (properties.containsKey("district")) { + address.setState(properties.getString("district")); + } + if (properties.containsKey("state")) { + address.setState(properties.getString("state")); + } + if (properties.containsKey("countrycode")) { + address.setCountry(properties.getString("countrycode").toUpperCase()); + } + if (properties.containsKey("postcode")) { + address.setPostcode(properties.getString("postcode")); + } + + return address; + } + return null; + } + +} diff --git a/src/test/java/org/traccar/geocoder/GeocoderTest.java b/src/test/java/org/traccar/geocoder/GeocoderTest.java index ef2dd062d..e05477ac3 100644 --- a/src/test/java/org/traccar/geocoder/GeocoderTest.java +++ b/src/test/java/org/traccar/geocoder/GeocoderTest.java @@ -122,4 +122,11 @@ public class GeocoderTest { assertEquals("114 East 13th Street, New York, New York, US", address); } + @Disabled + @Test + public void testPhoton() { + Geocoder geocoder = new PhotonGeocoder(client, null, null, null, 0, new AddressFormat()); + String address = geocoder.getAddress(40.7337807, -73.9974401, null); + assertEquals("35 West 9th Street, New York, New York, US", address); + } } -- cgit v1.2.3 From 0530bdb6c644d67ed90231e902898e74532ef1b7 Mon Sep 17 00:00:00 2001 From: Matjaž Črnko Date: Mon, 17 Jun 2024 14:47:53 +0200 Subject: refactor: GeocodeJSON implementation and basing BanGeocoder on it. --- src/main/java/org/traccar/MainModule.java | 6 +- .../java/org/traccar/geocoder/BanGeocoder.java | 35 ++-------- .../org/traccar/geocoder/GeocodeJSONGeocoder.java | 81 ++++++++++++++++++++++ .../java/org/traccar/geocoder/PhotonGeocoder.java | 78 --------------------- .../java/org/traccar/geocoder/GeocoderTest.java | 8 +-- 5 files changed, 94 insertions(+), 114 deletions(-) create mode 100644 src/main/java/org/traccar/geocoder/GeocodeJSONGeocoder.java delete mode 100644 src/main/java/org/traccar/geocoder/PhotonGeocoder.java (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index 5df8015d9..2b345847f 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -68,7 +68,7 @@ import org.traccar.geocoder.OpenCageGeocoder; import org.traccar.geocoder.PositionStackGeocoder; import org.traccar.geocoder.PlusCodesGeocoder; import org.traccar.geocoder.TomTomGeocoder; -import org.traccar.geocoder.PhotonGeocoder; +import org.traccar.geocoder.GeocodeJSONGeocoder; import org.traccar.geolocation.GeolocationProvider; import org.traccar.geolocation.GoogleGeolocationProvider; import org.traccar.geolocation.OpenCellIdGeolocationProvider; @@ -262,8 +262,8 @@ public class MainModule extends AbstractModule { case "geoapify": geocoder = new GeoapifyGeocoder(client, key, language, cacheSize, addressFormat); break; - case "photon": - geocoder = new PhotonGeocoder(client, url, key, language, cacheSize, addressFormat); + case "geocodejson": + geocoder = new GeocodeJSONGeocoder(client, url, key, language, cacheSize, addressFormat); break; default: geocoder = new GoogleGeocoder(client, key, language, cacheSize, addressFormat); diff --git a/src/main/java/org/traccar/geocoder/BanGeocoder.java b/src/main/java/org/traccar/geocoder/BanGeocoder.java index e2ff72311..91610e952 100644 --- a/src/main/java/org/traccar/geocoder/BanGeocoder.java +++ b/src/main/java/org/traccar/geocoder/BanGeocoder.java @@ -20,45 +20,22 @@ package org.traccar.geocoder; * API documentation: https://adresse.data.gouv.fr/api */ -import jakarta.json.JsonArray; import jakarta.json.JsonObject; import jakarta.ws.rs.client.Client; -public class BanGeocoder extends JsonGeocoder { +public class BanGeocoder extends GeocodeJSONGeocoder { public BanGeocoder(Client client, int cacheSize, AddressFormat addressFormat) { - super(client, "https://api-adresse.data.gouv.fr/reverse/?lat=%f&lon=%f", cacheSize, addressFormat); + super(client, "https://api-adresse.data.gouv.fr/reverse/", null, null, cacheSize, addressFormat); } @Override public Address parseAddress(JsonObject json) { - JsonArray result = json.getJsonArray("features"); + Address geodecoded = super.parseAddress(json); + if (geodecoded != null) { + geodecoded.setCountry("FR"); - if (result != null && !result.isEmpty()) { - JsonObject location = result.getJsonObject(0).getJsonObject("properties"); - Address address = new Address(); - - address.setCountry("FR"); - if (location.containsKey("postcode")) { - address.setPostcode(location.getString("postcode")); - } - if (location.containsKey("context")) { - address.setDistrict(location.getString("context")); - } - if (location.containsKey("name")) { - address.setStreet(location.getString("name")); - } - if (location.containsKey("city")) { - address.setSettlement(location.getString("city")); - } - if (location.containsKey("housenumber")) { - address.setHouse(location.getString("housenumber")); - } - if (location.containsKey("label")) { - address.setFormattedAddress(location.getString("label")); - } - - return address; + return geodecoded; } return null; diff --git a/src/main/java/org/traccar/geocoder/GeocodeJSONGeocoder.java b/src/main/java/org/traccar/geocoder/GeocodeJSONGeocoder.java new file mode 100644 index 000000000..bbadfa9f1 --- /dev/null +++ b/src/main/java/org/traccar/geocoder/GeocodeJSONGeocoder.java @@ -0,0 +1,81 @@ +/* + * Copyright 2014 - 2024 Anton Tananaev (anton@traccar.org) + * Copyright 2024 - 2024 Matjaž Črnko (m.crnko@txt.i) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.geocoder; + +import jakarta.json.JsonArray; +import jakarta.json.JsonObject; +import jakarta.ws.rs.client.Client; + +public class GeocodeJSONGeocoder extends JsonGeocoder { + + private static String formatUrl(String url, String key, String language) { + if (url == null) { + url = "https://photon.komoot.io/reverse"; + } + url += "?lat=%f&lon=%f"; + if (key != null) { + url += "&key=" + key; + } + if (language != null) { + url += "&lang=" + language; + } + return url; + } + + public GeocodeJSONGeocoder( + Client client, String url, String key, String language, int cacheSize, AddressFormat addressFormat) { + super(client, formatUrl(url, key, language), cacheSize, addressFormat); + } + + @Override + public Address parseAddress(JsonObject json) { + JsonArray features = json.getJsonArray("features"); + if (!features.isEmpty()) { + Address address = new Address(); + JsonObject properties = features.getJsonObject(0).getJsonObject("properties"); + + if (properties.containsKey("label")) { + address.setFormattedAddress(properties.getString("label")); + } + if (properties.containsKey("housenumber")) { + address.setHouse(properties.getString("housenumber")); + } + if (properties.containsKey("street")) { + address.setStreet(properties.getString("street")); + } + if (properties.containsKey("city")) { + address.setSettlement(properties.getString("city")); + } + if (properties.containsKey("district")) { + address.setDistrict(properties.getString("district")); + } + if (properties.containsKey("state")) { + address.setState(properties.getString("state")); + } + if (properties.containsKey("countrycode")) { + address.setCountry(properties.getString("countrycode").toUpperCase()); + } + if (properties.containsKey("postcode")) { + address.setPostcode(properties.getString("postcode")); + } + + return address; + } + return null; + } + +} diff --git a/src/main/java/org/traccar/geocoder/PhotonGeocoder.java b/src/main/java/org/traccar/geocoder/PhotonGeocoder.java deleted file mode 100644 index 05bd40b23..000000000 --- a/src/main/java/org/traccar/geocoder/PhotonGeocoder.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2014 - 2024 Anton Tananaev (anton@traccar.org) - * Copyright 2024 - 2024 Matjaž Črnko (m.crnko@txt.i) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -import jakarta.json.JsonArray; -import jakarta.json.JsonObject; -import jakarta.ws.rs.client.Client; - -public class PhotonGeocoder extends JsonGeocoder { - - private static String formatUrl(String url, String key, String language) { - if (url == null) { - url = "https://photon.komoot.io/reverse"; - } - url += "?lat=%f&lon=%f"; - if (key != null) { - url += "&key=" + key; - } - if (language != null) { - url += "&lang=" + language; - } - return url; - } - - public PhotonGeocoder( - Client client, String url, String key, String language, int cacheSize, AddressFormat addressFormat) { - super(client, formatUrl(url, key, language), cacheSize, addressFormat); - } - - @Override - public Address parseAddress(JsonObject json) { - JsonArray features = json.getJsonArray("features"); - if (!features.isEmpty()) { - Address address = new Address(); - JsonObject properties = features.getJsonObject(0).getJsonObject("properties"); - - if (properties.containsKey("housenumber")) { - address.setHouse(properties.getString("housenumber")); - } - if (properties.containsKey("street")) { - address.setStreet(properties.getString("street")); - } - if (properties.containsKey("city")) { - address.setSettlement(properties.getString("city")); - } - if (properties.containsKey("district")) { - address.setState(properties.getString("district")); - } - if (properties.containsKey("state")) { - address.setState(properties.getString("state")); - } - if (properties.containsKey("countrycode")) { - address.setCountry(properties.getString("countrycode").toUpperCase()); - } - if (properties.containsKey("postcode")) { - address.setPostcode(properties.getString("postcode")); - } - - return address; - } - return null; - } - -} diff --git a/src/test/java/org/traccar/geocoder/GeocoderTest.java b/src/test/java/org/traccar/geocoder/GeocoderTest.java index e05477ac3..fb2c5198f 100644 --- a/src/test/java/org/traccar/geocoder/GeocoderTest.java +++ b/src/test/java/org/traccar/geocoder/GeocoderTest.java @@ -69,9 +69,9 @@ public class GeocoderTest { @Disabled @Test public void testBan() { - Geocoder geocoder = new BanGeocoder(client, 0, new AddressFormat("%f [%d], %c")); + Geocoder geocoder = new BanGeocoder(client, 0, new AddressFormat()); String address = geocoder.getAddress(48.8575, 2.2944, null); - assertEquals("8 Avenue Gustave Eiffel 75007 Paris [75, Paris, Île-de-France], FR", address); + assertEquals("8 Avenue Gustave Eiffel, Paris, FR", address); } @Disabled @@ -124,8 +124,8 @@ public class GeocoderTest { @Disabled @Test - public void testPhoton() { - Geocoder geocoder = new PhotonGeocoder(client, null, null, null, 0, new AddressFormat()); + public void testGeocodeJSON() { + Geocoder geocoder = new GeocodeJSONGeocoder(client, null, null, null, 0, new AddressFormat()); String address = geocoder.getAddress(40.7337807, -73.9974401, null); assertEquals("35 West 9th Street, New York, New York, US", address); } -- cgit v1.2.3 From a12690a6acffb356cc90791159c1cb60161bf1af Mon Sep 17 00:00:00 2001 From: Matjaž Črnko Date: Mon, 17 Jun 2024 20:03:04 +0200 Subject: fix: CamelCase --- src/main/java/org/traccar/MainModule.java | 4 +- .../java/org/traccar/geocoder/BanGeocoder.java | 2 +- .../org/traccar/geocoder/GeocodeJSONGeocoder.java | 81 ---------------------- .../org/traccar/geocoder/GeocodeJsonGeocoder.java | 81 ++++++++++++++++++++++ .../java/org/traccar/geocoder/GeocoderTest.java | 2 +- 5 files changed, 85 insertions(+), 85 deletions(-) delete mode 100644 src/main/java/org/traccar/geocoder/GeocodeJSONGeocoder.java create mode 100644 src/main/java/org/traccar/geocoder/GeocodeJsonGeocoder.java (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index 2b345847f..806e6da18 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -68,7 +68,7 @@ import org.traccar.geocoder.OpenCageGeocoder; import org.traccar.geocoder.PositionStackGeocoder; import org.traccar.geocoder.PlusCodesGeocoder; import org.traccar.geocoder.TomTomGeocoder; -import org.traccar.geocoder.GeocodeJSONGeocoder; +import org.traccar.geocoder.GeocodeJsonGeocoder; import org.traccar.geolocation.GeolocationProvider; import org.traccar.geolocation.GoogleGeolocationProvider; import org.traccar.geolocation.OpenCellIdGeolocationProvider; @@ -263,7 +263,7 @@ public class MainModule extends AbstractModule { geocoder = new GeoapifyGeocoder(client, key, language, cacheSize, addressFormat); break; case "geocodejson": - geocoder = new GeocodeJSONGeocoder(client, url, key, language, cacheSize, addressFormat); + geocoder = new GeocodeJsonGeocoder(client, url, key, language, cacheSize, addressFormat); break; default: geocoder = new GoogleGeocoder(client, key, language, cacheSize, addressFormat); diff --git a/src/main/java/org/traccar/geocoder/BanGeocoder.java b/src/main/java/org/traccar/geocoder/BanGeocoder.java index 91610e952..128ef4b84 100644 --- a/src/main/java/org/traccar/geocoder/BanGeocoder.java +++ b/src/main/java/org/traccar/geocoder/BanGeocoder.java @@ -23,7 +23,7 @@ package org.traccar.geocoder; import jakarta.json.JsonObject; import jakarta.ws.rs.client.Client; -public class BanGeocoder extends GeocodeJSONGeocoder { +public class BanGeocoder extends GeocodeJsonGeocoder { public BanGeocoder(Client client, int cacheSize, AddressFormat addressFormat) { super(client, "https://api-adresse.data.gouv.fr/reverse/", null, null, cacheSize, addressFormat); diff --git a/src/main/java/org/traccar/geocoder/GeocodeJSONGeocoder.java b/src/main/java/org/traccar/geocoder/GeocodeJSONGeocoder.java deleted file mode 100644 index bbadfa9f1..000000000 --- a/src/main/java/org/traccar/geocoder/GeocodeJSONGeocoder.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2014 - 2024 Anton Tananaev (anton@traccar.org) - * Copyright 2024 - 2024 Matjaž Črnko (m.crnko@txt.i) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.geocoder; - -import jakarta.json.JsonArray; -import jakarta.json.JsonObject; -import jakarta.ws.rs.client.Client; - -public class GeocodeJSONGeocoder extends JsonGeocoder { - - private static String formatUrl(String url, String key, String language) { - if (url == null) { - url = "https://photon.komoot.io/reverse"; - } - url += "?lat=%f&lon=%f"; - if (key != null) { - url += "&key=" + key; - } - if (language != null) { - url += "&lang=" + language; - } - return url; - } - - public GeocodeJSONGeocoder( - Client client, String url, String key, String language, int cacheSize, AddressFormat addressFormat) { - super(client, formatUrl(url, key, language), cacheSize, addressFormat); - } - - @Override - public Address parseAddress(JsonObject json) { - JsonArray features = json.getJsonArray("features"); - if (!features.isEmpty()) { - Address address = new Address(); - JsonObject properties = features.getJsonObject(0).getJsonObject("properties"); - - if (properties.containsKey("label")) { - address.setFormattedAddress(properties.getString("label")); - } - if (properties.containsKey("housenumber")) { - address.setHouse(properties.getString("housenumber")); - } - if (properties.containsKey("street")) { - address.setStreet(properties.getString("street")); - } - if (properties.containsKey("city")) { - address.setSettlement(properties.getString("city")); - } - if (properties.containsKey("district")) { - address.setDistrict(properties.getString("district")); - } - if (properties.containsKey("state")) { - address.setState(properties.getString("state")); - } - if (properties.containsKey("countrycode")) { - address.setCountry(properties.getString("countrycode").toUpperCase()); - } - if (properties.containsKey("postcode")) { - address.setPostcode(properties.getString("postcode")); - } - - return address; - } - return null; - } - -} diff --git a/src/main/java/org/traccar/geocoder/GeocodeJsonGeocoder.java b/src/main/java/org/traccar/geocoder/GeocodeJsonGeocoder.java new file mode 100644 index 000000000..da4688423 --- /dev/null +++ b/src/main/java/org/traccar/geocoder/GeocodeJsonGeocoder.java @@ -0,0 +1,81 @@ +/* + * Copyright 2014 - 2024 Anton Tananaev (anton@traccar.org) + * Copyright 2024 - 2024 Matjaž Črnko (m.crnko@txt.i) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.geocoder; + +import jakarta.json.JsonArray; +import jakarta.json.JsonObject; +import jakarta.ws.rs.client.Client; + +public class GeocodeJsonGeocoder extends JsonGeocoder { + + private static String formatUrl(String url, String key, String language) { + if (url == null) { + url = "https://photon.komoot.io/reverse"; + } + url += "?lat=%f&lon=%f"; + if (key != null) { + url += "&key=" + key; + } + if (language != null) { + url += "&lang=" + language; + } + return url; + } + + public GeocodeJsonGeocoder( + Client client, String url, String key, String language, int cacheSize, AddressFormat addressFormat) { + super(client, formatUrl(url, key, language), cacheSize, addressFormat); + } + + @Override + public Address parseAddress(JsonObject json) { + JsonArray features = json.getJsonArray("features"); + if (!features.isEmpty()) { + Address address = new Address(); + JsonObject properties = features.getJsonObject(0).getJsonObject("properties"); + + if (properties.containsKey("label")) { + address.setFormattedAddress(properties.getString("label")); + } + if (properties.containsKey("housenumber")) { + address.setHouse(properties.getString("housenumber")); + } + if (properties.containsKey("street")) { + address.setStreet(properties.getString("street")); + } + if (properties.containsKey("city")) { + address.setSettlement(properties.getString("city")); + } + if (properties.containsKey("district")) { + address.setDistrict(properties.getString("district")); + } + if (properties.containsKey("state")) { + address.setState(properties.getString("state")); + } + if (properties.containsKey("countrycode")) { + address.setCountry(properties.getString("countrycode").toUpperCase()); + } + if (properties.containsKey("postcode")) { + address.setPostcode(properties.getString("postcode")); + } + + return address; + } + return null; + } + +} diff --git a/src/test/java/org/traccar/geocoder/GeocoderTest.java b/src/test/java/org/traccar/geocoder/GeocoderTest.java index fb2c5198f..3e65d20c7 100644 --- a/src/test/java/org/traccar/geocoder/GeocoderTest.java +++ b/src/test/java/org/traccar/geocoder/GeocoderTest.java @@ -125,7 +125,7 @@ public class GeocoderTest { @Disabled @Test public void testGeocodeJSON() { - Geocoder geocoder = new GeocodeJSONGeocoder(client, null, null, null, 0, new AddressFormat()); + Geocoder geocoder = new GeocodeJsonGeocoder(client, null, null, null, 0, new AddressFormat()); String address = geocoder.getAddress(40.7337807, -73.9974401, null); assertEquals("35 West 9th Street, New York, New York, US", address); } -- cgit v1.2.3 From e938fe96f5edca81551323d37ff8c9f02e28773c Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 19 Jun 2024 08:41:17 -0700 Subject: Updated Sucre Lee protocol --- .../java/org/traccar/protocol/Gt06ProtocolDecoder.java | 18 ++++++++++++++++-- src/test/java/org/traccar/ProtocolTest.java | 3 +++ .../org/traccar/protocol/Gt06ProtocolDecoderTest.java | 8 ++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index 0c23f42d3..319349d0e 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -360,7 +360,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { lac = buf.readUnsignedShort(); } long cid; - if (type == MSG_LBS_ALARM || type == MSG_GPS_LBS_7) { + if (type == MSG_LBS_ALARM || type == MSG_GPS_LBS_7 || variant == Variant.SL4X) { cid = buf.readLong(); } else if (type == MSG_GPS_LBS_6 || variant == Variant.SEEWORLD) { cid = buf.readUnsignedInt(); @@ -923,11 +923,21 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { position.set("humidity", buf.readUnsignedShort() * 0.01); } - if ((type == MSG_GPS_LBS_2 || type == MSG_GPS_LBS_3 || type == MSG_GPS_LBS_4) + if (type == MSG_GPS_LBS_STATUS_4 && variant == Variant.SL4X) { + position.setAltitude(buf.readShort()); + } + + if ((type == MSG_GPS_LBS_2 || type == MSG_GPS_LBS_3 || type == MSG_GPS_LBS_4 || type == MSG_GPS_LBS_5) && buf.readableBytes() >= 3 + 6) { position.set(Position.KEY_IGNITION, buf.readUnsignedByte() > 0); position.set(Position.KEY_EVENT, buf.readUnsignedByte()); // reason position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() > 0); + if (variant == Variant.SL4X) { + if (buf.readableBytes() > 2 + 6) { + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + } + position.setAltitude(buf.readShort()); + } } if (type == MSG_GPS_LBS_3) { @@ -1495,8 +1505,12 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { variant = Variant.JC400; } else if (header == 0x7878 && type == MSG_LBS_3 && length == 0x37) { variant = Variant.SL4X; + } else if (header == 0x7878 && type == MSG_GPS_LBS_5 && length == 0x2a) { + variant = Variant.SL4X; } else if (header == 0x7878 && type == MSG_GPS_LBS_STATUS_4 && length == 0x27) { variant = Variant.SL4X; + } else if (header == 0x7878 && type == MSG_GPS_LBS_STATUS_4 && length == 0x29) { + variant = Variant.SL4X; } else if (header == 0x7878 && type == MSG_GPS_LBS_2 && length == 0x2f) { variant = Variant.SEEWORLD; } else if (header == 0x7878 && type == MSG_GPS_LBS_STATUS_1 && length == 0x26) { diff --git a/src/test/java/org/traccar/ProtocolTest.java b/src/test/java/org/traccar/ProtocolTest.java index 23ba562f8..0726000be 100644 --- a/src/test/java/org/traccar/ProtocolTest.java +++ b/src/test/java/org/traccar/ProtocolTest.java @@ -123,6 +123,9 @@ public class ProtocolTest extends BaseTest { case "course": assertEquals(expected, position.getCourse()); break; + case "altitude": + assertEquals(expected, position.getAltitude()); + break; default: assertEquals(expected, position.getAttributes().get(key)); break; diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 962bcb5c8..32a492df5 100644 --- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -17,6 +17,14 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "78780D01086471700328358100093F040D0A")); + verifyAttribute(decoder, binary( + "7878293218061301261ccd0274c4ad050d7c960018000a02d4000ac3c70dbdc40b46f004210202af001784290d0a"), + "altitude", -31703.0); + + verifyAttribute(decoder, binary( + "78782a31180613012b39cc0274c4dc050d7cd000180002d4000ac3c70dbdc4150100000000000002a6000ea40b0d0a"), + "altitude", 678.0); + verifyAttribute(decoder, binary( "7878281718060e021831c6026e8acc0c361b1000140001cc00286d000f4dbf0000012ca7e001000004b2630d0a"), Position.KEY_DRIVER_UNIQUE_ID, "0000012ca7e00100"); -- cgit v1.2.3 From 3679bcc9dc31fbab434f79a71ccb012c53b61c5e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 19 Jun 2024 08:48:44 -0700 Subject: Updated Sucre Lee protocol --- src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java | 5 +++++ src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index 319349d0e..d088077e2 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -1155,6 +1155,11 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ICCID, ByteBufUtil.hexDump(buf.readSlice(10)).replaceAll("f", "")); return position; + } else if (subType == 0x0b) { + + position.set("networkTechnology", buf.readByte() > 0 ? "4G" : "2G"); + return position; + } else if (subType == 0x0d) { if (buf.getByte(buf.readerIndex()) != '!') { diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 32a492df5..aba0a6293 100644 --- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -17,6 +17,10 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "78780D01086471700328358100093F040D0A")); + verifyAttribute(decoder, binary( + "79790007940B010A0B5ACE0D0A"), + "networkTechnology", "4G"); + verifyAttribute(decoder, binary( "7878293218061301261ccd0274c4ad050d7c960018000a02d4000ac3c70dbdc40b46f004210202af001784290d0a"), "altitude", -31703.0); @@ -29,9 +33,8 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { "7878281718060e021831c6026e8acc0c361b1000140001cc00286d000f4dbf0000012ca7e001000004b2630d0a"), Position.KEY_DRIVER_UNIQUE_ID, "0000012ca7e00100"); - verifyAttribute(decoder, binary( - "78782732180214123324ca0162bdf0041f45d900190b0a02d4000bc5270000ec025206040202005e07e10d0a"), - Position.KEY_ALARM, Position.ALARM_POWER_CUT); + verifyNotNull(decoder, binary( + "78782732180214123324ca0162bdf0041f45d900190b0a02d4000bc5270000ec025206040202005e07e10d0a")); verifyAttribute(decoder, binary( "78782616170A080C0E24C0027C58AD0C2B8B0100454E0901CC0025030328E7A0005D4B13021EC373170D0A"), -- cgit v1.2.3 From e9b1392ddc72bd8d5adcde69012e90cb4004c930 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 24 Jun 2024 06:40:28 -0700 Subject: Change GT06 RFID decoding --- src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java | 2 +- src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index d088077e2..eb8ba2375 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -960,8 +960,8 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } if (type == MSG_GPS_LBS_RFID) { - buf.readUnsignedByte(); // validity position.set(Position.KEY_DRIVER_UNIQUE_ID, ByteBufUtil.hexDump(buf.readSlice(8))); + buf.readUnsignedByte(); // validity } if (buf.readableBytes() == 3 + 6 || buf.readableBytes() == 3 + 4 + 6) { diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java index aba0a6293..9e9d3667d 100644 --- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -31,7 +31,7 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { verifyAttribute(decoder, binary( "7878281718060e021831c6026e8acc0c361b1000140001cc00286d000f4dbf0000012ca7e001000004b2630d0a"), - Position.KEY_DRIVER_UNIQUE_ID, "0000012ca7e00100"); + Position.KEY_DRIVER_UNIQUE_ID, "bf0000012ca7e001"); verifyNotNull(decoder, binary( "78782732180214123324ca0162bdf0041f45d900190b0a02d4000bc5270000ec025206040202005e07e10d0a")); -- cgit v1.2.3 From b13e4dafc64f4531370ffd73121f4d769d161311 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 25 Jun 2024 07:22:12 -0700 Subject: Fix GTINF decoding (fix #5355) --- src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java | 2 ++ src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java | 3 +++ 2 files changed, 5 insertions(+) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java index cfed351f2..3afea3b1b 100644 --- a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java @@ -278,6 +278,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { position.set(Position.PREFIX_ADC + 2, parser.next()); if (model.equals("GV310LAU")) { position.set(Position.PREFIX_ADC + 3, parser.next()); + } else { + parser.next(); // skip for other devices } position.set(Position.KEY_INPUT, parser.next()); diff --git a/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java index 406a447ab..04980117b 100644 --- a/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class Gl200TextProtocolDecoderTest extends ProtocolTest { var decoder = inject(new Gl200TextProtocolDecoder(null)); + verifyAttributes(decoder, buffer( + "+RESP:GTINF,423036,866884046104139,,41,89103000000064820042,22,99,0,,,3.82,0,0,1,0,0,20240622183159,57,,,,,20240623011548,005C$")); + verifyAttribute(decoder, buffer( "+RESP:GTERI,8020050704,867488060246195,,00000004,28823,10,1,1,0.0,33,10.1,10.606120,43.656780,20240408084402,0222,0010,7D53,00DD120D,02,0,0.0,,,,,100,210100,0,1,FFFFF,YS2R4X20009288827,2,H1910197,58234.30,500,1,90,H1.5,P84.00,,0,4616.20,2.28,2.16,5.64,5358,1038,0010,00,00,20240408084403,1809$"), Position.KEY_BATTERY_LEVEL, 100); -- cgit v1.2.3 From 90e5c5a7ede05d5d06abda6474d593b5a7843c9e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 27 Jun 2024 06:48:31 -0700 Subject: Do not respond to TRV responses --- src/main/java/org/traccar/protocol/TrvProtocolDecoder.java | 2 +- src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java b/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java index 1187250f8..7f298c8cf 100644 --- a/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java @@ -180,7 +180,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { channel.writeAndFlush(new NetworkMessage(responseHeader + "," + time + ",0#", remoteAddress)); } else if (type.equals("AP14")) { channel.writeAndFlush(new NetworkMessage(responseHeader + ",0.000,0.000#", remoteAddress)); - } else { + } else if (!sentence.substring(responseHeader.length() + 1).matches("^\\d{6}$")) { channel.writeAndFlush(new NetworkMessage(responseHeader + "#", remoteAddress)); } } diff --git a/src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java index a17fc341f..2757064e4 100644 --- a/src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java @@ -14,6 +14,9 @@ public class TrvProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, text( "TRVAP00352121088015548")); + verifyNull(decoder, text( + "IWAPXL,080835")); + verifyAttribute(decoder, text( "IWAP10080524A2232.9806N11404.9355E000.1061830323.8706000908000502,460,0,9520,3671,01,zhcn,00,HOME|74-DE-2B-44-88-8C|97&HOME1|74-DE-2B-44-88-8C|97&HOME2|74-DE-2B-44-88-8C|97&HOME3|74-DE-2B-44-88-8C|97"), Position.KEY_ALARM, Position.ALARM_SOS); -- cgit v1.2.3 From 025f2dff7c93917484ed7b37ca49d4d958bfe450 Mon Sep 17 00:00:00 2001 From: jcardus Date: Sat, 29 Jun 2024 02:33:39 +0100 Subject: Implemented power and battery for aovx v series --- .../org/traccar/protocol/HuabaoProtocolDecoder.java | 7 +++++++ .../traccar/protocol/HuabaoProtocolDecoderTest.java | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java index d010a8fe0..e99caad5e 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -710,6 +710,8 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001); position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); break; + case 0xF1: + position.set(Position.KEY_POWER, buf.readUnsignedInt() * 0.001); case 0xF3: while (buf.readerIndex() < endIndex) { int extendedType = buf.readUnsignedShort(); @@ -772,6 +774,11 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { } } break; + case 0xF7: + position.set(Position.KEY_BATTERY, buf.readUnsignedInt() * 0.001); + position.set(Position.KEY_CHARGE, buf.readUnsignedByte() >= 2); + position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); + break; case 0xFE: if (length == 1) { position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); diff --git a/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java index 2ba37ab09..b5451ecec 100644 --- a/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java @@ -227,6 +227,26 @@ public class HuabaoProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "7e0002000004304832546500b7ca7e")); + verifyAttribute(decoder, binary( + "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), + Position.KEY_BATTERY, 3.719); + + verifyAttribute(decoder, binary( + "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), + Position.KEY_BATTERY, 3.719); + + verifyAttribute(decoder, binary( + "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), + Position.KEY_CHARGE, true); + + verifyAttribute(decoder, binary( + "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), + Position.KEY_BATTERY_LEVEL, 70); + + verifyAttribute(decoder, binary( + "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), + Position.KEY_POWER, 12.428); + } } -- cgit v1.2.3 From 467051e3de789e122316aa85b3f34096c2841a97 Mon Sep 17 00:00:00 2001 From: jcardus Date: Sat, 29 Jun 2024 03:07:56 +0100 Subject: removed duplicated test case --- src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/test/java/org') diff --git a/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java index b5451ecec..fa8fb2f29 100644 --- a/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java @@ -231,10 +231,6 @@ public class HuabaoProtocolDecoderTest extends ProtocolTest { "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), Position.KEY_BATTERY, 3.719); - verifyAttribute(decoder, binary( - "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), - Position.KEY_BATTERY, 3.719); - verifyAttribute(decoder, binary( "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), Position.KEY_CHARGE, true); -- cgit v1.2.3 From 64794efca6f23aa2e89085d4fc822e27cfedcbe2 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 29 Jun 2024 06:29:29 -0700 Subject: Support Farnear protocol --- .../java/org/traccar/protocol/GotopProtocolDecoder.java | 14 +++++++++----- .../org/traccar/protocol/GotopProtocolDecoderTest.java | 6 ++++++ 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/GotopProtocolDecoder.java b/src/main/java/org/traccar/protocol/GotopProtocolDecoder.java index 5c8d0bac2..933e6fe4f 100644 --- a/src/main/java/org/traccar/protocol/GotopProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GotopProtocolDecoder.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. @@ -37,10 +37,14 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder { .number("(d+),") // imei .expression("([^,]+),") // type .expression("([AV]),") // validity - .number("DATE:(dd)(dd)(dd),") // date (yyddmm) - .number("TIME:(dd)(dd)(dd),") // time (hhmmss) - .number("LAT:(d+.d+)([NS]),") // latitude - .number("LO[NT]:(d+.d+)([EW]),") // longitude + .text("DATE:").optional() + .number("(dd)(dd)(dd),") // date (yyddmm) + .text("TIME:").optional() + .number("(dd)(dd)(dd),") // time (hhmmss) + .text("LAT:").optional() + .number("(d+.d+)([NS]),") // latitude + .expression("LO[NT]:").optional() + .number("(d+.d+)([EW]),") // longitude .text("Speed:").number("(d+.d+),") // speed .expression("([^,]+),") // status .number("(d+)?") // course diff --git a/src/test/java/org/traccar/protocol/GotopProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/GotopProtocolDecoderTest.java index aea6e7592..8601618bd 100644 --- a/src/test/java/org/traccar/protocol/GotopProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/GotopProtocolDecoderTest.java @@ -11,6 +11,12 @@ public class GotopProtocolDecoderTest extends ProtocolTest { var decoder = inject(new GotopProtocolDecoder(null)); + verifyPosition(decoder, text( + "012896001901633,CMD-T,A,130104,175950,24.0234233S,029.4691133E,Speed:001.8,90-24,1.3,10,10,65501-0371-170D,12,1-1,00.00")); + + verifyPosition(decoder, text( + "012896001901633,CMD-T,A,130104,175950,24.0234233S,029.4691133E,Speed:001.8,90-24,1.3,00.00")); + verifyNull(decoder, text( "")); -- cgit v1.2.3 From 9c2c1566ab292ecc351c273c2ab0f3faf75a7daf Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 29 Jun 2024 06:52:44 -0700 Subject: Add LW2G and LW4G support --- .../org/traccar/protocol/Gt06ProtocolDecoder.java | 30 +++++++++++++++++++--- .../traccar/protocol/Gt06ProtocolDecoderTest.java | 3 +++ 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index eb8ba2375..372cf5f78 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -101,6 +101,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_GPS_LBS_7 = 0xA0; // GK310 & JM-VL03 public static final int MSG_LBS_2 = 0xA1; // GK310 public static final int MSG_WIFI_3 = 0xA2; // GK310 + public static final int MSG_GPS_LBS_STATUS_5 = 0xA2; // LWxG public static final int MSG_FENCE_SINGLE = 0xA3; // GK310 public static final int MSG_FENCE_MULTI = 0xA4; // GK310 & JM-LL301 public static final int MSG_LBS_ALARM = 0xA5; // GK310 & JM-LL301 @@ -127,6 +128,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { SL4X, SEEWORLD, RFID, + LW4G, } private Variant variant; @@ -174,6 +176,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { case MSG_GPS_LBS_STATUS_2: case MSG_GPS_LBS_STATUS_3: case MSG_GPS_LBS_STATUS_4: + case MSG_GPS_LBS_STATUS_5: case MSG_GPS_PHONE: case MSG_GPS_LBS_EXTEND: case MSG_GPS_LBS_7: @@ -199,6 +202,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { case MSG_GPS_LBS_STATUS_2: case MSG_GPS_LBS_STATUS_3: case MSG_GPS_LBS_STATUS_4: + case MSG_GPS_LBS_STATUS_5: case MSG_GPS_LBS_7: case MSG_GPS_LBS_RFID: case MSG_FENCE_SINGLE: @@ -219,6 +223,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { case MSG_GPS_LBS_STATUS_2: case MSG_GPS_LBS_STATUS_3: case MSG_GPS_LBS_STATUS_4: + case MSG_GPS_LBS_STATUS_5: case MSG_FENCE_MULTI: case MSG_LBS_ALARM: return true; @@ -354,13 +359,13 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { mnc = buf.readUnsignedByte(); } int lac; - if (type == MSG_LBS_ALARM || type == MSG_GPS_LBS_7) { + if (type == MSG_LBS_ALARM || type == MSG_GPS_LBS_7 || type == MSG_GPS_LBS_STATUS_5) { lac = buf.readInt(); } else { lac = buf.readUnsignedShort(); } long cid; - if (type == MSG_LBS_ALARM || type == MSG_GPS_LBS_7 || variant == Variant.SL4X) { + if (type == MSG_LBS_ALARM || type == MSG_GPS_LBS_7 || variant == Variant.SL4X || type == MSG_GPS_LBS_STATUS_5) { cid = buf.readLong(); } else if (type == MSG_GPS_LBS_6 || variant == Variant.SEEWORLD) { cid = buf.readUnsignedInt(); @@ -690,7 +695,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } else if (type == MSG_LBS_MULTIPLE_1 || type == MSG_LBS_MULTIPLE_2 || type == MSG_LBS_MULTIPLE_3 || type == MSG_LBS_EXTEND || type == MSG_LBS_WIFI || type == MSG_LBS_2 || type == MSG_LBS_3 - || type == MSG_WIFI_3 || type == MSG_WIFI_5) { + || (type == MSG_WIFI_3 && variant != Variant.LW4G) || type == MSG_WIFI_5) { DateBuilder dateBuilder = new DateBuilder((TimeZone) deviceSession.get(DeviceSession.KEY_TIMEZONE)) .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) @@ -828,11 +833,15 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { boolean hasLength = hasStatus(type) && type != MSG_LBS_STATUS && type != MSG_LBS_ALARM - && (type != MSG_GPS_LBS_STATUS_1 || variant != Variant.VXT01); + && (type != MSG_GPS_LBS_STATUS_1 || variant != Variant.VXT01) + && type != MSG_GPS_LBS_STATUS_5; decodeLbs(position, buf, type, hasLength); } if (hasStatus(type)) { + if (type == MSG_GPS_LBS_STATUS_5) { + buf.readUnsignedByte(); // network indicator + } decodeStatus(position, buf); if (variant == Variant.OBD6) { int signal = buf.readUnsignedShort(); @@ -846,6 +855,9 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // working mode position.set(Position.KEY_POWER, buf.readUnsignedShort() / 100.0); } else { + if (type == MSG_GPS_LBS_STATUS_5) { + position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01); + } int battery = buf.readUnsignedByte(); position.set(Position.KEY_BATTERY_LEVEL, battery <= 6 ? battery * 100 / 6 : battery); position.set(Position.KEY_RSSI, buf.readUnsignedByte()); @@ -856,6 +868,14 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } } + if (type == MSG_GPS_LBS_STATUS_5) { + buf.readUnsignedByte(); // language + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 1000); + buf.skipBytes(8); // terminal id + position.set(Position.KEY_INPUT, buf.readUnsignedShort()); + } + if (type == MSG_GPS_LBS_1) { if (variant == Variant.GT06E_CARD) { position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); @@ -1522,6 +1542,8 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { variant = Variant.SEEWORLD; } else if (header == 0x7878 && type == MSG_GPS_LBS_RFID && length == 0x28) { variant = Variant.RFID; + } else if (header == 0x7878 && type == MSG_GPS_LBS_STATUS_5 && length == 0x40) { + variant = Variant.LW4G; } else { variant = Variant.STANDARD; } diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 9e9d3667d..da070e224 100644 --- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -17,6 +17,9 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "78780D01086471700328358100093F040D0A")); + verifyPosition(decoder, binary( + "787840a218061b0e0f05cf021d22430aa2660b005c00014e140000026500000000024d4e02114504df06031c010007d00000000000086973105524576500c802a86fda0d0a")); + verifyAttribute(decoder, binary( "79790007940B010A0B5ACE0D0A"), "networkTechnology", "4G"); -- cgit v1.2.3 From e3ffb16089b742ea3868806237d1e9760395646d Mon Sep 17 00:00:00 2001 From: jcardus Date: Sun, 30 Jun 2024 00:54:55 +0100 Subject: fix KEY_CHARGE remove 2 tests --- .../java/org/traccar/protocol/HuabaoProtocolDecoder.java | 16 ++++++++++++++-- .../org/traccar/protocol/HuabaoProtocolDecoderTest.java | 8 -------- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java index 672d293e1..accc3a879 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -777,8 +777,20 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { break; case 0xF7: position.set(Position.KEY_BATTERY, buf.readUnsignedInt() * 0.001); - position.set(Position.KEY_CHARGE, buf.readUnsignedByte() >= 2); - position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); + if (length > 4) { + short batteryStatus = buf.readUnsignedByte(); + switch (batteryStatus) { + case 1: + position.set(Position.KEY_CHARGE, false); + break; + case 2: + case 3: + position.set(Position.KEY_CHARGE, true); + } + } + if (length > 5) { + position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); + } break; case 0xFE: if (length == 1) { diff --git a/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java index fa8fb2f29..286ebfed1 100644 --- a/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java @@ -227,18 +227,10 @@ public class HuabaoProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "7e0002000004304832546500b7ca7e")); - verifyAttribute(decoder, binary( - "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), - Position.KEY_BATTERY, 3.719); - verifyAttribute(decoder, binary( "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), Position.KEY_CHARGE, true); - verifyAttribute(decoder, binary( - "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), - Position.KEY_BATTERY_LEVEL, 70); - verifyAttribute(decoder, binary( "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), Position.KEY_POWER, 12.428); -- cgit v1.2.3 From 17d6db44d6a7f6beacb1a73594d96430063e3d33 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 4 Jul 2024 14:35:14 -0700 Subject: Fix Kingwo GPS cell info --- src/main/java/org/traccar/protocol/UproProtocolDecoder.java | 2 +- src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java index 8d2e5de0a..d3f9882dd 100644 --- a/src/main/java/org/traccar/protocol/UproProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/UproProtocolDecoder.java @@ -298,7 +298,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { mcc, mnc, Integer.parseInt(stringValue.substring(offset, offset + 4), 16), Long.parseLong(stringValue.substring(offset + 4, offset + 12), 16), - Integer.parseInt(stringValue.substring(offset + 12, offset + 14)))); + Integer.parseInt(stringValue.substring(offset + 12, offset + 14), 16))); } } else { position.set(Position.KEY_POWER, diff --git a/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java index f070c6201..ac9c83e01 100644 --- a/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/UproProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class UproProtocolDecoderTest extends ProtocolTest { var decoder = inject(new UproProtocolDecoder(null)); + verifyPosition(decoder, buffer( + "*HQ200862406278000161,AB1&A1103312243149711422697470000040724&B0100000000&F0000&R2900&N04&Y3246011F4202C1460D351F4202C146113A1F4204C1460B3C&Q06f4911e6155e127b04e2640509e325091e3cc45ed4e788a20e024a151f81a679be2a45250d4f7e7dff75b&T63&J000300&K00100&X(k89882280666065148193)(10)(J0000)(PMODE,0,10)(20)(5000A)#")); + verifyPosition(decoder, buffer( "*HQ201999999,BA&A1656512233362911356523660000230618&B0100060010&C00000<6<&F0000&R2405&V0109&W0000003E&K00100&T65&I54600027A00FCB6227A00FCA5727A00E955327A00E8B5327A00F9748&Y54600027A000000FCB6227A000000FCA5727A000000E955327A000000E8B5327A000000F9748&b00A7E81007607#")); -- cgit v1.2.3 From b8390005722dd1cdb24d762797ef3f98ebc37755 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 6 Jul 2024 17:46:17 -0700 Subject: Update instanceof expressions --- .../java/org/traccar/BaseMqttProtocolDecoder.java | 12 ++--- src/main/java/org/traccar/BasePipelineFactory.java | 16 +++---- src/main/java/org/traccar/BaseProtocolDecoder.java | 4 +- src/main/java/org/traccar/BaseProtocolEncoder.java | 6 +-- .../java/org/traccar/ExtendedObjectDecoder.java | 13 +++--- src/main/java/org/traccar/ProcessingHandler.java | 4 +- .../java/org/traccar/WrapperInboundHandler.java | 4 +- .../java/org/traccar/WrapperOutboundHandler.java | 3 +- .../java/org/traccar/api/BaseObjectResource.java | 9 ++-- .../java/org/traccar/api/ResourceErrorHandler.java | 3 +- .../traccar/api/security/PermissionsService.java | 9 ++-- .../handler/network/AcknowledgementHandler.java | 6 +-- .../handler/network/NetworkMessageHandler.java | 6 +-- .../handler/network/RemoteAddressHandler.java | 3 +- .../handler/network/StandardLoggingHandler.java | 6 +-- .../org/traccar/helper/model/AttributeUtil.java | 16 +++---- src/main/java/org/traccar/model/ExtendedModel.java | 16 +++---- .../traccar/notification/PropertiesProvider.java | 4 +- .../traccar/protocol/FlespiProtocolDecoder.java | 14 +++--- .../traccar/protocol/Gl200TextProtocolDecoder.java | 4 +- .../traccar/protocol/OutsafeProtocolDecoder.java | 8 ++-- .../org/traccar/protocol/T55ProtocolDecoder.java | 5 +-- .../org/traccar/session/cache/CacheManager.java | 8 ++-- .../java/org/traccar/storage/DatabaseStorage.java | 30 +++++-------- .../java/org/traccar/storage/MemoryStorage.java | 34 +++++---------- .../java/org/traccar/storage/QueryBuilder.java | 24 +++++----- src/test/java/org/traccar/ProtocolTest.java | 51 +++++++++++----------- 27 files changed, 135 insertions(+), 183 deletions(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/BaseMqttProtocolDecoder.java b/src/main/java/org/traccar/BaseMqttProtocolDecoder.java index 0388563f5..5a55eee74 100644 --- a/src/main/java/org/traccar/BaseMqttProtocolDecoder.java +++ b/src/main/java/org/traccar/BaseMqttProtocolDecoder.java @@ -38,9 +38,7 @@ public abstract class BaseMqttProtocolDecoder extends BaseProtocolDecoder { protected final Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - if (msg instanceof MqttConnectMessage) { - - MqttConnectMessage message = (MqttConnectMessage) msg; + if (msg instanceof MqttConnectMessage message) { DeviceSession deviceSession = getDeviceSession( channel, remoteAddress, message.payload().clientIdentifier()); @@ -55,9 +53,7 @@ public abstract class BaseMqttProtocolDecoder extends BaseProtocolDecoder { channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } - } else if (msg instanceof MqttSubscribeMessage) { - - MqttSubscribeMessage message = (MqttSubscribeMessage) msg; + } else if (msg instanceof MqttSubscribeMessage message) { MqttMessage response = MqttMessageBuilders.subAck() .packetId(message.variableHeader().messageId()) @@ -67,15 +63,13 @@ public abstract class BaseMqttProtocolDecoder extends BaseProtocolDecoder { channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } - } else if (msg instanceof MqttPublishMessage) { + } else if (msg instanceof MqttPublishMessage message) { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession == null) { return null; } - MqttPublishMessage message = (MqttPublishMessage) msg; - Object result = decode(deviceSession, message); MqttMessage response = MqttMessageBuilders.pubAck() diff --git a/src/main/java/org/traccar/BasePipelineFactory.java b/src/main/java/org/traccar/BasePipelineFactory.java index 40360cca7..92b9759c1 100644 --- a/src/main/java/org/traccar/BasePipelineFactory.java +++ b/src/main/java/org/traccar/BasePipelineFactory.java @@ -64,10 +64,10 @@ public abstract class BasePipelineFactory extends ChannelInitializer { public static T getHandler(ChannelPipeline pipeline, Class clazz) { for (Map.Entry handlerEntry : pipeline) { ChannelHandler handler = handlerEntry.getValue(); - if (handler instanceof WrapperInboundHandler) { - handler = ((WrapperInboundHandler) handler).getWrappedHandler(); - } else if (handler instanceof WrapperOutboundHandler) { - handler = ((WrapperOutboundHandler) handler).getWrappedHandler(); + if (handler instanceof WrapperInboundHandler wrapperHandler) { + handler = wrapperHandler.getWrappedHandler(); + } else if (handler instanceof WrapperOutboundHandler wrapperHandler) { + handler = wrapperHandler.getWrappedHandler(); } if (clazz.isAssignableFrom(handler.getClass())) { return (T) handler; @@ -106,10 +106,10 @@ public abstract class BasePipelineFactory extends ChannelInitializer { if (handler instanceof BaseProtocolDecoder || handler instanceof BaseProtocolEncoder) { injectMembers(handler); } else { - if (handler instanceof ChannelInboundHandler) { - handler = new WrapperInboundHandler((ChannelInboundHandler) handler); - } else { - handler = new WrapperOutboundHandler((ChannelOutboundHandler) handler); + if (handler instanceof ChannelInboundHandler channelHandler) { + handler = new WrapperInboundHandler(channelHandler); + } else if (handler instanceof ChannelOutboundHandler channelHandler) { + handler = new WrapperOutboundHandler(channelHandler); } } pipeline.addLast(handler); diff --git a/src/main/java/org/traccar/BaseProtocolDecoder.java b/src/main/java/org/traccar/BaseProtocolDecoder.java index b764e5cdf..2f9c75ec2 100644 --- a/src/main/java/org/traccar/BaseProtocolDecoder.java +++ b/src/main/java/org/traccar/BaseProtocolDecoder.java @@ -168,8 +168,8 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { } Set deviceIds = new HashSet<>(); if (decodedMessage != null) { - if (decodedMessage instanceof Position) { - deviceIds.add(((Position) decodedMessage).getDeviceId()); + if (decodedMessage instanceof Position position) { + deviceIds.add(position.getDeviceId()); } else if (decodedMessage instanceof Collection) { Collection positions = (Collection) decodedMessage; for (Position position : positions) { diff --git a/src/main/java/org/traccar/BaseProtocolEncoder.java b/src/main/java/org/traccar/BaseProtocolEncoder.java index e357c27dc..2724a59b1 100644 --- a/src/main/java/org/traccar/BaseProtocolEncoder.java +++ b/src/main/java/org/traccar/BaseProtocolEncoder.java @@ -82,11 +82,9 @@ public abstract class BaseProtocolEncoder extends ChannelOutboundHandlerAdapter @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { - if (msg instanceof NetworkMessage) { - NetworkMessage networkMessage = (NetworkMessage) msg; - if (networkMessage.getMessage() instanceof Command) { + if (msg instanceof NetworkMessage networkMessage) { + if (networkMessage.getMessage() instanceof Command command) { - Command command = (Command) networkMessage.getMessage(); Object encodedCommand = encodeCommand(ctx.channel(), command); StringBuilder s = new StringBuilder(); diff --git a/src/main/java/org/traccar/ExtendedObjectDecoder.java b/src/main/java/org/traccar/ExtendedObjectDecoder.java index 9468e2fff..8d693c7cf 100644 --- a/src/main/java/org/traccar/ExtendedObjectDecoder.java +++ b/src/main/java/org/traccar/ExtendedObjectDecoder.java @@ -54,14 +54,12 @@ public abstract class ExtendedObjectDecoder extends ChannelInboundHandlerAdapter } private void saveOriginal(Object decodedMessage, Object originalMessage) { - if (getConfig().getBoolean(Keys.DATABASE_SAVE_ORIGINAL) && decodedMessage instanceof Position) { - Position position = (Position) decodedMessage; - if (originalMessage instanceof ByteBuf) { - ByteBuf buf = (ByteBuf) originalMessage; + if (getConfig().getBoolean(Keys.DATABASE_SAVE_ORIGINAL) && decodedMessage instanceof Position position) { + if (originalMessage instanceof ByteBuf buf) { position.set(Position.KEY_ORIGINAL, ByteBufUtil.hexDump(buf, 0, buf.writerIndex())); - } else if (originalMessage instanceof String) { + } else if (originalMessage instanceof String stringMessage) { position.set(Position.KEY_ORIGINAL, DataConverter.printHex( - ((String) originalMessage).getBytes(StandardCharsets.US_ASCII))); + stringMessage.getBytes(StandardCharsets.US_ASCII))); } } } @@ -78,8 +76,7 @@ public abstract class ExtendedObjectDecoder extends ChannelInboundHandlerAdapter decodedMessage = handleEmptyMessage(ctx.channel(), networkMessage.getRemoteAddress(), originalMessage); } if (decodedMessage != null) { - if (decodedMessage instanceof Collection) { - var collection = (Collection) decodedMessage; + if (decodedMessage instanceof Collection collection) { ctx.writeAndFlush(new AcknowledgementHandler.EventDecoded(collection)); for (Object o : collection) { saveOriginal(o, originalMessage); diff --git a/src/main/java/org/traccar/ProcessingHandler.java b/src/main/java/org/traccar/ProcessingHandler.java index bb040bfff..76442d402 100644 --- a/src/main/java/org/traccar/ProcessingHandler.java +++ b/src/main/java/org/traccar/ProcessingHandler.java @@ -131,8 +131,8 @@ public class ProcessingHandler extends ChannelInboundHandlerAdapter implements B @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - if (msg instanceof Position) { - bufferingManager.accept(ctx, (Position) msg); + if (msg instanceof Position position) { + bufferingManager.accept(ctx, position); } else { super.channelRead(ctx, msg); } diff --git a/src/main/java/org/traccar/WrapperInboundHandler.java b/src/main/java/org/traccar/WrapperInboundHandler.java index 5e2b1d304..7acca9c50 100644 --- a/src/main/java/org/traccar/WrapperInboundHandler.java +++ b/src/main/java/org/traccar/WrapperInboundHandler.java @@ -52,8 +52,7 @@ public class WrapperInboundHandler implements ChannelInboundHandler { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - if (msg instanceof NetworkMessage) { - NetworkMessage nm = (NetworkMessage) msg; + if (msg instanceof NetworkMessage nm) { handler.channelRead(new WrapperContext(ctx, nm.getRemoteAddress()), nm.getMessage()); } else { handler.channelRead(ctx, msg); @@ -85,7 +84,6 @@ public class WrapperInboundHandler implements ChannelInboundHandler { handler.handlerRemoved(ctx); } - @SuppressWarnings("deprecation") @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { handler.exceptionCaught(ctx, cause); diff --git a/src/main/java/org/traccar/WrapperOutboundHandler.java b/src/main/java/org/traccar/WrapperOutboundHandler.java index ae2b06ad2..8b9c01405 100644 --- a/src/main/java/org/traccar/WrapperOutboundHandler.java +++ b/src/main/java/org/traccar/WrapperOutboundHandler.java @@ -67,8 +67,7 @@ public class WrapperOutboundHandler implements ChannelOutboundHandler { @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { - if (msg instanceof NetworkMessage) { - NetworkMessage nm = (NetworkMessage) msg; + if (msg instanceof NetworkMessage nm) { handler.write(new WrapperContext(ctx, nm.getRemoteAddress()), nm.getMessage(), promise); } else { handler.write(ctx, msg, promise); diff --git a/src/main/java/org/traccar/api/BaseObjectResource.java b/src/main/java/org/traccar/api/BaseObjectResource.java index 3c97dd1f8..e35850e1f 100644 --- a/src/main/java/org/traccar/api/BaseObjectResource.java +++ b/src/main/java/org/traccar/api/BaseObjectResource.java @@ -89,15 +89,13 @@ public abstract class BaseObjectResource extends BaseResour permissionsService.checkPermission(baseClass, getUserId(), entity.getId()); boolean skipReadonly = false; - if (entity instanceof User) { - User after = (User) entity; + if (entity instanceof User after) { User before = storage.getObject(User.class, new Request( new Columns.All(), new Condition.Equals("id", entity.getId()))); permissionsService.checkUserUpdate(getUserId(), before, (User) entity); skipReadonly = permissionsService.getUser(getUserId()) .compare(after, "notificationTokens", "termsAccepted"); - } else if (entity instanceof Group) { - Group group = (Group) entity; + } else if (entity instanceof Group group) { if (group.getId() == group.getGroupId()) { throw new IllegalArgumentException("Cycle in group hierarchy"); } @@ -108,8 +106,7 @@ public abstract class BaseObjectResource extends BaseResour storage.updateObject(entity, new Request( new Columns.Exclude("id"), new Condition.Equals("id", entity.getId()))); - if (entity instanceof User) { - User user = (User) entity; + if (entity instanceof User user) { if (user.getHashedPassword() != null) { storage.updateObject(entity, new Request( new Columns.Include("hashedPassword", "salt"), diff --git a/src/main/java/org/traccar/api/ResourceErrorHandler.java b/src/main/java/org/traccar/api/ResourceErrorHandler.java index 387f3db6a..5f5e70632 100644 --- a/src/main/java/org/traccar/api/ResourceErrorHandler.java +++ b/src/main/java/org/traccar/api/ResourceErrorHandler.java @@ -25,8 +25,7 @@ public class ResourceErrorHandler implements ExceptionMapper { @Override public Response toResponse(Exception e) { - if (e instanceof WebApplicationException) { - WebApplicationException webException = (WebApplicationException) e; + if (e instanceof WebApplicationException webException) { return Response.fromResponse(webException.getResponse()).entity(Log.exceptionStack(webException)).build(); } else { return Response.status(Response.Status.BAD_REQUEST).entity(Log.exceptionStack(e)).build(); diff --git a/src/main/java/org/traccar/api/security/PermissionsService.java b/src/main/java/org/traccar/api/security/PermissionsService.java index d4a6fba1a..721793c2f 100644 --- a/src/main/java/org/traccar/api/security/PermissionsService.java +++ b/src/main/java/org/traccar/api/security/PermissionsService.java @@ -128,8 +128,7 @@ public class PermissionsService { throws StorageException, SecurityException { if (!getUser(userId).getAdministrator()) { checkEdit(userId, object.getClass(), addition, skipReadonly); - if (object instanceof GroupedModel) { - GroupedModel after = ((GroupedModel) object); + if (object instanceof GroupedModel after) { if (after.getGroupId() > 0) { GroupedModel before = null; if (!addition) { @@ -141,8 +140,7 @@ public class PermissionsService { } } } - if (object instanceof Schedulable) { - Schedulable after = ((Schedulable) object); + if (object instanceof Schedulable after) { if (after.getCalendarId() > 0) { Schedulable before = null; if (!addition) { @@ -154,8 +152,7 @@ public class PermissionsService { } } } - if (object instanceof Notification) { - Notification after = ((Notification) object); + if (object instanceof Notification after) { if (after.getCommandId() > 0) { Notification before = null; if (!addition) { diff --git a/src/main/java/org/traccar/handler/network/AcknowledgementHandler.java b/src/main/java/org/traccar/handler/network/AcknowledgementHandler.java index e87f5d34c..7ba625e00 100644 --- a/src/main/java/org/traccar/handler/network/AcknowledgementHandler.java +++ b/src/main/java/org/traccar/handler/network/AcknowledgementHandler.java @@ -92,12 +92,10 @@ public class AcknowledgementHandler extends ChannelOutboundHandlerAdapter { if (queue == null) { queue = new LinkedList<>(); } - } else if (msg instanceof EventDecoded) { - EventDecoded event = (EventDecoded) msg; + } else if (msg instanceof EventDecoded event) { LOGGER.debug("Event decoded {}", event.getObjects().size()); waiting.addAll(event.getObjects()); - } else if (msg instanceof EventHandled) { - EventHandled event = (EventHandled) msg; + } else if (msg instanceof EventHandled event) { LOGGER.debug("Event handled"); waiting.remove(event.getObject()); } diff --git a/src/main/java/org/traccar/handler/network/NetworkMessageHandler.java b/src/main/java/org/traccar/handler/network/NetworkMessageHandler.java index c2fb9016a..f151c91a9 100644 --- a/src/main/java/org/traccar/handler/network/NetworkMessageHandler.java +++ b/src/main/java/org/traccar/handler/network/NetworkMessageHandler.java @@ -32,16 +32,14 @@ public class NetworkMessageHandler extends ChannelDuplexHandler { if (ctx.channel() instanceof DatagramChannel) { DatagramPacket packet = (DatagramPacket) msg; ctx.fireChannelRead(new NetworkMessage(packet.content(), packet.sender())); - } else if (msg instanceof ByteBuf) { - ByteBuf buffer = (ByteBuf) msg; + } else if (msg instanceof ByteBuf buffer) { ctx.fireChannelRead(new NetworkMessage(buffer, ctx.channel().remoteAddress())); } } @Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { - if (msg instanceof NetworkMessage) { - NetworkMessage message = (NetworkMessage) msg; + if (msg instanceof NetworkMessage message) { if (ctx.channel() instanceof DatagramChannel) { InetSocketAddress recipient = (InetSocketAddress) message.getRemoteAddress(); InetSocketAddress sender = (InetSocketAddress) ctx.channel().localAddress(); diff --git a/src/main/java/org/traccar/handler/network/RemoteAddressHandler.java b/src/main/java/org/traccar/handler/network/RemoteAddressHandler.java index c52bb2be1..9d5504ce1 100644 --- a/src/main/java/org/traccar/handler/network/RemoteAddressHandler.java +++ b/src/main/java/org/traccar/handler/network/RemoteAddressHandler.java @@ -44,8 +44,7 @@ public class RemoteAddressHandler extends ChannelInboundHandlerAdapter { InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress(); String hostAddress = remoteAddress != null ? remoteAddress.getAddress().getHostAddress() : null; - if (msg instanceof Position) { - Position position = (Position) msg; + if (msg instanceof Position position) { position.set(Position.KEY_IP, hostAddress); } } diff --git a/src/main/java/org/traccar/handler/network/StandardLoggingHandler.java b/src/main/java/org/traccar/handler/network/StandardLoggingHandler.java index f6ee08756..8e63cae4d 100644 --- a/src/main/java/org/traccar/handler/network/StandardLoggingHandler.java +++ b/src/main/java/org/traccar/handler/network/StandardLoggingHandler.java @@ -72,12 +72,10 @@ public class StandardLoggingHandler extends ChannelDuplexHandler { } private LogRecord createLogRecord(ChannelHandlerContext ctx, Object msg) { - if (msg instanceof NetworkMessage) { - NetworkMessage networkMessage = (NetworkMessage) msg; - if (networkMessage.getMessage() instanceof ByteBuf) { + if (msg instanceof NetworkMessage networkMessage) { + if (networkMessage.getMessage() instanceof ByteBuf data) { LogRecord record = new LogRecord(ctx.channel().localAddress(), networkMessage.getRemoteAddress()); record.setProtocol(protocol); - ByteBuf data = (ByteBuf) networkMessage.getMessage(); if (decodeTextData && BufferUtil.isPrintable(data, data.readableBytes())) { record.setData(data.getCharSequence( data.readerIndex(), data.readableBytes(), StandardCharsets.US_ASCII).toString() diff --git a/src/main/java/org/traccar/helper/model/AttributeUtil.java b/src/main/java/org/traccar/helper/model/AttributeUtil.java index 2630f64f0..0e3d91766 100644 --- a/src/main/java/org/traccar/helper/model/AttributeUtil.java +++ b/src/main/java/org/traccar/helper/model/AttributeUtil.java @@ -70,20 +70,20 @@ public final class AttributeUtil { if (result != null) { Class valueClass = key.getValueClass(); if (valueClass.equals(Boolean.class)) { - return (T) (result instanceof String - ? Boolean.parseBoolean((String) result) + return (T) (result instanceof String stringResult + ? Boolean.parseBoolean(stringResult) : result); } else if (valueClass.equals(Integer.class)) { - return (T) (Object) (result instanceof String - ? Integer.parseInt((String) result) + return (T) (Object) (result instanceof String stringResult + ? Integer.parseInt(stringResult) : ((Number) result).intValue()); } else if (valueClass.equals(Long.class)) { - return (T) (Object) (result instanceof String - ? Long.parseLong((String) result) + return (T) (Object) (result instanceof String stringResult + ? Long.parseLong(stringResult) : ((Number) result).longValue()); } else if (valueClass.equals(Double.class)) { - return (T) (Object) (result instanceof String - ? Double.parseDouble((String) result) + return (T) (Object) (result instanceof String stringResult + ? Double.parseDouble(stringResult) : ((Number) result).doubleValue()); } else { return (T) result; diff --git a/src/main/java/org/traccar/model/ExtendedModel.java b/src/main/java/org/traccar/model/ExtendedModel.java index d5cd094da..f1183e11a 100644 --- a/src/main/java/org/traccar/model/ExtendedModel.java +++ b/src/main/java/org/traccar/model/ExtendedModel.java @@ -105,8 +105,8 @@ public class ExtendedModel extends BaseModel { public double getDouble(String key) { if (attributes.containsKey(key)) { Object value = attributes.get(key); - if (value instanceof Number) { - return ((Number) attributes.get(key)).doubleValue(); + if (value instanceof Number numberValue) { + return numberValue.doubleValue(); } else { return Double.parseDouble(value.toString()); } @@ -118,8 +118,8 @@ public class ExtendedModel extends BaseModel { public boolean getBoolean(String key) { if (attributes.containsKey(key)) { Object value = attributes.get(key); - if (value instanceof Boolean) { - return (Boolean) attributes.get(key); + if (value instanceof Boolean booleanValue) { + return booleanValue; } else { return Boolean.parseBoolean(value.toString()); } @@ -131,8 +131,8 @@ public class ExtendedModel extends BaseModel { public int getInteger(String key) { if (attributes.containsKey(key)) { Object value = attributes.get(key); - if (value instanceof Number) { - return ((Number) attributes.get(key)).intValue(); + if (value instanceof Number numberValue) { + return numberValue.intValue(); } else { return Integer.parseInt(value.toString()); } @@ -144,8 +144,8 @@ public class ExtendedModel extends BaseModel { public long getLong(String key) { if (attributes.containsKey(key)) { Object value = attributes.get(key); - if (value instanceof Number) { - return ((Number) attributes.get(key)).longValue(); + if (value instanceof Number numberValue) { + return numberValue.longValue(); } else { return Long.parseLong(value.toString()); } diff --git a/src/main/java/org/traccar/notification/PropertiesProvider.java b/src/main/java/org/traccar/notification/PropertiesProvider.java index 91887b5d4..5178b9a9e 100644 --- a/src/main/java/org/traccar/notification/PropertiesProvider.java +++ b/src/main/java/org/traccar/notification/PropertiesProvider.java @@ -48,7 +48,7 @@ public class PropertiesProvider { } else { Object result = extendedModel.getAttributes().get(key.getKey()); if (result != null) { - return result instanceof String ? Integer.parseInt((String) result) : (Integer) result; + return result instanceof String stringResult ? Integer.parseInt(stringResult) : (Integer) result; } else { return key.getDefaultValue(); } @@ -65,7 +65,7 @@ public class PropertiesProvider { } else { Object result = extendedModel.getAttributes().get(key.getKey()); if (result != null) { - return result instanceof String ? Boolean.valueOf((String) result) : (Boolean) result; + return result instanceof String stringResult ? Boolean.valueOf(stringResult) : (Boolean) result; } else { return null; } diff --git a/src/main/java/org/traccar/protocol/FlespiProtocolDecoder.java b/src/main/java/org/traccar/protocol/FlespiProtocolDecoder.java index ea076afd8..168b3b3cd 100644 --- a/src/main/java/org/traccar/protocol/FlespiProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/FlespiProtocolDecoder.java @@ -247,15 +247,15 @@ public class FlespiProtocolDecoder extends BaseHttpProtocolDecoder { } private void decodeUnknownParam(String name, JsonValue value, Position position) { - if (value instanceof JsonNumber) { - if (((JsonNumber) value).isIntegral()) { - position.set(name, ((JsonNumber) value).longValue()); + if (value instanceof JsonNumber jsonNumber) { + if (jsonNumber.isIntegral()) { + position.set(name, jsonNumber.longValue()); } else { - position.set(name, ((JsonNumber) value).doubleValue()); + position.set(name, jsonNumber.doubleValue()); } - position.set(name, ((JsonNumber) value).doubleValue()); - } else if (value instanceof JsonString) { - position.set(name, ((JsonString) value).getString()); + position.set(name, jsonNumber.doubleValue()); + } else if (value instanceof JsonString jsonString) { + position.set(name, jsonString.getString()); } else if (value == JsonValue.TRUE || value == JsonValue.FALSE) { position.set(name, value == JsonValue.TRUE); } diff --git a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java index 3afea3b1b..373e1c91c 100644 --- a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java @@ -1729,8 +1729,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { } if (result != null) { - if (result instanceof Position) { - ((Position) result).set(Position.KEY_TYPE, type); + if (result instanceof Position position) { + position.set(Position.KEY_TYPE, type); } else { for (Position p : (List) result) { p.set(Position.KEY_TYPE, type); diff --git a/src/main/java/org/traccar/protocol/OutsafeProtocolDecoder.java b/src/main/java/org/traccar/protocol/OutsafeProtocolDecoder.java index f71778412..0a6026d91 100644 --- a/src/main/java/org/traccar/protocol/OutsafeProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/OutsafeProtocolDecoder.java @@ -77,10 +77,10 @@ public class OutsafeProtocolDecoder extends BaseHttpProtocolDecoder { } private void decodeUnknownParam(String name, JsonValue value, Position position) { - if (value instanceof JsonNumber) { - position.set(name, ((JsonNumber) value).doubleValue()); - } else if (value instanceof JsonString) { - position.set(name, ((JsonString) value).getString()); + if (value instanceof JsonNumber jsonNumber) { + position.set(name, jsonNumber.doubleValue()); + } else if (value instanceof JsonString jsonString) { + position.set(name, jsonString.getString()); } else if (value == JsonValue.TRUE || value == JsonValue.FALSE) { position.set(name, value == JsonValue.TRUE); } diff --git a/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java b/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java index 9e7518ce5..2538c914d 100644 --- a/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java @@ -420,9 +420,8 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { sentence = sentence.substring(index); } else { deviceSession = getDeviceSession(channel, remoteAddress); - if (deviceSession == null && remoteAddress instanceof InetSocketAddress) { - String host = ((InetSocketAddress) remoteAddress).getHostString(); - deviceSession = getDeviceSession(channel, remoteAddress, host); + if (deviceSession == null && remoteAddress instanceof InetSocketAddress inetSocketAddress) { + deviceSession = getDeviceSession(channel, remoteAddress, inetSocketAddress.getHostString()); } } diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java index f7458567c..39546a5a7 100644 --- a/src/main/java/org/traccar/session/cache/CacheManager.java +++ b/src/main/java/org/traccar/session/cache/CacheManager.java @@ -296,8 +296,8 @@ public class CacheManager implements BroadcastInterface { } } } else { - if (object instanceof GroupedModel) { - long groupId = ((GroupedModel) object).getGroupId(); + if (object instanceof GroupedModel groupedModel) { + long groupId = groupedModel.getGroupId(); if (groupId > 0) { invalidatePermission(object.getClass(), object.getId(), Group.class, groupId, true); } @@ -319,8 +319,8 @@ public class CacheManager implements BroadcastInterface { } } - if (object instanceof Schedulable) { - long calendarId = ((Schedulable) object).getCalendarId(); + if (object instanceof Schedulable schedulable) { + long calendarId = schedulable.getCalendarId(); if (calendarId > 0) { invalidatePermission(object.getClass(), object.getId(), Calendar.class, calendarId, true); } diff --git a/src/main/java/org/traccar/storage/DatabaseStorage.java b/src/main/java/org/traccar/storage/DatabaseStorage.java index d20429319..1ff043e77 100644 --- a/src/main/java/org/traccar/storage/DatabaseStorage.java +++ b/src/main/java/org/traccar/storage/DatabaseStorage.java @@ -206,28 +206,23 @@ public class DatabaseStorage extends Storage { private Map getConditionVariables(Condition genericCondition) { Map results = new HashMap<>(); - if (genericCondition instanceof Condition.Compare) { - var condition = (Condition.Compare) genericCondition; + if (genericCondition instanceof Condition.Compare condition) { if (condition.getValue() != null) { results.put(condition.getVariable(), condition.getValue()); } - } else if (genericCondition instanceof Condition.Between) { - var condition = (Condition.Between) genericCondition; + } else if (genericCondition instanceof Condition.Between condition) { results.put(condition.getFromVariable(), condition.getFromValue()); results.put(condition.getToVariable(), condition.getToValue()); - } else if (genericCondition instanceof Condition.Binary) { - var condition = (Condition.Binary) genericCondition; + } else if (genericCondition instanceof Condition.Binary condition) { results.putAll(getConditionVariables(condition.getFirst())); results.putAll(getConditionVariables(condition.getSecond())); - } else if (genericCondition instanceof Condition.Permission) { - var condition = (Condition.Permission) genericCondition; + } else if (genericCondition instanceof Condition.Permission condition) { if (condition.getOwnerId() > 0) { results.put(Permission.getKey(condition.getOwnerClass()), condition.getOwnerId()); } else { results.put(Permission.getKey(condition.getPropertyClass()), condition.getPropertyId()); } - } else if (genericCondition instanceof Condition.LatestPositions) { - var condition = (Condition.LatestPositions) genericCondition; + } else if (genericCondition instanceof Condition.LatestPositions condition) { if (condition.getDeviceId() > 0) { results.put("deviceId", condition.getDeviceId()); } @@ -249,43 +244,38 @@ public class DatabaseStorage extends Storage { if (appendWhere) { result.append(" WHERE "); } - if (genericCondition instanceof Condition.Compare) { + if (genericCondition instanceof Condition.Compare condition) { - var condition = (Condition.Compare) genericCondition; result.append(condition.getColumn()); result.append(" "); result.append(condition.getOperator()); result.append(" :"); result.append(condition.getVariable()); - } else if (genericCondition instanceof Condition.Between) { + } else if (genericCondition instanceof Condition.Between condition) { - var condition = (Condition.Between) genericCondition; result.append(condition.getColumn()); result.append(" BETWEEN :"); result.append(condition.getFromVariable()); result.append(" AND :"); result.append(condition.getToVariable()); - } else if (genericCondition instanceof Condition.Binary) { + } else if (genericCondition instanceof Condition.Binary condition) { - var condition = (Condition.Binary) genericCondition; result.append(formatCondition(condition.getFirst(), false)); result.append(" "); result.append(condition.getOperator()); result.append(" "); result.append(formatCondition(condition.getSecond(), false)); - } else if (genericCondition instanceof Condition.Permission) { + } else if (genericCondition instanceof Condition.Permission condition) { - var condition = (Condition.Permission) genericCondition; result.append("id IN ("); result.append(formatPermissionQuery(condition)); result.append(")"); - } else if (genericCondition instanceof Condition.LatestPositions) { + } else if (genericCondition instanceof Condition.LatestPositions condition) { - var condition = (Condition.LatestPositions) genericCondition; result.append("id IN ("); result.append("SELECT positionId FROM "); result.append(getStorageName(Device.class)); diff --git a/src/main/java/org/traccar/storage/MemoryStorage.java b/src/main/java/org/traccar/storage/MemoryStorage.java index 9b5db1209..18cb6a294 100644 --- a/src/main/java/org/traccar/storage/MemoryStorage.java +++ b/src/main/java/org/traccar/storage/MemoryStorage.java @@ -60,47 +60,37 @@ public class MemoryStorage extends Storage { return true; } - if (genericCondition instanceof Condition.Compare) { + if (genericCondition instanceof Condition.Compare condition) { - var condition = (Condition.Compare) genericCondition; Object value = retrieveValue(object, condition.getVariable()); int result = ((Comparable) value).compareTo(condition.getValue()); - switch (condition.getOperator()) { - case "<": - return result < 0; - case "<=": - return result <= 0; - case ">": - return result > 0; - case ">=": - return result >= 0; - case "=": - return result == 0; - default: - throw new RuntimeException("Unsupported comparison condition"); - } + return switch (condition.getOperator()) { + case "<" -> result < 0; + case "<=" -> result <= 0; + case ">" -> result > 0; + case ">=" -> result >= 0; + case "=" -> result == 0; + default -> throw new RuntimeException("Unsupported comparison condition"); + }; - } else if (genericCondition instanceof Condition.Between) { + } else if (genericCondition instanceof Condition.Between condition) { - var condition = (Condition.Between) genericCondition; Object fromValue = retrieveValue(object, condition.getFromVariable()); int fromResult = ((Comparable) fromValue).compareTo(condition.getFromValue()); Object toValue = retrieveValue(object, condition.getToVariable()); int toResult = ((Comparable) toValue).compareTo(condition.getToValue()); return fromResult >= 0 && toResult <= 0; - } else if (genericCondition instanceof Condition.Binary) { + } else if (genericCondition instanceof Condition.Binary condition) { - var condition = (Condition.Binary) genericCondition; if (condition.getOperator().equals("AND")) { return checkCondition(condition.getFirst(), object) && checkCondition(condition.getSecond(), object); } else if (condition.getOperator().equals("OR")) { return checkCondition(condition.getFirst(), object) || checkCondition(condition.getSecond(), object); } - } else if (genericCondition instanceof Condition.Permission) { + } else if (genericCondition instanceof Condition.Permission condition) { - var condition = (Condition.Permission) genericCondition; long id = (Long) retrieveValue(object, "id"); return getPermissionsSet(condition.getOwnerClass(), condition.getPropertyClass()).stream() .anyMatch(pair -> { diff --git a/src/main/java/org/traccar/storage/QueryBuilder.java b/src/main/java/org/traccar/storage/QueryBuilder.java index 2f4c07406..6a9c46807 100644 --- a/src/main/java/org/traccar/storage/QueryBuilder.java +++ b/src/main/java/org/traccar/storage/QueryBuilder.java @@ -267,18 +267,18 @@ public final class QueryBuilder { } public QueryBuilder setValue(String name, Object value) throws SQLException { - if (value instanceof Boolean) { - setBoolean(name, (Boolean) value); - } else if (value instanceof Integer) { - setInteger(name, (Integer) value); - } else if (value instanceof Long) { - setLong(name, (Long) value); - } else if (value instanceof Double) { - setDouble(name, (Double) value); - } else if (value instanceof String) { - setString(name, (String) value); - } else if (value instanceof Date) { - setDate(name, (Date) value); + if (value instanceof Boolean booleanValue) { + setBoolean(name, booleanValue); + } else if (value instanceof Integer integerValue) { + setInteger(name, integerValue); + } else if (value instanceof Long longValue) { + setLong(name, longValue); + } else if (value instanceof Double doubleValue) { + setDouble(name, doubleValue); + } else if (value instanceof String stringValue) { + setString(name, stringValue); + } else if (value instanceof Date dateValue) { + setDate(name, dateValue); } return this; } diff --git a/src/test/java/org/traccar/ProtocolTest.java b/src/test/java/org/traccar/ProtocolTest.java index 0726000be..273520155 100644 --- a/src/test/java/org/traccar/ProtocolTest.java +++ b/src/test/java/org/traccar/ProtocolTest.java @@ -28,6 +28,7 @@ import java.util.TimeZone; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -159,7 +160,7 @@ public class ProtocolTest extends BaseTest { private void verifyDecodedList(Object decodedObject, boolean checkLocation, Position expected) { assertNotNull(decodedObject, "list is null"); - assertTrue(decodedObject instanceof List, "not a list"); + assertInstanceOf(List.class, decodedObject, "not a list"); assertFalse(((List) decodedObject).isEmpty(), "list is empty"); for (Object item : (List) decodedObject) { @@ -171,7 +172,7 @@ public class ProtocolTest extends BaseTest { private void verifyDecodedPosition(Object decodedObject, boolean checkLocation, boolean checkAttributes, Position expected) { assertNotNull(decodedObject, "position is null"); - assertTrue(decodedObject instanceof Position, "not a position"); + assertInstanceOf(Position.class, decodedObject, "not a position"); Position position = (Position) decodedObject; @@ -225,55 +226,55 @@ public class ProtocolTest extends BaseTest { } if (attributes.containsKey(Position.KEY_INDEX)) { - assertTrue(attributes.get(Position.KEY_INDEX) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_INDEX)); } if (attributes.containsKey(Position.KEY_HDOP)) { - assertTrue(attributes.get(Position.KEY_HDOP) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_HDOP)); } if (attributes.containsKey(Position.KEY_VDOP)) { - assertTrue(attributes.get(Position.KEY_VDOP) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_VDOP)); } if (attributes.containsKey(Position.KEY_PDOP)) { - assertTrue(attributes.get(Position.KEY_PDOP) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_PDOP)); } if (attributes.containsKey(Position.KEY_SATELLITES)) { - assertTrue(attributes.get(Position.KEY_SATELLITES) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_SATELLITES)); } if (attributes.containsKey(Position.KEY_SATELLITES_VISIBLE)) { - assertTrue(attributes.get(Position.KEY_SATELLITES_VISIBLE) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_SATELLITES_VISIBLE)); } if (attributes.containsKey(Position.KEY_RSSI)) { - assertTrue(attributes.get(Position.KEY_RSSI) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_RSSI)); } if (attributes.containsKey(Position.KEY_ODOMETER)) { - assertTrue(attributes.get(Position.KEY_ODOMETER) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_ODOMETER)); } if (attributes.containsKey(Position.KEY_RPM)) { - assertTrue(attributes.get(Position.KEY_RPM) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_RPM)); } if (attributes.containsKey(Position.KEY_FUEL_LEVEL)) { - assertTrue(attributes.get(Position.KEY_FUEL_LEVEL) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_FUEL_LEVEL)); } if (attributes.containsKey(Position.KEY_FUEL_USED)) { - assertTrue(attributes.get(Position.KEY_FUEL_USED) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_FUEL_USED)); } if (attributes.containsKey(Position.KEY_POWER)) { - assertTrue(attributes.get(Position.KEY_POWER) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_POWER)); } if (attributes.containsKey(Position.KEY_BATTERY)) { - assertTrue(attributes.get(Position.KEY_BATTERY) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_BATTERY)); } if (attributes.containsKey(Position.KEY_BATTERY_LEVEL)) { @@ -282,39 +283,39 @@ public class ProtocolTest extends BaseTest { } if (attributes.containsKey(Position.KEY_CHARGE)) { - assertTrue(attributes.get(Position.KEY_CHARGE) instanceof Boolean); + assertInstanceOf(Boolean.class, attributes.get(Position.KEY_CHARGE)); } if (attributes.containsKey(Position.KEY_IGNITION)) { - assertTrue(attributes.get(Position.KEY_IGNITION) instanceof Boolean); + assertInstanceOf(Boolean.class, attributes.get(Position.KEY_IGNITION)); } if (attributes.containsKey(Position.KEY_MOTION)) { - assertTrue(attributes.get(Position.KEY_MOTION) instanceof Boolean); + assertInstanceOf(Boolean.class, attributes.get(Position.KEY_MOTION)); } if (attributes.containsKey(Position.KEY_ARCHIVE)) { - assertTrue(attributes.get(Position.KEY_ARCHIVE) instanceof Boolean); + assertInstanceOf(Boolean.class, attributes.get(Position.KEY_ARCHIVE)); } if (attributes.containsKey(Position.KEY_DRIVER_UNIQUE_ID)) { - assertTrue(attributes.get(Position.KEY_DRIVER_UNIQUE_ID) instanceof String); + assertInstanceOf(String.class, attributes.get(Position.KEY_DRIVER_UNIQUE_ID)); } if (attributes.containsKey(Position.KEY_STEPS)) { - assertTrue(attributes.get(Position.KEY_STEPS) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_STEPS)); } if (attributes.containsKey(Position.KEY_ROAMING)) { - assertTrue(attributes.get(Position.KEY_ROAMING) instanceof Boolean); + assertInstanceOf(Boolean.class, attributes.get(Position.KEY_ROAMING)); } if (attributes.containsKey(Position.KEY_HOURS)) { - assertTrue(attributes.get(Position.KEY_HOURS) instanceof Number); + assertInstanceOf(Number.class, attributes.get(Position.KEY_HOURS)); } if (attributes.containsKey(Position.KEY_RESULT)) { - assertTrue(attributes.get(Position.KEY_RESULT) instanceof String); + assertInstanceOf(String.class, attributes.get(Position.KEY_RESULT)); } if (position.getNetwork() != null) { @@ -351,7 +352,7 @@ public class ProtocolTest extends BaseTest { protected void verifyFrame(ByteBuf expected, Object object) { assertNotNull(object, "buffer is null"); - assertTrue(object instanceof ByteBuf, "not a buffer"); + assertInstanceOf(ByteBuf.class, object, "not a buffer"); assertEquals(ByteBufUtil.hexDump(expected), ByteBufUtil.hexDump((ByteBuf) object)); } -- cgit v1.2.3 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 --- gradle/checkstyle.xml | 2 +- src/main/java/org/traccar/BaseProtocolDecoder.java | 17 +- src/main/java/org/traccar/MainModule.java | 160 ++---- src/main/java/org/traccar/WindowsService.java | 15 +- .../traccar/api/resource/AttributeResource.java | 14 +- .../org/traccar/api/resource/DeviceResource.java | 22 +- .../java/org/traccar/database/LdapProvider.java | 23 +- .../org/traccar/geocoder/MapTilerGeocoder.java | 5 - .../traccar/handler/ComputedAttributesHandler.java | 47 +- .../handler/events/MaintenanceEventHandler.java | 16 +- src/main/java/org/traccar/helper/Log.java | 24 +- src/main/java/org/traccar/helper/ObdDecoder.java | 78 +-- .../org/traccar/protocol/AdmProtocolDecoder.java | 41 +- .../org/traccar/protocol/AdmProtocolEncoder.java | 15 +- .../traccar/protocol/AplicomProtocolDecoder.java | 150 ++---- .../traccar/protocol/ArknavX8ProtocolDecoder.java | 15 +- .../protocol/ArnaviBinaryProtocolDecoder.java | 12 +- .../traccar/protocol/AtrackProtocolDecoder.java | 562 ++++++--------------- .../traccar/protocol/AtrackProtocolEncoder.java | 10 +- .../org/traccar/protocol/AutoFonFrameDecoder.java | 29 +- .../traccar/protocol/AutoTrackProtocolDecoder.java | 11 +- .../org/traccar/protocol/B2316ProtocolDecoder.java | 41 +- .../org/traccar/protocol/BlueProtocolDecoder.java | 16 +- .../org/traccar/protocol/BstplProtocolDecoder.java | 22 +- .../traccar/protocol/C2stekProtocolDecoder.java | 28 +- .../traccar/protocol/CarcellProtocolEncoder.java | 13 +- .../traccar/protocol/CastelProtocolDecoder.java | 108 ++-- .../traccar/protocol/CastelProtocolEncoder.java | 17 +- .../traccar/protocol/CellocatorFrameDecoder.java | 26 +- .../protocol/CellocatorProtocolDecoder.java | 16 +- .../protocol/CellocatorProtocolEncoder.java | 12 +- .../traccar/protocol/CguardProtocolDecoder.java | 20 +- .../traccar/protocol/CityeasyProtocolEncoder.java | 15 +- .../traccar/protocol/DmtHttpProtocolDecoder.java | 12 +- .../org/traccar/protocol/DmtProtocolDecoder.java | 58 +-- .../traccar/protocol/EasyTrackProtocolEncoder.java | 19 +- .../traccar/protocol/EelinkProtocolDecoder.java | 58 +-- .../traccar/protocol/EelinkProtocolEncoder.java | 22 +- .../traccar/protocol/EnforaProtocolEncoder.java | 16 +- .../traccar/protocol/EnvotechProtocolDecoder.java | 10 +- .../org/traccar/protocol/EsealProtocolDecoder.java | 32 +- .../org/traccar/protocol/EsealProtocolEncoder.java | 22 +- .../traccar/protocol/FifotrackProtocolDecoder.java | 66 +-- .../traccar/protocol/FifotrackProtocolEncoder.java | 13 +- .../protocol/FleetGuideProtocolDecoder.java | 14 +- .../traccar/protocol/FlespiProtocolDecoder.java | 210 ++++---- .../traccar/protocol/FlexApiProtocolDecoder.java | 14 +- .../protocol/FreematicsProtocolDecoder.java | 91 +--- .../traccar/protocol/GalileoProtocolDecoder.java | 114 ++--- .../traccar/protocol/GalileoProtocolEncoder.java | 16 +- .../org/traccar/protocol/GatorProtocolEncoder.java | 29 +- .../org/traccar/protocol/GenxProtocolDecoder.java | 43 +- .../protocol/Gl200BinaryProtocolDecoder.java | 63 +-- .../org/traccar/protocol/Gl200FrameDecoder.java | 28 +- .../org/traccar/protocol/Gl200ProtocolEncoder.java | 29 +- .../traccar/protocol/Gl200TextProtocolDecoder.java | 180 ++----- .../traccar/protocol/GlobalSatProtocolEncoder.java | 20 +- .../traccar/protocol/Gps103ProtocolDecoder.java | 44 +- .../traccar/protocol/Gps103ProtocolEncoder.java | 44 +- .../traccar/protocol/GranitProtocolEncoder.java | 16 +- .../traccar/protocol/GranitProtocolSmsEncoder.java | 13 +- .../org/traccar/protocol/Gt06ProtocolDecoder.java | 237 +++------ .../org/traccar/protocol/Gt30ProtocolDecoder.java | 21 +- .../org/traccar/protocol/H02ProtocolDecoder.java | 35 +- .../org/traccar/protocol/H02ProtocolEncoder.java | 26 +- .../traccar/protocol/HuabaoProtocolDecoder.java | 304 +++-------- .../java/org/traccar/schedule/TaskReports.java | 24 +- .../org/traccar/session/ConnectionManager.java | 16 +- src/test/java/org/traccar/ProtocolTest.java | 16 +- 69 files changed, 1172 insertions(+), 2405 deletions(-) (limited to 'src/test/java/org') diff --git a/gradle/checkstyle.xml b/gradle/checkstyle.xml index bb89450d6..fc016c6f6 100644 --- a/gradle/checkstyle.xml +++ b/gradle/checkstyle.xml @@ -115,7 +115,7 @@ - + diff --git a/src/main/java/org/traccar/BaseProtocolDecoder.java b/src/main/java/org/traccar/BaseProtocolDecoder.java index 2f9c75ec2..5e3f668ed 100644 --- a/src/main/java/org/traccar/BaseProtocolDecoder.java +++ b/src/main/java/org/traccar/BaseProtocolDecoder.java @@ -108,17 +108,12 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { } protected double convertSpeed(double value, String defaultUnits) { - switch (getConfig().getString(getProtocolName() + ".speed", defaultUnits)) { - case "kmh": - return UnitsConverter.knotsFromKph(value); - case "mps": - return UnitsConverter.knotsFromMps(value); - case "mph": - return UnitsConverter.knotsFromMph(value); - case "kn": - default: - return value; - } + return switch (getConfig().getString(getProtocolName() + ".speed", defaultUnits)) { + case "kmh" -> UnitsConverter.knotsFromKph(value); + case "mps" -> UnitsConverter.knotsFromMps(value); + case "mph" -> UnitsConverter.knotsFromMph(value); + default -> value; + }; } protected TimeZone getTimeZone(long deviceId) { diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index 806e6da18..c7b74d049 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -206,69 +206,28 @@ public class MainModule extends AbstractModule { AddressFormat addressFormat = formatString != null ? new AddressFormat(formatString) : new AddressFormat(); int cacheSize = config.getInteger(Keys.GEOCODER_CACHE_SIZE); - Geocoder geocoder; - switch (type) { - case "pluscodes": - geocoder = new PlusCodesGeocoder(); - break; - case "nominatim": - geocoder = new NominatimGeocoder(client, url, key, language, cacheSize, addressFormat); - break; - case "locationiq": - geocoder = new LocationIqGeocoder(client, url, key, language, cacheSize, addressFormat); - break; - case "gisgraphy": - geocoder = new GisgraphyGeocoder(client, url, cacheSize, addressFormat); - break; - case "mapquest": - geocoder = new MapQuestGeocoder(client, url, key, cacheSize, addressFormat); - break; - case "opencage": - geocoder = new OpenCageGeocoder(client, url, key, language, cacheSize, addressFormat); - break; - case "bingmaps": - geocoder = new BingMapsGeocoder(client, url, key, cacheSize, addressFormat); - break; - case "factual": - geocoder = new FactualGeocoder(client, url, key, cacheSize, addressFormat); - break; - case "geocodefarm": - geocoder = new GeocodeFarmGeocoder(client, key, language, cacheSize, addressFormat); - break; - case "geocodexyz": - geocoder = new GeocodeXyzGeocoder(client, key, cacheSize, addressFormat); - break; - case "ban": - geocoder = new BanGeocoder(client, cacheSize, addressFormat); - break; - case "here": - geocoder = new HereGeocoder(client, url, key, language, cacheSize, addressFormat); - break; - case "mapmyindia": - geocoder = new MapmyIndiaGeocoder(client, url, key, cacheSize, addressFormat); - break; - case "tomtom": - geocoder = new TomTomGeocoder(client, url, key, cacheSize, addressFormat); - break; - case "positionstack": - geocoder = new PositionStackGeocoder(client, key, cacheSize, addressFormat); - break; - case "mapbox": - geocoder = new MapboxGeocoder(client, key, cacheSize, addressFormat); - break; - case "maptiler": - geocoder = new MapTilerGeocoder(client, key, cacheSize, addressFormat); - break; - case "geoapify": - geocoder = new GeoapifyGeocoder(client, key, language, cacheSize, addressFormat); - break; - case "geocodejson": - geocoder = new GeocodeJsonGeocoder(client, url, key, language, cacheSize, addressFormat); - break; - default: - geocoder = new GoogleGeocoder(client, key, language, cacheSize, addressFormat); - break; - } + Geocoder geocoder = switch (type) { + case "pluscodes" -> new PlusCodesGeocoder(); + case "nominatim" -> new NominatimGeocoder(client, url, key, language, cacheSize, addressFormat); + case "locationiq" -> new LocationIqGeocoder(client, url, key, language, cacheSize, addressFormat); + case "gisgraphy" -> new GisgraphyGeocoder(client, url, cacheSize, addressFormat); + case "mapquest" -> new MapQuestGeocoder(client, url, key, cacheSize, addressFormat); + case "opencage" -> new OpenCageGeocoder(client, url, key, language, cacheSize, addressFormat); + case "bingmaps" -> new BingMapsGeocoder(client, url, key, cacheSize, addressFormat); + case "factual" -> new FactualGeocoder(client, url, key, cacheSize, addressFormat); + case "geocodefarm" -> new GeocodeFarmGeocoder(client, key, language, cacheSize, addressFormat); + case "geocodexyz" -> new GeocodeXyzGeocoder(client, key, cacheSize, addressFormat); + case "ban" -> new BanGeocoder(client, cacheSize, addressFormat); + case "here" -> new HereGeocoder(client, url, key, language, cacheSize, addressFormat); + case "mapmyindia" -> new MapmyIndiaGeocoder(client, url, key, cacheSize, addressFormat); + case "tomtom" -> new TomTomGeocoder(client, url, key, cacheSize, addressFormat); + case "positionstack" -> new PositionStackGeocoder(client, key, cacheSize, addressFormat); + case "mapbox" -> new MapboxGeocoder(client, key, cacheSize, addressFormat); + case "maptiler" -> new MapTilerGeocoder(client, key, cacheSize, addressFormat); + case "geoapify" -> new GeoapifyGeocoder(client, key, language, cacheSize, addressFormat); + case "geocodejson" -> new GeocodeJsonGeocoder(client, url, key, language, cacheSize, addressFormat); + default -> new GoogleGeocoder(client, key, language, cacheSize, addressFormat); + }; geocoder.setStatisticsManager(statisticsManager); return geocoder; } @@ -282,14 +241,11 @@ public class MainModule extends AbstractModule { String type = config.getString(Keys.GEOLOCATION_TYPE, "google"); String url = config.getString(Keys.GEOLOCATION_URL); String key = config.getString(Keys.GEOLOCATION_KEY); - switch (type) { - case "opencellid": - return new OpenCellIdGeolocationProvider(client, url, key); - case "unwired": - return new UnwiredGeolocationProvider(client, url, key); - default: - return new GoogleGeolocationProvider(client, key); - } + return switch (type) { + case "opencellid" -> new OpenCellIdGeolocationProvider(client, url, key); + case "unwired" -> new UnwiredGeolocationProvider(client, url, key); + default -> new GoogleGeolocationProvider(client, key); + }; } return null; } @@ -300,11 +256,10 @@ public class MainModule extends AbstractModule { if (config.getBoolean(Keys.SPEED_LIMIT_ENABLE)) { String type = config.getString(Keys.SPEED_LIMIT_TYPE, "overpass"); String url = config.getString(Keys.SPEED_LIMIT_URL); - switch (type) { - case "overpass": - default: - return new OverpassSpeedLimitProvider(config, client, url); - } + return switch (type) { + case "overpass" -> new OverpassSpeedLimitProvider(config, client, url); + default -> throw new IllegalArgumentException("Unknown speed limit provider"); + }; } return null; } @@ -372,14 +327,11 @@ public class MainModule extends AbstractModule { public static BroadcastService provideBroadcastService( Config config, ObjectMapper objectMapper) throws IOException { if (config.hasKey(Keys.BROADCAST_TYPE)) { - switch (config.getString(Keys.BROADCAST_TYPE)) { - case "multicast": - return new MulticastBroadcastService(config, objectMapper); - case "redis": - return new RedisBroadcastService(config, objectMapper); - default: - break; - } + return switch (config.getString(Keys.BROADCAST_TYPE)) { + case "multicast" -> new MulticastBroadcastService(config, objectMapper); + case "redis" -> new RedisBroadcastService(config, objectMapper); + default -> new NullBroadcastService(); + }; } return new NullBroadcastService(); } @@ -389,17 +341,12 @@ public class MainModule extends AbstractModule { public static EventForwarder provideEventForwarder(Config config, Client client, ObjectMapper objectMapper) { if (config.hasKey(Keys.EVENT_FORWARD_URL)) { String forwardType = config.getString(Keys.EVENT_FORWARD_TYPE); - switch (forwardType) { - case "amqp": - return new EventForwarderAmqp(config, objectMapper); - case "kafka": - return new EventForwarderKafka(config, objectMapper); - case "mqtt": - return new EventForwarderMqtt(config, objectMapper); - case "json": - default: - return new EventForwarderJson(config, client); - } + return switch (forwardType) { + case "amqp" -> new EventForwarderAmqp(config, objectMapper); + case "kafka" -> new EventForwarderKafka(config, objectMapper); + case "mqtt" -> new EventForwarderMqtt(config, objectMapper); + default -> new EventForwarderJson(config, client); + }; } return null; } @@ -408,21 +355,14 @@ public class MainModule extends AbstractModule { @Provides public static PositionForwarder providePositionForwarder(Config config, Client client, ObjectMapper objectMapper) { if (config.hasKey(Keys.FORWARD_URL)) { - switch (config.getString(Keys.FORWARD_TYPE)) { - case "json": - return new PositionForwarderJson(config, client, objectMapper); - case "amqp": - return new PositionForwarderAmqp(config, objectMapper); - case "kafka": - return new PositionForwarderKafka(config, objectMapper); - case "mqtt": - return new PositionForwarderMqtt(config, objectMapper); - case "redis": - return new PositionForwarderRedis(config, objectMapper); - case "url": - default: - return new PositionForwarderUrl(config, client, objectMapper); - } + return switch (config.getString(Keys.FORWARD_TYPE)) { + case "json" -> new PositionForwarderJson(config, client, objectMapper); + case "amqp" -> new PositionForwarderAmqp(config, objectMapper); + case "kafka" -> new PositionForwarderKafka(config, objectMapper); + case "mqtt" -> new PositionForwarderMqtt(config, objectMapper); + case "redis" -> new PositionForwarderRedis(config, objectMapper); + default -> new PositionForwarderUrl(config, client, objectMapper); + }; } return null; } diff --git a/src/main/java/org/traccar/WindowsService.java b/src/main/java/org/traccar/WindowsService.java index 08eba25a6..61606c5be 100644 --- a/src/main/java/org/traccar/WindowsService.java +++ b/src/main/java/org/traccar/WindowsService.java @@ -206,16 +206,11 @@ public abstract class WindowsService { private final class ServiceControl implements HandlerEx { public int callback(int dwControl, int dwEventType, Pointer lpEventData, Pointer lpContext) { - switch (dwControl) { - case Winsvc.SERVICE_CONTROL_STOP: - case Winsvc.SERVICE_CONTROL_SHUTDOWN: - reportStatus(Winsvc.SERVICE_STOP_PENDING, WinError.NO_ERROR, 5000); - synchronized (waitObject) { - waitObject.notifyAll(); - } - break; - default: - break; + if (dwControl == Winsvc.SERVICE_CONTROL_STOP || dwControl == Winsvc.SERVICE_CONTROL_SHUTDOWN) { + reportStatus(Winsvc.SERVICE_STOP_PENDING, WinError.NO_ERROR, 5000); + synchronized (waitObject) { + waitObject.notifyAll(); + } } return WinError.NO_ERROR; } diff --git a/src/main/java/org/traccar/api/resource/AttributeResource.java b/src/main/java/org/traccar/api/resource/AttributeResource.java index 52c4d6324..8debb2e50 100644 --- a/src/main/java/org/traccar/api/resource/AttributeResource.java +++ b/src/main/java/org/traccar/api/resource/AttributeResource.java @@ -62,16 +62,10 @@ public class AttributeResource extends ExtendedObjectResource { Object result = computedAttributesHandler.computeAttribute(entity, position); if (result != null) { - switch (entity.getType()) { - case "number": - Number numberValue = (Number) result; - return Response.ok(numberValue).build(); - case "boolean": - Boolean booleanValue = (Boolean) result; - return Response.ok(booleanValue).build(); - default: - return Response.ok(result.toString()).build(); - } + return switch (entity.getType()) { + case "number", "boolean" -> Response.ok(result).build(); + default -> Response.ok(result.toString()).build(); + }; } else { return Response.noContent().build(); } diff --git a/src/main/java/org/traccar/api/resource/DeviceResource.java b/src/main/java/org/traccar/api/resource/DeviceResource.java index 61d96669e..4be8dbb12 100644 --- a/src/main/java/org/traccar/api/resource/DeviceResource.java +++ b/src/main/java/org/traccar/api/resource/DeviceResource.java @@ -174,20 +174,14 @@ public class DeviceResource extends BaseObjectResource { } private String imageExtension(String type) { - switch (type) { - case "image/jpeg": - return "jpg"; - case "image/png": - return "png"; - case "image/gif": - return "gif"; - case "image/webp": - return "webp"; - case "image/svg+xml": - return "svg"; - default: - throw new IllegalArgumentException("Unsupported image type"); - } + return switch (type) { + case "image/jpeg" -> "jpg"; + case "image/png" -> "png"; + case "image/gif" -> "gif"; + case "image/webp" -> "webp"; + case "image/svg+xml" -> "svg"; + default -> throw new IllegalArgumentException("Unsupported image type"); + }; } @Path("{id}/image") diff --git a/src/main/java/org/traccar/database/LdapProvider.java b/src/main/java/org/traccar/database/LdapProvider.java index d517294b8..549b68e6c 100644 --- a/src/main/java/org/traccar/database/LdapProvider.java +++ b/src/main/java/org/traccar/database/LdapProvider.java @@ -189,23 +189,12 @@ public class LdapProvider { for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); switch (c) { - case '\\': - sb.append("\\5c"); - break; - case '*': - sb.append("\\2a"); - break; - case '(': - sb.append("\\28"); - break; - case ')': - sb.append("\\29"); - break; - case '\0': - sb.append("\\00"); - break; - default: - sb.append(c); + case '\\' -> sb.append("\\5c"); + case '*' -> sb.append("\\2a"); + case '(' -> sb.append("\\28"); + case ')' -> sb.append("\\29"); + case '\0' -> sb.append("\\00"); + default -> sb.append(c); } } return sb.toString(); diff --git a/src/main/java/org/traccar/geocoder/MapTilerGeocoder.java b/src/main/java/org/traccar/geocoder/MapTilerGeocoder.java index 24c9da2ad..11394339a 100644 --- a/src/main/java/org/traccar/geocoder/MapTilerGeocoder.java +++ b/src/main/java/org/traccar/geocoder/MapTilerGeocoder.java @@ -66,9 +66,4 @@ public class MapTilerGeocoder extends JsonGeocoder { return null; } - @Override - protected String parseError(JsonObject json) { - return null; - } - } diff --git a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java index b7d7a5ed5..f4079f127 100644 --- a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java +++ b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java @@ -150,44 +150,29 @@ public class ComputedAttributesHandler extends BasePositionHandler { Object result = computeAttribute(attribute, position); if (result != null) { switch (attribute.getAttribute()) { - case "valid": - position.setValid((Boolean) result); - break; - case "latitude": - position.setLatitude(((Number) result).doubleValue()); - break; - case "longitude": - position.setLongitude(((Number) result).doubleValue()); - break; - case "altitude": - position.setAltitude(((Number) result).doubleValue()); - break; - case "speed": - position.setSpeed(((Number) result).doubleValue()); - break; - case "course": - position.setCourse(((Number) result).doubleValue()); - break; - case "address": - position.setAddress((String) result); - break; - case "accuracy": - position.setAccuracy(((Number) result).doubleValue()); - break; - default: + case "valid" -> position.setValid((Boolean) result); + case "latitude" -> position.setLatitude(((Number) result).doubleValue()); + case "longitude" -> position.setLongitude(((Number) result).doubleValue()); + case "altitude" -> position.setAltitude(((Number) result).doubleValue()); + case "speed" -> position.setSpeed(((Number) result).doubleValue()); + case "course" -> position.setCourse(((Number) result).doubleValue()); + case "address" -> position.setAddress((String) result); + case "accuracy" -> position.setAccuracy(((Number) result).doubleValue()); + default -> { switch (attribute.getType()) { - case "number": + case "number" -> { Number numberValue = (Number) result; position.getAttributes().put(attribute.getAttribute(), numberValue); - break; - case "boolean": + } + case "boolean" -> { Boolean booleanValue = (Boolean) result; position.getAttributes().put(attribute.getAttribute(), booleanValue); - break; - default: + } + default -> { position.getAttributes().put(attribute.getAttribute(), result.toString()); + } } - break; + } } } else { position.getAttributes().remove(attribute.getAttribute()); diff --git a/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java b/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java index 573ad4ad6..7fc6086aa 100644 --- a/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java +++ b/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java @@ -57,16 +57,12 @@ public class MaintenanceEventHandler extends BaseEventHandler { } private double getValue(Position position, String type) { - switch (type) { - case "serverTime": - return position.getServerTime().getTime(); - case "deviceTime": - return position.getDeviceTime().getTime(); - case "fixTime": - return position.getFixTime().getTime(); - default: - return position.getDouble(type); - } + return switch (type) { + case "serverTime" -> position.getServerTime().getTime(); + case "deviceTime" -> position.getDeviceTime().getTime(); + case "fixTime" -> position.getFixTime().getTime(); + default -> position.getDouble(type); + }; } } diff --git a/src/main/java/org/traccar/helper/Log.java b/src/main/java/org/traccar/helper/Log.java index 6c6d49550..c68198542 100644 --- a/src/main/java/org/traccar/helper/Log.java +++ b/src/main/java/org/traccar/helper/Log.java @@ -126,21 +126,13 @@ public final class Log { } private static String formatLevel(Level level) { - switch (level.getName()) { - case "FINEST": - return "TRACE"; - case "FINER": - case "FINE": - case "CONFIG": - return "DEBUG"; - case "INFO": - return "INFO"; - case "WARNING": - return "WARN"; - case "SEVERE": - default: - return "ERROR"; - } + return switch (level.getName()) { + case "FINEST" -> "TRACE"; + case "FINER", "FINE", "CONFIG" -> "DEBUG"; + case "INFO" -> "INFO"; + case "WARNING" -> "WARN"; + default -> "ERROR"; + }; } @Override @@ -152,7 +144,7 @@ public final class Log { } if (record.getThrown() != null) { - if (message.length() > 0) { + if (!message.isEmpty()) { message.append(" - "); } if (fullStackTraces) { diff --git a/src/main/java/org/traccar/helper/ObdDecoder.java b/src/main/java/org/traccar/helper/ObdDecoder.java index 3cbae334a..091747225 100644 --- a/src/main/java/org/traccar/helper/ObdDecoder.java +++ b/src/main/java/org/traccar/helper/ObdDecoder.java @@ -30,17 +30,13 @@ public final class ObdDecoder { private static final int MODE_CODES = 0x03; public static Map.Entry decode(int mode, String value) { - switch (mode) { - case MODE_CURRENT: - case MODE_FREEZE_FRAME: - return decodeData( - Integer.parseInt(value.substring(0, 2), 16), - Long.parseLong(value.substring(2), 16), true); - case MODE_CODES: - return decodeCodes(value); - default: - return null; - } + return switch (mode) { + case MODE_CURRENT, MODE_FREEZE_FRAME -> decodeData( + Integer.parseInt(value.substring(0, 2), 16), + Long.parseLong(value.substring(2), 16), true); + case MODE_CODES -> decodeCodes(value); + default -> null; + }; } private static Map.Entry createEntry(String key, Object value) { @@ -53,7 +49,7 @@ public final class ObdDecoder { int numValue = Integer.parseInt(value.substring(i * 4, (i + 1) * 4), 16); codes.append(' ').append(decodeCode(numValue)); } - if (codes.length() > 0) { + if (!codes.isEmpty()) { return createEntry(Position.KEY_DTCS, codes.toString().trim()); } else { return null; @@ -61,49 +57,29 @@ public final class ObdDecoder { } public static String decodeCode(int value) { - char prefix; - switch (value >> 14) { - case 1: - prefix = 'C'; - break; - case 2: - prefix = 'B'; - break; - case 3: - prefix = 'U'; - break; - default: - prefix = 'P'; - break; - } + char prefix = switch (value >> 14) { + case 1 -> 'C'; + case 2 -> 'B'; + case 3 -> 'U'; + default -> 'P'; + }; return String.format("%c%04X", prefix, value & 0x3FFF); } public static Map.Entry decodeData(int pid, long value, boolean convert) { - switch (pid) { - case 0x04: - return createEntry(Position.KEY_ENGINE_LOAD, convert ? value * 100 / 255 : value); - case 0x05: - return createEntry(Position.KEY_COOLANT_TEMP, convert ? value - 40 : value); - case 0x0B: - return createEntry("mapIntake", value); - case 0x0C: - return createEntry(Position.KEY_RPM, convert ? value / 4 : value); - case 0x0D: - return createEntry(Position.KEY_OBD_SPEED, value); - case 0x0F: - return createEntry("intakeTemp", convert ? value - 40 : value); - case 0x11: - return createEntry(Position.KEY_THROTTLE, convert ? value * 100 / 255 : value); - case 0x21: - return createEntry("milDistance", value); - case 0x2F: - return createEntry(Position.KEY_FUEL_LEVEL, convert ? value * 100 / 255 : value); - case 0x31: - return createEntry("clearedDistance", value); - default: - return null; - } + return switch (pid) { + case 0x04 -> createEntry(Position.KEY_ENGINE_LOAD, convert ? value * 100 / 255 : value); + case 0x05 -> createEntry(Position.KEY_COOLANT_TEMP, convert ? value - 40 : value); + case 0x0B -> createEntry("mapIntake", value); + case 0x0C -> createEntry(Position.KEY_RPM, convert ? value / 4 : value); + case 0x0D -> createEntry(Position.KEY_OBD_SPEED, value); + case 0x0F -> createEntry("intakeTemp", convert ? value - 40 : value); + case 0x11 -> createEntry(Position.KEY_THROTTLE, convert ? value * 100 / 255 : value); + case 0x21 -> createEntry("milDistance", value); + case 0x2F -> createEntry(Position.KEY_FUEL_LEVEL, convert ? value * 100 / 255 : value); + case 0x31 -> createEntry("clearedDistance", value); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/AdmProtocolDecoder.java b/src/main/java/org/traccar/protocol/AdmProtocolDecoder.java index 1f940f7e2..3eab90988 100644 --- a/src/main/java/org/traccar/protocol/AdmProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/AdmProtocolDecoder.java @@ -108,38 +108,19 @@ public class AdmProtocolDecoder extends BaseProtocolDecoder { int endIndex = buf.readerIndex() + buf.readUnsignedByte(); while (buf.readerIndex() < endIndex) { int mask = buf.readUnsignedByte(); - long value; - switch (BitUtil.from(mask, 6)) { - case 3: - value = buf.readLongLE(); - break; - case 2: - value = buf.readUnsignedIntLE(); - break; - case 1: - value = buf.readUnsignedShortLE(); - break; - default: - value = buf.readUnsignedByte(); - break; - } + long value = switch (BitUtil.from(mask, 6)) { + case 3 -> buf.readLongLE(); + case 2 -> buf.readUnsignedIntLE(); + case 1 -> buf.readUnsignedShortLE(); + default -> buf.readUnsignedByte(); + }; int index = BitUtil.to(mask, 6); switch (index) { - case 1: - position.set(Position.PREFIX_TEMP + 1, value); - break; - case 2: - position.set("humidity", value); - break; - case 3: - position.set("illumination", value); - break; - case 4: - position.set(Position.KEY_BATTERY, value); - break; - default: - position.set("can" + index, value); - break; + case 1 -> position.set(Position.PREFIX_TEMP + 1, value); + case 2 -> position.set("humidity", value); + case 3 -> position.set("illumination", value); + case 4 -> position.set(Position.KEY_BATTERY, value); + default -> position.set("can" + index, value); } } } diff --git a/src/main/java/org/traccar/protocol/AdmProtocolEncoder.java b/src/main/java/org/traccar/protocol/AdmProtocolEncoder.java index c02fa4112..9bd0e7909 100644 --- a/src/main/java/org/traccar/protocol/AdmProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/AdmProtocolEncoder.java @@ -29,16 +29,11 @@ public class AdmProtocolEncoder extends StringProtocolEncoder { @Override protected Object encodeCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_GET_DEVICE_STATUS: - return formatCommand(command, "STATUS\r\n"); - - case Command.TYPE_CUSTOM: - return formatCommand(command, "%s\r\n", Command.KEY_DATA); - - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_GET_DEVICE_STATUS -> formatCommand(command, "STATUS\r\n"); + case Command.TYPE_CUSTOM -> formatCommand(command, "%s\r\n", Command.KEY_DATA); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/AplicomProtocolDecoder.java b/src/main/java/org/traccar/protocol/AplicomProtocolDecoder.java index 0cd8ca37e..d560620b7 100644 --- a/src/main/java/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/AplicomProtocolDecoder.java @@ -88,40 +88,19 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { private void decodeEventData(Position position, ByteBuf buf, int event) { switch (event) { - case 2: - case 40: - buf.readUnsignedByte(); - break; - case 9: - buf.readUnsignedMedium(); - break; - case 31: - case 32: - buf.readUnsignedShort(); - break; - case 38: - buf.skipBytes(4 * 9); - break; - case 113: + case 2, 40 -> buf.readUnsignedByte(); + case 9 -> buf.readUnsignedMedium(); + case 31, 32 -> buf.readUnsignedShort(); + case 38 -> buf.skipBytes(4 * 9); + case 113 -> { buf.readUnsignedInt(); buf.readUnsignedByte(); - break; - case 119: - position.set("eventData", ByteBufUtil.hexDump( - buf, buf.readerIndex(), Math.min(buf.readableBytes(), 1024))); - break; - case 121: - case 142: - buf.readLong(); - break; - case 130: - buf.readUnsignedInt(); // incorrect - break; - case 188: - decodeEB(position, buf); - break; - default: - break; + } + case 119 -> position.set("eventData", ByteBufUtil.hexDump( + buf, buf.readerIndex(), Math.min(buf.readableBytes(), 1024))); + case 121, 142 -> buf.readLong(); + case 130 -> buf.readUnsignedInt(); // incorrect + case 188 -> decodeEB(position, buf); } } @@ -145,62 +124,42 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { for (int i = 0; i < count; i++) { ByteBuf value = values.get(i); switch (buf.readInt()) { - case 0x20D: + case 0x20D -> { position.set(Position.KEY_RPM, value.readShortLE()); position.set("dieselTemperature", value.readShortLE() * 0.1); position.set("batteryVoltage", value.readShortLE() * 0.01); position.set("supplyAirTempDep1", value.readShortLE() * 0.1); - break; - case 0x30D: - position.set("activeAlarm", ByteBufUtil.hexDump(value)); - break; - case 0x40C: + } + case 0x30D -> position.set("activeAlarm", ByteBufUtil.hexDump(value)); + case 0x40C -> { position.set("airTempDep1", value.readShortLE() * 0.1); position.set("airTempDep2", value.readShortLE() * 0.1); - break; - case 0x40D: - position.set("coldUnitState", ByteBufUtil.hexDump(value)); - break; - case 0x50C: + } + case 0x40D -> position.set("coldUnitState", ByteBufUtil.hexDump(value)); + case 0x50C -> { position.set("defrostTempDep1", value.readShortLE() * 0.1); position.set("defrostTempDep2", value.readShortLE() * 0.1); - break; - case 0x50D: + } + case 0x50D -> { position.set("condenserPressure", value.readShortLE() * 0.1); position.set("suctionPressure", value.readShortLE() * 0.1); - break; - case 0x58C: + } + case 0x58C -> { value.readByte(); value.readShort(); // index switch (value.readByte()) { - case 0x01: - position.set("setpointZone1", value.readIntLE() * 0.1); - break; - case 0x02: - position.set("setpointZone2", value.readIntLE() * 0.1); - break; - case 0x05: - position.set("unitType", value.readIntLE()); - break; - case 0x13: - position.set("dieselHours", value.readIntLE() / 60 / 60); - break; - case 0x14: - position.set("electricHours", value.readIntLE() / 60 / 60); - break; - case 0x17: - position.set("serviceIndicator", value.readIntLE()); - break; - case 0x18: - position.set("softwareVersion", value.readIntLE() * 0.01); - break; - default: - break; + case 0x01 -> position.set("setpointZone1", value.readIntLE() * 0.1); + case 0x02 -> position.set("setpointZone2", value.readIntLE() * 0.1); + case 0x05 -> position.set("unitType", value.readIntLE()); + case 0x13 -> position.set("dieselHours", value.readIntLE() / 60 / 60); + case 0x14 -> position.set("electricHours", value.readIntLE() / 60 / 60); + case 0x17 -> position.set("serviceIndicator", value.readIntLE()); + case 0x18 -> position.set("softwareVersion", value.readIntLE() * 0.01); + default -> { + } } - break; - default: - LOGGER.warn("Aplicom CAN decoding error", new UnsupportedOperationException()); - break; + } + default -> LOGGER.warn("Aplicom CAN decoding error", new UnsupportedOperationException()); } } } @@ -487,50 +446,39 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { int end = buf.readerIndex() + length; switch (type) { - case 0x01: - position.set("brakeFlags", ByteBufUtil.hexDump(buf.readSlice(length))); - break; - case 0x02: + case 0x01 -> position.set("brakeFlags", ByteBufUtil.hexDump(buf.readSlice(length))); + case 0x02 -> { position.set("wheelSpeed", buf.readUnsignedShort() / 256.0); position.set("wheelSpeedDifference", buf.readUnsignedShort() / 256.0 - 125.0); position.set("lateralAcceleration", buf.readUnsignedByte() / 10.0 - 12.5); position.set("vehicleSpeed", buf.readUnsignedShort() / 256.0); - break; - case 0x03: - position.set(Position.KEY_AXLE_WEIGHT, buf.readUnsignedShort() * 2); - break; - case 0x04: + } + case 0x03 -> position.set(Position.KEY_AXLE_WEIGHT, buf.readUnsignedShort() * 2); + case 0x04 -> { position.set("tirePressure", buf.readUnsignedByte() * 10); position.set("pneumaticPressure", buf.readUnsignedByte() * 5); - break; - case 0x05: + } + case 0x05 -> { position.set("brakeLining", buf.readUnsignedByte() * 0.4); position.set("brakeTemperature", buf.readUnsignedByte() * 10); - break; - case 0x06: + } + case 0x06 -> { position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 5L); position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt() * 5L); position.set(Position.KEY_ODOMETER_SERVICE, (buf.readUnsignedInt() - 2105540607) * 5L); - break; - case 0x0A: + } + case 0x0A -> { position.set("absStatusCounter", buf.readUnsignedShort()); position.set("atvbStatusCounter", buf.readUnsignedShort()); position.set("vdcActiveCounter", buf.readUnsignedShort()); - break; - case 0x0B: - position.set("brakeMinMaxData", ByteBufUtil.hexDump(buf.readSlice(length))); - break; - case 0x0C: - position.set("missingPgn", ByteBufUtil.hexDump(buf.readSlice(length))); - break; - case 0x0D: + } + case 0x0B -> position.set("brakeMinMaxData", ByteBufUtil.hexDump(buf.readSlice(length))); + case 0x0C -> position.set("missingPgn", ByteBufUtil.hexDump(buf.readSlice(length))); + case 0x0D -> { buf.readUnsignedByte(); position.set("towedDetectionStatus", buf.readUnsignedInt()); buf.skipBytes(17); // vin - break; - case 0x0E: - default: - break; + } } buf.readerIndex(end); diff --git a/src/main/java/org/traccar/protocol/ArknavX8ProtocolDecoder.java b/src/main/java/org/traccar/protocol/ArknavX8ProtocolDecoder.java index 22c0344d6..ac32abb93 100644 --- a/src/main/java/org/traccar/protocol/ArknavX8ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/ArknavX8ProtocolDecoder.java @@ -67,16 +67,11 @@ public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder { return null; } - switch (sentence.substring(0, 2)) { - case "1G": - case "1R": - case "1M": - return decode1G(channel, remoteAddress, sentence); - case "2G": - return decode2G(channel, remoteAddress, sentence); - default: - return null; - } + return switch (sentence.substring(0, 2)) { + case "1G", "1R", "1M" -> decode1G(channel, remoteAddress, sentence); + case "2G" -> decode2G(channel, remoteAddress, sentence); + default -> null; + }; } private Position decode1G(Channel channel, SocketAddress remoteAddress, String sentence) { diff --git a/src/main/java/org/traccar/protocol/ArnaviBinaryProtocolDecoder.java b/src/main/java/org/traccar/protocol/ArnaviBinaryProtocolDecoder.java index 0f6b7a33f..7735d8ff4 100644 --- a/src/main/java/org/traccar/protocol/ArnaviBinaryProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/ArnaviBinaryProtocolDecoder.java @@ -147,11 +147,7 @@ public class ArnaviBinaryProtocolDecoder extends BaseProtocolDecoder { byte recordType = buf.readByte(); while (buf.readableBytes() > 0) { switch (recordType) { - case RECORD_PING: - case RECORD_DATA: - case RECORD_TEXT: - case RECORD_FILE: - case RECORD_BINARY: + case RECORD_PING, RECORD_DATA, RECORD_TEXT, RECORD_FILE, RECORD_BINARY -> { int length = buf.readUnsignedShortLE(); Date time = new Date(buf.readUnsignedIntLE() * 1000); @@ -162,10 +158,10 @@ public class ArnaviBinaryProtocolDecoder extends BaseProtocolDecoder { } buf.readUnsignedByte(); // checksum - break; - - default: + } + default -> { return null; + } } recordType = buf.readByte(); diff --git a/src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java index 834f4f16c..0ef977e53 100644 --- a/src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java @@ -127,7 +127,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { position.set("tag" + i + "Id", ByteBufUtil.hexDump(data.readSlice(6))); } switch (mode) { - case 1: + case 1 -> { if (BitUtil.check(mask, 6)) { data.readUnsignedShort(); // major } @@ -140,8 +140,8 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(mask, 3)) { position.set("tag" + i + "Rssi", data.readUnsignedByte()); } - break; - case 2: + } + case 2 -> { if (BitUtil.check(mask, 6)) { data.readUnsignedShort(); // battery voltage } @@ -154,8 +154,8 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(mask, 3)) { position.set("tag" + i + "Rssi", data.readUnsignedByte()); } - break; - case 3: + } + case 3 -> { if (BitUtil.check(mask, 6)) { position.set("tag" + i + "Humidity", data.readUnsignedShort()); } @@ -168,36 +168,23 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(mask, 2)) { data.readUnsignedShort(); } - break; - case 4: + } + case 4 -> { if (BitUtil.check(mask, 6)) { int hardwareId = data.readUnsignedByte(); if (BitUtil.check(mask, 5)) { switch (hardwareId) { - case 1: - case 4: - data.skipBytes(11); // fuel - break; - case 2: - data.skipBytes(2); // temperature - break; - case 3: - data.skipBytes(6); // temperature and luminosity - break; - case 5: - data.skipBytes(10); // temperature, humidity, luminosity and pressure - break; - default: - break; + case 1, 4 -> data.skipBytes(11); // fuel + case 2 -> data.skipBytes(2); // temperature + case 3 -> data.skipBytes(6); // temperature and luminosity + case 5 -> data.skipBytes(10); // temperature, humidity, luminosity and pressure } } } if (BitUtil.check(mask, 4)) { data.skipBytes(9); // name } - break; - default: - break; + } } i += 1; } @@ -209,101 +196,58 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { String[] values = data.split(",|\r\n"); for (int i = 0; i < Math.min(keys.length, values.length); i++) { switch (keys[i]) { - case "SA": - position.set(Position.KEY_SATELLITES, Integer.parseInt(values[i])); - break; - case "MV": - position.set(Position.KEY_POWER, Integer.parseInt(values[i]) * 0.1); - break; - case "BV": - position.set(Position.KEY_BATTERY, Integer.parseInt(values[i]) * 0.1); - break; - case "GQ": - cellTower.setSignalStrength(Integer.parseInt(values[i])); - break; - case "CE": - cellTower.setCellId(Long.parseLong(values[i])); - break; - case "LC": - cellTower.setLocationAreaCode(Integer.parseInt(values[i])); - break; - case "CN": + case "SA" -> position.set(Position.KEY_SATELLITES, Integer.parseInt(values[i])); + case "MV" -> position.set(Position.KEY_POWER, Integer.parseInt(values[i]) * 0.1); + case "BV" -> position.set(Position.KEY_BATTERY, Integer.parseInt(values[i]) * 0.1); + case "GQ" -> cellTower.setSignalStrength(Integer.parseInt(values[i])); + case "CE" -> cellTower.setCellId(Long.parseLong(values[i])); + case "LC" -> cellTower.setLocationAreaCode(Integer.parseInt(values[i])); + case "CN" -> { if (values[i].length() > 3) { cellTower.setMobileCountryCode(Integer.parseInt(values[i].substring(0, 3))); cellTower.setMobileNetworkCode(Integer.parseInt(values[i].substring(3))); } - break; - case "PC": - position.set(Position.PREFIX_COUNT + 1, Integer.parseInt(values[i])); - break; - case "AT": - position.setAltitude(Integer.parseInt(values[i])); - break; - case "RP": - position.set(Position.KEY_RPM, Integer.parseInt(values[i])); - break; - case "GS": - position.set(Position.KEY_RSSI, Integer.parseInt(values[i])); - break; - case "DT": - position.set(Position.KEY_ARCHIVE, Integer.parseInt(values[i]) == 1); - break; - case "VN": - position.set(Position.KEY_VIN, values[i]); - break; - case "TR": - position.set(Position.KEY_THROTTLE, Integer.parseInt(values[i])); - break; - case "ET": - position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(values[i])); - break; - case "FL": - position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(values[i])); - break; - case "FC": - position.set(Position.KEY_FUEL_CONSUMPTION, Integer.parseInt(values[i])); - break; - case "AV1": - position.set(Position.PREFIX_ADC + 1, Integer.parseInt(values[i])); - break; - case "CD": - position.set(Position.KEY_ICCID, values[i]); - break; - case "EH": - position.set(Position.KEY_HOURS, UnitsConverter.msFromHours(Integer.parseInt(values[i]) * 0.1)); - break; - case "IA": - position.set("intakeTemp", Integer.parseInt(values[i])); - break; - case "EL": - position.set(Position.KEY_ENGINE_LOAD, Integer.parseInt(values[i])); - break; - case "HA": + } + case "PC" -> position.set(Position.PREFIX_COUNT + 1, Integer.parseInt(values[i])); + case "AT" -> position.setAltitude(Integer.parseInt(values[i])); + case "RP" -> position.set(Position.KEY_RPM, Integer.parseInt(values[i])); + case "GS" -> position.set(Position.KEY_RSSI, Integer.parseInt(values[i])); + case "DT" -> position.set(Position.KEY_ARCHIVE, Integer.parseInt(values[i]) == 1); + case "VN" -> position.set(Position.KEY_VIN, values[i]); + case "TR" -> position.set(Position.KEY_THROTTLE, Integer.parseInt(values[i])); + case "ET" -> position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(values[i])); + case "FL" -> position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(values[i])); + case "FC" -> position.set(Position.KEY_FUEL_CONSUMPTION, Integer.parseInt(values[i])); + case "AV1" -> position.set(Position.PREFIX_ADC + 1, Integer.parseInt(values[i])); + case "CD" -> position.set(Position.KEY_ICCID, values[i]); + case "EH" -> + position.set(Position.KEY_HOURS, UnitsConverter.msFromHours(Integer.parseInt(values[i]) * 0.1)); + case "IA" -> position.set("intakeTemp", Integer.parseInt(values[i])); + case "EL" -> position.set(Position.KEY_ENGINE_LOAD, Integer.parseInt(values[i])); + case "HA" -> { if (Integer.parseInt(values[i]) > 0) { position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); } - break; - case "HB": + } + case "HB" -> { if (Integer.parseInt(values[i]) > 0) { position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); } - break; - case "HC": + } + case "HC" -> { if (Integer.parseInt(values[i]) > 0) { position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); } - break; - case "MT": - position.set(Position.KEY_MOTION, Integer.parseInt(values[i]) > 0); - break; - case "BC": + } + case "MT" -> position.set(Position.KEY_MOTION, Integer.parseInt(values[i]) > 0); + case "BC" -> { String[] beaconValues = values[i].split(":"); decodeBeaconData( position, Integer.parseInt(beaconValues[0]), Integer.parseInt(beaconValues[1]), Unpooled.wrappedBuffer(DataConverter.parseHex(beaconValues[2]))); - break; - default: - break; + } + default -> { + } } } @@ -322,320 +266,122 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { String[] keys = form.substring(1).split("%"); for (String key : keys) { switch (key) { - case "SA": - position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); - break; - case "MT": - position.set(Position.KEY_MOTION, buf.readUnsignedByte() > 0); - break; - case "MV": - position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.1); - break; - case "BV": - position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.1); - break; - case "GQ": - cellTower.setSignalStrength((int) buf.readUnsignedByte()); - break; - case "CE": - cellTower.setCellId(buf.readUnsignedInt()); - break; - case "LC": - cellTower.setLocationAreaCode(buf.readUnsignedShort()); - break; - case "CN": + case "SA" -> position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + case "MT" -> position.set(Position.KEY_MOTION, buf.readUnsignedByte() > 0); + case "MV" -> position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.1); + case "BV" -> position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.1); + case "GQ" -> cellTower.setSignalStrength((int) buf.readUnsignedByte()); + case "CE" -> cellTower.setCellId(buf.readUnsignedInt()); + case "LC" -> cellTower.setLocationAreaCode(buf.readUnsignedShort()); + case "CN" -> { int combinedMobileCodes = (int) (buf.readUnsignedInt() % 100000); // cccnn cellTower.setMobileCountryCode(combinedMobileCodes / 100); cellTower.setMobileNetworkCode(combinedMobileCodes % 100); - break; - case "RL": - buf.readUnsignedByte(); // rxlev - break; - case "PC": - position.set(Position.PREFIX_COUNT + 1, buf.readUnsignedInt()); - break; - case "AT": - position.setAltitude(buf.readUnsignedInt()); - break; - case "RP": - position.set(Position.KEY_RPM, buf.readUnsignedShort()); - break; - case "GS": - position.set(Position.KEY_RSSI, buf.readUnsignedByte()); - break; - case "DT": - position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() == 1); - break; - case "VN": - position.set(Position.KEY_VIN, readString(buf)); - break; - case "MF": - buf.readUnsignedShort(); // mass air flow rate - break; - case "EL": - buf.readUnsignedByte(); // engine load - break; - case "TR": - position.set(Position.KEY_THROTTLE, buf.readUnsignedByte()); - break; - case "ET": - position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort()); - break; - case "FL": - position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte()); - break; - case "ML": - buf.readUnsignedByte(); // mil status - break; - case "FC": - position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt()); - break; - case "CI": - readString(buf); // format string - break; - case "AV1": - position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort()); - break; - case "NC": - readString(buf); // gsm neighbor cell info - break; - case "SM": - buf.readUnsignedShort(); // max speed between reports - break; - case "GL": - readString(buf); // google link - break; - case "MA": - readString(buf); // mac address - break; - case "PD": - buf.readUnsignedByte(); // pending code status - break; - case "CD": - position.set(Position.KEY_ICCID, readString(buf)); - break; - case "CM": - buf.readLong(); // imsi - break; - case "GN": - buf.skipBytes(60); // g sensor data - break; - case "GV": - buf.skipBytes(6); // maximum g force - break; - case "ME": - buf.readLong(); // imei - break; - case "IA": - buf.readUnsignedByte(); // intake air temperature - break; - case "MP": - buf.readUnsignedByte(); // manifold absolute pressure - break; - case "EO": - position.set(Position.KEY_ODOMETER, UnitsConverter.metersFromMiles(buf.readUnsignedInt())); - break; - case "EH": - position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 360000); - break; - case "ZO1": - buf.readUnsignedByte(); // brake stroke status - break; - case "ZO2": - buf.readUnsignedByte(); // warning indicator status - break; - case "ZO3": - buf.readUnsignedByte(); // abs control status - break; - case "ZO4": - position.set(Position.KEY_THROTTLE, buf.readUnsignedByte() * 0.4); - break; - case "ZO5": - buf.readUnsignedByte(); // parking brake status - break; - case "ZO6": - position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte() * 0.805); - break; - case "ZO7": - buf.readUnsignedByte(); // cruise control status - break; - case "ZO8": - buf.readUnsignedByte(); // accelector pedal position - break; - case "ZO9": - position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte() * 0.5); - break; - case "ZO10": - position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.5); - break; - case "ZO11": - buf.readUnsignedByte(); // engine oil pressure - break; - case "ZO12": - buf.readUnsignedByte(); // boost pressure - break; - case "ZO13": - buf.readUnsignedByte(); // intake temperature - break; - case "ZO14": - position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte()); - break; - case "ZO15": - buf.readUnsignedByte(); // brake application pressure - break; - case "ZO16": - buf.readUnsignedByte(); // brake primary pressure - break; - case "ZO17": - buf.readUnsignedByte(); // brake secondary pressure - break; - case "ZH1": - buf.readUnsignedShort(); // cargo weight - break; - case "ZH2": - position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 16.428 / 3600); - break; - case "ZH3": - position.set(Position.KEY_RPM, buf.readUnsignedShort() * 0.25); - break; - case "ZL1": - buf.readUnsignedInt(); // fuel used (natural gas) - break; - case "ZL2": - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 161); - break; - case "ZL3": - buf.readUnsignedInt(); // vehicle hours - break; - case "ZL4": - position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 5 * 36000); - break; - case "ZS1": - position.set(Position.KEY_VIN, readString(buf)); - break; - case "JO1": - buf.readUnsignedByte(); // pedals - break; - case "JO2": - buf.readUnsignedByte(); // power takeoff device - break; - case "JO3": - buf.readUnsignedByte(); // accelector pedal position - break; - case "JO4": - position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte()); - break; - case "JO5": - position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4); - break; - case "JO6": - buf.readUnsignedByte(); // fms vehicle interface - break; - case "JO7": - buf.readUnsignedByte(); // driver 2 - break; - case "JO8": - buf.readUnsignedByte(); // driver 1 - break; - case "JO9": - buf.readUnsignedByte(); // drivers - break; - case "JO10": - buf.readUnsignedByte(); // system information - break; - case "JO11": - position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40); - break; - case "JO12": - buf.readUnsignedByte(); // pto engaged - break; - case "JH1": - position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() / 256.0); - break; - case "JH2": - position.set(Position.KEY_RPM, buf.readUnsignedShort() * 0.125); - break; - case "JH3": - case "JH4": - case "JH5": - case "JH6": - case "JH7": + } + case "RL" -> buf.readUnsignedByte(); // rxlev + case "PC" -> position.set(Position.PREFIX_COUNT + 1, buf.readUnsignedInt()); + case "AT" -> position.setAltitude(buf.readUnsignedInt()); + case "RP" -> position.set(Position.KEY_RPM, buf.readUnsignedShort()); + case "GS" -> position.set(Position.KEY_RSSI, buf.readUnsignedByte()); + case "DT" -> position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() == 1); + case "VN" -> position.set(Position.KEY_VIN, readString(buf)); + case "MF" -> buf.readUnsignedShort(); // mass air flow rate + case "EL" -> buf.readUnsignedByte(); // engine load + case "TR" -> position.set(Position.KEY_THROTTLE, buf.readUnsignedByte()); + case "ET" -> position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort()); + case "FL" -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte()); + case "ML" -> buf.readUnsignedByte(); // mil status + case "FC" -> position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt()); + case "CI" -> readString(buf); // format string + case "AV1" -> position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort()); + case "NC" -> readString(buf); // gsm neighbor cell info + case "SM" -> buf.readUnsignedShort(); // max speed between reports + case "GL" -> readString(buf); // google link + case "MA" -> readString(buf); // mac address + case "PD" -> buf.readUnsignedByte(); // pending code status + case "CD" -> position.set(Position.KEY_ICCID, readString(buf)); + case "CM" -> buf.readLong(); // imsi + case "GN" -> buf.skipBytes(60); // g sensor data + case "GV" -> buf.skipBytes(6); // maximum g force + case "ME" -> buf.readLong(); // imei + case "IA" -> buf.readUnsignedByte(); // intake air temperature + case "MP" -> buf.readUnsignedByte(); // manifold absolute pressure + case "EO" -> position.set(Position.KEY_ODOMETER, UnitsConverter.metersFromMiles(buf.readUnsignedInt())); + case "EH" -> position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 360000); + case "ZO1" -> buf.readUnsignedByte(); // brake stroke status + case "ZO2" -> buf.readUnsignedByte(); // warning indicator status + case "ZO3" -> buf.readUnsignedByte(); // abs control status + case "ZO4" -> position.set(Position.KEY_THROTTLE, buf.readUnsignedByte() * 0.4); + case "ZO5" -> buf.readUnsignedByte(); // parking brake status + case "ZO6" -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte() * 0.805); + case "ZO7" -> buf.readUnsignedByte(); // cruise control status + case "ZO8" -> buf.readUnsignedByte(); // accelector pedal position + case "ZO9" -> position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte() * 0.5); + case "ZO10" -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.5); + case "ZO11" -> buf.readUnsignedByte(); // engine oil pressure + case "ZO12" -> buf.readUnsignedByte(); // boost pressure + case "ZO13" -> buf.readUnsignedByte(); // intake temperature + case "ZO14" -> position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte()); + case "ZO15" -> buf.readUnsignedByte(); // brake application pressure + case "ZO16" -> buf.readUnsignedByte(); // brake primary pressure + case "ZO17" -> buf.readUnsignedByte(); // brake secondary pressure + case "ZH1" -> buf.readUnsignedShort(); // cargo weight + case "ZH2" -> position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 16.428 / 3600); + case "ZH3" -> position.set(Position.KEY_RPM, buf.readUnsignedShort() * 0.25); + case "ZL1" -> buf.readUnsignedInt(); // fuel used (natural gas) + case "ZL2" -> position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 161); + case "ZL3" -> buf.readUnsignedInt(); // vehicle hours + case "ZL4" -> position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 5 * 36000); + case "ZS1" -> position.set(Position.KEY_VIN, readString(buf)); + case "JO1" -> buf.readUnsignedByte(); // pedals + case "JO2" -> buf.readUnsignedByte(); // power takeoff device + case "JO3" -> buf.readUnsignedByte(); // accelector pedal position + case "JO4" -> position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte()); + case "JO5" -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4); + case "JO6" -> buf.readUnsignedByte(); // fms vehicle interface + case "JO7" -> buf.readUnsignedByte(); // driver 2 + case "JO8" -> buf.readUnsignedByte(); // driver 1 + case "JO9" -> buf.readUnsignedByte(); // drivers + case "JO10" -> buf.readUnsignedByte(); // system information + case "JO11" -> position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40); + case "JO12" -> buf.readUnsignedByte(); // pto engaged + case "JH1" -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() / 256.0); + case "JH2" -> position.set(Position.KEY_RPM, buf.readUnsignedShort() * 0.125); + case "JH3", "JH4", "JH5", "JH6", "JH7" -> { int index = Integer.parseInt(key.substring(2)) - 2; position.set("axleWeight" + index, buf.readUnsignedShort() * 0.5); - break; - case "JH8": - position.set(Position.KEY_ODOMETER_SERVICE, buf.readUnsignedShort() * 5); - break; - case "JH9": - buf.readUnsignedShort(); // tachograph speed - break; - case "JH10": - buf.readUnsignedShort(); // ambient air temperature - break; - case "JH11": - position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.05); - break; - case "JH12": - buf.readUnsignedShort(); // fuel economy - break; - case "JL1": - position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.5); - break; - case "JL2": - position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 5 * 36000); - break; - case "JL3": - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000); - break; - case "JL4": - position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.001); - break; - case "JS1": - position.set(Position.KEY_VIN, readString(buf)); - break; - case "JS2": - readString(buf); // fms version supported - break; - case "JS3": - position.set("driver1", readString(buf)); - break; - case "JS4": - position.set("driver2", readString(buf)); - break; - case "JN1": - buf.readUnsignedInt(); // cruise control distance - break; - case "JN2": - buf.readUnsignedInt(); // excessive idling time - break; - case "JN3": - buf.readUnsignedInt(); // excessive idling fuel - break; - case "JN4": - buf.readUnsignedInt(); // pto time - break; - case "JN5": - buf.readUnsignedInt(); // pto fuel - break; - case "IN0": - position.set(Position.KEY_IGNITION, buf.readUnsignedByte() > 0); - break; - case "IN1": - case "IN2": - case "IN3": + } + case "JH8" -> position.set(Position.KEY_ODOMETER_SERVICE, buf.readUnsignedShort() * 5); + case "JH9" -> buf.readUnsignedShort(); // tachograph speed + case "JH10" -> buf.readUnsignedShort(); // ambient air temperature + case "JH11" -> position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.05); + case "JH12" -> buf.readUnsignedShort(); // fuel economy + case "JL1" -> position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.5); + case "JL2" -> position.set(Position.KEY_HOURS, buf.readUnsignedInt() * 5 * 36000); + case "JL3" -> position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000); + case "JL4" -> position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.001); + case "JS1" -> position.set(Position.KEY_VIN, readString(buf)); + case "JS2" -> readString(buf); // fms version supported + case "JS3" -> position.set("driver1", readString(buf)); + case "JS4" -> position.set("driver2", readString(buf)); + case "JN1" -> buf.readUnsignedInt(); // cruise control distance + case "JN2" -> buf.readUnsignedInt(); // excessive idling time + case "JN3" -> buf.readUnsignedInt(); // excessive idling fuel + case "JN4" -> buf.readUnsignedInt(); // pto time + case "JN5" -> buf.readUnsignedInt(); // pto fuel + case "IN0" -> position.set(Position.KEY_IGNITION, buf.readUnsignedByte() > 0); + case "IN1", "IN2", "IN3" -> { position.set(Position.PREFIX_IN + key.charAt(2), buf.readUnsignedByte() > 0); - break; - case "HA": + } + case "HA" -> { position.set(Position.KEY_ALARM, buf.readUnsignedByte() > 0 ? Position.ALARM_ACCELERATION : null); - break; - case "HB": + } + case "HB" -> { position.set(Position.KEY_ALARM, buf.readUnsignedByte() > 0 ? Position.ALARM_BRAKING : null); - break; - case "HC": + } + case "HC" -> { position.set(Position.KEY_ALARM, buf.readUnsignedByte() > 0 ? Position.ALARM_CORNERING : null); - break; - default: - break; + } } } diff --git a/src/main/java/org/traccar/protocol/AtrackProtocolEncoder.java b/src/main/java/org/traccar/protocol/AtrackProtocolEncoder.java index d803ae391..00752dbc6 100644 --- a/src/main/java/org/traccar/protocol/AtrackProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/AtrackProtocolEncoder.java @@ -31,13 +31,11 @@ public class AtrackProtocolEncoder extends BaseProtocolEncoder { @Override protected Object encodeCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_CUSTOM: - return Unpooled.copiedBuffer( - command.getString(Command.KEY_DATA) + "\r\n", StandardCharsets.US_ASCII); - default: - return null; + if (command.getType().equals(Command.TYPE_CUSTOM)) { + return Unpooled.copiedBuffer( + command.getString(Command.KEY_DATA) + "\r\n", StandardCharsets.US_ASCII); } + return null; } } diff --git a/src/main/java/org/traccar/protocol/AutoFonFrameDecoder.java b/src/main/java/org/traccar/protocol/AutoFonFrameDecoder.java index 69f28133f..f0545279a 100644 --- a/src/main/java/org/traccar/protocol/AutoFonFrameDecoder.java +++ b/src/main/java/org/traccar/protocol/AutoFonFrameDecoder.java @@ -32,27 +32,14 @@ public class AutoFonFrameDecoder extends BaseFrameDecoder { return null; } - int length; - switch (buf.getUnsignedByte(buf.readerIndex())) { - case AutoFonProtocolDecoder.MSG_LOGIN: - length = 12; - break; - case AutoFonProtocolDecoder.MSG_LOCATION: - length = 78; - break; - case AutoFonProtocolDecoder.MSG_HISTORY: - length = 257; - break; - case AutoFonProtocolDecoder.MSG_45_LOGIN: - length = 19; - break; - case AutoFonProtocolDecoder.MSG_45_LOCATION: - length = 34; - break; - default: - length = 0; - break; - } + int length = switch (buf.getUnsignedByte(buf.readerIndex())) { + case AutoFonProtocolDecoder.MSG_LOGIN -> 12; + case AutoFonProtocolDecoder.MSG_LOCATION -> 78; + case AutoFonProtocolDecoder.MSG_HISTORY -> 257; + case AutoFonProtocolDecoder.MSG_45_LOGIN -> 19; + case AutoFonProtocolDecoder.MSG_45_LOCATION -> 34; + default -> 0; + }; // Check length and return buffer if (length != 0 && buf.readableBytes() >= length) { diff --git a/src/main/java/org/traccar/protocol/AutoTrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/AutoTrackProtocolDecoder.java index 938d170e6..78243b76a 100644 --- a/src/main/java/org/traccar/protocol/AutoTrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/AutoTrackProtocolDecoder.java @@ -103,7 +103,7 @@ public class AutoTrackProtocolDecoder extends BaseProtocolDecoder { DeviceSession deviceSession; switch (type) { - case MSG_LOGIN_REQUEST: + case MSG_LOGIN_REQUEST -> { String imei = ByteBufUtil.hexDump(buf.readSlice(8)); deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { @@ -123,16 +123,17 @@ public class AutoTrackProtocolDecoder extends BaseProtocolDecoder { channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } return null; - case MSG_TELEMETRY_1: - case MSG_TELEMETRY_2: - case MSG_TELEMETRY_3: + } + case MSG_TELEMETRY_1, MSG_TELEMETRY_2, MSG_TELEMETRY_3 -> { deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession == null) { return null; } return decodeTelemetry(channel, remoteAddress, deviceSession, buf); - default: + } + default -> { return null; + } } } diff --git a/src/main/java/org/traccar/protocol/B2316ProtocolDecoder.java b/src/main/java/org/traccar/protocol/B2316ProtocolDecoder.java index b0a5411f7..a0c059898 100644 --- a/src/main/java/org/traccar/protocol/B2316ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/B2316ProtocolDecoder.java @@ -40,35 +40,24 @@ public class B2316ProtocolDecoder extends BaseProtocolDecoder { } private String decodeAlarm(int value) { - switch (value) { - case 1: - return Position.ALARM_LOW_BATTERY; - case 2: - return Position.ALARM_SOS; - case 3: - return Position.ALARM_POWER_OFF; - case 4: - return Position.ALARM_REMOVING; - default: - return null; - } + return switch (value) { + case 1 -> Position.ALARM_LOW_BATTERY; + case 2 -> Position.ALARM_SOS; + case 3 -> Position.ALARM_POWER_OFF; + case 4 -> Position.ALARM_REMOVING; + default -> null; + }; } private Integer decodeBattery(int value) { - switch (value) { - case 0: - return 10; - case 1: - return 30; - case 2: - return 60; - case 3: - return 80; - case 4: - return 100; - default: - return null; - } + return switch (value) { + case 0 -> 10; + case 1 -> 30; + case 2 -> 60; + case 3 -> 80; + case 4 -> 100; + default -> null; + }; } @Override diff --git a/src/main/java/org/traccar/protocol/BlueProtocolDecoder.java b/src/main/java/org/traccar/protocol/BlueProtocolDecoder.java index db59c564d..c3fbddbeb 100644 --- a/src/main/java/org/traccar/protocol/BlueProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/BlueProtocolDecoder.java @@ -67,16 +67,12 @@ public class BlueProtocolDecoder extends BaseProtocolDecoder { } private String decodeAlarm(int value) { - switch (value) { - case 1: - return Position.ALARM_SOS; - case 8: - return Position.ALARM_OVERSPEED; - case 19: - return Position.ALARM_LOW_POWER; - default: - return null; - } + return switch (value) { + case 1 -> Position.ALARM_SOS; + case 8 -> Position.ALARM_OVERSPEED; + case 19 -> Position.ALARM_LOW_POWER; + default -> null; + }; } @Override diff --git a/src/main/java/org/traccar/protocol/BstplProtocolDecoder.java b/src/main/java/org/traccar/protocol/BstplProtocolDecoder.java index 15c114642..5dee16cba 100644 --- a/src/main/java/org/traccar/protocol/BstplProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/BstplProtocolDecoder.java @@ -61,20 +61,14 @@ public class BstplProtocolDecoder extends BaseProtocolDecoder { .compile(); private String decodeAlarm(int value) { - switch (value) { - case 4: - return Position.ALARM_LOW_BATTERY; - case 5: - return Position.ALARM_ACCELERATION; - case 6: - return Position.ALARM_BRAKING; - case 7: - return Position.ALARM_OVERSPEED; - case 9: - return Position.ALARM_SOS; - default: - return null; - } + return switch (value) { + case 4 -> Position.ALARM_LOW_BATTERY; + case 5 -> Position.ALARM_ACCELERATION; + case 6 -> Position.ALARM_BRAKING; + case 7 -> Position.ALARM_OVERSPEED; + case 9 -> Position.ALARM_SOS; + default -> null; + }; } @Override protected Object decode( diff --git a/src/main/java/org/traccar/protocol/C2stekProtocolDecoder.java b/src/main/java/org/traccar/protocol/C2stekProtocolDecoder.java index aef158fc7..908f5d0f3 100644 --- a/src/main/java/org/traccar/protocol/C2stekProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/C2stekProtocolDecoder.java @@ -60,24 +60,16 @@ public class C2stekProtocolDecoder extends BaseProtocolDecoder { .compile(); private String decodeAlarm(int alarm) { - switch (alarm) { - case 0x2: - return Position.ALARM_VIBRATION; - case 0x3: - return Position.ALARM_POWER_CUT; - case 0x4: - return Position.ALARM_OVERSPEED; - case 0x5: - return Position.ALARM_SOS; - case 0x6: - return Position.ALARM_DOOR; - case 0xA: - return Position.ALARM_LOW_BATTERY; - case 0xB: - return Position.ALARM_FAULT; - default: - return null; - } + return switch (alarm) { + case 0x2 -> Position.ALARM_VIBRATION; + case 0x3 -> Position.ALARM_POWER_CUT; + case 0x4 -> Position.ALARM_OVERSPEED; + case 0x5 -> Position.ALARM_SOS; + case 0x6 -> Position.ALARM_DOOR; + case 0xA -> Position.ALARM_LOW_BATTERY; + case 0xB -> Position.ALARM_FAULT; + default -> null; + }; } @Override diff --git a/src/main/java/org/traccar/protocol/CarcellProtocolEncoder.java b/src/main/java/org/traccar/protocol/CarcellProtocolEncoder.java index 78dbe7e91..7a460b7c4 100644 --- a/src/main/java/org/traccar/protocol/CarcellProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/CarcellProtocolEncoder.java @@ -28,14 +28,11 @@ public class CarcellProtocolEncoder extends StringProtocolEncoder { @Override protected Object encodeCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_ENGINE_STOP: - return formatCommand(command, "$SRVCMD,%s,BA#\r\n", Command.KEY_UNIQUE_ID); - case Command.TYPE_ENGINE_RESUME: - return formatCommand(command, "$SRVCMD,%s,BD#\r\n", Command.KEY_UNIQUE_ID); - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_ENGINE_STOP -> formatCommand(command, "$SRVCMD,%s,BA#\r\n", Command.KEY_UNIQUE_ID); + case Command.TYPE_ENGINE_RESUME -> formatCommand(command, "$SRVCMD,%s,BD#\r\n", Command.KEY_UNIQUE_ID); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java b/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java index b076b9f66..5cabeb5a4 100644 --- a/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java @@ -162,20 +162,12 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { if (!PID_LENGTH_MAP.containsKey(pids[i])) { throw new RuntimeException(String.format("Unknown PID 0x%02x", pids[i])); } - switch (PID_LENGTH_MAP.get(pids[i])) { - case 1: - value = buf.readUnsignedByte(); - break; - case 2: - value = buf.readUnsignedShortLE(); - break; - case 4: - value = buf.readIntLE(); - break; - default: - value = 0; - break; - } + value = switch (PID_LENGTH_MAP.get(pids[i])) { + case 1 -> buf.readUnsignedByte(); + case 2 -> buf.readUnsignedShortLE(); + case 4 -> buf.readIntLE(); + default -> 0; + }; position.add(ObdDecoder.decodeData(pids[i], value, false)); } } @@ -250,62 +242,24 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { private void decodeAlarm(Position position, int alarm) { switch (alarm) { - case 0x01: - position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); - break; - case 0x02: - position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER); - break; - case 0x03: - position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE); - break; - case 0x04: - position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); - break; - case 0x05: - position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); - break; - case 0x06: - position.set(Position.KEY_ALARM, Position.ALARM_IDLE); - break; - case 0x07: - position.set(Position.KEY_ALARM, Position.ALARM_TOW); - break; - case 0x08: - position.set(Position.KEY_ALARM, Position.ALARM_HIGH_RPM); - break; - case 0x09: - position.set(Position.KEY_ALARM, Position.ALARM_POWER_ON); - break; - case 0x0B: - position.set(Position.KEY_ALARM, Position.ALARM_LANE_CHANGE); - break; - case 0x0C: - position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); - break; - case 0x0D: - position.set(Position.KEY_ALARM, Position.ALARM_FATIGUE_DRIVING); - break; - case 0x0E: - position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF); - break; - case 0x11: - position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); - break; - case 0x12: - position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING); - break; - case 0x16: - position.set(Position.KEY_IGNITION, true); - break; - case 0x17: - position.set(Position.KEY_IGNITION, false); - break; - case 0x1C: - position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION); - break; - default: - break; + case 0x01 -> position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); + case 0x02 -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER); + case 0x03 -> position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE); + case 0x04 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); + case 0x05 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); + case 0x06 -> position.set(Position.KEY_ALARM, Position.ALARM_IDLE); + case 0x07 -> position.set(Position.KEY_ALARM, Position.ALARM_TOW); + case 0x08 -> position.set(Position.KEY_ALARM, Position.ALARM_HIGH_RPM); + case 0x09 -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_ON); + case 0x0B -> position.set(Position.KEY_ALARM, Position.ALARM_LANE_CHANGE); + case 0x0C -> position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); + case 0x0D -> position.set(Position.KEY_ALARM, Position.ALARM_FATIGUE_DRIVING); + case 0x0E -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF); + case 0x11 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); + case 0x12 -> position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING); + case 0x16 -> position.set(Position.KEY_IGNITION, true); + case 0x17 -> position.set(Position.KEY_IGNITION, false); + case 0x1C -> position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION); } } @@ -623,15 +577,11 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { return null; } - switch (version) { - case -1: - return decodeMpip(channel, remoteAddress, buf, version, id, type, deviceSession); - case 3: - case 4: - return decodeSc(channel, remoteAddress, buf, version, id, type, deviceSession); - default: - return decodeCc(channel, remoteAddress, buf, version, id, type, deviceSession); - } + return switch (version) { + case -1 -> decodeMpip(channel, remoteAddress, buf, version, id, type, deviceSession); + case 3, 4 -> decodeSc(channel, remoteAddress, buf, version, id, type, deviceSession); + default -> decodeCc(channel, remoteAddress, buf, version, id, type, deviceSession); + }; } } diff --git a/src/main/java/org/traccar/protocol/CastelProtocolEncoder.java b/src/main/java/org/traccar/protocol/CastelProtocolEncoder.java index 61dde3e80..867db7a09 100644 --- a/src/main/java/org/traccar/protocol/CastelProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/CastelProtocolEncoder.java @@ -59,16 +59,17 @@ public class CastelProtocolEncoder extends BaseProtocolEncoder { @Override protected Object encodeCommand(Command command) { ByteBuf content = Unpooled.buffer(0); - switch (command.getType()) { - case Command.TYPE_ENGINE_STOP: + return switch (command.getType()) { + case Command.TYPE_ENGINE_STOP -> { content.writeByte(1); - return encodeContent(command.getDeviceId(), CastelProtocolDecoder.MSG_CC_PETROL_CONTROL, content); - case Command.TYPE_ENGINE_RESUME: + yield encodeContent(command.getDeviceId(), CastelProtocolDecoder.MSG_CC_PETROL_CONTROL, content); + } + case Command.TYPE_ENGINE_RESUME -> { content.writeByte(0); - return encodeContent(command.getDeviceId(), CastelProtocolDecoder.MSG_CC_PETROL_CONTROL, content); - default: - return null; - } + yield encodeContent(command.getDeviceId(), CastelProtocolDecoder.MSG_CC_PETROL_CONTROL, content); + } + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/CellocatorFrameDecoder.java b/src/main/java/org/traccar/protocol/CellocatorFrameDecoder.java index ee2adde6d..6dc299c7a 100644 --- a/src/main/java/org/traccar/protocol/CellocatorFrameDecoder.java +++ b/src/main/java/org/traccar/protocol/CellocatorFrameDecoder.java @@ -35,28 +35,20 @@ public class CellocatorFrameDecoder extends BaseFrameDecoder { int length = 0; int type = buf.getUnsignedByte(4); switch (type) { - case CellocatorProtocolDecoder.MSG_CLIENT_STATUS: - length = 70; - break; - case CellocatorProtocolDecoder.MSG_CLIENT_PROGRAMMING: - length = 31; - break; - case CellocatorProtocolDecoder.MSG_CLIENT_SERIAL_LOG: - length = 70; - break; - case CellocatorProtocolDecoder.MSG_CLIENT_SERIAL: + case CellocatorProtocolDecoder.MSG_CLIENT_STATUS -> length = 70; + case CellocatorProtocolDecoder.MSG_CLIENT_PROGRAMMING -> length = 31; + case CellocatorProtocolDecoder.MSG_CLIENT_SERIAL_LOG -> length = 70; + case CellocatorProtocolDecoder.MSG_CLIENT_SERIAL -> { if (buf.readableBytes() >= 19) { length = 19 + buf.getUnsignedShortLE(buf.readerIndex() + 16); } - break; - case CellocatorProtocolDecoder.MSG_CLIENT_MODULAR: + } + case CellocatorProtocolDecoder.MSG_CLIENT_MODULAR -> { length = 15 + buf.getUnsignedByte(buf.readerIndex() + 13); - break; - case CellocatorProtocolDecoder.MSG_CLIENT_MODULAR_EXT: + } + case CellocatorProtocolDecoder.MSG_CLIENT_MODULAR_EXT -> { length = 16 + buf.getUnsignedShortLE(buf.readerIndex() + 13); - break; - default: - break; + } } if (length > 0 && buf.readableBytes() >= length) { diff --git a/src/main/java/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/main/java/org/traccar/protocol/CellocatorProtocolDecoder.java index 3573a95ca..27fc8452c 100644 --- a/src/main/java/org/traccar/protocol/CellocatorProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/CellocatorProtocolDecoder.java @@ -95,16 +95,12 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { } private String decodeAlarm(short reason) { - switch (reason) { - case 70: - return Position.ALARM_SOS; - case 80: - return Position.ALARM_POWER_CUT; - case 81: - return Position.ALARM_LOW_POWER; - default: - return null; - } + return switch (reason) { + case 70 -> Position.ALARM_SOS; + case 80 -> Position.ALARM_POWER_CUT; + case 81 -> Position.ALARM_LOW_POWER; + default -> null; + }; } private Position decodeStatus(ByteBuf buf, DeviceSession deviceSession, boolean alternative) { diff --git a/src/main/java/org/traccar/protocol/CellocatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/CellocatorProtocolEncoder.java index 76fa67686..738eabbb2 100644 --- a/src/main/java/org/traccar/protocol/CellocatorProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/CellocatorProtocolEncoder.java @@ -69,14 +69,12 @@ public class CellocatorProtocolEncoder extends BaseProtocolEncoder { @Override protected Object encodeCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_OUTPUT_CONTROL: - int data = Integer.parseInt(command.getString(Command.KEY_DATA)) << 4 - + command.getInteger(Command.KEY_INDEX); - return encodeCommand(command.getDeviceId(), 0x03, data, 0); - default: - return null; + if (command.getType().equals(Command.TYPE_OUTPUT_CONTROL)) { + int data = Integer.parseInt(command.getString(Command.KEY_DATA)) << 4 + + command.getInteger(Command.KEY_INDEX); + return encodeCommand(command.getDeviceId(), 0x03, data, 0); } + return null; } } diff --git a/src/main/java/org/traccar/protocol/CguardProtocolDecoder.java b/src/main/java/org/traccar/protocol/CguardProtocolDecoder.java index 90f8e0caf..fef90dbb5 100644 --- a/src/main/java/org/traccar/protocol/CguardProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/CguardProtocolDecoder.java @@ -94,25 +94,17 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder { String key = data[i * 2]; String value = data[i * 2 + 1]; switch (key) { - case "CSQ1": - position.set(Position.KEY_RSSI, Integer.parseInt(value)); - break; - case "NSQ1": - position.set(Position.KEY_SATELLITES, Integer.parseInt(value)); - break; - case "BAT1": + case "CSQ1" -> position.set(Position.KEY_RSSI, Integer.parseInt(value)); + case "NSQ1" -> position.set(Position.KEY_SATELLITES, Integer.parseInt(value)); + case "BAT1" -> { if (value.contains(".")) { position.set(Position.KEY_BATTERY, Double.parseDouble(value)); } else { position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(value)); } - break; - case "PWR1": - position.set(Position.KEY_POWER, Double.parseDouble(value)); - break; - default: - position.set(key.toLowerCase(), value); - break; + } + case "PWR1" -> position.set(Position.KEY_POWER, Double.parseDouble(value)); + default -> position.set(key.toLowerCase(), value); } } diff --git a/src/main/java/org/traccar/protocol/CityeasyProtocolEncoder.java b/src/main/java/org/traccar/protocol/CityeasyProtocolEncoder.java index 934105862..563d13206 100644 --- a/src/main/java/org/traccar/protocol/CityeasyProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/CityeasyProtocolEncoder.java @@ -53,15 +53,18 @@ public class CityeasyProtocolEncoder extends BaseProtocolEncoder { ByteBuf content = Unpooled.buffer(); switch (command.getType()) { - case Command.TYPE_POSITION_SINGLE: + case Command.TYPE_POSITION_SINGLE -> { return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_REQUEST, content); - case Command.TYPE_POSITION_PERIODIC: + } + case Command.TYPE_POSITION_PERIODIC -> { content.writeShort(command.getInteger(Command.KEY_FREQUENCY)); return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_INTERVAL, content); - case Command.TYPE_POSITION_STOP: + } + case Command.TYPE_POSITION_STOP -> { content.writeShort(0); return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_INTERVAL, content); - case Command.TYPE_SET_TIMEZONE: + } + case Command.TYPE_SET_TIMEZONE -> { int timezone = TimeZone.getTimeZone(command.getString(Command.KEY_TIMEZONE)).getRawOffset() / 60000; if (timezone < 0) { content.writeByte(1); @@ -70,8 +73,10 @@ public class CityeasyProtocolEncoder extends BaseProtocolEncoder { } content.writeShort(Math.abs(timezone)); return encodeContent(CityeasyProtocolDecoder.MSG_TIMEZONE, content); - default: + } + default -> { return null; + } } } diff --git a/src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java b/src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java index c2e617a2a..672848174 100644 --- a/src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java @@ -199,15 +199,9 @@ public class DmtHttpProtocolDecoder extends BaseHttpProtocolDecoder { for (int i = 0; i < counters.size(); i++) { JsonObject counter = counters.getJsonObject(i); switch (counter.getInt("id")) { - case 0: - position.set(Position.KEY_BATTERY, counter.getInt("val") * 0.001); - break; - case 1: - position.set(Position.KEY_BATTERY_LEVEL, counter.getInt("val") * 0.01); - break; - default: - position.set("counter" + counter.getInt("id"), counter.getInt("val")); - break; + case 0 -> position.set(Position.KEY_BATTERY, counter.getInt("val") * 0.001); + case 1 -> position.set(Position.KEY_BATTERY_LEVEL, counter.getInt("val") * 0.01); + default -> position.set("counter" + counter.getInt("id"), counter.getInt("val")); } } diff --git a/src/main/java/org/traccar/protocol/DmtProtocolDecoder.java b/src/main/java/org/traccar/protocol/DmtProtocolDecoder.java index f8295543f..a18e8bc53 100644 --- a/src/main/java/org/traccar/protocol/DmtProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/DmtProtocolDecoder.java @@ -201,24 +201,12 @@ public class DmtProtocolDecoder extends BaseProtocolDecoder { while (buf.readerIndex() < fieldEnd) { int number = buf.readUnsignedByte(); switch (number) { - case 1: - position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001); - break; - case 2: - position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.01); - break; - case 3: - position.set(Position.KEY_DEVICE_TEMP, buf.readShortLE() * 0.01); - break; - case 4: - position.set(Position.KEY_RSSI, buf.readUnsignedShortLE()); - break; - case 5: - position.set("solarPower", buf.readUnsignedShortLE() * 0.001); - break; - default: - position.set(Position.PREFIX_IO + number, buf.readUnsignedShortLE()); - break; + case 1 -> position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001); + case 2 -> position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.01); + case 3 -> position.set(Position.KEY_DEVICE_TEMP, buf.readShortLE() * 0.01); + case 4 -> position.set(Position.KEY_RSSI, buf.readUnsignedShortLE()); + case 5 -> position.set("solarPower", buf.readUnsignedShortLE() * 0.001); + default -> position.set(Position.PREFIX_IO + number, buf.readUnsignedShortLE()); } } @@ -249,28 +237,18 @@ public class DmtProtocolDecoder extends BaseProtocolDecoder { } private String decodeAlarm(int value) { - switch (value) { - case 12: - return Position.ALARM_BRAKING; - case 13: - return Position.ALARM_ACCELERATION; - case 14: - return Position.ALARM_CORNERING; - case 18: - return Position.ALARM_OVERSPEED; - case 20: - return Position.ALARM_TOW; - case 23: - return Position.ALARM_ACCIDENT; - case 29: - return Position.ALARM_TAMPERING; - case 44: - return Position.ALARM_GEOFENCE_ENTER; - case 45: - return Position.ALARM_GEOFENCE_EXIT; - default: - return null; - } + return switch (value) { + case 12 -> Position.ALARM_BRAKING; + case 13 -> Position.ALARM_ACCELERATION; + case 14 -> Position.ALARM_CORNERING; + case 18 -> Position.ALARM_OVERSPEED; + case 20 -> Position.ALARM_TOW; + case 23 -> Position.ALARM_ACCIDENT; + case 29 -> Position.ALARM_TAMPERING; + case 44 -> Position.ALARM_GEOFENCE_ENTER; + case 45 -> Position.ALARM_GEOFENCE_EXIT; + default -> null; + }; } @Override diff --git a/src/main/java/org/traccar/protocol/EasyTrackProtocolEncoder.java b/src/main/java/org/traccar/protocol/EasyTrackProtocolEncoder.java index 3f2a142d6..124c3e0a3 100644 --- a/src/main/java/org/traccar/protocol/EasyTrackProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/EasyTrackProtocolEncoder.java @@ -28,18 +28,13 @@ public class EasyTrackProtocolEncoder extends StringProtocolEncoder { @Override protected Object encodeCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_ENGINE_STOP: - return formatCommand(command, "*ET,%s,FD,Y1#", Command.KEY_UNIQUE_ID); - case Command.TYPE_ENGINE_RESUME: - return formatCommand(command, "*ET,%s,FD,Y2#", Command.KEY_UNIQUE_ID); - case Command.TYPE_ALARM_ARM: - return formatCommand(command, "*ET,%s,FD,F1#", Command.KEY_UNIQUE_ID); - case Command.TYPE_ALARM_DISARM: - return formatCommand(command, "*ET,%s,FD,F2#", Command.KEY_UNIQUE_ID); - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_ENGINE_STOP -> formatCommand(command, "*ET,%s,FD,Y1#", Command.KEY_UNIQUE_ID); + case Command.TYPE_ENGINE_RESUME -> formatCommand(command, "*ET,%s,FD,Y2#", Command.KEY_UNIQUE_ID); + case Command.TYPE_ALARM_ARM -> formatCommand(command, "*ET,%s,FD,F1#", Command.KEY_UNIQUE_ID); + case Command.TYPE_ALARM_DISARM -> formatCommand(command, "*ET,%s,FD,F2#", Command.KEY_UNIQUE_ID); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/EelinkProtocolDecoder.java b/src/main/java/org/traccar/protocol/EelinkProtocolDecoder.java index db1b365c3..f1cc43394 100644 --- a/src/main/java/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/EelinkProtocolDecoder.java @@ -67,35 +67,21 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_CAMERA_DATA = 0x1F; private String decodeAlarm(Short value) { - switch (value) { - case 0x01: - return Position.ALARM_POWER_OFF; - case 0x02: - return Position.ALARM_SOS; - case 0x03: - return Position.ALARM_LOW_BATTERY; - case 0x04: - return Position.ALARM_VIBRATION; - case 0x08: - case 0x09: - return Position.ALARM_GPS_ANTENNA_CUT; - case 0x25: - return Position.ALARM_REMOVING; - case 0x81: - return Position.ALARM_LOW_SPEED; - case 0x82: - return Position.ALARM_OVERSPEED; - case 0x83: - return Position.ALARM_GEOFENCE_ENTER; - case 0x84: - return Position.ALARM_GEOFENCE_EXIT; - case 0x85: - return Position.ALARM_ACCIDENT; - case 0x86: - return Position.ALARM_FALL_DOWN; - default: - return null; - } + return switch (value) { + case 0x01 -> Position.ALARM_POWER_OFF; + case 0x02 -> Position.ALARM_SOS; + case 0x03 -> Position.ALARM_LOW_BATTERY; + case 0x04 -> Position.ALARM_VIBRATION; + case 0x08, 0x09 -> Position.ALARM_GPS_ANTENNA_CUT; + case 0x25 -> Position.ALARM_REMOVING; + case 0x81 -> Position.ALARM_LOW_SPEED; + case 0x82 -> Position.ALARM_OVERSPEED; + case 0x83 -> Position.ALARM_GEOFENCE_ENTER; + case 0x84 -> Position.ALARM_GEOFENCE_EXIT; + case 0x85 -> Position.ALARM_ACCIDENT; + case 0x86 -> Position.ALARM_FALL_DOWN; + default -> null; + }; } private void decodeStatus(Position position, int status) { @@ -407,17 +393,9 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { int pid = buf.readUnsignedByte(); int value = buf.readInt(); switch (pid) { - case 0x89: - position.set(Position.KEY_FUEL_CONSUMPTION, value); - break; - case 0x8a: - position.set(Position.KEY_ODOMETER, value * 1000L); - break; - case 0x8b: - position.set(Position.KEY_FUEL_LEVEL, value / 10); - break; - default: - break; + case 0x89 -> position.set(Position.KEY_FUEL_CONSUMPTION, value); + case 0x8a -> position.set(Position.KEY_ODOMETER, value * 1000L); + case 0x8b -> position.set(Position.KEY_FUEL_LEVEL, value / 10); } } diff --git a/src/main/java/org/traccar/protocol/EelinkProtocolEncoder.java b/src/main/java/org/traccar/protocol/EelinkProtocolEncoder.java index 3673c35b3..d3f7aa30b 100644 --- a/src/main/java/org/traccar/protocol/EelinkProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/EelinkProtocolEncoder.java @@ -90,20 +90,14 @@ public class EelinkProtocolEncoder extends BaseProtocolEncoder { @Override protected Object encodeCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_CUSTOM: - return encodeContent(command.getDeviceId(), command.getString(Command.KEY_DATA)); - case Command.TYPE_POSITION_SINGLE: - return encodeContent(command.getDeviceId(), "WHERE#"); - case Command.TYPE_ENGINE_STOP: - return encodeContent(command.getDeviceId(), "RELAY,1#"); - case Command.TYPE_ENGINE_RESUME: - return encodeContent(command.getDeviceId(), "RELAY,0#"); - case Command.TYPE_REBOOT_DEVICE: - return encodeContent(command.getDeviceId(), "RESET#"); - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_CUSTOM -> encodeContent(command.getDeviceId(), command.getString(Command.KEY_DATA)); + case Command.TYPE_POSITION_SINGLE -> encodeContent(command.getDeviceId(), "WHERE#"); + case Command.TYPE_ENGINE_STOP -> encodeContent(command.getDeviceId(), "RELAY,1#"); + case Command.TYPE_ENGINE_RESUME -> encodeContent(command.getDeviceId(), "RELAY,0#"); + case Command.TYPE_REBOOT_DEVICE -> encodeContent(command.getDeviceId(), "RESET#"); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/EnforaProtocolEncoder.java b/src/main/java/org/traccar/protocol/EnforaProtocolEncoder.java index 8cc24dc0f..7cd10a2ed 100644 --- a/src/main/java/org/traccar/protocol/EnforaProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/EnforaProtocolEncoder.java @@ -45,16 +45,12 @@ public class EnforaProtocolEncoder extends StringProtocolEncoder { @Override protected Object encodeCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_CUSTOM: - return encodeContent(command.getString(Command.KEY_DATA)); - case Command.TYPE_ENGINE_STOP: - return encodeContent("AT$IOGP3=1"); - case Command.TYPE_ENGINE_RESUME: - return encodeContent("AT$IOGP3=0"); - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_CUSTOM -> encodeContent(command.getString(Command.KEY_DATA)); + case Command.TYPE_ENGINE_STOP -> encodeContent("AT$IOGP3=1"); + case Command.TYPE_ENGINE_RESUME -> encodeContent("AT$IOGP3=0"); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/EnvotechProtocolDecoder.java b/src/main/java/org/traccar/protocol/EnvotechProtocolDecoder.java index 750ff2bda..f4d1f5747 100644 --- a/src/main/java/org/traccar/protocol/EnvotechProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/EnvotechProtocolDecoder.java @@ -75,14 +75,8 @@ public class EnvotechProtocolDecoder extends BaseProtocolDecoder { int event = parser.nextHexInt(); switch (event) { - case 0x60: - position.set(Position.KEY_ALARM, Position.ALARM_LOCK); - break; - case 0x61: - position.set(Position.KEY_ALARM, Position.ALARM_UNLOCK); - break; - default: - break; + case 0x60 -> position.set(Position.KEY_ALARM, Position.ALARM_LOCK); + case 0x61 -> position.set(Position.KEY_ALARM, Position.ALARM_UNLOCK); } position.set(Position.KEY_EVENT, event); diff --git a/src/main/java/org/traccar/protocol/EsealProtocolDecoder.java b/src/main/java/org/traccar/protocol/EsealProtocolDecoder.java index dd15c4276..7958265c3 100644 --- a/src/main/java/org/traccar/protocol/EsealProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/EsealProtocolDecoder.java @@ -74,20 +74,14 @@ public class EsealProtocolDecoder extends BaseProtocolDecoder { } private String decodeAlarm(String type) { - switch (type) { - case "Event-Door": - return Position.ALARM_DOOR; - case "Event-Shock": - return Position.ALARM_VIBRATION; - case "Event-Drop": - return Position.ALARM_FALL_DOWN; - case "Event-Lock": - return Position.ALARM_LOCK; - case "Event-RC-Unlock": - return Position.ALARM_UNLOCK; - default: - return null; - } + return switch (type) { + case "Event-Door" -> Position.ALARM_DOOR; + case "Event-Shock" -> Position.ALARM_VIBRATION; + case "Event-Drop" -> Position.ALARM_FALL_DOWN; + case "Event-Lock" -> Position.ALARM_LOCK; + case "Event-RC-Unlock" -> Position.ALARM_UNLOCK; + default -> null; + }; } @Override @@ -141,14 +135,8 @@ public class EsealProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt())); switch (parser.next()) { - case "Open": - position.set(Position.KEY_DOOR, true); - break; - case "Close": - position.set(Position.KEY_DOOR, false); - break; - default: - break; + case "Open" -> position.set(Position.KEY_DOOR, true); + case "Close" -> position.set(Position.KEY_DOOR, false); } position.set(Position.KEY_ACCELERATION, parser.nextDouble()); diff --git a/src/main/java/org/traccar/protocol/EsealProtocolEncoder.java b/src/main/java/org/traccar/protocol/EsealProtocolEncoder.java index 74f9e22ab..4af36b245 100644 --- a/src/main/java/org/traccar/protocol/EsealProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/EsealProtocolEncoder.java @@ -28,19 +28,15 @@ public class EsealProtocolEncoder extends StringProtocolEncoder { @Override protected Object encodeCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_CUSTOM: - return formatCommand( - command, "##S,eSeal,%s,256,3.0.8,%s,E##", Command.KEY_UNIQUE_ID, Command.KEY_DATA); - case Command.TYPE_ALARM_ARM: - return formatCommand( - command, "##S,eSeal,%s,256,3.0.8,RC-Power Control,Power OFF,E##", Command.KEY_UNIQUE_ID); - case Command.TYPE_ALARM_DISARM: - return formatCommand( - command, "##S,eSeal,%s,256,3.0.8,RC-Unlock,E##", Command.KEY_UNIQUE_ID); - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_CUSTOM -> formatCommand( + command, "##S,eSeal,%s,256,3.0.8,%s,E##", Command.KEY_UNIQUE_ID, Command.KEY_DATA); + case Command.TYPE_ALARM_ARM -> formatCommand( + command, "##S,eSeal,%s,256,3.0.8,RC-Power Control,Power OFF,E##", Command.KEY_UNIQUE_ID); + case Command.TYPE_ALARM_DISARM -> formatCommand( + command, "##S,eSeal,%s,256,3.0.8,RC-Unlock,E##", Command.KEY_UNIQUE_ID); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java index 59019830f..0a0392acd 100644 --- a/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java @@ -157,50 +157,28 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder { private String decodeAlarm(Integer alarm) { if (alarm != null) { - switch (alarm) { - case 2: - return Position.ALARM_SOS; - case 14: - return Position.ALARM_LOW_POWER; - case 15: - return Position.ALARM_POWER_CUT; - case 16: - return Position.ALARM_POWER_RESTORED; - case 17: - return Position.ALARM_LOW_BATTERY; - case 18: - return Position.ALARM_OVERSPEED; - case 20: - return Position.ALARM_GPS_ANTENNA_CUT; - case 21: - return Position.ALARM_VIBRATION; - case 23: - return Position.ALARM_ACCELERATION; - case 24: - return Position.ALARM_BRAKING; - case 27: - return Position.ALARM_FATIGUE_DRIVING; - case 30: - case 32: - return Position.ALARM_JAMMING; - case 31: - return Position.ALARM_FALL_DOWN; - case 33: - return Position.ALARM_GEOFENCE_EXIT; - case 34: - return Position.ALARM_GEOFENCE_ENTER; - case 35: - return Position.ALARM_IDLE; - case 40: - case 41: - return Position.ALARM_TEMPERATURE; - case 53: - return Position.ALARM_POWER_ON; - case 54: - return Position.ALARM_POWER_OFF; - default: - return null; - } + return switch (alarm) { + case 2 -> Position.ALARM_SOS; + case 14 -> Position.ALARM_LOW_POWER; + case 15 -> Position.ALARM_POWER_CUT; + case 16 -> Position.ALARM_POWER_RESTORED; + case 17 -> Position.ALARM_LOW_BATTERY; + case 18 -> Position.ALARM_OVERSPEED; + case 20 -> Position.ALARM_GPS_ANTENNA_CUT; + case 21 -> Position.ALARM_VIBRATION; + case 23 -> Position.ALARM_ACCELERATION; + case 24 -> Position.ALARM_BRAKING; + case 27 -> Position.ALARM_FATIGUE_DRIVING; + case 30, 32 -> Position.ALARM_JAMMING; + case 31 -> Position.ALARM_FALL_DOWN; + case 33 -> Position.ALARM_GEOFENCE_EXIT; + case 34 -> Position.ALARM_GEOFENCE_ENTER; + case 35 -> Position.ALARM_IDLE; + case 40, 41 -> Position.ALARM_TEMPERATURE; + case 53 -> Position.ALARM_POWER_ON; + case 54 -> Position.ALARM_POWER_OFF; + default -> null; + }; } return null; } diff --git a/src/main/java/org/traccar/protocol/FifotrackProtocolEncoder.java b/src/main/java/org/traccar/protocol/FifotrackProtocolEncoder.java index a4e69b47b..2c01fc691 100644 --- a/src/main/java/org/traccar/protocol/FifotrackProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/FifotrackProtocolEncoder.java @@ -37,14 +37,11 @@ public class FifotrackProtocolEncoder extends StringProtocolEncoder { @Override protected Object encodeCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_CUSTOM: - return formatCommand(command, command.getString(Command.KEY_DATA)); - case Command.TYPE_REQUEST_PHOTO: - return formatCommand(command, "D05,3"); - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_CUSTOM -> formatCommand(command, command.getString(Command.KEY_DATA)); + case Command.TYPE_REQUEST_PHOTO -> formatCommand(command, "D05,3"); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/FleetGuideProtocolDecoder.java b/src/main/java/org/traccar/protocol/FleetGuideProtocolDecoder.java index 8f679525b..6163a24c8 100644 --- a/src/main/java/org/traccar/protocol/FleetGuideProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/FleetGuideProtocolDecoder.java @@ -205,17 +205,9 @@ public class FleetGuideProtocolDecoder extends BaseProtocolDecoder { case 18: int sensorIndex = data.readUnsignedByte(); switch (recordLength - 1) { - case 1: - position.set("sensor" + sensorIndex, data.readUnsignedByte()); - break; - case 2: - position.set("sensor" + sensorIndex, data.readUnsignedShortLE()); - break; - case 4: - position.set("sensor" + sensorIndex, data.readUnsignedIntLE()); - break; - default: - break; + case 1 -> position.set("sensor" + sensorIndex, data.readUnsignedByte()); + case 2 -> position.set("sensor" + sensorIndex, data.readUnsignedShortLE()); + case 4 -> position.set("sensor" + sensorIndex, data.readUnsignedIntLE()); } break; default: diff --git a/src/main/java/org/traccar/protocol/FlespiProtocolDecoder.java b/src/main/java/org/traccar/protocol/FlespiProtocolDecoder.java index 168b3b3cd..e6ea994df 100644 --- a/src/main/java/org/traccar/protocol/FlespiProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/FlespiProtocolDecoder.java @@ -93,157 +93,193 @@ public class FlespiProtocolDecoder extends BaseHttpProtocolDecoder { } private boolean decodeParam(String name, int index, JsonValue value, Position position) { - switch (name) { - case "timestamp": + return switch (name) { + case "timestamp" -> { position.setTime(new Date(((JsonNumber) value).longValue() * 1000)); - return true; - case "position.latitude": + yield true; + } + case "position.latitude" -> { position.setLatitude(((JsonNumber) value).doubleValue()); - return true; - case "position.longitude": + yield true; + } + case "position.longitude" -> { position.setLongitude(((JsonNumber) value).doubleValue()); - return true; - case "position.speed": + yield true; + } + case "position.speed" -> { position.setSpeed(UnitsConverter.knotsFromKph(((JsonNumber) value).doubleValue())); - return true; - case "position.direction": + yield true; + } + case "position.direction" -> { position.setCourse(((JsonNumber) value).doubleValue()); - return true; - case "position.altitude": + yield true; + } + case "position.altitude" -> { position.setAltitude(((JsonNumber) value).doubleValue()); - return true; - case "position.satellites": + yield true; + } + case "position.satellites" -> { position.set(Position.KEY_SATELLITES, ((JsonNumber) value).intValue()); - return true; - case "position.valid": + yield true; + } + case "position.valid" -> { position.setValid(value == JsonValue.TRUE); - return true; - case "position.hdop": + yield true; + } + case "position.hdop" -> { position.set(Position.KEY_HDOP, ((JsonNumber) value).doubleValue()); - return true; - case "position.pdop": + yield true; + } + case "position.pdop" -> { position.set(Position.KEY_PDOP, ((JsonNumber) value).doubleValue()); - return true; - case "din": + yield true; + } + case "din" -> { position.set(Position.KEY_INPUT, ((JsonNumber) value).intValue()); - return true; - case "dout": + yield true; + } + case "dout" -> { position.set(Position.KEY_OUTPUT, ((JsonNumber) value).intValue()); - return true; - case "report.reason": + yield true; + } + case "report.reason" -> { position.set(Position.KEY_EVENT, ((JsonNumber) value).intValue()); - return true; - case "gps.vehicle.mileage": + yield true; + } + case "gps.vehicle.mileage" -> { position.set(Position.KEY_ODOMETER, ((JsonNumber) value).doubleValue()); - return true; - case "external.powersource.voltage": + yield true; + } + case "external.powersource.voltage" -> { position.set(Position.KEY_POWER, ((JsonNumber) value).doubleValue()); - return true; - case "battery.voltage": + yield true; + } + case "battery.voltage" -> { position.set(Position.KEY_BATTERY, ((JsonNumber) value).doubleValue()); - return true; - case "battery.level": + yield true; + } + case "battery.level" -> { position.set(Position.KEY_BATTERY_LEVEL, ((JsonNumber) value).intValue()); - return true; - case "fuel.level": - case "can.fuel.level": + yield true; + } + case "fuel.level", "can.fuel.level" -> { position.set(Position.KEY_FUEL_LEVEL, ((JsonNumber) value).doubleValue()); - return true; - case "engine.rpm": - case "can.engine.rpm": + yield true; + } + case "engine.rpm", "can.engine.rpm" -> { position.set(Position.KEY_RPM, ((JsonNumber) value).doubleValue()); - return true; - case "can.engine.temperature": + yield true; + } + case "can.engine.temperature" -> { position.set(Position.PREFIX_TEMP + Math.max(index, 0), ((JsonNumber) value).doubleValue()); - return true; - case "engine.ignition.status": + yield true; + } + case "engine.ignition.status" -> { position.set(Position.KEY_IGNITION, value == JsonValue.TRUE); - return true; - case "movement.status": + yield true; + } + case "movement.status" -> { position.set(Position.KEY_MOTION, value == JsonValue.TRUE); - return true; - case "device.temperature": + yield true; + } + case "device.temperature" -> { position.set(Position.KEY_DEVICE_TEMP, ((JsonNumber) value).doubleValue()); - return true; - case "ibutton.code": + yield true; + } + case "ibutton.code" -> { position.set(Position.KEY_DRIVER_UNIQUE_ID, ((JsonString) value).getString()); - return true; - case "vehicle.vin": + yield true; + } + case "vehicle.vin" -> { position.set(Position.KEY_VIN, ((JsonString) value).getString()); - return true; - case "alarm.event.trigger": + yield true; + } + case "alarm.event.trigger" -> { if (value == JsonValue.TRUE) { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } - return true; - case "towing.event.trigger": - case "towing.alarm.status": + yield true; + } + case "towing.event.trigger", "towing.alarm.status" -> { if (value == JsonValue.TRUE) { position.set(Position.KEY_ALARM, Position.ALARM_TOW); } - return true; - case "geofence.event.enter": + yield true; + } + case "geofence.event.enter" -> { if (value == JsonValue.TRUE) { position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_ENTER); } - return true; - case "geofence.event.exit": + yield true; + } + case "geofence.event.exit" -> { if (value == JsonValue.TRUE) { position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT); } - return true; - case "shock.event.trigger": + yield true; + } + case "shock.event.trigger" -> { if (value == JsonValue.TRUE) { position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION); } - return true; - case "overspeeding.event.trigger": + yield true; + } + case "overspeeding.event.trigger" -> { if (value == JsonValue.TRUE) { position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); } - return true; - case "harsh.acceleration.event.trigger": + yield true; + } + case "harsh.acceleration.event.trigger" -> { if (value == JsonValue.TRUE) { position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); } - return true; - case "harsh.braking.event.trigger": + yield true; + } + case "harsh.braking.event.trigger" -> { if (value == JsonValue.TRUE) { position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); } - return true; - case "harsh.cornering.event.trigger": + yield true; + } + case "harsh.cornering.event.trigger" -> { if (value == JsonValue.TRUE) { position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); } - return true; - case "gnss.antenna.cut.status": + yield true; + } + case "gnss.antenna.cut.status" -> { if (value == JsonValue.TRUE) { position.set(Position.KEY_ALARM, Position.ALARM_GPS_ANTENNA_CUT); } - return true; - case "gsm.jamming.event.trigger": + yield true; + } + case "gsm.jamming.event.trigger" -> { if (value == JsonValue.TRUE) { position.set(Position.KEY_ALARM, Position.ALARM_JAMMING); } - return true; - case "hood.open.status": + yield true; + } + case "hood.open.status" -> { if (value == JsonValue.TRUE) { position.set(Position.KEY_ALARM, Position.ALARM_BONNET); } - return true; - case "custom.wln_accel_max": + yield true; + } + case "custom.wln_accel_max" -> { position.set("maxAcceleration", ((JsonNumber) value).doubleValue()); - return true; - case "custom.wln_brk_max": + yield true; + } + case "custom.wln_brk_max" -> { position.set("maxBraking", ((JsonNumber) value).doubleValue()); - return true; - case "custom.wln_crn_max": + yield true; + } + case "custom.wln_crn_max" -> { position.set("maxCornering", ((JsonNumber) value).doubleValue()); - return true; - default: - return false; - } + yield true; + } + default -> false; + }; } private void decodeUnknownParam(String name, JsonValue value, Position position) { diff --git a/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java b/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java index fb76673ca..c39f774b7 100644 --- a/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java @@ -93,17 +93,9 @@ public class FlexApiProtocolDecoder extends BaseProtocolDecoder { Integer.parseInt(payload.getString("modem1.cell_id"), 16), payload.getInt("modem1.rssi")); switch (payload.getInt("modem1.network")) { - case 1: - cellTower.setRadioType("gsm"); - break; - case 2: - cellTower.setRadioType("wcdma"); - break; - case 3: - cellTower.setRadioType("lte"); - break; - default: - break; + case 1 -> cellTower.setRadioType("gsm"); + case 2 -> cellTower.setRadioType("wcdma"); + case 3 -> cellTower.setRadioType("lte"); } position.setNetwork(new Network(cellTower)); } diff --git a/src/main/java/org/traccar/protocol/FreematicsProtocolDecoder.java b/src/main/java/org/traccar/protocol/FreematicsProtocolDecoder.java index d0402cc94..d7d9d62ed 100644 --- a/src/main/java/org/traccar/protocol/FreematicsProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/FreematicsProtocolDecoder.java @@ -48,20 +48,13 @@ public class FreematicsProtocolDecoder extends BaseProtocolDecoder { String key = data[0]; String value = data[1]; switch (key) { - case "ID": - case "VIN": + case "ID", "VIN" -> { if (deviceSession == null) { deviceSession = getDeviceSession(channel, remoteAddress, value); } - break; - case "EV": - event = value; - break; - case "TS": - time = value; - break; - default: - break; + } + case "EV" -> event = value; + case "TS" -> time = value; } } @@ -105,74 +98,44 @@ public class FreematicsProtocolDecoder extends BaseProtocolDecoder { dateBuilder = new DateBuilder(new Date()); } else if (position != null) { switch (key) { - case 0x11: + case 0x11 -> { value = ("000000" + value).substring(value.length()); dateBuilder.setDateReverse( Integer.parseInt(value.substring(0, 2)), Integer.parseInt(value.substring(2, 4)), Integer.parseInt(value.substring(4))); - break; - case 0x10: + } + case 0x10 -> { value = ("00000000" + value).substring(value.length()); dateBuilder.setTime( Integer.parseInt(value.substring(0, 2)), Integer.parseInt(value.substring(2, 4)), Integer.parseInt(value.substring(4, 6)), Integer.parseInt(value.substring(6)) * 10); - break; - case 0xA: + } + case 0xA -> { position.setValid(true); position.setLatitude(Double.parseDouble(value)); - break; - case 0xB: + } + case 0xB -> { position.setValid(true); position.setLongitude(Double.parseDouble(value)); - break; - case 0xC: - position.setAltitude(Double.parseDouble(value)); - break; - case 0xD: - position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(value))); - break; - case 0xE: - position.setCourse(Integer.parseInt(value)); - break; - case 0xF: - position.set(Position.KEY_SATELLITES, Integer.parseInt(value)); - break; - case 0x12: - position.set(Position.KEY_HDOP, Integer.parseInt(value)); - break; - case 0x20: - position.set(Position.KEY_ACCELERATION, value); - break; - case 0x24: - position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.01); - break; - case 0x81: - position.set(Position.KEY_RSSI, Integer.parseInt(value)); - break; - case 0x82: - position.set(Position.KEY_DEVICE_TEMP, Double.parseDouble(value) * 0.1); - break; - case 0x104: - position.set(Position.KEY_ENGINE_LOAD, Integer.parseInt(value)); - break; - case 0x105: - position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(value)); - break; - case 0x10c: - position.set(Position.KEY_RPM, Integer.parseInt(value)); - break; - case 0x10d: - position.set(Position.KEY_OBD_SPEED, Integer.parseInt(value)); - break; - case 0x111: - position.set(Position.KEY_THROTTLE, Integer.parseInt(value)); - break; - default: - position.set(Position.PREFIX_IO + key, value); - break; + } + case 0xC -> position.setAltitude(Double.parseDouble(value)); + case 0xD -> position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(value))); + case 0xE -> position.setCourse(Integer.parseInt(value)); + case 0xF -> position.set(Position.KEY_SATELLITES, Integer.parseInt(value)); + case 0x12 -> position.set(Position.KEY_HDOP, Integer.parseInt(value)); + case 0x20 -> position.set(Position.KEY_ACCELERATION, value); + case 0x24 -> position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.01); + case 0x81 -> position.set(Position.KEY_RSSI, Integer.parseInt(value)); + case 0x82 -> position.set(Position.KEY_DEVICE_TEMP, Double.parseDouble(value) * 0.1); + case 0x104 -> position.set(Position.KEY_ENGINE_LOAD, Integer.parseInt(value)); + case 0x105 -> position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(value)); + case 0x10c -> position.set(Position.KEY_RPM, Integer.parseInt(value)); + case 0x10d -> position.set(Position.KEY_OBD_SPEED, Integer.parseInt(value)); + case 0x111 -> position.set(Position.KEY_THROTTLE, Integer.parseInt(value)); + default -> position.set(Position.PREFIX_IO + key, value); } } } diff --git a/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java b/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java index 44baa94ea..1ac735407 100644 --- a/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java @@ -149,94 +149,42 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { private void decodeTagOther(Position position, ByteBuf buf, int tag) { switch (tag) { - case 0x01: - position.set(Position.KEY_VERSION_HW, buf.readUnsignedByte()); - break; - case 0x02: - position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte()); - break; - case 0x04: - position.set("deviceId", buf.readUnsignedShortLE()); - break; - case 0x10: - position.set(Position.KEY_INDEX, buf.readUnsignedShortLE()); - break; - case 0x20: - position.setTime(new Date(buf.readUnsignedIntLE() * 1000)); - break; - case 0x33: + case 0x01 -> position.set(Position.KEY_VERSION_HW, buf.readUnsignedByte()); + case 0x02 -> position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte()); + case 0x04 -> position.set("deviceId", buf.readUnsignedShortLE()); + case 0x10 -> position.set(Position.KEY_INDEX, buf.readUnsignedShortLE()); + case 0x20 -> position.setTime(new Date(buf.readUnsignedIntLE() * 1000)); + case 0x33 -> { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE() * 0.1)); position.setCourse(buf.readUnsignedShortLE() * 0.1); - break; - case 0x34: - position.setAltitude(buf.readShortLE()); - break; - case 0x35: - position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1); - break; - case 0x40: - position.set(Position.KEY_STATUS, buf.readUnsignedShortLE()); - break; - case 0x41: - position.set(Position.KEY_POWER, buf.readUnsignedShortLE() / 1000.0); - break; - case 0x42: - position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() / 1000.0); - break; - case 0x43: - position.set(Position.KEY_DEVICE_TEMP, buf.readByte()); - break; - case 0x44: - position.set(Position.KEY_ACCELERATION, buf.readUnsignedIntLE()); - break; - case 0x45: - position.set(Position.KEY_OUTPUT, buf.readUnsignedShortLE()); - break; - case 0x46: - position.set(Position.KEY_INPUT, buf.readUnsignedShortLE()); - break; - case 0x48: - position.set("statusExtended", buf.readUnsignedShortLE()); - break; - case 0x58: - position.set("rs2320", buf.readUnsignedShortLE()); - break; - case 0x59: - position.set("rs2321", buf.readUnsignedShortLE()); - break; - case 0x90: - position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE())); - break; - case 0xc0: - position.set("fuelTotal", buf.readUnsignedIntLE() * 0.5); - break; - case 0xc1: + } + case 0x34 -> position.setAltitude(buf.readShortLE()); + case 0x35 -> position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1); + case 0x40 -> position.set(Position.KEY_STATUS, buf.readUnsignedShortLE()); + case 0x41 -> position.set(Position.KEY_POWER, buf.readUnsignedShortLE() / 1000.0); + case 0x42 -> position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() / 1000.0); + case 0x43 -> position.set(Position.KEY_DEVICE_TEMP, buf.readByte()); + case 0x44 -> position.set(Position.KEY_ACCELERATION, buf.readUnsignedIntLE()); + case 0x45 -> position.set(Position.KEY_OUTPUT, buf.readUnsignedShortLE()); + case 0x46 -> position.set(Position.KEY_INPUT, buf.readUnsignedShortLE()); + case 0x48 -> position.set("statusExtended", buf.readUnsignedShortLE()); + case 0x58 -> position.set("rs2320", buf.readUnsignedShortLE()); + case 0x59 -> position.set("rs2321", buf.readUnsignedShortLE()); + case 0x90 -> position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE())); + case 0xc0 -> position.set("fuelTotal", buf.readUnsignedIntLE() * 0.5); + case 0xc1 -> { position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4); position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedByte() - 40); position.set(Position.KEY_RPM, buf.readUnsignedShortLE() * 0.125); - break; - case 0xc2: - position.set("canB0", buf.readUnsignedIntLE()); - break; - case 0xc3: - position.set("canB1", buf.readUnsignedIntLE()); - break; - case 0xd4: - position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); - break; - case 0xe0: - position.set(Position.KEY_INDEX, buf.readUnsignedIntLE()); - break; - case 0xe1: - position.set(Position.KEY_RESULT, - buf.readSlice(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII)); - break; - case 0xea: - position.set("userDataArray", ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedByte()))); - break; - default: - buf.skipBytes(getTagLength(tag)); - break; + } + case 0xc2 -> position.set("canB0", buf.readUnsignedIntLE()); + case 0xc3 -> position.set("canB1", buf.readUnsignedIntLE()); + case 0xd4 -> position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); + case 0xe0 -> position.set(Position.KEY_INDEX, buf.readUnsignedIntLE()); + case 0xe1 -> position.set(Position.KEY_RESULT, + buf.readSlice(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII)); + case 0xea -> position.set("userDataArray", ByteBufUtil.hexDump(buf.readSlice(buf.readUnsignedByte()))); + default -> buf.skipBytes(getTagLength(tag)); } } diff --git a/src/main/java/org/traccar/protocol/GalileoProtocolEncoder.java b/src/main/java/org/traccar/protocol/GalileoProtocolEncoder.java index cd068b251..b0033a2ba 100644 --- a/src/main/java/org/traccar/protocol/GalileoProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/GalileoProtocolEncoder.java @@ -58,15 +58,13 @@ public class GalileoProtocolEncoder extends BaseProtocolEncoder { @Override protected Object encodeCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_CUSTOM: - return encodeText(getUniqueId(command.getDeviceId()), command.getString(Command.KEY_DATA)); - case Command.TYPE_OUTPUT_CONTROL: - return encodeText(getUniqueId(command.getDeviceId()), - "Out " + command.getInteger(Command.KEY_INDEX) + "," + command.getString(Command.KEY_DATA)); - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_CUSTOM -> encodeText(getUniqueId(command.getDeviceId()), + command.getString(Command.KEY_DATA)); + case Command.TYPE_OUTPUT_CONTROL -> encodeText(getUniqueId(command.getDeviceId()), + "Out " + command.getInteger(Command.KEY_INDEX) + "," + command.getString(Command.KEY_DATA)); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java index 6c6b9a54a..2bd56592b 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java @@ -73,21 +73,22 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder { ByteBuf content = Unpooled.buffer(); - switch (command.getType()) { - case Command.TYPE_POSITION_SINGLE: - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_REQUEST, null); - case Command.TYPE_ENGINE_STOP: - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_CLOSE_OIL_DUCT, null); - case Command.TYPE_ENGINE_RESUME: - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESTORE_OIL_DUCT, null); - case Command.TYPE_SET_SPEED_LIMIT: + return switch (command.getType()) { + case Command.TYPE_POSITION_SINGLE -> + encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_REQUEST, null); + case Command.TYPE_ENGINE_STOP -> + encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_CLOSE_OIL_DUCT, null); + case Command.TYPE_ENGINE_RESUME -> + encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESTORE_OIL_DUCT, null); + case Command.TYPE_SET_SPEED_LIMIT -> { content.writeByte(command.getInteger(Command.KEY_DATA)); - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESET_MILEAGE, content); - case Command.TYPE_SET_ODOMETER: + yield encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESET_MILEAGE, content); + } + case Command.TYPE_SET_ODOMETER -> { content.writeShort(command.getInteger(Command.KEY_DATA)); - return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_OVERSPEED_ALARM, content); - default: - return null; - } + yield encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_OVERSPEED_ALARM, content); + } + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/GenxProtocolDecoder.java b/src/main/java/org/traccar/protocol/GenxProtocolDecoder.java index 6448b6a5a..30416a07b 100644 --- a/src/main/java/org/traccar/protocol/GenxProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GenxProtocolDecoder.java @@ -57,42 +57,21 @@ public class GenxProtocolDecoder extends BaseProtocolDecoder { for (int i = 0; i < Math.min(values.length, reportColumns.length); i++) { switch (reportColumns[i]) { - case 1: - case 28: + case 1, 28 -> { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[i]); if (deviceSession != null) { position.setDeviceId(deviceSession.getDeviceId()); } - break; - case 2: - position.setTime(new SimpleDateFormat("MM/dd/yy HH:mm:ss").parse(values[i])); - break; - case 3: - position.setLatitude(Double.parseDouble(values[i])); - break; - case 4: - position.setLongitude(Double.parseDouble(values[i])); - break; - case 11: - position.set(Position.KEY_IGNITION, values[i].equals("ON")); - break; - case 13: - position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(values[i]))); - break; - case 17: - position.setCourse(Integer.parseInt(values[i])); - break; - case 23: - position.set(Position.KEY_ODOMETER, Double.parseDouble(values[i]) * 1000); - break; - case 27: - position.setAltitude(UnitsConverter.metersFromFeet(Integer.parseInt(values[i]))); - break; - case 46: - position.set(Position.KEY_SATELLITES, Integer.parseInt(values[i])); - break; - default: - break; + } + case 2 -> position.setTime(new SimpleDateFormat("MM/dd/yy HH:mm:ss").parse(values[i])); + case 3 -> position.setLatitude(Double.parseDouble(values[i])); + case 4 -> position.setLongitude(Double.parseDouble(values[i])); + case 11 -> position.set(Position.KEY_IGNITION, values[i].equals("ON")); + case 13 -> position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(values[i]))); + case 17 -> position.setCourse(Integer.parseInt(values[i])); + case 23 -> position.set(Position.KEY_ODOMETER, Double.parseDouble(values[i]) * 1000); + case 27 -> position.setAltitude(UnitsConverter.metersFromFeet(Integer.parseInt(values[i]))); + case 46 -> position.set(Position.KEY_SATELLITES, Integer.parseInt(values[i])); } } diff --git a/src/main/java/org/traccar/protocol/Gl200BinaryProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gl200BinaryProtocolDecoder.java index ecd1f5bfa..359af8e5a 100644 --- a/src/main/java/org/traccar/protocol/Gl200BinaryProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gl200BinaryProtocolDecoder.java @@ -230,52 +230,39 @@ public class Gl200BinaryProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); switch (type) { - case MSG_EVT_BPL: - buf.readUnsignedShort(); // backup battery voltage - break; - case MSG_EVT_VGN: - case MSG_EVT_VGF: + case MSG_EVT_BPL -> buf.readUnsignedShort(); // backup battery voltage + case MSG_EVT_VGN, MSG_EVT_VGF -> { buf.readUnsignedShort(); // reserved buf.readUnsignedByte(); // report type buf.readUnsignedInt(); // ignition duration - break; - case MSG_EVT_UPD: + } + case MSG_EVT_UPD -> { buf.readUnsignedShort(); // code buf.readUnsignedByte(); // retry - break; - case MSG_EVT_IDF: - buf.readUnsignedInt(); // idling duration - break; - case MSG_EVT_GSS: + } + case MSG_EVT_IDF -> buf.readUnsignedInt(); // idling duration + case MSG_EVT_GSS -> { buf.readUnsignedByte(); // gps signal status buf.readUnsignedInt(); // reserved - break; - case MSG_EVT_GES: + } + case MSG_EVT_GES -> { buf.readUnsignedShort(); // trigger geo id buf.readUnsignedByte(); // trigger geo enable buf.readUnsignedByte(); // trigger mode buf.readUnsignedInt(); // radius buf.readUnsignedInt(); // check interval - break; - case MSG_EVT_GPJ: + } + case MSG_EVT_GPJ -> { buf.readUnsignedByte(); // cw jamming value buf.readUnsignedByte(); // gps jamming state - break; - case MSG_EVT_RMD: - buf.readUnsignedByte(); // roaming state - break; - case MSG_EVT_JDS: - buf.readUnsignedByte(); // jamming state - break; - case MSG_EVT_CRA: - buf.readUnsignedByte(); // crash counter - break; - case MSG_EVT_UPC: + } + case MSG_EVT_RMD -> buf.readUnsignedByte(); // roaming state + case MSG_EVT_JDS -> buf.readUnsignedByte(); // jamming state + case MSG_EVT_CRA -> buf.readUnsignedByte(); // crash counter + case MSG_EVT_UPC -> { buf.readUnsignedByte(); // command id buf.readUnsignedShort(); // result - break; - default: - break; + } } buf.readUnsignedByte(); // count @@ -388,16 +375,12 @@ public class Gl200BinaryProtocolDecoder extends BaseProtocolDecoder { ByteBuf buf = (ByteBuf) msg; - switch (buf.readSlice(4).toString(StandardCharsets.US_ASCII)) { - case "+RSP": - return decodeLocation(channel, remoteAddress, buf); - case "+INF": - return decodeInformation(channel, remoteAddress, buf); - case "+EVT": - return decodeEvent(channel, remoteAddress, buf); - default: - return null; - } + return switch (buf.readSlice(4).toString(StandardCharsets.US_ASCII)) { + case "+RSP" -> decodeLocation(channel, remoteAddress, buf); + case "+INF" -> decodeInformation(channel, remoteAddress, buf); + case "+EVT" -> decodeEvent(channel, remoteAddress, buf); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/Gl200FrameDecoder.java b/src/main/java/org/traccar/protocol/Gl200FrameDecoder.java index 4ce243425..b011ede8b 100644 --- a/src/main/java/org/traccar/protocol/Gl200FrameDecoder.java +++ b/src/main/java/org/traccar/protocol/Gl200FrameDecoder.java @@ -52,27 +52,13 @@ public class Gl200FrameDecoder extends BaseFrameDecoder { if (isBinary(buf)) { - int length; - switch (buf.toString(buf.readerIndex(), 4, StandardCharsets.US_ASCII)) { - case "+ACK": - length = buf.getUnsignedByte(buf.readerIndex() + 6); - break; - case "+INF": - case "+BNF": - length = buf.getUnsignedShort(buf.readerIndex() + 7); - break; - case "+HBD": - length = buf.getUnsignedByte(buf.readerIndex() + 5); - break; - case "+CRD": - case "+BRD": - case "+LGN": - length = buf.getUnsignedShort(buf.readerIndex() + 6); - break; - default: - length = buf.getUnsignedShort(buf.readerIndex() + 9); - break; - } + int length = switch (buf.toString(buf.readerIndex(), 4, StandardCharsets.US_ASCII)) { + case "+ACK" -> buf.getUnsignedByte(buf.readerIndex() + 6); + case "+INF", "+BNF" -> buf.getUnsignedShort(buf.readerIndex() + 7); + case "+HBD" -> buf.getUnsignedByte(buf.readerIndex() + 5); + case "+CRD", "+BRD", "+LGN" -> buf.getUnsignedShort(buf.readerIndex() + 6); + default -> buf.getUnsignedShort(buf.readerIndex() + 9); + }; if (buf.readableBytes() >= length) { return buf.readRetainedSlice(length); diff --git a/src/main/java/org/traccar/protocol/Gl200ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Gl200ProtocolEncoder.java index dd0672c23..1d48db623 100644 --- a/src/main/java/org/traccar/protocol/Gl200ProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/Gl200ProtocolEncoder.java @@ -30,22 +30,19 @@ public class Gl200ProtocolEncoder extends StringProtocolEncoder { initDevicePassword(command, ""); - switch (command.getType()) { - case Command.TYPE_POSITION_SINGLE: - return formatCommand(command, "AT+GTRTO=%s,1,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD); - case Command.TYPE_ENGINE_STOP: - return formatCommand(command, "AT+GTOUT=%s,1,,,0,0,0,0,0,0,0,,,,,,,FFFF$", - Command.KEY_DEVICE_PASSWORD); - case Command.TYPE_ENGINE_RESUME: - return formatCommand(command, "AT+GTOUT=%s,0,,,0,0,0,0,0,0,0,,,,,,,FFFF$", - Command.KEY_DEVICE_PASSWORD); - case Command.TYPE_IDENTIFICATION: - return formatCommand(command, "AT+GTRTO=%s,8,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD); - case Command.TYPE_REBOOT_DEVICE: - return formatCommand(command, "AT+GTRTO=%s,3,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD); - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_POSITION_SINGLE -> formatCommand( + command, "AT+GTRTO=%s,1,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD); + case Command.TYPE_ENGINE_STOP -> formatCommand( + command, "AT+GTOUT=%s,1,,,0,0,0,0,0,0,0,,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD); + case Command.TYPE_ENGINE_RESUME -> formatCommand( + command, "AT+GTOUT=%s,0,,,0,0,0,0,0,0,0,,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD); + case Command.TYPE_IDENTIFICATION -> formatCommand( + command, "AT+GTRTO=%s,8,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD); + case Command.TYPE_REBOOT_DEVICE -> formatCommand( + command, "AT+GTRTO=%s,3,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java index 373e1c91c..edcd0fa8b 100644 --- a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java @@ -229,32 +229,24 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); switch (parser.nextHexInt()) { - case 0x16: - case 0x1A: - case 0x12: + case 0x16, 0x1A, 0x12 -> { position.set(Position.KEY_IGNITION, false); position.set(Position.KEY_MOTION, true); - break; - case 0x11: + } + case 0x11 -> { position.set(Position.KEY_IGNITION, false); position.set(Position.KEY_MOTION, false); - break; - case 0x21: + } + case 0x21 -> { position.set(Position.KEY_IGNITION, true); position.set(Position.KEY_MOTION, false); - break; - case 0x22: + } + case 0x22 -> { position.set(Position.KEY_IGNITION, true); position.set(Position.KEY_MOTION, true); - break; - case 0x41: - position.set(Position.KEY_MOTION, false); - break; - case 0x42: - position.set(Position.KEY_MOTION, true); - break; - default: - break; + } + case 0x41 -> position.set(Position.KEY_MOTION, false); + case 0x42 -> position.set(Position.KEY_MOTION, true); } position.set(Position.KEY_ICCID, parser.next()); @@ -1495,19 +1487,9 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_IGNITION, reportType % 0x10 == 1); } else if (type.equals("HBM")) { switch (reportType % 0x10) { - case 0: - case 3: - position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); - break; - case 1: - case 4: - position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); - break; - case 2: - position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); - break; - default: - break; + case 0, 3 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); + case 1, 4 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); + case 2 -> position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); } } @@ -1595,45 +1577,17 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { decodeDeviceTime(position, parser); switch (type) { - case "TOW": - position.set(Position.KEY_ALARM, Position.ALARM_TOW); - break; - case "IDL": - position.set(Position.KEY_ALARM, Position.ALARM_IDLE); - break; - case "PNA": - position.set(Position.KEY_ALARM, Position.ALARM_POWER_ON); - break; - case "PFA": - position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF); - break; - case "EPN": - case "MPN": - position.set(Position.KEY_ALARM, Position.ALARM_POWER_RESTORED); - break; - case "EPF": - case "MPF": - position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT); - break; - case "BPL": - position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); - break; - case "STT": - position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT); - break; - case "SWG": - position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE); - break; - case "TMP": - case "TEM": - position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE); - break; - case "JDR": - case "JDS": - position.set(Position.KEY_ALARM, Position.ALARM_JAMMING); - break; - default: - break; + case "TOW" -> position.set(Position.KEY_ALARM, Position.ALARM_TOW); + case "IDL" -> position.set(Position.KEY_ALARM, Position.ALARM_IDLE); + case "PNA" -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_ON); + case "PFA" -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF); + case "EPN", "MPN" -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_RESTORED); + case "EPF", "MPF" -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT); + case "BPL" -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); + case "STT" -> position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT); + case "SWG" -> position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE); + case "TMP", "TEM" -> position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE); + case "JDR", "JDS" -> position.set(Position.KEY_ALARM, Position.ALARM_JAMMING); } return position; @@ -1657,72 +1611,26 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { if (sentence.startsWith("+ACK")) { result = decodeAck(channel, remoteAddress, values); } else { - switch (type) { - case "INF": - result = decodeInf(channel, remoteAddress, sentence); - break; - case "OBD": - result = decodeObd(channel, remoteAddress, sentence); - break; - case "CAN": - result = decodeCan(channel, remoteAddress, values); - break; - case "CTN": - case "FRI": - case "GEO": - case "RTL": - case "DOG": - case "STR": - result = decodeFri(channel, remoteAddress, sentence); - break; - case "ERI": - result = decodeEri(channel, remoteAddress, values); - break; - case "IGN": - case "IGF": - case "VGN": - case "VGF": - result = decodeIgn(channel, remoteAddress, values, type); - break; - case "LSW": - case "TSW": - result = decodeLsw(channel, remoteAddress, sentence); - break; - case "IDA": - result = decodeIda(channel, remoteAddress, sentence); - break; - case "WIF": - result = decodeWif(channel, remoteAddress, sentence); - break; - case "GSM": - result = decodeGsm(channel, remoteAddress, sentence); - break; - case "VER": - result = decodeVer(channel, remoteAddress, sentence); - break; - case "PNA": - case "PFA": - result = decodePna(channel, remoteAddress, sentence); - break; - case "DAR": - result = decodeDar(channel, remoteAddress, sentence); - break; - case "DTT": - result = decodeDtt(channel, remoteAddress, sentence); - break; - case "BAA": - result = decodeBaa(channel, remoteAddress, sentence); - break; - case "BID": - result = decodeBid(channel, remoteAddress, sentence); - break; - case "LSA": - result = decodeLsa(channel, remoteAddress, sentence); - break; - default: - result = decodeOther(channel, remoteAddress, sentence, type); - break; - } + result = switch (type) { + case "INF" -> decodeInf(channel, remoteAddress, sentence); + case "OBD" -> decodeObd(channel, remoteAddress, sentence); + case "CAN" -> decodeCan(channel, remoteAddress, values); + case "CTN", "FRI", "GEO", "RTL", "DOG", "STR" -> decodeFri(channel, remoteAddress, sentence); + case "ERI" -> decodeEri(channel, remoteAddress, values); + case "IGN", "IGF", "VGN", "VGF" -> decodeIgn(channel, remoteAddress, values, type); + case "LSW", "TSW" -> decodeLsw(channel, remoteAddress, sentence); + case "IDA" -> decodeIda(channel, remoteAddress, sentence); + case "WIF" -> decodeWif(channel, remoteAddress, sentence); + case "GSM" -> decodeGsm(channel, remoteAddress, sentence); + case "VER" -> decodeVer(channel, remoteAddress, sentence); + case "PNA", "PFA" -> decodePna(channel, remoteAddress, sentence); + case "DAR" -> decodeDar(channel, remoteAddress, sentence); + case "DTT" -> decodeDtt(channel, remoteAddress, sentence); + case "BAA" -> decodeBaa(channel, remoteAddress, sentence); + case "BID" -> decodeBid(channel, remoteAddress, sentence); + case "LSA" -> decodeLsa(channel, remoteAddress, sentence); + default -> decodeOther(channel, remoteAddress, sentence, type); + }; if (result == null) { result = decodeBasic(channel, remoteAddress, sentence, type); diff --git a/src/main/java/org/traccar/protocol/GlobalSatProtocolEncoder.java b/src/main/java/org/traccar/protocol/GlobalSatProtocolEncoder.java index 4f56274da..c39410371 100644 --- a/src/main/java/org/traccar/protocol/GlobalSatProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/GlobalSatProtocolEncoder.java @@ -32,20 +32,12 @@ public class GlobalSatProtocolEncoder extends StringProtocolEncoder { String formattedCommand = null; switch (command.getType()) { - case Command.TYPE_CUSTOM: - formattedCommand = formatCommand( - command, "GSC,%s,%s", Command.KEY_UNIQUE_ID, Command.KEY_DATA); - break; - case Command.TYPE_ALARM_DISMISS: - formattedCommand = formatCommand( - command, "GSC,%s,Na", Command.KEY_UNIQUE_ID); - break; - case Command.TYPE_OUTPUT_CONTROL: - formattedCommand = formatCommand( - command, "GSC,%s,Lo(%s,%s)", Command.KEY_UNIQUE_ID, Command.KEY_INDEX, Command.KEY_DATA); - break; - default: - break; + case Command.TYPE_CUSTOM -> formattedCommand = formatCommand( + command, "GSC,%s,%s", Command.KEY_UNIQUE_ID, Command.KEY_DATA); + case Command.TYPE_ALARM_DISMISS -> formattedCommand = formatCommand( + command, "GSC,%s,Na", Command.KEY_UNIQUE_ID); + case Command.TYPE_OUTPUT_CONTROL -> formattedCommand = formatCommand( + command, "GSC,%s,Lo(%s,%s)", Command.KEY_UNIQUE_ID, Command.KEY_INDEX, Command.KEY_DATA); } if (formattedCommand != null) { diff --git a/src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java index d1c35b478..554a23915 100644 --- a/src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -141,35 +141,21 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { } else if (value.startsWith("oil")) { return Position.ALARM_FUEL_LEAK; } - switch (value) { - case "help me": - return Position.ALARM_SOS; - case "low battery": - return Position.ALARM_LOW_BATTERY; - case "stockade": - return Position.ALARM_GEOFENCE; - case "move": - return Position.ALARM_MOVEMENT; - case "speed": - return Position.ALARM_OVERSPEED; - case "door alarm": - return Position.ALARM_DOOR; - case "ac alarm": - return Position.ALARM_POWER_CUT; - case "accident alarm": - return Position.ALARM_ACCIDENT; - case "sensor alarm": - return Position.ALARM_VIBRATION; - case "bonnet alarm": - return Position.ALARM_BONNET; - case "footbrake alarm": - return Position.ALARM_FOOT_BRAKE; - case "DTC": - return Position.ALARM_FAULT; - case "tracker": - default: - return null; - } + return switch (value) { + case "help me" -> Position.ALARM_SOS; + case "low battery" -> Position.ALARM_LOW_BATTERY; + case "stockade" -> Position.ALARM_GEOFENCE; + case "move" -> Position.ALARM_MOVEMENT; + case "speed" -> Position.ALARM_OVERSPEED; + case "door alarm" -> Position.ALARM_DOOR; + case "ac alarm" -> Position.ALARM_POWER_CUT; + case "accident alarm" -> Position.ALARM_ACCIDENT; + case "sensor alarm" -> Position.ALARM_VIBRATION; + case "bonnet alarm" -> Position.ALARM_BONNET; + case "footbrake alarm" -> Position.ALARM_FOOT_BRAKE; + case "DTC" -> Position.ALARM_FAULT; + default -> null; + }; } private Position decodeRegular(Channel channel, SocketAddress remoteAddress, String sentence) { diff --git a/src/main/java/org/traccar/protocol/Gps103ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Gps103ProtocolEncoder.java index 9a899eeeb..1af99d647 100644 --- a/src/main/java/org/traccar/protocol/Gps103ProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/Gps103ProtocolEncoder.java @@ -45,29 +45,27 @@ public class Gps103ProtocolEncoder extends StringProtocolEncoder implements Stri @Override protected Object encodeCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_CUSTOM: - return formatCommand(command, "**,imei:%s,%s", Command.KEY_UNIQUE_ID, Command.KEY_DATA); - case Command.TYPE_POSITION_STOP: - return formatCommand(command, "**,imei:%s,D", Command.KEY_UNIQUE_ID); - case Command.TYPE_POSITION_SINGLE: - return formatCommand(command, "**,imei:%s,B", Command.KEY_UNIQUE_ID); - case Command.TYPE_POSITION_PERIODIC: - return formatCommand( - command, "**,imei:%s,C,%s", this, Command.KEY_UNIQUE_ID, Command.KEY_FREQUENCY); - case Command.TYPE_ENGINE_STOP: - return formatCommand(command, "**,imei:%s,J", Command.KEY_UNIQUE_ID); - case Command.TYPE_ENGINE_RESUME: - return formatCommand(command, "**,imei:%s,K", Command.KEY_UNIQUE_ID); - case Command.TYPE_ALARM_ARM: - return formatCommand(command, "**,imei:%s,L", Command.KEY_UNIQUE_ID); - case Command.TYPE_ALARM_DISARM: - return formatCommand(command, "**,imei:%s,M", Command.KEY_UNIQUE_ID); - case Command.TYPE_REQUEST_PHOTO: - return formatCommand(command, "**,imei:%s,160", Command.KEY_UNIQUE_ID); - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_CUSTOM -> formatCommand( + command, "**,imei:%s,%s", Command.KEY_UNIQUE_ID, Command.KEY_DATA); + case Command.TYPE_POSITION_STOP -> formatCommand( + command, "**,imei:%s,D", Command.KEY_UNIQUE_ID); + case Command.TYPE_POSITION_SINGLE -> formatCommand( + command, "**,imei:%s,B", Command.KEY_UNIQUE_ID); + case Command.TYPE_POSITION_PERIODIC -> formatCommand( + command, "**,imei:%s,C,%s", this, Command.KEY_UNIQUE_ID, Command.KEY_FREQUENCY); + case Command.TYPE_ENGINE_STOP -> formatCommand( + command, "**,imei:%s,J", Command.KEY_UNIQUE_ID); + case Command.TYPE_ENGINE_RESUME -> formatCommand( + command, "**,imei:%s,K", Command.KEY_UNIQUE_ID); + case Command.TYPE_ALARM_ARM -> formatCommand( + command, "**,imei:%s,L", Command.KEY_UNIQUE_ID); + case Command.TYPE_ALARM_DISARM -> formatCommand( + command, "**,imei:%s,M", Command.KEY_UNIQUE_ID); + case Command.TYPE_REQUEST_PHOTO -> formatCommand( + command, "**,imei:%s,160", Command.KEY_UNIQUE_ID); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/GranitProtocolEncoder.java b/src/main/java/org/traccar/protocol/GranitProtocolEncoder.java index 66c2a4973..a171e2b6a 100644 --- a/src/main/java/org/traccar/protocol/GranitProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/GranitProtocolEncoder.java @@ -38,16 +38,12 @@ public class GranitProtocolEncoder extends BaseProtocolEncoder { @Override protected Object encodeCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_IDENTIFICATION: - return encodeCommand("BB+IDNT"); - case Command.TYPE_REBOOT_DEVICE: - return encodeCommand("BB+RESET"); - case Command.TYPE_POSITION_SINGLE: - return encodeCommand("BB+RRCD"); - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_IDENTIFICATION -> encodeCommand("BB+IDNT"); + case Command.TYPE_REBOOT_DEVICE -> encodeCommand("BB+RESET"); + case Command.TYPE_POSITION_SINGLE -> encodeCommand("BB+RRCD"); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/GranitProtocolSmsEncoder.java b/src/main/java/org/traccar/protocol/GranitProtocolSmsEncoder.java index be0ab5130..6b8ef0969 100644 --- a/src/main/java/org/traccar/protocol/GranitProtocolSmsEncoder.java +++ b/src/main/java/org/traccar/protocol/GranitProtocolSmsEncoder.java @@ -28,14 +28,11 @@ public class GranitProtocolSmsEncoder extends StringProtocolEncoder { @Override protected String encodeCommand(Command command) { - switch (command.getType()) { - case Command.TYPE_REBOOT_DEVICE: - return "BB+RESET"; - case Command.TYPE_POSITION_PERIODIC: - return formatCommand(command, "BB+BBMD=%s", Command.KEY_FREQUENCY); - default: - return null; - } + return switch (command.getType()) { + case Command.TYPE_REBOOT_DEVICE -> "BB+RESET"; + case Command.TYPE_POSITION_PERIODIC -> formatCommand(command, "BB+BBMD=%s", Command.KEY_FREQUENCY); + default -> null; + }; } } diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index 1d77f75d7..f17671cd7 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -421,54 +421,27 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { private String decodeAlarm(short value, String model) { boolean modelLW = model != null && model.toUpperCase().startsWith("LW"); - switch (value) { - case 0x01: - return Position.ALARM_SOS; - case 0x02: - return Position.ALARM_POWER_CUT; - case 0x03: - case 0x09: - return Position.ALARM_VIBRATION; - case 0x04: - return Position.ALARM_GEOFENCE_ENTER; - case 0x05: - return Position.ALARM_GEOFENCE_EXIT; - case 0x06: - return Position.ALARM_OVERSPEED; - case 0x0E: - case 0x0F: - return Position.ALARM_LOW_BATTERY; - case 0x11: - return Position.ALARM_POWER_OFF; - case 0x0C: - case 0x13: - case 0x25: - return Position.ALARM_TAMPERING; - case 0x14: - return Position.ALARM_DOOR; - case 0x18: - return modelLW ? Position.ALARM_ACCIDENT : Position.ALARM_REMOVING; - case 0x19: - return modelLW ? Position.ALARM_ACCELERATION : Position.ALARM_LOW_BATTERY; - case 0x1A: - case 0x28: - return Position.ALARM_BRAKING; - case 0x1B: - case 0x2A: - case 0x2B: - case 0x2E: - return Position.ALARM_CORNERING; - case 0x23: - return Position.ALARM_FALL_DOWN; - case 0x29: - return Position.ALARM_ACCELERATION; - case 0x2C: - return Position.ALARM_ACCIDENT; - case 0x30: - return Position.ALARM_JAMMING; - default: - return null; - } + return switch (value) { + case 0x01 -> Position.ALARM_SOS; + case 0x02 -> Position.ALARM_POWER_CUT; + case 0x03, 0x09 -> Position.ALARM_VIBRATION; + case 0x04 -> Position.ALARM_GEOFENCE_ENTER; + case 0x05 -> Position.ALARM_GEOFENCE_EXIT; + case 0x06 -> Position.ALARM_OVERSPEED; + case 0x0E, 0x0F -> Position.ALARM_LOW_BATTERY; + case 0x11 -> Position.ALARM_POWER_OFF; + case 0x0C, 0x13, 0x25 -> Position.ALARM_TAMPERING; + case 0x14 -> Position.ALARM_DOOR; + case 0x18 -> modelLW ? Position.ALARM_ACCIDENT : Position.ALARM_REMOVING; + case 0x19 -> modelLW ? Position.ALARM_ACCELERATION : Position.ALARM_LOW_BATTERY; + case 0x1A, 0x28 -> Position.ALARM_BRAKING; + case 0x1B, 0x2A, 0x2B, 0x2E -> Position.ALARM_CORNERING; + case 0x23 -> Position.ALARM_FALL_DOWN; + case 0x29 -> Position.ALARM_ACCELERATION; + case 0x2C -> Position.ALARM_ACCIDENT; + case 0x30 -> Position.ALARM_JAMMING; + default -> null; + }; } private Object decodeBasic(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { @@ -968,18 +941,10 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { int module = buf.readUnsignedShort(); int subLength = buf.readUnsignedByte(); switch (module) { - case 0x0027: - position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01); - break; - case 0x002E: - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); - break; - case 0x003B: - position.setAccuracy(buf.readUnsignedShort() * 0.01); - break; - default: - buf.skipBytes(subLength); - break; + case 0x0027 -> position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01); + case 0x002E -> position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + case 0x003B -> position.setAccuracy(buf.readUnsignedShort() * 0.01); + default -> buf.skipBytes(subLength); } } @@ -1022,38 +987,17 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { short event = buf.readUnsignedByte(); position.set(Position.KEY_EVENT, event); switch (event) { - case 0x01: - position.set(Position.KEY_ALARM, extendedAlarm ? Position.ALARM_SOS : Position.ALARM_GENERAL); - break; - case 0x0E: - position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER); - break; - case 0x76: - position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE); - break; - case 0x80: - position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION); - break; - case 0x87: - position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); - break; - case 0x88: - position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT); - break; - case 0x90: - position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); - break; - case 0x91: - position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); - break; - case 0x92: - position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); - break; - case 0x93: - position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); - break; - default: - break; + case 0x01 -> position.set( + Position.KEY_ALARM, extendedAlarm ? Position.ALARM_SOS : Position.ALARM_GENERAL); + case 0x0E -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER); + case 0x76 -> position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE); + case 0x80 -> position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION); + case 0x87 -> position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); + case 0x88 -> position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT); + case 0x90 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); + case 0x91 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); + case 0x92 -> position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); + case 0x93 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); } } else { @@ -1251,24 +1195,11 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_AZ735_ALARM) { switch (status) { - case 0xA0: - position.set(Position.KEY_ARMED, true); - break; - case 0xA1: - position.set(Position.KEY_ARMED, false); - break; - case 0xA2: - case 0xA3: - position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); - break; - case 0xA4: - position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); - break; - case 0xA5: - position.set(Position.KEY_ALARM, Position.ALARM_DOOR); - break; - default: - break; + case 0xA0 -> position.set(Position.KEY_ARMED, true); + case 0xA1 -> position.set(Position.KEY_ARMED, false); + case 0xA2, 0xA3 -> position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); + case 0xA4 -> position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); + case 0xA5 -> position.set(Position.KEY_ALARM, Position.ALARM_DOOR); } } @@ -1293,32 +1224,14 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { String[] values = pair.split("="); if (values.length >= 2) { switch (Integer.parseInt(values[0].substring(0, 2), 16)) { - case 40: - position.set(Position.KEY_ODOMETER, Integer.parseInt(values[1], 16) * 0.01); - break; - case 43: - position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(values[1], 16) * 0.01); - break; - case 45: - position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(values[1], 16) * 0.01); - break; - case 53: - position.set(Position.KEY_OBD_SPEED, Integer.parseInt(values[1], 16) * 0.01); - break; - case 54: - position.set(Position.KEY_RPM, Integer.parseInt(values[1], 16) * 0.01); - break; - case 71: - position.set(Position.KEY_FUEL_USED, Integer.parseInt(values[1], 16) * 0.01); - break; - case 73: - position.set(Position.KEY_HOURS, Integer.parseInt(values[1], 16) * 0.01); - break; - case 74: - position.set(Position.KEY_VIN, values[1]); - break; - default: - break; + case 40 -> position.set(Position.KEY_ODOMETER, Integer.parseInt(values[1], 16) * 0.01); + case 43 -> position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(values[1], 16) * 0.01); + case 45 -> position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(values[1], 16) * 0.01); + case 53 -> position.set(Position.KEY_OBD_SPEED, Integer.parseInt(values[1], 16) * 0.01); + case 54 -> position.set(Position.KEY_RPM, Integer.parseInt(values[1], 16) * 0.01); + case 71 -> position.set(Position.KEY_FUEL_USED, Integer.parseInt(values[1], 16) * 0.01); + case 73 -> position.set(Position.KEY_HOURS, Integer.parseInt(values[1], 16) * 0.01); + case 74 -> position.set(Position.KEY_VIN, values[1]); } } } @@ -1332,16 +1245,10 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { int moduleLength = buf.readUnsignedShort(); switch (moduleType) { - case 0x03: - position.set(Position.KEY_ICCID, ByteBufUtil.hexDump(buf.readSlice(10))); - break; - case 0x09: - position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); - break; - case 0x0a: - position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte()); - break; - case 0x11: + case 0x03 -> position.set(Position.KEY_ICCID, ByteBufUtil.hexDump(buf.readSlice(10))); + case 0x09 -> position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + case 0x0a -> position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte()); + case 0x11 -> { CellTower cellTower = CellTower.from( buf.readUnsignedShort(), buf.readUnsignedShort(), @@ -1351,22 +1258,16 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { if (cellTower.getCellId() > 0) { position.setNetwork(new Network(cellTower)); } - break; - case 0x18: - position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.01); - break; - case 0x28: - position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1); - break; - case 0x29: - position.set(Position.KEY_INDEX, buf.readUnsignedInt()); - break; - case 0x2a: + } + case 0x18 -> position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.01); + case 0x28 -> position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1); + case 0x29 -> position.set(Position.KEY_INDEX, buf.readUnsignedInt()); + case 0x2a -> { int input = buf.readUnsignedByte(); position.set(Position.KEY_DOOR, BitUtil.to(input, 4) > 0); position.set("tamper", BitUtil.from(input, 4) > 0); - break; - case 0x2b: + } + case 0x2b -> { int event = buf.readUnsignedByte(); switch (event) { case 0x11: @@ -1385,11 +1286,9 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { break; } position.set(Position.KEY_EVENT, event); - break; - case 0x2e: - position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); - break; - case 0x33: + } + case 0x2e -> position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); + case 0x33 -> { position.setTime(new Date(buf.readUnsignedInt() * 1000)); position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.setAltitude(buf.readShort()); @@ -1411,15 +1310,13 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { position.setLatitude(latitude); position.setLongitude(longitude); - break; - case 0x34: + } + case 0x34 -> { position.set(Position.KEY_EVENT, buf.readUnsignedByte()); buf.readUnsignedIntLE(); // time buf.skipBytes(buf.readUnsignedByte()); // content - break; - default: - buf.skipBytes(moduleLength); - break; + } + default -> buf.skipBytes(moduleLength); } } diff --git a/src/main/java/org/traccar/protocol/Gt30ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt30ProtocolDecoder.java index fb3a2b8ae..b02285f69 100644 --- a/src/main/java/org/traccar/protocol/Gt30ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt30ProtocolDecoder.java @@ -55,20 +55,13 @@ public class Gt30ProtocolDecoder extends BaseProtocolDecoder { .compile(); private String decodeAlarm(int value) { - switch (value) { - case 0x01: - case 0x02: - case 0x03: - return Position.ALARM_SOS; - case 0x10: - return Position.ALARM_LOW_BATTERY; - case 0x11: - return Position.ALARM_OVERSPEED; - case 0x12: - return Position.ALARM_GEOFENCE; - default: - return null; - } + return switch (value) { + case 0x01, 0x02, 0x03 -> Position.ALARM_SOS; + case 0x10 -> Position.ALARM_LOW_BATTERY; + case 0x11 -> Position.ALARM_OVERSPEED; + case 0x12 -> Position.ALARM_GEOFENCE; + default -> null; + }; } @Override 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; + } } } diff --git a/src/main/java/org/traccar/protocol/H02ProtocolEncoder.java b/src/main/java/org/traccar/protocol/H02ProtocolEncoder.java index 86b8c80d4..8a0d232a0 100644 --- a/src/main/java/org/traccar/protocol/H02ProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/H02ProtocolEncoder.java @@ -49,27 +49,23 @@ public class H02ProtocolEncoder extends StringProtocolEncoder { protected Object encodeCommand(Command command, Date time) { String uniqueId = getUniqueId(command.getDeviceId()); - switch (command.getType()) { - case Command.TYPE_ALARM_ARM: - return formatCommand(time, uniqueId, "SCF", "0", "0"); - case Command.TYPE_ALARM_DISARM: - return formatCommand(time, uniqueId, "SCF", "1", "1"); - case Command.TYPE_ENGINE_STOP: - return formatCommand(time, uniqueId, "S20", "1", "1"); - case Command.TYPE_ENGINE_RESUME: - return formatCommand(time, uniqueId, "S20", "1", "0"); - case Command.TYPE_POSITION_PERIODIC: + return switch (command.getType()) { + case Command.TYPE_ALARM_ARM -> formatCommand(time, uniqueId, "SCF", "0", "0"); + case Command.TYPE_ALARM_DISARM -> formatCommand(time, uniqueId, "SCF", "1", "1"); + case Command.TYPE_ENGINE_STOP -> formatCommand(time, uniqueId, "S20", "1", "1"); + case Command.TYPE_ENGINE_RESUME -> formatCommand(time, uniqueId, "S20", "1", "0"); + case Command.TYPE_POSITION_PERIODIC -> { String frequency = command.getAttributes().get(Command.KEY_FREQUENCY).toString(); if (AttributeUtil.lookup( getCacheManager(), Keys.PROTOCOL_ALTERNATIVE.withPrefix(getProtocolName()), command.getDeviceId())) { - return formatCommand(time, uniqueId, "D1", frequency); + yield formatCommand(time, uniqueId, "D1", frequency); } else { - return formatCommand(time, uniqueId, "S71", "22", frequency); + yield formatCommand(time, uniqueId, "S71", "22", frequency); } - default: - return null; - } + } + default -> null; + }; } @Override diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java index 8afe04d0f..443da28a3 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -323,77 +323,39 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedByte(); int length = buf.readUnsignedByte(); switch (type) { - case 0x01: - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100L); - break; - case 0x02: - position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort() * 0.1); - break; - case 0x03: - position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1); - break; - case 0x56: + case 0x01 -> position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100L); + case 0x02 -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort() * 0.1); + case 0x03 -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1); + case 0x56 -> { buf.readUnsignedByte(); // power level position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); - break; - case 0x61: - position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01); - break; - case 0x69: - position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.01); - break; - case 0x80: - position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte()); - break; - case 0x81: - position.set(Position.KEY_RPM, buf.readUnsignedShort()); - break; - case 0x82: - position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.1); - break; - case 0x83: - position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte()); - break; - case 0x84: - position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40); - break; - case 0x85: - position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort()); - break; - case 0x86: - position.set("intakeTemp", buf.readUnsignedByte() - 40); - break; - case 0x87: - position.set("intakeFlow", buf.readUnsignedShort()); - break; - case 0x88: - position.set("intakePressure", buf.readUnsignedByte()); - break; - case 0x89: - position.set(Position.KEY_THROTTLE, buf.readUnsignedByte()); - break; - case 0x8B: + } + case 0x61 -> position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01); + case 0x69 -> position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.01); + case 0x80 -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte()); + case 0x81 -> position.set(Position.KEY_RPM, buf.readUnsignedShort()); + case 0x82 -> position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.1); + case 0x83 -> position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte()); + case 0x84 -> position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40); + case 0x85 -> position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort()); + case 0x86 -> position.set("intakeTemp", buf.readUnsignedByte() - 40); + case 0x87 -> position.set("intakeFlow", buf.readUnsignedShort()); + case 0x88 -> position.set("intakePressure", buf.readUnsignedByte()); + case 0x89 -> position.set(Position.KEY_THROTTLE, buf.readUnsignedByte()); + case 0x8B -> { position.set(Position.KEY_VIN, buf.readCharSequence(17, StandardCharsets.US_ASCII).toString()); - break; - case 0x8C: - position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 100L); - break; - case 0x8D: - position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort() * 1000L); - break; - case 0x8E: - position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte()); - break; - case 0xA0: + } + case 0x8C -> position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 100L); + case 0x8D -> position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort() * 1000L); + case 0x8E -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte()); + case 0xA0 -> { String codes = buf.readCharSequence(length, StandardCharsets.US_ASCII).toString(); position.set(Position.KEY_DTCS, codes.replace(',', ' ')); - break; - case 0xCC: + } + case 0xCC -> { position.set(Position.KEY_ICCID, buf.readCharSequence(20, StandardCharsets.US_ASCII).toString()); - break; - default: - buf.skipBytes(length); - break; + } + default -> buf.skipBytes(length); } } } @@ -543,20 +505,10 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedInt(); // alarm serial number buf.readUnsignedByte(); // alarm status switch (buf.readUnsignedByte()) { - case 0x01: - position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); - break; - case 0x02: - position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); - break; - case 0x03: - position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); - break; - case 0x16: - position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); - break; - default: - break; + case 0x01 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); + case 0x02 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); + case 0x03 -> position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); + case 0x16 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); } break; case 0x69: @@ -718,60 +670,26 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { int extendedType = buf.readUnsignedShort(); int extendedLength = buf.readUnsignedByte(); switch (extendedType) { - case 0x0002: - position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1); - break; - case 0x0003: - position.set(Position.KEY_RPM, buf.readUnsignedShort()); - break; - case 0x0004: - position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001); - break; - case 0x0005: - position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 100); - break; - case 0x0007: - position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.1); - break; - case 0x0008: - position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedShort() * 0.1); - break; - case 0x0009: - position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedShort() - 40); - break; - case 0x000B: - position.set("intakePressure", buf.readUnsignedShort()); - break; - case 0x000C: - position.set("intakeTemp", buf.readUnsignedShort() - 40); - break; - case 0x000D: - position.set("intakeFlow", buf.readUnsignedShort()); - break; - case 0x000E: - position.set(Position.KEY_THROTTLE, buf.readUnsignedShort() * 100 / 255); - break; - case 0x0050: + case 0x0002 -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1); + case 0x0003 -> position.set(Position.KEY_RPM, buf.readUnsignedShort()); + case 0x0004 -> position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001); + case 0x0005 -> position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 100); + case 0x0007 -> position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.1); + case 0x0008 -> position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedShort() * 0.1); + case 0x0009 -> position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedShort() - 40); + case 0x000B -> position.set("intakePressure", buf.readUnsignedShort()); + case 0x000C -> position.set("intakeTemp", buf.readUnsignedShort() - 40); + case 0x000D -> position.set("intakeFlow", buf.readUnsignedShort()); + case 0x000E -> position.set(Position.KEY_THROTTLE, buf.readUnsignedShort() * 100 / 255); + case 0x0050 -> { position.set(Position.KEY_VIN, buf.readSlice(17).toString(StandardCharsets.US_ASCII)); - break; - case 0x0100: - position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort() * 0.1); - break; - case 0x0102: - position.set("tripFuel", buf.readUnsignedShort() * 0.1); - break; - case 0x0112: - position.set("hardAccelerationCount", buf.readUnsignedShort()); - break; - case 0x0113: - position.set("hardDecelerationCount", buf.readUnsignedShort()); - break; - case 0x0114: - position.set("hardCorneringCount", buf.readUnsignedShort()); - break; - default: - buf.skipBytes(extendedLength); - break; + } + case 0x0100 -> position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort() * 0.1); + case 0x0102 -> position.set("tripFuel", buf.readUnsignedShort() * 0.1); + case 0x0112 -> position.set("hardAccelerationCount", buf.readUnsignedShort()); + case 0x0113 -> position.set("hardDecelerationCount", buf.readUnsignedShort()); + case 0x0114 -> position.set("hardCorneringCount", buf.readUnsignedShort()); + default -> buf.skipBytes(extendedLength); } } break; @@ -779,11 +697,8 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, buf.readUnsignedInt() * 0.001); if (length >= 5) { short batteryStatus = buf.readUnsignedByte(); - switch (batteryStatus) { - case 2: - case 3: - position.set(Position.KEY_CHARGE, true); - default: + if (batteryStatus == 2 || batteryStatus == 3) { + position.set(Position.KEY_CHARGE, true); } } if (length >= 6) { @@ -1000,77 +915,34 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { int id = buf.readUnsignedShort(); int length = buf.readUnsignedByte(); switch (id) { - case 0x0102: - case 0x0528: - case 0x0546: + case 0x0102, 0x0528, 0x0546 -> { position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100); - break; - case 0x0103: - position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedInt() * 0.01); - break; - case 0x0111: - position.set("fuelTemp", buf.readUnsignedByte() - 40); - break; - case 0x012E: - position.set("oilLevel", buf.readUnsignedShort() * 0.1); - break; - case 0x052A: - position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort() * 0.01); - break; - case 0x0105: - case 0x052C: - position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.01); - break; - case 0x014A: - case 0x0537: - case 0x0538: - case 0x0539: + } + case 0x0103 -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedInt() * 0.01); + case 0x0111 -> position.set("fuelTemp", buf.readUnsignedByte() - 40); + case 0x012E -> position.set("oilLevel", buf.readUnsignedShort() * 0.1); + case 0x052A -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort() * 0.01); + case 0x0105, 0x052C -> position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.01); + case 0x014A, 0x0537, 0x0538, 0x0539 -> { position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort() * 0.01); - break; - case 0x052B: - position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte()); - break; - case 0x052D: - position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40); - break; - case 0x052E: - position.set("airTemp", buf.readUnsignedByte() - 40); - break; - case 0x0530: - position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001); - break; - case 0x0535: - position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1); - break; - case 0x0536: - position.set(Position.KEY_RPM, buf.readUnsignedShort()); - break; - case 0x053D: - position.set("intakePressure", buf.readUnsignedShort() * 0.1); - break; - case 0x0544: - position.set("liquidLevel", buf.readUnsignedByte()); - break; - case 0x0547: - case 0x0548: - position.set(Position.KEY_THROTTLE, buf.readUnsignedByte()); - break; - default: + } + case 0x052B -> position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte()); + case 0x052D -> position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40); + case 0x052E -> position.set("airTemp", buf.readUnsignedByte() - 40); + case 0x0530 -> position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001); + case 0x0535 -> position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1); + case 0x0536 -> position.set(Position.KEY_RPM, buf.readUnsignedShort()); + case 0x053D -> position.set("intakePressure", buf.readUnsignedShort() * 0.1); + case 0x0544 -> position.set("liquidLevel", buf.readUnsignedByte()); + case 0x0547, 0x0548 -> position.set(Position.KEY_THROTTLE, buf.readUnsignedByte()); + default -> { switch (length) { - case 1: - position.set(Position.PREFIX_IO + id, buf.readUnsignedByte()); - break; - case 2: - position.set(Position.PREFIX_IO + id, buf.readUnsignedShort()); - break; - case 4: - position.set(Position.PREFIX_IO + id, buf.readUnsignedInt()); - break; - default: - buf.skipBytes(length); - break; + case 1 -> position.set(Position.PREFIX_IO + id, buf.readUnsignedByte()); + case 2 -> position.set(Position.PREFIX_IO + id, buf.readUnsignedShort()); + case 4 -> position.set(Position.PREFIX_IO + id, buf.readUnsignedInt()); + default -> buf.skipBytes(length); } - break; + } } } getLastLocation(position, time); @@ -1151,24 +1023,12 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { case 0x15: int event = buf.readInt(); switch (event) { - case 51: - position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); - break; - case 52: - position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); - break; - case 53: - position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); - break; - case 54: - position.set(Position.KEY_ALARM, Position.ALARM_LANE_CHANGE); - break; - case 56: - position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); - break; - default: - position.set(Position.KEY_EVENT, event); - break; + case 51 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); + case 52 -> position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); + case 53 -> position.set(Position.KEY_ALARM, Position.ALARM_CORNERING); + case 54 -> position.set(Position.KEY_ALARM, Position.ALARM_LANE_CHANGE); + case 56 -> position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT); + default -> position.set(Position.KEY_EVENT, event); } getLastLocation(position, time); break; diff --git a/src/main/java/org/traccar/schedule/TaskReports.java b/src/main/java/org/traccar/schedule/TaskReports.java index 070fa9d2b..c57158cb9 100644 --- a/src/main/java/org/traccar/schedule/TaskReports.java +++ b/src/main/java/org/traccar/schedule/TaskReports.java @@ -116,34 +116,32 @@ public class TaskReports implements ScheduleTask { for (User user : users) { LogAction.report(user.getId(), true, report.getType(), from, to, deviceIds, groupIds); switch (report.getType()) { - case "events": + case "events" -> { var eventsReportProvider = injector.getInstance(EventsReportProvider.class); reportMailer.sendAsync(user.getId(), stream -> eventsReportProvider.getExcel( stream, user.getId(), deviceIds, groupIds, List.of(), from, to)); - break; - case "route": + } + case "route" -> { var routeReportProvider = injector.getInstance(RouteReportProvider.class); reportMailer.sendAsync(user.getId(), stream -> routeReportProvider.getExcel( stream, user.getId(), deviceIds, groupIds, from, to)); - break; - case "summary": + } + case "summary" -> { var summaryReportProvider = injector.getInstance(SummaryReportProvider.class); reportMailer.sendAsync(user.getId(), stream -> summaryReportProvider.getExcel( stream, user.getId(), deviceIds, groupIds, from, to, false)); - break; - case "trips": + } + case "trips" -> { var tripsReportProvider = injector.getInstance(TripsReportProvider.class); reportMailer.sendAsync(user.getId(), stream -> tripsReportProvider.getExcel( stream, user.getId(), deviceIds, groupIds, from, to)); - break; - case "stops": + } + case "stops" -> { var stopsReportProvider = injector.getInstance(StopsReportProvider.class); reportMailer.sendAsync(user.getId(), stream -> stopsReportProvider.getExcel( stream, user.getId(), deviceIds, groupIds, from, to)); - break; - default: - LOGGER.warn("Unsupported report type {}", report.getType()); - break; + } + default -> LOGGER.warn("Unsupported report type {}", report.getType()); } } } diff --git a/src/main/java/org/traccar/session/ConnectionManager.java b/src/main/java/org/traccar/session/ConnectionManager.java index 8431a0327..a80c6aad1 100644 --- a/src/main/java/org/traccar/session/ConnectionManager.java +++ b/src/main/java/org/traccar/session/ConnectionManager.java @@ -241,17 +241,11 @@ public class ConnectionManager implements BroadcastInterface { if (!status.equals(oldStatus)) { String eventType; Map events = new HashMap<>(); - switch (status) { - case Device.STATUS_ONLINE: - eventType = Event.TYPE_DEVICE_ONLINE; - break; - case Device.STATUS_UNKNOWN: - eventType = Event.TYPE_DEVICE_UNKNOWN; - break; - default: - eventType = Event.TYPE_DEVICE_OFFLINE; - break; - } + eventType = switch (status) { + case Device.STATUS_ONLINE -> Event.TYPE_DEVICE_ONLINE; + case Device.STATUS_UNKNOWN -> Event.TYPE_DEVICE_UNKNOWN; + default -> Event.TYPE_DEVICE_OFFLINE; + }; events.put(new Event(eventType, deviceId), null); notificationManager.updateEvents(events); } diff --git a/src/test/java/org/traccar/ProtocolTest.java b/src/test/java/org/traccar/ProtocolTest.java index 273520155..1ad192f85 100644 --- a/src/test/java/org/traccar/ProtocolTest.java +++ b/src/test/java/org/traccar/ProtocolTest.java @@ -118,18 +118,10 @@ public class ProtocolTest extends BaseTest { position = (Position) decodedObject; } switch (key) { - case "speed": - assertEquals(expected, position.getSpeed()); - break; - case "course": - assertEquals(expected, position.getCourse()); - break; - case "altitude": - assertEquals(expected, position.getAltitude()); - break; - default: - assertEquals(expected, position.getAttributes().get(key)); - break; + case "speed" -> assertEquals(expected, position.getSpeed()); + case "course" -> assertEquals(expected, position.getCourse()); + case "altitude" -> assertEquals(expected, position.getAltitude()); + default -> assertEquals(expected, position.getAttributes().get(key)); } } -- 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/test/java/org') 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/test/java/org') 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 From b1a8f303c90f087dcefdabfd06c3d312aa1f6212 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 9 Jul 2024 20:33:15 -0700 Subject: Support Meitrack custom commands --- .../org/traccar/protocol/MeitrackProtocol.java | 3 ++- .../traccar/protocol/MeitrackProtocolEncoder.java | 30 +++++++++++----------- .../protocol/MeitrackProtocolEncoderTest.java | 6 ++--- 3 files changed, 20 insertions(+), 19 deletions(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocol.java b/src/main/java/org/traccar/protocol/MeitrackProtocol.java index 4109b22c9..560ec87e8 100644 --- a/src/main/java/org/traccar/protocol/MeitrackProtocol.java +++ b/src/main/java/org/traccar/protocol/MeitrackProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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. @@ -29,6 +29,7 @@ public class MeitrackProtocol extends BaseProtocol { @Inject public MeitrackProtocol(Config config) { setSupportedDataCommands( + Command.TYPE_CUSTOM, Command.TYPE_POSITION_SINGLE, Command.TYPE_ENGINE_STOP, Command.TYPE_ENGINE_RESUME, diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java index b66fc3241..9b43f3988 100644 --- a/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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. @@ -22,18 +22,16 @@ import org.traccar.helper.Checksum; import org.traccar.helper.model.AttributeUtil; import org.traccar.model.Command; -import java.util.Map; - public class MeitrackProtocolEncoder extends StringProtocolEncoder { public MeitrackProtocolEncoder(Protocol protocol) { super(protocol); } - private Object formatCommand(Command command, char dataId, String content) { + private Object formatCommand(Command command, String content) { String uniqueId = getUniqueId(command.getDeviceId()); int length = 1 + uniqueId.length() + 1 + content.length() + 5; - String result = String.format("@@%c%02d,%s,%s*", dataId, length, uniqueId, content); + String result = String.format("@@A%02d,%s,%s*", length, uniqueId, content); result += Checksum.sum(result) + "\r\n"; return result; } @@ -41,23 +39,25 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder { @Override protected Object encodeCommand(Command command) { - Map attributes = command.getAttributes(); - boolean alternative = AttributeUtil.lookup( getCacheManager(), Keys.PROTOCOL_ALTERNATIVE.withPrefix(getProtocolName()), command.getDeviceId()); return switch (command.getType()) { - case Command.TYPE_POSITION_SINGLE -> formatCommand(command, 'Q', "A10"); - case Command.TYPE_ENGINE_STOP -> formatCommand(command, 'M', "C01,0,12222"); - case Command.TYPE_ENGINE_RESUME -> formatCommand(command, 'M', "C01,0,02222"); - case Command.TYPE_ALARM_ARM -> formatCommand(command, 'M', alternative ? "B21,1" : "C01,0,22122"); - case Command.TYPE_ALARM_DISARM -> formatCommand(command, 'M', alternative ? "B21,0" : "C01,0,22022"); + case Command.TYPE_CUSTOM -> formatCommand(command, command.getString(Command.KEY_DATA)); + case Command.TYPE_POSITION_SINGLE -> formatCommand(command, "A10"); + case Command.TYPE_ENGINE_STOP -> formatCommand(command, "C01,0,12222"); + case Command.TYPE_ENGINE_RESUME -> formatCommand(command, "C01,0,02222"); + case Command.TYPE_ALARM_ARM -> formatCommand(command, alternative ? "B21,1" : "C01,0,22122"); + case Command.TYPE_ALARM_DISARM -> formatCommand(command, alternative ? "B21,0" : "C01,0,22022"); case Command.TYPE_REQUEST_PHOTO -> { int index = command.getInteger(Command.KEY_INDEX); - yield formatCommand(command, 'D', "D03," + (index > 0 ? index : 1) + ",camera_picture.jpg"); + yield formatCommand(command, "D03," + (index > 0 ? index : 1) + ",camera_picture.jpg"); + } + case Command.TYPE_SEND_SMS -> { + String phone = command.getString(Command.KEY_PHONE); + String message = command.getString(Command.KEY_MESSAGE); + yield formatCommand(command, "C02,0," + phone + "," + message); } - case Command.TYPE_SEND_SMS -> formatCommand(command, 'f', "C02,0," - + attributes.get(Command.KEY_PHONE) + "," + attributes.get(Command.KEY_MESSAGE)); default -> null; }; } diff --git a/src/test/java/org/traccar/protocol/MeitrackProtocolEncoderTest.java b/src/test/java/org/traccar/protocol/MeitrackProtocolEncoderTest.java index ac9854b8e..71620b967 100644 --- a/src/test/java/org/traccar/protocol/MeitrackProtocolEncoderTest.java +++ b/src/test/java/org/traccar/protocol/MeitrackProtocolEncoderTest.java @@ -17,19 +17,19 @@ public class MeitrackProtocolEncoderTest extends ProtocolTest { command.setDeviceId(1); command.setType(Command.TYPE_POSITION_SINGLE); - assertEquals("@@Q25,123456789012345,A10*68\r\n", encoder.encodeCommand(command)); + assertEquals("@@A25,123456789012345,A10*58\r\n", encoder.encodeCommand(command)); command.setDeviceId(1); command.setType(Command.TYPE_REQUEST_PHOTO); - assertEquals("@@D46,123456789012345,D03,1,camera_picture.jpg*1F\r\n", encoder.encodeCommand(command)); + assertEquals("@@A46,123456789012345,D03,1,camera_picture.jpg*1C\r\n", encoder.encodeCommand(command)); command.setDeviceId(1); command.setType(Command.TYPE_SEND_SMS); command.set(Command.KEY_PHONE, "15360853789"); command.set(Command.KEY_MESSAGE, "Meitrack"); - assertEquals("@@f48,123456789012345,C02,0,15360853789,Meitrack*B0\r\n", encoder.encodeCommand(command)); + assertEquals("@@A48,123456789012345,C02,0,15360853789,Meitrack*8B\r\n", encoder.encodeCommand(command)); } -- cgit v1.2.3 From 12a6b088cc478f1b2aff363534c87ca0a6a27815 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 10 Jul 2024 07:45:25 -0700 Subject: No response for AP12 result --- src/main/java/org/traccar/protocol/TrvProtocolDecoder.java | 2 +- src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java b/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java index 2f2b7d8c2..e39b17307 100644 --- a/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java @@ -180,7 +180,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { channel.writeAndFlush(new NetworkMessage(responseHeader + "," + time + ",0#", remoteAddress)); } else if (type.equals("AP14")) { channel.writeAndFlush(new NetworkMessage(responseHeader + ",0.000,0.000#", remoteAddress)); - } else if (!sentence.substring(responseHeader.length() + 1).matches("^\\d{6}$")) { + } else if (!type.equals("AP12") && !sentence.substring(responseHeader.length() + 1).matches("^\\d{6}$")) { channel.writeAndFlush(new NetworkMessage(responseHeader + "#", remoteAddress)); } } diff --git a/src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java index 2757064e4..944b684d0 100644 --- a/src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/TrvProtocolDecoderTest.java @@ -99,6 +99,9 @@ public class TrvProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "TRVYP14220217A5235.7885N00724.1840E000.0130919177.561000050660000200004,262,01,14635,52789,FritzBox7|DC-39-8F-7E-94-73|-89&FritzBox7|24-4E-5D-71-C3-9C|-90&MY_IOT|80-B4-F7-77-9C-7C|-81&MYAP|44-D4-F7-77-9C-7C|-80#")); + verifyNull(decoder, text( + "IWAP12,080835,+491773329827,+491773329826,+49306618438")); + } } -- cgit v1.2.3 From e1be8916132fd0102cfe298a75abcfdcd43f244b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 20 Jul 2024 17:37:32 -0700 Subject: Support Jimi IoT extended heartbeat --- .../java/org/traccar/protocol/Gt06ProtocolDecoder.java | 16 ++++++++++++++++ .../org/traccar/protocol/Gt06ProtocolDecoderTest.java | 4 ++++ 2 files changed, 20 insertions(+) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index f17671cd7..e25499190 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -88,6 +88,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_X1_GPS = 0x34; public static final int MSG_X1_PHOTO_INFO = 0x35; public static final int MSG_X1_PHOTO_DATA = 0x36; + public static final int MSG_STATUS_2 = 0x36; // Jimi IoT 4G public static final int MSG_WIFI_2 = 0x69; public static final int MSG_GPS_MODULAR = 0x70; public static final int MSG_WIFI_4 = 0xF3; @@ -218,6 +219,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { private static boolean hasStatus(int type) { switch (type) { case MSG_STATUS: + case MSG_STATUS_2: case MSG_LBS_STATUS: case MSG_GPS_LBS_STATUS_1: case MSG_GPS_LBS_STATUS_2: @@ -845,6 +847,20 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } } + if (type == MSG_STATUS_2) { + buf.readUnsignedByte(); // language + while (buf.readableBytes() > 6) { + int moduleType = buf.readUnsignedShort(); + int moduleLength = buf.readUnsignedByte(); + switch (moduleType) { + case 0x0018 -> position.set(Position.KEY_BATTERY, buf.readUnsignedShort() / 100.0); + case 0x0032 -> position.set("startupStatus", buf.readUnsignedByte()); + case 0x006A -> position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); + default -> buf.skipBytes(moduleLength); + } + } + } + if (type == MSG_GPS_LBS_STATUS_5) { buf.readUnsignedByte(); // language position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java index da070e224..bb809529a 100644 --- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -17,6 +17,10 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "78780D01086471700328358100093F040D0A")); + verifyAttribute(decoder, binary( + "787817360005040002003201010018020192006a015f0324aeaf0d0a"), + Position.KEY_BATTERY, 4.02); + verifyPosition(decoder, binary( "787840a218061b0e0f05cf021d22430aa2660b005c00014e140000026500000000024d4e02114504df06031c010007d00000000000086973105524576500c802a86fda0d0a")); -- cgit v1.2.3 From 4620fc2db16f05bcd3578b4f5a3239b229d7c99f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 24 Jul 2024 06:51:44 -0700 Subject: Refactor Astra decoder --- .../java/org/traccar/protocol/AstraProtocolDecoder.java | 16 ++++++++++++---- .../org/traccar/protocol/AstraProtocolDecoderTest.java | 3 +++ 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/AstraProtocolDecoder.java b/src/main/java/org/traccar/protocol/AstraProtocolDecoder.java index 366bf9e8b..a7bfd4625 100644 --- a/src/main/java/org/traccar/protocol/AstraProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/AstraProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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. @@ -51,13 +51,21 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder { ByteBuf buf = (ByteBuf) msg; + byte protocol = buf.readByte(); + buf.readUnsignedShort(); // length + + return switch (protocol) { + case 'K' -> decodeK(channel, remoteAddress, buf); + default -> null; + }; + } + + private Object decodeK(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + if (channel != null) { channel.writeAndFlush(new NetworkMessage(Unpooled.wrappedBuffer(new byte[] {0x06}), remoteAddress)); } - buf.readUnsignedByte(); // protocol - buf.readUnsignedShort(); // length - String imei = String.format("%08d", buf.readUnsignedInt()) + String.format("%07d", buf.readUnsignedMedium()); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { diff --git a/src/test/java/org/traccar/protocol/AstraProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/AstraProtocolDecoderTest.java index 3dabcac5d..cf1978f4e 100644 --- a/src/test/java/org/traccar/protocol/AstraProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/AstraProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class AstraProtocolDecoderTest extends ProtocolTest { var decoder = inject(new AstraProtocolDecoder(null)); + verifyNull(decoder, binary( + "58003d018b0000000000bf514f00b70000006000093e60514f00b6032fec49ffdc7627000041020000000100010000000000090001010000008f00aba3")); + verifyPositions(decoder, binary( "4b00700529c0c265976b8202cba9ff00676d864554a9c30000000020073401006436000300030008000000000000a0000100001920c43d00009600428302cba9ff00676d864554aa3e000000002007240100643b000300020008000000000000b0000100001920c43d00009600420f0e")); -- cgit v1.2.3 From 1f6028589096a89fbec98cbe20e609ce6d6c974a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 26 Jul 2024 08:39:59 -0700 Subject: Add Astra protocol X support --- .../org/traccar/protocol/AstraProtocolDecoder.java | 219 +++++++++++++++++++-- .../traccar/protocol/AstraProtocolDecoderTest.java | 4 +- 2 files changed, 210 insertions(+), 13 deletions(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/AstraProtocolDecoder.java b/src/main/java/org/traccar/protocol/AstraProtocolDecoder.java index a7bfd4625..a1e133c23 100644 --- a/src/main/java/org/traccar/protocol/AstraProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/AstraProtocolDecoder.java @@ -16,6 +16,7 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import org.slf4j.Logger; @@ -31,6 +32,7 @@ import org.traccar.model.Position; import java.net.SocketAddress; import java.nio.charset.StandardCharsets; +import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -54,20 +56,30 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder { byte protocol = buf.readByte(); buf.readUnsignedShort(); // length + if (channel != null) { + channel.writeAndFlush(new NetworkMessage(Unpooled.wrappedBuffer(new byte[] {0x06}), remoteAddress)); + } + return switch (protocol) { case 'K' -> decodeK(channel, remoteAddress, buf); + case 'X' -> decodeX(channel, remoteAddress, buf); default -> null; }; } - private Object decodeK(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + private String readImei(ByteBuf buf) { + return String.format("%08d", buf.readUnsignedInt()) + String.format("%07d", buf.readUnsignedMedium()); + } - if (channel != null) { - channel.writeAndFlush(new NetworkMessage(Unpooled.wrappedBuffer(new byte[] {0x06}), remoteAddress)); - } + private Date readTime(ByteBuf buf) { + DateBuilder dateBuilder = new DateBuilder() + .setDate(1980, 1, 6).addMillis(buf.readUnsignedInt() * 1000L); + return dateBuilder.getDate(); + } - String imei = String.format("%08d", buf.readUnsignedInt()) + String.format("%07d", buf.readUnsignedMedium()); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); + private Object decodeK(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readImei(buf)); if (deviceSession == null) { return null; } @@ -84,11 +96,7 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder { position.setValid(true); position.setLatitude(buf.readInt() * 0.000001); position.setLongitude(buf.readInt() * 0.000001); - - DateBuilder dateBuilder = new DateBuilder() - .setDate(1980, 1, 6).addMillis(buf.readUnsignedInt() * 1000L); - position.setTime(dateBuilder.getDate()); - + position.setTime(readTime(buf)); position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte() * 2)); position.setCourse(buf.readUnsignedByte() * 2); @@ -134,4 +142,193 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder { return positions; } + private Object decodeX(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + + int count = buf.readUnsignedByte(); + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readImei(buf)); + if (deviceSession == null) { + return null; + } + + List positions = new LinkedList<>(); + for (int i = 0; i < count; i++) { + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + position.set(Position.KEY_INDEX, buf.readUnsignedByte()); + long mask = (long) buf.readUnsignedShort() << 32 + buf.readUnsignedInt(); + position.setDeviceTime(readTime(buf)); + position.set(Position.KEY_EVENT, buf.readUnsignedInt()); + position.set(Position.KEY_STATUS, buf.readUnsignedShort()); + + if ((mask & 1L) > 0) { + position.set(Position.KEY_POWER, buf.readUnsignedByte() * 0.2); + position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); + } + + if ((mask & 2L) > 0) { + position.setValid(true); + position.setFixTime(readTime(buf)); + position.setLatitude(buf.readInt() * 0.000001); + position.setLongitude(buf.readInt() * 0.000001); + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte() * 2)); + buf.readUnsignedByte(); // max speed since last report + position.setCourse(buf.readUnsignedByte() * 2); + position.setAltitude(buf.readUnsignedByte() * 20); + position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort() * 100); + } else { + getLastLocation(position, position.getDeviceTime()); + } + + if ((mask & 4L) > 0) { + buf.readUnsignedShort(); // states + buf.readUnsignedShort(); // changes mask + } + + if ((mask & 8L) > 0) { + buf.readUnsignedShort(); // adc1 + buf.readUnsignedShort(); // adc2 + } + + if ((mask & 16L) > 0) { + position.set("xMax", buf.readByte()); + position.set("xMin", buf.readByte()); + position.set("yMax", buf.readByte()); + position.set("yMin", buf.readByte()); + position.set("zMax", buf.readByte()); + position.set("zMin", buf.readByte()); + position.set("idleHours", buf.readUnsignedShort()); + } + + if ((mask & 32L) > 0) { + int value = buf.readUnsignedByte(); + position.set(Position.KEY_SATELLITES, BitUtil.to(value, 4)); + position.set(Position.KEY_RSSI, BitUtil.from(value, 4)); + } + + if ((mask & 64L) > 0) { + buf.readUnsignedShort(); // mcc + buf.readUnsignedShort(); // mnc + } + + if ((mask & 128L) > 0) { + buf.readUnsignedByte(); // geofences + } + + if ((mask & 256L) > 0) { + buf.readUnsignedByte(); // source + buf.readLong(); // driver id + } + + if ((mask & 512L) > 0) { + buf.readUnsignedByte(); // source + buf.skipBytes(10); // trailer id + buf.readUnsignedByte(); // status + } + + if ((mask & 1024L) > 0) { + position.set("axleWeight", buf.readUnsignedShort()); + } + + if ((mask & 2048L) > 0) { + position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium() * 1000); + position.set(Position.KEY_HOURS, buf.readUnsignedShort() * 3_600_000); + } + + if ((mask & 4096L) > 0) { + position.set("wheelSpeedMax", buf.readUnsignedByte()); + position.set("wheelSpeedAvg", buf.readUnsignedByte()); + position.set("rpmMax", buf.readUnsignedByte() * 32); + position.set("rpmAvg", buf.readUnsignedByte() * 32); + position.set("acceleratorMax", buf.readUnsignedByte()); + position.set("acceleratorAvg", buf.readUnsignedByte()); + position.set("engineLoadMax", buf.readUnsignedByte()); + position.set("engineLoadAvg", buf.readUnsignedByte()); + position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort() * 100); + position.set(Position.KEY_COOLANT_TEMP, buf.readByte() + 40); + position.set("fmsStatus", buf.readUnsignedShort()); + position.set("fmsEvents", buf.readUnsignedShort()); + position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte()); + position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.5); + } + + if ((mask & 8192L) > 0) { + position.set("wheelSpeedMax", buf.readUnsignedByte()); + position.set("wheelSpeedAvg", buf.readUnsignedByte()); + position.set("rpmMax", buf.readUnsignedByte() * 32); + position.set("rpmAvg", buf.readUnsignedByte() * 32); + position.set("acceleratorMax", buf.readUnsignedByte()); + position.set("acceleratorAvg", buf.readUnsignedByte()); + position.set("engineLoadMax", buf.readUnsignedByte()); + position.set("engineLoadAvg", buf.readUnsignedByte()); + position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort() * 100); + position.set(Position.KEY_COOLANT_TEMP, buf.readByte() + 40); + position.set("obdStatus", buf.readUnsignedShort()); + position.set("obdEvents", buf.readUnsignedShort()); + position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte()); + position.set(Position.KEY_FUEL_USED, buf.readUnsignedShort() * 0.1); + } + + if ((mask & 16384L) > 0) { + for (int j = 1; j <= 5; j++) { + position.set("dtc" + j, buf.readCharSequence(5, StandardCharsets.US_ASCII).toString()); + } + } + + if ((mask & 32768L) > 0) { + position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium() * 1000); + position.set(Position.KEY_HOURS, buf.readUnsignedShort() * 3_600_000); + position.set("axleWeight", buf.readUnsignedShort()); + position.set("tripFuelUsed", buf.readUnsignedShort() * 0.1); + position.set("tripCruise", buf.readUnsignedShort()); + position.set(Position.KEY_ODOMETER_SERVICE, buf.readUnsignedShort() * 5); + } + + if ((mask & 65536L) > 0) { + position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium() * 1000); + position.set(Position.KEY_HOURS, buf.readUnsignedShort() * 3_600_000); + buf.readUnsignedShort(); // time with mil on + buf.readUnsignedShort(); // distance with mil on + } + + if ((mask & 131072L) > 0) { + for (int j = 1; j <= 6; j++) { + position.set(Position.PREFIX_TEMP + j, buf.readShort() * 0.1); + } + for (int j = 1; j <= 3; j++) { + position.set("setpoint" + j, buf.readByte() * 0.5); + } + buf.readUnsignedByte(); // refrigerator fuel level + buf.readUnsignedShort(); // refrigerator total engine hours + buf.readUnsignedShort(); // refrigerator total standby hours + buf.readUnsignedShort(); // refrigerator status + buf.readUnsignedMedium(); // alarm flags + } + + if ((mask & 262144L) > 0) { + for (int j = 1; j <= 4; j++) { + position.set(Position.PREFIX_TEMP + j, (buf.readUnsignedShort() - 550) * 0.1); + } + } + + if ((mask & 524288L) > 0) { + position.set("alarmCount", buf.readUnsignedByte()); + position.set("alarmQueue", ByteBufUtil.hexDump(buf.readSlice(16))); + } + + if ((mask & 4294967296L) > 0) { + for (int j = 1; j <= 6; j++) { + position.set("sensor" + j, buf.readUnsignedMedium()); + } + } + + positions.add(position); + + } + + return positions; + } + } diff --git a/src/test/java/org/traccar/protocol/AstraProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/AstraProtocolDecoderTest.java index cf1978f4e..dc48fc829 100644 --- a/src/test/java/org/traccar/protocol/AstraProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/AstraProtocolDecoderTest.java @@ -10,8 +10,8 @@ public class AstraProtocolDecoderTest extends ProtocolTest { var decoder = inject(new AstraProtocolDecoder(null)); - verifyNull(decoder, binary( - "58003d018b0000000000bf514f00b70000006000093e60514f00b6032fec49ffdc7627000041020000000100010000000000090001010000008f00aba3")); + verifyPositions(decoder, false, binary( + "5800cb02052196881aff5b3c0000200010bf53cbfab10000000100393d5853cbfab0031b93affffb034b0000ae00000000010000000c000c00000000000000787e00000000000000000000000000000000000000000000000000000000000000000000000000000000003d0000200010bf53cbfae60000280000293c5853cbfae6031b93affffb034b0000ae00000000010000000d000c00000000000000ae7e0000000000000000000000000000000000000000000000000000000000000000000000000000000000e604")); verifyPositions(decoder, binary( "4b00700529c0c265976b8202cba9ff00676d864554a9c30000000020073401006436000300030008000000000000a0000100001920c43d00009600428302cba9ff00676d864554aa3e000000002007240100643b000300020008000000000000b0000100001920c43d00009600420f0e")); -- cgit v1.2.3 From 62f1cb5cd3374ac0012c9c054f3556c5e43a8549 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 26 Jul 2024 18:02:32 -0700 Subject: Support TopTen TK218 OBD --- .../traccar/protocol/MeiligaoProtocolDecoder.java | 55 ++++++++++++++++------ .../protocol/MeiligaoProtocolDecoderTest.java | 4 ++ 2 files changed, 44 insertions(+), 15 deletions(-) (limited to 'src/test/java/org') diff --git a/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java index c18b29288..524d86289 100644 --- a/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -141,6 +141,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_OBD_RT = 0x9901; public static final int MSG_OBD_RTA = 0x9902; + public static final int MSG_DTC = 0x9903; public static final int MSG_TRACK_ON_DEMAND = 0x4101; public static final int MSG_TRACK_BY_INTERVAL = 0x4102; @@ -208,20 +209,36 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } } - private String decodeAlarm(short value) { - return switch (value) { - case 0x01 -> Position.ALARM_SOS; - case 0x10 -> Position.ALARM_LOW_BATTERY; - case 0x11 -> Position.ALARM_OVERSPEED; - case 0x12 -> Position.ALARM_MOVEMENT; - case 0x13 -> Position.ALARM_GEOFENCE_ENTER; - case 0x14 -> Position.ALARM_ACCIDENT; - case 0x50 -> Position.ALARM_POWER_OFF; - case 0x53 -> Position.ALARM_GPS_ANTENNA_CUT; - case 0x72 -> Position.ALARM_BRAKING; - case 0x73 -> Position.ALARM_ACCELERATION; - default -> null; - }; + private String decodeAlarm(String model, short value) { + if ("TK218".equals(model)) { + return switch (value) { + case 0x01 -> Position.ALARM_SOS; + case 0x10 -> Position.ALARM_LOW_BATTERY; + case 0x11 -> Position.ALARM_OVERSPEED; + case 0x12 -> Position.ALARM_MOVEMENT; + case 0x13 -> Position.ALARM_GEOFENCE; + case 0x60 -> Position.ALARM_FATIGUE_DRIVING; + case 0x71 -> Position.ALARM_BRAKING; + case 0x72 -> Position.ALARM_ACCELERATION; + case 0x73 -> Position.ALARM_ACCIDENT; + case 0x74 -> Position.ALARM_IDLE; + default -> null; + }; + } else { + return switch (value) { + case 0x01 -> Position.ALARM_SOS; + case 0x10 -> Position.ALARM_LOW_BATTERY; + case 0x11 -> Position.ALARM_OVERSPEED; + case 0x12 -> Position.ALARM_MOVEMENT; + case 0x13 -> Position.ALARM_GEOFENCE_ENTER; + case 0x14 -> Position.ALARM_ACCIDENT; + case 0x50 -> Position.ALARM_POWER_OFF; + case 0x53 -> Position.ALARM_GPS_ANTENNA_CUT; + case 0x72 -> Position.ALARM_BRAKING; + case 0x73 -> Position.ALARM_ACCELERATION; + default -> null; + }; + } } private Position decodeRegular(Position position, String sentence) { @@ -341,6 +358,12 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { return position; } + private Position decodeDtc(Position position, String sentence) { + getLastLocation(position, null); + position.set(Position.KEY_DTCS, sentence.replace(',', ' ')); + return position; + } + private List decodeRetransmission(ByteBuf buf, DeviceSession deviceSession) { List positions = new LinkedList<>(); @@ -437,7 +460,8 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { if (command == MSG_ALARM) { short alarmCode = buf.readUnsignedByte(); - position.set(Position.KEY_ALARM, decodeAlarm(alarmCode)); + String model = getDeviceModel(deviceSession); + position.set(Position.KEY_ALARM, decodeAlarm(model, alarmCode)); if (alarmCode >= 0x02 && alarmCode <= 0x05) { position.set(Position.PREFIX_IN + alarmCode, 1); } else if (alarmCode >= 0x32 && alarmCode <= 0x35) { @@ -473,6 +497,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { case MSG_RFID -> decodeRfid(position, sentence); case MSG_OBD_RT -> decodeObd(position, sentence); case MSG_OBD_RTA -> decodeObdA(position, sentence); + case MSG_DTC -> decodeDtc(position, sentence); default -> null; }; diff --git a/src/test/java/org/traccar/protocol/MeiligaoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MeiligaoProtocolDecoderTest.java index 8074636a3..8e2f55117 100644 --- a/src/test/java/org/traccar/protocol/MeiligaoProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/MeiligaoProtocolDecoderTest.java @@ -11,6 +11,10 @@ public class MeiligaoProtocolDecoderTest extends ProtocolTest { var decoder = inject(new MeiligaoProtocolDecoder(null)); + verifyAttribute(decoder, binary( + "242400166578902354329399034331453838d2c40d0a"), + Position.KEY_DTCS, "C1E88"); + verifyAttribute(decoder, binary( "2424008f142180340967ff99553033333233302e3030302c412c313531362e383039392c4e2c31303435322e383835352c452c302e30302c33332c3038313232302c2c2a33367c302e387c3132337c323130307c303030302c303030302c303230452c303241417c30323038303030353038394530304531434638347c31437c31373243353832437c3042a8060d0a"), Position.KEY_SATELLITES, 11); -- cgit v1.2.3 From b4ee8b7126eb6b57f8abbe2b32f28bacb62f33f8 Mon Sep 17 00:00:00 2001 From: Syed Mujeer Hashmi Date: Sat, 27 Jul 2024 07:03:41 +0530 Subject: Update GeocoderTest.java --- src/test/java/org/traccar/geocoder/GeocoderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/test/java/org') diff --git a/src/test/java/org/traccar/geocoder/GeocoderTest.java b/src/test/java/org/traccar/geocoder/GeocoderTest.java index 3e65d20c7..2aa7ab77c 100644 --- a/src/test/java/org/traccar/geocoder/GeocoderTest.java +++ b/src/test/java/org/traccar/geocoder/GeocoderTest.java @@ -20,7 +20,7 @@ public class GeocoderTest { @Disabled @Test public void testGoogle() { - Geocoder geocoder = new GoogleGeocoder(client, null, null, 0, new AddressFormat()); + Geocoder geocoder = new GoogleGeocoder(client, null, null, null, 0, new AddressFormat()); String address = geocoder.getAddress(31.776797, 35.211489, null); assertEquals("1 Ibn Shaprut St, Jerusalem, Jerusalem District, IL", address); } -- cgit v1.2.3