aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/BaseProtocolDecoder.java17
-rw-r--r--src/main/java/org/traccar/MainModule.java160
-rw-r--r--src/main/java/org/traccar/WindowsService.java15
-rw-r--r--src/main/java/org/traccar/api/resource/AttributeResource.java14
-rw-r--r--src/main/java/org/traccar/api/resource/DeviceResource.java22
-rw-r--r--src/main/java/org/traccar/database/LdapProvider.java23
-rw-r--r--src/main/java/org/traccar/geocoder/MapTilerGeocoder.java5
-rw-r--r--src/main/java/org/traccar/handler/ComputedAttributesHandler.java47
-rw-r--r--src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java16
-rw-r--r--src/main/java/org/traccar/helper/Log.java24
-rw-r--r--src/main/java/org/traccar/helper/ObdDecoder.java78
-rw-r--r--src/main/java/org/traccar/protocol/AdmProtocolDecoder.java41
-rw-r--r--src/main/java/org/traccar/protocol/AdmProtocolEncoder.java15
-rw-r--r--src/main/java/org/traccar/protocol/AplicomProtocolDecoder.java150
-rw-r--r--src/main/java/org/traccar/protocol/ArknavX8ProtocolDecoder.java15
-rw-r--r--src/main/java/org/traccar/protocol/ArnaviBinaryProtocolDecoder.java12
-rw-r--r--src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java562
-rw-r--r--src/main/java/org/traccar/protocol/AtrackProtocolEncoder.java10
-rw-r--r--src/main/java/org/traccar/protocol/AutoFonFrameDecoder.java29
-rw-r--r--src/main/java/org/traccar/protocol/AutoTrackProtocolDecoder.java11
-rw-r--r--src/main/java/org/traccar/protocol/B2316ProtocolDecoder.java41
-rw-r--r--src/main/java/org/traccar/protocol/BlueProtocolDecoder.java16
-rw-r--r--src/main/java/org/traccar/protocol/BstplProtocolDecoder.java22
-rw-r--r--src/main/java/org/traccar/protocol/C2stekProtocolDecoder.java28
-rw-r--r--src/main/java/org/traccar/protocol/CarcellProtocolEncoder.java13
-rw-r--r--src/main/java/org/traccar/protocol/CastelProtocolDecoder.java108
-rw-r--r--src/main/java/org/traccar/protocol/CastelProtocolEncoder.java17
-rw-r--r--src/main/java/org/traccar/protocol/CellocatorFrameDecoder.java26
-rw-r--r--src/main/java/org/traccar/protocol/CellocatorProtocolDecoder.java16
-rw-r--r--src/main/java/org/traccar/protocol/CellocatorProtocolEncoder.java12
-rw-r--r--src/main/java/org/traccar/protocol/CguardProtocolDecoder.java20
-rw-r--r--src/main/java/org/traccar/protocol/CityeasyProtocolEncoder.java15
-rw-r--r--src/main/java/org/traccar/protocol/DmtHttpProtocolDecoder.java12
-rw-r--r--src/main/java/org/traccar/protocol/DmtProtocolDecoder.java58
-rw-r--r--src/main/java/org/traccar/protocol/EasyTrackProtocolEncoder.java19
-rw-r--r--src/main/java/org/traccar/protocol/EelinkProtocolDecoder.java58
-rw-r--r--src/main/java/org/traccar/protocol/EelinkProtocolEncoder.java22
-rw-r--r--src/main/java/org/traccar/protocol/EnforaProtocolEncoder.java16
-rw-r--r--src/main/java/org/traccar/protocol/EnvotechProtocolDecoder.java10
-rw-r--r--src/main/java/org/traccar/protocol/EsealProtocolDecoder.java32
-rw-r--r--src/main/java/org/traccar/protocol/EsealProtocolEncoder.java22
-rw-r--r--src/main/java/org/traccar/protocol/FifotrackProtocolDecoder.java66
-rw-r--r--src/main/java/org/traccar/protocol/FifotrackProtocolEncoder.java13
-rw-r--r--src/main/java/org/traccar/protocol/FleetGuideProtocolDecoder.java14
-rw-r--r--src/main/java/org/traccar/protocol/FlespiProtocolDecoder.java210
-rw-r--r--src/main/java/org/traccar/protocol/FlexApiProtocolDecoder.java14
-rw-r--r--src/main/java/org/traccar/protocol/FreematicsProtocolDecoder.java91
-rw-r--r--src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java114
-rw-r--r--src/main/java/org/traccar/protocol/GalileoProtocolEncoder.java16
-rw-r--r--src/main/java/org/traccar/protocol/GatorProtocolEncoder.java29
-rw-r--r--src/main/java/org/traccar/protocol/GenxProtocolDecoder.java43
-rw-r--r--src/main/java/org/traccar/protocol/Gl200BinaryProtocolDecoder.java63
-rw-r--r--src/main/java/org/traccar/protocol/Gl200FrameDecoder.java28
-rw-r--r--src/main/java/org/traccar/protocol/Gl200ProtocolEncoder.java29
-rw-r--r--src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java180
-rw-r--r--src/main/java/org/traccar/protocol/GlobalSatProtocolEncoder.java20
-rw-r--r--src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java44
-rw-r--r--src/main/java/org/traccar/protocol/Gps103ProtocolEncoder.java44
-rw-r--r--src/main/java/org/traccar/protocol/GranitProtocolEncoder.java16
-rw-r--r--src/main/java/org/traccar/protocol/GranitProtocolSmsEncoder.java13
-rw-r--r--src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java237
-rw-r--r--src/main/java/org/traccar/protocol/Gt30ProtocolDecoder.java21
-rw-r--r--src/main/java/org/traccar/protocol/H02ProtocolDecoder.java35
-rw-r--r--src/main/java/org/traccar/protocol/H02ProtocolEncoder.java26
-rw-r--r--src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java304
-rw-r--r--src/main/java/org/traccar/schedule/TaskReports.java24
-rw-r--r--src/main/java/org/traccar/session/ConnectionManager.java16
67 files changed, 1167 insertions, 2392 deletions
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<Attribute> {
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<Device> {
}
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<String, Object> 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<String, Object> 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<String, Object> 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<Event, Position> 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);
}