aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-30 14:04:24 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-30 14:04:24 -0700
commit014cf82a9e63a36e944e293932f9edf27e452919 (patch)
tree7ac5899f535fbf47e66dc1321738c951473a009b /src/main
parentce661ec77a957b70c15509c6801e6f34b32ad11d (diff)
downloadtrackermap-server-014cf82a9e63a36e944e293932f9edf27e452919.tar.gz
trackermap-server-014cf82a9e63a36e944e293932f9edf27e452919.tar.bz2
trackermap-server-014cf82a9e63a36e944e293932f9edf27e452919.zip
No context dependency for decoder
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/BaseProtocolDecoder.java42
-rw-r--r--src/main/java/org/traccar/Main.java2
-rw-r--r--src/main/java/org/traccar/model/BaseModel.java6
-rw-r--r--src/main/java/org/traccar/model/CellTower.java14
-rw-r--r--src/main/java/org/traccar/protocol/AplicomProtocolDecoder.java3
-rw-r--r--src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java16
-rw-r--r--src/main/java/org/traccar/protocol/Avl301ProtocolDecoder.java2
-rw-r--r--src/main/java/org/traccar/protocol/CastelProtocolDecoder.java4
-rw-r--r--src/main/java/org/traccar/protocol/EsealProtocolDecoder.java9
-rw-r--r--src/main/java/org/traccar/protocol/GenxProtocolDecoder.java7
-rw-r--r--src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java11
-rw-r--r--src/main/java/org/traccar/protocol/GlobalSatProtocolDecoder.java8
-rw-r--r--src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java3
-rw-r--r--src/main/java/org/traccar/protocol/H02ProtocolDecoder.java6
-rw-r--r--src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java3
-rw-r--r--src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java7
-rw-r--r--src/main/java/org/traccar/protocol/OrbcommProtocol.java3
-rw-r--r--src/main/java/org/traccar/protocol/OrbcommProtocolPoller.java12
-rw-r--r--src/main/java/org/traccar/protocol/SkypatrolProtocolDecoder.java9
-rw-r--r--src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java9
-rw-r--r--src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java2
-rw-r--r--src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java11
-rw-r--r--src/main/java/org/traccar/protocol/ThinkRaceProtocolDecoder.java2
-rw-r--r--src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java9
-rw-r--r--src/main/java/org/traccar/protocol/TotemProtocolDecoder.java6
-rw-r--r--src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java5
-rw-r--r--src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java7
-rw-r--r--src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java6
28 files changed, 143 insertions, 81 deletions
diff --git a/src/main/java/org/traccar/BaseProtocolDecoder.java b/src/main/java/org/traccar/BaseProtocolDecoder.java
index 505e7926f..0f62c87df 100644
--- a/src/main/java/org/traccar/BaseProtocolDecoder.java
+++ b/src/main/java/org/traccar/BaseProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2022 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.
@@ -50,17 +50,47 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
private static final String PROTOCOL_UNKNOWN = "unknown";
- private final Config config = Context.getConfig();
- private final IdentityManager identityManager = Context.getIdentityManager();
- private final ConnectionManager connectionManager = Context.getConnectionManager();
- private final StatisticsManager statisticsManager;
private final Protocol protocol;
+ private Config config;
+ private IdentityManager identityManager;
+ private ConnectionManager connectionManager;
+ private StatisticsManager statisticsManager;
private MediaManager mediaManager;
public BaseProtocolDecoder(Protocol protocol) {
this.protocol = protocol;
- statisticsManager = Main.getInjector() != null ? Main.getInjector().getInstance(StatisticsManager.class) : null;
+ }
+
+ /**
+ * Method called when config is initialized.
+ */
+ protected void init() {
+ }
+
+ public Config getConfig() {
+ return config;
+ }
+
+ @Inject
+ public void setConfig(Config config) {
+ this.config = config;
+ init();
+ }
+
+ @Inject
+ public void setIdentityManager(IdentityManager identityManager) {
+ this.identityManager = identityManager;
+ }
+
+ @Inject
+ public void setConnectionManager(ConnectionManager connectionManager) {
+ this.connectionManager = connectionManager;
+ }
+
+ @Inject
+ public void setStatisticsManager(StatisticsManager statisticsManager) {
+ this.statisticsManager = statisticsManager;
}
@Inject
diff --git a/src/main/java/org/traccar/Main.java b/src/main/java/org/traccar/Main.java
index 2eaf394af..016365837 100644
--- a/src/main/java/org/traccar/Main.java
+++ b/src/main/java/org/traccar/Main.java
@@ -110,8 +110,8 @@ public final class Main {
public static void run(String configFile) {
try {
- Context.init(configFile);
injector = Guice.createInjector(new MainModule());
+ Context.init(configFile);
logSystemInfo();
LOGGER.info("Version: " + Main.class.getPackage().getImplementationVersion());
LOGGER.info("Starting server...");
diff --git a/src/main/java/org/traccar/model/BaseModel.java b/src/main/java/org/traccar/model/BaseModel.java
index 8bdb916e8..acde0f83d 100644
--- a/src/main/java/org/traccar/model/BaseModel.java
+++ b/src/main/java/org/traccar/model/BaseModel.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,11 +20,11 @@ public class BaseModel {
private long id;
- public final long getId() {
+ public long getId() {
return id;
}
- public final void setId(long id) {
+ public void setId(long id) {
this.id = id;
}
diff --git a/src/main/java/org/traccar/model/CellTower.java b/src/main/java/org/traccar/model/CellTower.java
index 254487471..af33b1f5c 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 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 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.
@@ -16,7 +16,7 @@
package org.traccar.model;
import com.fasterxml.jackson.annotation.JsonInclude;
-import org.traccar.Context;
+import org.traccar.config.Config;
import org.traccar.config.Keys;
@JsonInclude(JsonInclude.Include.NON_NULL)
@@ -37,14 +37,12 @@ public class CellTower {
return cellTower;
}
- public static CellTower fromLacCid(int lac, long cid) {
- return from(
- Context.getConfig().getInteger(Keys.GEOLOCATION_MCC),
- Context.getConfig().getInteger(Keys.GEOLOCATION_MCC), lac, cid);
+ public static CellTower fromLacCid(Config config, int lac, long cid) {
+ return from(config.getInteger(Keys.GEOLOCATION_MCC), config.getInteger(Keys.GEOLOCATION_MCC), lac, cid);
}
- public static CellTower fromCidLac(long cid, int lac) {
- return fromLacCid(lac, cid);
+ public static CellTower fromCidLac(Config config, long cid, int lac) {
+ return fromLacCid(config, lac, cid);
}
private String radioType;
diff --git a/src/main/java/org/traccar/protocol/AplicomProtocolDecoder.java b/src/main/java/org/traccar/protocol/AplicomProtocolDecoder.java
index f11312428..692a2058a 100644
--- a/src/main/java/org/traccar/protocol/AplicomProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/AplicomProtocolDecoder.java
@@ -21,7 +21,6 @@ import io.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.Protocol;
import org.traccar.config.Keys;
@@ -303,7 +302,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
decodeEventData(position, buf, event);
}
- if (Context.getConfig().getBoolean(Keys.PROTOCOL_CAN.withPrefix(getProtocolName()))
+ if (getConfig().getBoolean(Keys.PROTOCOL_CAN.withPrefix(getProtocolName()))
&& buf.isReadable() && (selector & 0x1000) != 0 && event == EVENT_DATA) {
decodeCanData(buf, position);
}
diff --git a/src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java
index 247a1b696..9a5d537ef 100644
--- a/src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java
@@ -20,7 +20,6 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
@@ -54,7 +53,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
private static final int MIN_DATA_LENGTH = 40;
private boolean longDate;
- private final boolean decimalFuel;
+ private boolean decimalFuel;
private boolean custom;
private String form;
@@ -64,17 +63,20 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
public AtrackProtocolDecoder(Protocol protocol) {
super(protocol);
+ }
- longDate = Context.getConfig().getBoolean(Keys.PROTOCOL_LONG_DATE.withPrefix(getProtocolName()));
- decimalFuel = Context.getConfig().getBoolean(Keys.PROTOCOL_DECIMAL_FUEL.withPrefix(getProtocolName()));
+ @Override
+ protected void init() {
+ longDate = getConfig().getBoolean(Keys.PROTOCOL_LONG_DATE.withPrefix(getProtocolName()));
+ decimalFuel = getConfig().getBoolean(Keys.PROTOCOL_DECIMAL_FUEL.withPrefix(getProtocolName()));
- custom = Context.getConfig().getBoolean(Keys.PROTOCOL_CUSTOM.withPrefix(getProtocolName()));
- form = Context.getConfig().getString(Keys.PROTOCOL_FORM.withPrefix(getProtocolName()));
+ custom = getConfig().getBoolean(Keys.PROTOCOL_CUSTOM.withPrefix(getProtocolName()));
+ form = getConfig().getString(Keys.PROTOCOL_FORM.withPrefix(getProtocolName()));
if (form != null) {
custom = true;
}
- String alarmMapString = Context.getConfig().getString(Keys.PROTOCOL_ALARM_MAP.withPrefix(getProtocolName()));
+ String alarmMapString = getConfig().getString(Keys.PROTOCOL_ALARM_MAP.withPrefix(getProtocolName()));
if (alarmMapString != null) {
for (String pair : alarmMapString.split(",")) {
if (!pair.isEmpty()) {
diff --git a/src/main/java/org/traccar/protocol/Avl301ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Avl301ProtocolDecoder.java
index f6b7db2d6..9f6ded26a 100644
--- a/src/main/java/org/traccar/protocol/Avl301ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Avl301ProtocolDecoder.java
@@ -125,7 +125,7 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder {
}
position.setNetwork(new Network(
- CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedMedium())));
+ CellTower.fromLacCid(getConfig(), buf.readUnsignedShort(), buf.readUnsignedMedium())));
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
int flags = buf.readUnsignedByte();
diff --git a/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java b/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java
index 23401b5ee..85ac29336 100644
--- a/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/CastelProtocolDecoder.java
@@ -443,7 +443,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
decodeStat(position, buf);
position.setNetwork(new Network(
- CellTower.fromLacCid(buf.readUnsignedShortLE(), buf.readUnsignedShortLE())));
+ CellTower.fromLacCid(getConfig(), buf.readUnsignedShortLE(), buf.readUnsignedShortLE())));
return position;
@@ -499,7 +499,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // additional flags
position.setNetwork(new Network(
- CellTower.fromLacCid(buf.readUnsignedShortLE(), buf.readUnsignedShortLE())));
+ CellTower.fromLacCid(getConfig(), buf.readUnsignedShortLE(), buf.readUnsignedShortLE())));
positions.add(position);
}
diff --git a/src/main/java/org/traccar/protocol/EsealProtocolDecoder.java b/src/main/java/org/traccar/protocol/EsealProtocolDecoder.java
index 0a12f781d..27fcf1394 100644
--- a/src/main/java/org/traccar/protocol/EsealProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/EsealProtocolDecoder.java
@@ -17,7 +17,6 @@ package org.traccar.protocol;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
@@ -32,11 +31,15 @@ import java.util.regex.Pattern;
public class EsealProtocolDecoder extends BaseProtocolDecoder {
- private final String config;
+ private String config;
public EsealProtocolDecoder(Protocol protocol) {
super(protocol);
- config = Context.getConfig().getString(Keys.PROTOCOL_CONFIG.withPrefix(getProtocolName()));
+ }
+
+ @Override
+ protected void init() {
+ config = getConfig().getString(Keys.PROTOCOL_CONFIG.withPrefix(getProtocolName()));
}
private static final Pattern PATTERN = new PatternBuilder()
diff --git a/src/main/java/org/traccar/protocol/GenxProtocolDecoder.java b/src/main/java/org/traccar/protocol/GenxProtocolDecoder.java
index 2ae9de7a0..b787b7467 100644
--- a/src/main/java/org/traccar/protocol/GenxProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/GenxProtocolDecoder.java
@@ -17,7 +17,6 @@ package org.traccar.protocol;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.Protocol;
import org.traccar.helper.UnitsConverter;
@@ -32,7 +31,11 @@ public class GenxProtocolDecoder extends BaseProtocolDecoder {
public GenxProtocolDecoder(Protocol protocol) {
super(protocol);
- setReportColumns(Context.getConfig().getString(getProtocolName() + ".reportColumns", "1,2,3,4"));
+ }
+
+ @Override
+ protected void init() {
+ setReportColumns(getConfig().getString(getProtocolName() + ".reportColumns", "1,2,3,4"));
}
public void setReportColumns(String format) {
diff --git a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java
index 280986165..72d3ef592 100644
--- a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java
@@ -16,7 +16,6 @@
package org.traccar.protocol;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
@@ -46,11 +45,15 @@ import java.util.regex.Pattern;
public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
- private final boolean ignoreFixTime;
+ private boolean ignoreFixTime;
public Gl200TextProtocolDecoder(Protocol protocol) {
super(protocol);
- ignoreFixTime = Context.getConfig().getBoolean(Keys.PROTOCOL_IGNORE_FIX_TIME.withPrefix(getProtocolName()));
+ }
+
+ @Override
+ protected void init() {
+ ignoreFixTime = getConfig().getBoolean(Keys.PROTOCOL_IGNORE_FIX_TIME.withPrefix(getProtocolName()));
}
private static final Pattern PATTERN_ACK = new PatternBuilder()
@@ -1333,7 +1336,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
}
}
- if (channel != null && Context.getConfig().getBoolean(Keys.PROTOCOL_ACK.withPrefix(getProtocolName()))) {
+ if (channel != null && getConfig().getBoolean(Keys.PROTOCOL_ACK.withPrefix(getProtocolName()))) {
String checksum;
if (sentence.endsWith("$")) {
checksum = sentence.substring(sentence.length() - 1 - 4, sentence.length() - 1);
diff --git a/src/main/java/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/main/java/org/traccar/protocol/GlobalSatProtocolDecoder.java
index b48df4047..d5c834284 100644
--- a/src/main/java/org/traccar/protocol/GlobalSatProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/GlobalSatProtocolDecoder.java
@@ -17,7 +17,6 @@ package org.traccar.protocol;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
@@ -40,9 +39,12 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder {
public GlobalSatProtocolDecoder(Protocol protocol) {
super(protocol);
+ }
- format0 = Context.getConfig().getString(getProtocolName() + ".format0", "TSPRXAB27GHKLMnaicz*U!");
- format1 = Context.getConfig().getString(getProtocolName() + ".format1", "SARY*U!");
+ @Override
+ protected void init() {
+ format0 = getConfig().getString(getProtocolName() + ".format0", "TSPRXAB27GHKLMnaicz*U!");
+ format1 = getConfig().getString(getProtocolName() + ".format1", "SARY*U!");
}
public void setFormat0(String format) {
diff --git a/src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java
index d5aa45b9c..510f5eca2 100644
--- a/src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -221,7 +221,8 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, null);
- position.setNetwork(new Network(CellTower.fromLacCid(parser.nextHexInt(0), parser.nextHexInt(0))));
+ position.setNetwork(new Network(CellTower.fromLacCid(
+ getConfig(), parser.nextHexInt(0), parser.nextHexInt(0))));
} else {
diff --git a/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java b/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java
index 10a272bff..dcfb36fd1 100644
--- a/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/H02ProtocolDecoder.java
@@ -19,7 +19,6 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
@@ -334,7 +333,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
if (parser.hasNext() && parser.next().equals("V1")) {
sendResponse(channel, remoteAddress, id, "V1");
- } else if (Context.getConfig().getBoolean(Keys.PROTOCOL_ACK.withPrefix(getProtocolName()))) {
+ } else if (getConfig().getBoolean(Keys.PROTOCOL_ACK.withPrefix(getProtocolName()))) {
sendResponse(channel, remoteAddress, id, "R12");
}
@@ -392,7 +391,8 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
position.setAltitude(parser.nextInt(0));
- position.setNetwork(new Network(CellTower.fromLacCid(parser.nextHexInt(0), parser.nextHexInt(0))));
+ position.setNetwork(new Network(CellTower.fromLacCid(
+ getConfig(), parser.nextHexInt(0), parser.nextHexInt(0))));
}
if (parser.hasNext()) {
diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
index 9f54c8486..84120028a 100644
--- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
@@ -585,7 +585,8 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_CHARGE, true);
}
- position.setNetwork(new Network(CellTower.fromCidLac(buf.readUnsignedInt(), buf.readUnsignedShort())));
+ position.setNetwork(new Network(CellTower.fromCidLac(
+ getConfig(), buf.readUnsignedInt(), buf.readUnsignedShort())));
int product = buf.readUnsignedByte();
int status = buf.readUnsignedShort();
diff --git a/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java
index b4b70091b..2c1b5dcec 100644
--- a/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -177,7 +177,8 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_BATTERY_LEVEL, battery);
}
- CellTower cellTower = CellTower.fromCidLac(buf.readUnsignedShort(), buf.readUnsignedShort());
+ CellTower cellTower = CellTower.fromCidLac(
+ getConfig(), buf.readUnsignedShort(), buf.readUnsignedShort());
cellTower.setSignalStrength((int) buf.readUnsignedByte());
position.setNetwork(new Network(cellTower));
@@ -201,7 +202,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
int rssi = buf.readUnsignedByte();
if (cid != 0 && lac != 0) {
- CellTower cellTower = CellTower.fromCidLac(cid, lac);
+ CellTower cellTower = CellTower.fromCidLac(getConfig(), cid, lac);
cellTower.setSignalStrength(rssi);
position.setNetwork(new Network(cellTower));
} else {
@@ -356,7 +357,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
position.set(Position.KEY_STATUS, parser.nextBinInt(0));
- CellTower cellTower = CellTower.fromCidLac(parser.nextInt(0), parser.nextInt(0));
+ CellTower cellTower = CellTower.fromCidLac(getConfig(), parser.nextInt(0), parser.nextInt(0));
cellTower.setSignalStrength(parser.nextInt(0));
position.setNetwork(new Network(cellTower));
diff --git a/src/main/java/org/traccar/protocol/OrbcommProtocol.java b/src/main/java/org/traccar/protocol/OrbcommProtocol.java
index bdfce3b1e..2f9f56641 100644
--- a/src/main/java/org/traccar/protocol/OrbcommProtocol.java
+++ b/src/main/java/org/traccar/protocol/OrbcommProtocol.java
@@ -19,6 +19,7 @@ import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestEncoder;
import io.netty.handler.codec.http.HttpResponseDecoder;
import org.traccar.BaseProtocol;
+import org.traccar.Context;
import org.traccar.PipelineBuilder;
import org.traccar.TrackerClient;
@@ -32,7 +33,7 @@ public class OrbcommProtocol extends BaseProtocol {
pipeline.addLast(new HttpResponseDecoder());
pipeline.addLast(new HttpObjectAggregator(65535));
pipeline.addLast(new OrbcommProtocolDecoder(OrbcommProtocol.this));
- pipeline.addLast(new OrbcommProtocolPoller(OrbcommProtocol.this));
+ pipeline.addLast(new OrbcommProtocolPoller(OrbcommProtocol.this, Context.getConfig()));
}
});
}
diff --git a/src/main/java/org/traccar/protocol/OrbcommProtocolPoller.java b/src/main/java/org/traccar/protocol/OrbcommProtocolPoller.java
index 6a2d7a92d..0f57bfb49 100644
--- a/src/main/java/org/traccar/protocol/OrbcommProtocolPoller.java
+++ b/src/main/java/org/traccar/protocol/OrbcommProtocolPoller.java
@@ -24,8 +24,8 @@ import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.QueryStringEncoder;
import org.traccar.BaseProtocolPoller;
-import org.traccar.Context;
import org.traccar.Protocol;
+import org.traccar.config.Config;
import org.traccar.config.Keys;
import java.net.SocketAddress;
@@ -46,11 +46,11 @@ public class OrbcommProtocolPoller extends BaseProtocolPoller {
this.startTime = startTime;
}
- public OrbcommProtocolPoller(Protocol protocol) {
- super(Context.getConfig().getLong(Keys.PROTOCOL_INTERVAL.withPrefix(protocol.getName())));
- accessId = Context.getConfig().getString(Keys.ORBCOMM_ACCESS_ID);
- password = Context.getConfig().getString(Keys.ORBCOMM_PASSWORD);
- host = Context.getConfig().getString(Keys.PROTOCOL_ADDRESS.withPrefix(protocol.getName()));
+ public OrbcommProtocolPoller(Protocol protocol, Config config) {
+ super(config.getLong(Keys.PROTOCOL_INTERVAL.withPrefix(protocol.getName())));
+ accessId = config.getString(Keys.ORBCOMM_ACCESS_ID);
+ password = config.getString(Keys.ORBCOMM_PASSWORD);
+ host = config.getString(Keys.PROTOCOL_ADDRESS.withPrefix(protocol.getName()));
}
@Override
diff --git a/src/main/java/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/main/java/org/traccar/protocol/SkypatrolProtocolDecoder.java
index 8aae310bb..818acd805 100644
--- a/src/main/java/org/traccar/protocol/SkypatrolProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/SkypatrolProtocolDecoder.java
@@ -20,7 +20,6 @@ import io.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.Protocol;
import org.traccar.config.Keys;
@@ -35,11 +34,15 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder {
private static final Logger LOGGER = LoggerFactory.getLogger(SkypatrolProtocolDecoder.class);
- private final long defaultMask;
+ private long defaultMask;
public SkypatrolProtocolDecoder(Protocol protocol) {
super(protocol);
- defaultMask = Context.getConfig().getInteger(Keys.PROTOCOL_MASK.withPrefix(getProtocolName()));
+ }
+
+ @Override
+ protected void init() {
+ defaultMask = getConfig().getInteger(Keys.PROTOCOL_MASK.withPrefix(getProtocolName()));
}
private static double convertCoordinate(long coordinate) {
diff --git a/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java b/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java
index 7a6b6f4fe..5e631017e 100644
--- a/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/StarLinkProtocolDecoder.java
@@ -55,12 +55,15 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder {
public StarLinkProtocolDecoder(Protocol protocol) {
super(protocol);
+ }
- setFormat(Context.getConfig().getString(
+ @Override
+ protected void init() {
+ setFormat(getConfig().getString(
getProtocolName() + ".format", "#EDT#,#EID#,#PDT#,#LAT#,#LONG#,#SPD#,#HEAD#,#ODO#,"
+ "#IN1#,#IN2#,#IN3#,#IN4#,#OUT1#,#OUT2#,#OUT3#,#OUT4#,#LAC#,#CID#,#VIN#,#VBAT#,#DEST#,#IGN#,#ENG#"));
- setDateFormat(Context.getConfig().getString(getProtocolName() + ".dateFormat", "yyMMddHHmmss"));
+ setDateFormat(getConfig().getString(getProtocolName() + ".dateFormat", "yyMMddHHmmss"));
}
public String[] getFormat(long deviceId) {
@@ -313,7 +316,7 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder {
}
if (lac != null && cid != null) {
- position.setNetwork(new Network(CellTower.fromLacCid(lac, cid)));
+ position.setNetwork(new Network(CellTower.fromLacCid(getConfig(), lac, cid)));
}
if (event == 20) {
diff --git a/src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java b/src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java
index 17f5c80fa..b6091136a 100644
--- a/src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TechTltProtocolDecoder.java
@@ -110,7 +110,7 @@ public class TechTltProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_SATELLITES, parser.nextInt());
- position.setNetwork(new Network(CellTower.fromLacCid(parser.nextInt(), parser.nextInt())));
+ position.setNetwork(new Network(CellTower.fromLacCid(getConfig(), parser.nextInt(), parser.nextInt())));
return position;
}
diff --git a/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
index 61a61b900..407488527 100644
--- a/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -55,7 +55,11 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
public TeltonikaProtocolDecoder(Protocol protocol, boolean connectionless) {
super(protocol);
this.connectionless = connectionless;
- this.extended = Context.getConfig().getBoolean(Keys.PROTOCOL_EXTENDED.withPrefix(getProtocolName()));
+ }
+
+ @Override
+ protected void init() {
+ this.extended = getConfig().getBoolean(Keys.PROTOCOL_EXTENDED.withPrefix(getProtocolName()));
}
private void parseIdentification(Channel channel, SocketAddress remoteAddress, ByteBuf buf) {
@@ -360,7 +364,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
long cid = position.getLong(Position.PREFIX_IO + 205);
int lac = position.getInteger(Position.PREFIX_IO + 206);
if (cid != 0 && lac != 0) {
- CellTower cellTower = CellTower.fromLacCid(lac, cid);
+ CellTower cellTower = CellTower.fromLacCid(getConfig(), lac, cid);
long operator = position.getInteger(Position.KEY_OPERATOR);
if (operator >= 1000) {
cellTower.setOperator(operator);
@@ -422,7 +426,8 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
}
if (BitUtil.check(locationMask, 5)) {
- CellTower cellTower = CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort());
+ CellTower cellTower = CellTower.fromLacCid(
+ getConfig(), buf.readUnsignedShort(), buf.readUnsignedShort());
if (BitUtil.check(locationMask, 6)) {
cellTower.setSignalStrength((int) buf.readUnsignedByte());
diff --git a/src/main/java/org/traccar/protocol/ThinkRaceProtocolDecoder.java b/src/main/java/org/traccar/protocol/ThinkRaceProtocolDecoder.java
index 0928b25e0..82033598d 100644
--- a/src/main/java/org/traccar/protocol/ThinkRaceProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/ThinkRaceProtocolDecoder.java
@@ -104,7 +104,7 @@ public class ThinkRaceProtocolDecoder extends BaseProtocolDecoder {
position.setCourse(buf.readUnsignedByte());
position.setNetwork(new Network(
- CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort())));
+ CellTower.fromLacCid(getConfig(), buf.readUnsignedShort(), buf.readUnsignedShort())));
return position;
diff --git a/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java
index ff33cb103..476d1d682 100644
--- a/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -17,7 +17,6 @@ package org.traccar.protocol;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
@@ -36,11 +35,15 @@ import java.util.regex.Pattern;
public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
- private final boolean decodeLow;
+ private boolean decodeLow;
public Tk103ProtocolDecoder(Protocol protocol) {
super(protocol);
- decodeLow = Context.getConfig().getBoolean(Keys.PROTOCOL_DECODE_LOW.withPrefix(getProtocolName()));
+ }
+
+ @Override
+ protected void init() {
+ decodeLow = getConfig().getBoolean(Keys.PROTOCOL_DECODE_LOW.withPrefix(getProtocolName()));
}
private static final Pattern PATTERN = new PatternBuilder()
diff --git a/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java b/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java
index 58c66031e..b76d5b307 100644
--- a/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java
@@ -320,7 +320,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
int lac = parser.nextHexInt(0);
int cid = parser.nextHexInt(0);
if (lac != 0 && cid != 0) {
- position.setNetwork(new Network(CellTower.fromLacCid(lac, cid)));
+ position.setNetwork(new Network(CellTower.fromLacCid(getConfig(), lac, cid)));
}
position.set(Position.PREFIX_TEMP + 1, parser.next());
@@ -346,7 +346,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.PREFIX_TEMP + 2, parser.next());
position.setNetwork(new Network(
- CellTower.fromLacCid(parser.nextHexInt(0), parser.nextHexInt(0))));
+ CellTower.fromLacCid(getConfig(), parser.nextHexInt(0), parser.nextHexInt(0))));
position.setValid(parser.next().equals("A"));
position.set(Position.KEY_SATELLITES, parser.nextInt());
@@ -403,7 +403,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
int mcc = parser.nextInt();
cellTower = CellTower.from(mcc, mnc, lac, cid);
} else {
- cellTower = CellTower.fromLacCid(lac, cid);
+ cellTower = CellTower.fromLacCid(getConfig(), lac, cid);
}
position.set(Position.KEY_SATELLITES, parser.nextInt());
cellTower.setSignalStrength(parser.nextInt());
diff --git a/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java b/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java
index 819c42471..b1ddc5203 100644
--- a/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/TzoneProtocolDecoder.java
@@ -20,7 +20,6 @@ import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
@@ -284,7 +283,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
if (hardware == 0x10A || hardware == 0x10B || hardware == 0x406) {
position.setNetwork(new Network(
- CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort())));
+ CellTower.fromLacCid(getConfig(), buf.readUnsignedShort(), buf.readUnsignedShort())));
} else if (hardware == 0x407) {
@@ -371,7 +370,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
}
- if (Context.getConfig().getBoolean(Keys.PROTOCOL_ACK.withPrefix(getProtocolName()))) {
+ if (getConfig().getBoolean(Keys.PROTOCOL_ACK.withPrefix(getProtocolName()))) {
sendResponse(channel, remoteAddress, buf.getUnsignedShort(buf.writerIndex() - 6));
}
diff --git a/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java b/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java
index 630fe5aed..b53a42ac3 100644
--- a/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/XirgoProtocolDecoder.java
@@ -18,7 +18,6 @@ package org.traccar.protocol;
import io.netty.channel.Channel;
import io.netty.channel.socket.nio.NioDatagramChannel;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
@@ -40,7 +39,11 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder {
public XirgoProtocolDecoder(Protocol protocol) {
super(protocol);
- form = Context.getConfig().getString(Keys.PROTOCOL_FORM.withPrefix(getProtocolName()));
+ }
+
+ @Override
+ protected void init() {
+ form = getConfig().getString(Keys.PROTOCOL_FORM.withPrefix(getProtocolName()));
}
public void setForm(String form) {
diff --git a/src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java
index 85e8e140f..b3f6493a8 100644
--- a/src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Xt2400ProtocolDecoder.java
@@ -18,7 +18,6 @@ package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.Protocol;
import org.traccar.config.Keys;
@@ -38,8 +37,11 @@ public class Xt2400ProtocolDecoder extends BaseProtocolDecoder {
public Xt2400ProtocolDecoder(Protocol protocol) {
super(protocol);
+ }
- String config = Context.getConfig().getString(Keys.PROTOCOL_CONFIG.withPrefix(getProtocolName()));
+ @Override
+ protected void init() {
+ String config = getConfig().getString(Keys.PROTOCOL_CONFIG.withPrefix(getProtocolName()));
if (config != null) {
setConfig(config);
}