From d97c43c29e96503d1ba943ec780cd6f8d419a0dd Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 29 Dec 2020 11:27:46 -0800 Subject: Migrate remaining int keys --- src/main/java/org/traccar/config/Config.java | 5 ---- src/main/java/org/traccar/config/Keys.java | 28 ++++++++++++++++++++++ src/main/java/org/traccar/model/CellTower.java | 7 +++--- .../java/org/traccar/protocol/H02Protocol.java | 5 ++-- .../traccar/protocol/SkypatrolProtocolDecoder.java | 5 ++-- 5 files changed, 38 insertions(+), 12 deletions(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/config/Config.java b/src/main/java/org/traccar/config/Config.java index 54e6efd06..815a6e86a 100644 --- a/src/main/java/org/traccar/config/Config.java +++ b/src/main/java/org/traccar/config/Config.java @@ -112,11 +112,6 @@ public class Config { } } - @Deprecated - public int getInteger(String key) { - return getInteger(key, 0); - } - public int getInteger(ConfigKey key, int defaultValue) { return getInteger(key.getKey(), defaultValue); } diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index f1efa7515..3f09190a1 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -44,6 +44,20 @@ public final class Keys { ".timeout", Collections.singletonList(KeyType.GLOBAL)); + /** + * Default protocol mask to use. Currently used only by Skypatrol protocol. + */ + public static final ConfigSuffix PROTOCOL_MASK = new ConfigSuffix<>( + ".mask", + Collections.singletonList(KeyType.GLOBAL)); + + /** + * Custom message length. Currently used only by H2 protocol for specifying binary message length. + */ + public static final ConfigSuffix PROTOCOL_MESSAGE_LENGTH = new ConfigSuffix<>( + ".messageLength", + Collections.singletonList(KeyType.GLOBAL)); + /** * Server wide connection timeout value in seconds. See protocol timeout for more information. */ @@ -750,6 +764,20 @@ public final class Keys { "geolocation.processInvalidPositions", Collections.singletonList(KeyType.GLOBAL)); + /** + * Default MCC value to use if device doesn't report MCC. + */ + public static final ConfigKey GEOLOCATION_MCC = new ConfigKey<>( + "geolocation.mcc", + Collections.singletonList(KeyType.GLOBAL)); + + /** + * Default MNC value to use if device doesn't report MNC. + */ + public static final ConfigKey GEOLOCATION_MNC = new ConfigKey<>( + "geolocation.mnc", + Collections.singletonList(KeyType.GLOBAL)); + /** * Boolean flag to enable speed limit API to get speed limit values depending on location. Default value is false. */ diff --git a/src/main/java/org/traccar/model/CellTower.java b/src/main/java/org/traccar/model/CellTower.java index 6d1dfbd7f..254487471 100644 --- a/src/main/java/org/traccar/model/CellTower.java +++ b/src/main/java/org/traccar/model/CellTower.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2020 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.traccar.model; import com.fasterxml.jackson.annotation.JsonInclude; import org.traccar.Context; +import org.traccar.config.Keys; @JsonInclude(JsonInclude.Include.NON_NULL) public class CellTower { @@ -38,8 +39,8 @@ public class CellTower { public static CellTower fromLacCid(int lac, long cid) { return from( - Context.getConfig().getInteger("geolocation.mcc"), - Context.getConfig().getInteger("geolocation.mnc"), lac, cid); + Context.getConfig().getInteger(Keys.GEOLOCATION_MCC), + Context.getConfig().getInteger(Keys.GEOLOCATION_MCC), lac, cid); } public static CellTower fromCidLac(long cid, int lac) { diff --git a/src/main/java/org/traccar/protocol/H02Protocol.java b/src/main/java/org/traccar/protocol/H02Protocol.java index b897d83ad..a5246abc6 100644 --- a/src/main/java/org/traccar/protocol/H02Protocol.java +++ b/src/main/java/org/traccar/protocol/H02Protocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2020 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import org.traccar.BaseProtocol; import org.traccar.Context; import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; +import org.traccar.config.Keys; import org.traccar.model.Command; public class H02Protocol extends BaseProtocol { @@ -35,7 +36,7 @@ public class H02Protocol extends BaseProtocol { addServer(new TrackerServer(false, getName()) { @Override protected void addProtocolHandlers(PipelineBuilder pipeline) { - int messageLength = Context.getConfig().getInteger(getName() + ".messageLength"); + int messageLength = Context.getConfig().getInteger(Keys.PROTOCOL_MESSAGE_LENGTH.withPrefix(getName())); pipeline.addLast(new H02FrameDecoder(messageLength)); pipeline.addLast(new StringEncoder()); pipeline.addLast(new H02ProtocolEncoder(H02Protocol.this)); diff --git a/src/main/java/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/main/java/org/traccar/protocol/SkypatrolProtocolDecoder.java index 3c7ca6dc5..8aae310bb 100644 --- a/src/main/java/org/traccar/protocol/SkypatrolProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/SkypatrolProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2020 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; import org.traccar.Protocol; +import org.traccar.config.Keys; import org.traccar.helper.BitUtil; import org.traccar.helper.DateBuilder; import org.traccar.model.Position; @@ -38,7 +39,7 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder { public SkypatrolProtocolDecoder(Protocol protocol) { super(protocol); - defaultMask = Context.getConfig().getInteger(getProtocolName() + ".mask"); + defaultMask = Context.getConfig().getInteger(Keys.PROTOCOL_MASK.withPrefix(getProtocolName())); } private static double convertCoordinate(long coordinate) { -- cgit v1.2.3