aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-04-23 15:49:56 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-04-23 15:49:56 +1200
commit2a3fad9496decd83f06ae5abf067f8d4337ec741 (patch)
tree69837f0bf89cf6ff78915d70380118575cc5c47a /src/org/traccar/protocol
parenta8d2a0170b7ac891ffe784320ac2d1389f11bf68 (diff)
downloadtrackermap-server-2a3fad9496decd83f06ae5abf067f8d4337ec741.tar.gz
trackermap-server-2a3fad9496decd83f06ae5abf067f8d4337ec741.tar.bz2
trackermap-server-2a3fad9496decd83f06ae5abf067f8d4337ec741.zip
Major code refacroting
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/ApelProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/AplicomProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/Ardi01ProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/AtrackProtocolDecoder.java19
-rw-r--r--src/org/traccar/protocol/AutoFon45ProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/AutoFonProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/BceProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/BoxProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/CalAmpProtocolDecoder.java22
-rw-r--r--src/org/traccar/protocol/CarTrackProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/CarscopProtocolDecoder.java17
-rw-r--r--src/org/traccar/protocol/CellocatorProtocolDecoder.java16
-rw-r--r--src/org/traccar/protocol/EasyTrackProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/EelinkProtocolDecoder.java19
-rw-r--r--src/org/traccar/protocol/EnforaProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/Ev603ProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/FreedomProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/GalileoProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/GatorProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/Gl100ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/GlobalSatProtocolDecoder.java19
-rw-r--r--src/org/traccar/protocol/GoSafeProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/GotopProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/GpsGateProtocolDecoder.java23
-rw-r--r--src/org/traccar/protocol/Gt02ProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolDecoder.java31
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java20
-rw-r--r--src/org/traccar/protocol/HaicomProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/IntellitracProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolDecoder.java19
-rw-r--r--src/org/traccar/protocol/KhdProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/LaipacProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/M2mProtocolDecoder.java17
-rw-r--r--src/org/traccar/protocol/ManPowerProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/MaxonProtocolDecoder.java28
-rw-r--r--src/org/traccar/protocol/MegastekProtocolDecoder.java24
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolDecoder.java21
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocolDecoder.java17
-rw-r--r--src/org/traccar/protocol/Mta6ProtocolDecoder.java22
-rw-r--r--src/org/traccar/protocol/MtxProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/NavigilProtocolDecoder.java47
-rw-r--r--src/org/traccar/protocol/NavisProtocolDecoder.java21
-rw-r--r--src/org/traccar/protocol/NoranProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/OrionProtocolDecoder.java17
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/PiligrimProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/ProgressProtocolDecoder.java23
-rw-r--r--src/org/traccar/protocol/Pt3000ProtocolDecoder.java16
-rw-r--r--src/org/traccar/protocol/Pt502ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/RitiProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/SanavProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/SkypatrolProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/Stl060ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/SuntechProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/SyrusProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/T55ProtocolDecoder.java32
-rw-r--r--src/org/traccar/protocol/TelikProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/Tk102ProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/Tlt2hProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/TopflytechProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/TotemProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/Tr20ProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/Tr900ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/TrackboxProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/TramigoProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/TytanProtocolDecoder.java17
-rw-r--r--src/org/traccar/protocol/UlbotechProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/V680ProtocolDecoder.java23
-rw-r--r--src/org/traccar/protocol/VisiontekProtocolDecoder.java23
-rw-r--r--src/org/traccar/protocol/WialonProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/WondexProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Xexun2ProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/XexunProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/XirgoProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Xt013ProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Xt7ProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/YwtProtocolDecoder.java11
83 files changed, 457 insertions, 833 deletions
diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java
index c772ce6f7..619831f0f 100644
--- a/src/org/traccar/protocol/ApelProtocolDecoder.java
+++ b/src/org/traccar/protocol/ApelProtocolDecoder.java
@@ -29,6 +29,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
import org.traccar.database.DataManager;
import org.traccar.helper.Crc;
import org.traccar.helper.Log;
@@ -37,12 +38,11 @@ import org.traccar.model.Position;
public class ApelProtocolDecoder extends BaseProtocolDecoder {
- private long deviceId;
private long lastIndex;
private long newIndex;
- public ApelProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public ApelProtocolDecoder(String protocol) {
+ super(protocol);
}
/*
@@ -140,13 +140,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder {
int length = buf.readUnsignedShort();
buf.skipBytes(length);
length = buf.readUnsignedShort();
- String imei = buf.readBytes(length).toString(Charset.defaultCharset());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- loadLastIndex();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei + " (id - " + id + ")");
- }
+ identify(buf.readBytes(length).toString(Charset.defaultCharset()));
}
else if (type == MSG_TYPE_LAST_LOG_INDEX) {
@@ -158,7 +152,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder {
}
// Position
- else if (deviceId != 0 && (type == MSG_TYPE_CURRENT_GPS_DATA || type == MSG_TYPE_STATE_FULL_INFO_T104 || type == MSG_TYPE_LOG_RECORDS)) {
+ else if (hasDeviceId() && (type == MSG_TYPE_CURRENT_GPS_DATA || type == MSG_TYPE_STATE_FULL_INFO_T104 || type == MSG_TYPE_LOG_RECORDS)) {
List<Position> positions = new LinkedList<Position>();
int recordCount = 1;
@@ -169,7 +163,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder {
for (int j = 0; j < recordCount; j++) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// Message index
int subtype = type;
diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java
index c47731759..aee1517e4 100644
--- a/src/org/traccar/protocol/AplicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java
@@ -23,6 +23,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
import org.traccar.database.DataManager;
import org.traccar.helper.Log;
import org.traccar.model.ExtendedInfoFormatter;
@@ -30,8 +31,8 @@ import org.traccar.model.Position;
public class AplicomProtocolDecoder extends BaseProtocolDecoder {
- public AplicomProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public AplicomProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final long IMEI_BASE_TC65_V20 = 0x1437207000000L;
@@ -128,13 +129,12 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
+ position.setDeviceId(getDeviceId());
+
// Event
extendedInfo.set("event", buf.readUnsignedByte());
buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
index e25ff1c57..4e90134ae 100644
--- a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
@@ -31,8 +31,8 @@ import java.util.regex.Pattern;
public class Ardi01ProtocolDecoder extends BaseProtocolDecoder {
- public Ardi01ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Ardi01ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -68,14 +68,11 @@ public class Ardi01ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Detect device
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Date and time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java
index 607b3e558..e2f3e924f 100644
--- a/src/org/traccar/protocol/AtrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class AtrackProtocolDecoder extends BaseProtocolDecoder {
- public AtrackProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public AtrackProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int MSG_HEARTBEAT = 0x1A;
@@ -91,18 +91,13 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
int index = buf.readUnsignedShort();
// Get device id
- long deviceId;
- long rawId = buf.readLong();
- String id = String.valueOf(rawId);
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ long id = buf.readLong();
+ if (!identify(String.valueOf(id))) {
return null;
}
-
+
// Send acknowledgement
- sendResponse(channel, remoteAddress, rawId, index);
+ sendResponse(channel, remoteAddress, id, index);
List<Position> positions = new LinkedList<Position>();
@@ -110,7 +105,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
// Date and time
diff --git a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java
index df98fa93b..c72139c50 100644
--- a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java
+++ b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java
@@ -32,15 +32,14 @@ import org.traccar.model.Position;
import java.util.*;
public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder {
- private long deviceId;
private static double convertCoordinate(short degrees, int raw) {
double seconds = (raw >> 4 & 0xffffff) / 600000.0;
return (degrees + seconds) * ((raw & 0x0f) == 0 ? -1 : 1);
}
- public AutoFon45ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public AutoFon45ProtocolDecoder(String protocol) {
+ super(protocol);
}
@Override
@@ -54,10 +53,7 @@ public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder {
buf.readBytes(bytes);
String imei = ChannelBufferTools.readHexString(ChannelBuffers.wrappedBuffer(bytes, 1, 16), 16).substring(1);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
@@ -74,7 +70,7 @@ public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
short status = buf.readUnsignedByte();
extendedInfo.set("alarm", (status & 0x80) != 0);
diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
index fbc142846..2c563d6d2 100644
--- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java
+++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
@@ -30,16 +30,14 @@ import java.util.*;
public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
- public AutoFonProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public AutoFonProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int MSG_LOGIN = 0x10;
private static final int MSG_LOCATION = 0x11;
private static final int MSG_HISTORY = 0x12;
- private long deviceId;
-
private static double convertCoordinate(int raw) {
double result = raw / 1000000;
result += (raw % 1000000) / 600000.0;
@@ -51,7 +49,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
if (!history) {
buf.readUnsignedByte(); // interval
@@ -127,10 +125,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // software version
String imei = ChannelBufferTools.readHexString(buf, 16).substring(1);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
diff --git a/src/org/traccar/protocol/BceProtocolDecoder.java b/src/org/traccar/protocol/BceProtocolDecoder.java
index a1c45758c..2f96ab317 100644
--- a/src/org/traccar/protocol/BceProtocolDecoder.java
+++ b/src/org/traccar/protocol/BceProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class BceProtocolDecoder extends BaseProtocolDecoder {
- public BceProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public BceProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int DATA_TYPE = 7;
@@ -57,11 +57,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
ChannelBuffer buf = (ChannelBuffer) msg;
String imei = String.format("%015d", buf.readLong());
- long deviceId;
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch (Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
@@ -77,7 +73,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
int structEnd = buf.readUnsignedByte() + buf.readerIndex();
diff --git a/src/org/traccar/protocol/BoxProtocolDecoder.java b/src/org/traccar/protocol/BoxProtocolDecoder.java
index cdbd3932e..d2de48489 100644
--- a/src/org/traccar/protocol/BoxProtocolDecoder.java
+++ b/src/org/traccar/protocol/BoxProtocolDecoder.java
@@ -31,11 +31,9 @@ import org.traccar.model.ExtendedInfoFormatter;
import org.traccar.model.Position;
public class BoxProtocolDecoder extends BaseProtocolDecoder {
-
- private Long deviceId;
- public BoxProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public BoxProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -63,12 +61,7 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder {
int index = sentence.indexOf(',', 2) + 1;
String id = sentence.substring(index, sentence.indexOf(',', index));
-
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
- }
+ identify(id);
}
else if (sentence.startsWith("L,")) {
@@ -81,7 +74,7 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
Integer index = 1;
diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
index 8fe75bf93..04ac8f165 100644
--- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java
+++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
- public CalAmpProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public CalAmpProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int MSG_NULL = 0;
@@ -91,8 +91,6 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
ChannelBuffer buf = (ChannelBuffer) msg;
- Long deviceId = null;
-
// Check options header
if ((buf.getByte(buf.readerIndex()) & 0x80) != 0) {
@@ -112,14 +110,7 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
}
}
- // Find device in database
- String stringId = String.valueOf(id);
- try {
- deviceId = getDataManager().getDeviceByImei(stringId).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + stringId);
- }
-
+ identify(String.valueOf(id));
}
// Identifier type
@@ -150,8 +141,7 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
}
// Unidentified device
- if (deviceId == null) {
- Log.warning("Unknown device");
+ if (!hasDeviceId()) {
return null;
}
@@ -170,8 +160,8 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
- ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("calamp");
+ position.setDeviceId(getDeviceId());
+ ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
// Location data
position.setTime(new Date(buf.readUnsignedInt() * 1000));
diff --git a/src/org/traccar/protocol/CarTrackProtocolDecoder.java b/src/org/traccar/protocol/CarTrackProtocolDecoder.java
index 170db3130..425115fe9 100644
--- a/src/org/traccar/protocol/CarTrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/CarTrackProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class CarTrackProtocolDecoder extends BaseProtocolDecoder {
- public CarTrackProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public CarTrackProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -77,13 +77,10 @@ public class CarTrackProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by unique identifier
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Command
extendedInfo.set("command", parser.group(index++));
diff --git a/src/org/traccar/protocol/CarscopProtocolDecoder.java b/src/org/traccar/protocol/CarscopProtocolDecoder.java
index e56036d0b..e7c4d6192 100644
--- a/src/org/traccar/protocol/CarscopProtocolDecoder.java
+++ b/src/org/traccar/protocol/CarscopProtocolDecoder.java
@@ -32,13 +32,10 @@ import org.traccar.model.Position;
public class CarscopProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public CarscopProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public CarscopProtocolDecoder(String protocol) {
+ super(protocol);
}
- // Very similar to TK103 protocol
static private Pattern pattern = Pattern.compile(
"\\*.*" +
"(\\d{2})(\\d{2})(\\d{2})" + // Time (HHMMSS)
@@ -64,13 +61,9 @@ public class CarscopProtocolDecoder extends BaseProtocolDecoder {
int index = sentence.indexOf("UB05");
if (index != -1) {
String imei = sentence.substring(index + 4, index + 4 + 15);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
+ identify(imei);
}
- if (deviceId == null) {
+ if (!hasDeviceId()) {
return null;
}
@@ -82,7 +75,7 @@ public class CarscopProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
index = 1;
diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
index 178e17530..a61c5b79f 100644
--- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
- public CellocatorProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public CellocatorProtocolDecoder(String protocol) {
+ super(protocol);
}
private String readImei(ChannelBuffer buf) {
@@ -93,7 +93,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(4); // system code
int type = buf.readUnsignedByte();
- long deviceId = buf.readUnsignedInt();
+ long deviceUniqueId = buf.readUnsignedInt();
if (type != MSG_CLIENT_SERIAL) {
buf.readUnsignedShort(); // communication control
@@ -101,7 +101,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
byte packetNumber = buf.readByte();
// Send reply
- sendReply(channel, deviceId, packetNumber);
+ sendReply(channel, deviceUniqueId, packetNumber);
// Parse location
if (type == MSG_CLIENT_STATUS) {
@@ -109,13 +109,11 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
// Device identifier
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(String.valueOf(deviceId)).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + deviceId);
+ if (!identify(String.valueOf(deviceUniqueId))) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
buf.readUnsignedByte(); // hardware version
buf.readUnsignedByte(); // software version
buf.readUnsignedByte(); // protocol version
diff --git a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
index bbf1ce817..c32ac2228 100644
--- a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
@@ -32,11 +32,10 @@ import org.traccar.model.Position;
public class EasyTrackProtocolDecoder extends BaseProtocolDecoder {
- public EasyTrackProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public EasyTrackProtocolDecoder(String protocol) {
+ super(protocol);
}
- //ET,358155100003016,HB,A,0d081e,07381e,8038ee09,03d2e9be,004f,0000,40c00000,0f,100,0000,00037c,29
static private Pattern pattern = Pattern.compile(
"\\*..," + // Manufacturer
"(\\d+)," + // IMEI
@@ -82,19 +81,16 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Command
extendedInfo.set("command", parser.group(index++));
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java
index e63189dae..929153033 100644
--- a/src/org/traccar/protocol/EelinkProtocolDecoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class EelinkProtocolDecoder extends BaseProtocolDecoder {
- public EelinkProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public EelinkProtocolDecoder(String protocol) {
+ super(protocol);
}
private String readImei(ChannelBuffer buf) {
@@ -60,9 +60,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
private static final int MSG_OBD = 0x07;
private static final int MSG_INTERACTIVE = 0x80;
private static final int MSG_DATA = 0x81;
-
- private Long deviceId;
-
+
private void sendResponse(Channel channel, int type, int index) {
if (channel != null) {
ChannelBuffer response = ChannelBuffers.buffer(7);
@@ -91,15 +89,10 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
}
if (type == MSG_LOGIN) {
- String imei = ChannelBufferTools.readHexString(buf, 16).substring(1);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
+ identify(ChannelBufferTools.readHexString(buf, 16).substring(1));
}
- else if (deviceId != null &&
+ else if (hasDeviceId() &&
(type == MSG_GPS ||
type == MSG_ALARM ||
type == MSG_STATE ||
@@ -107,7 +100,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
extendedInfo.set("index", index);
diff --git a/src/org/traccar/protocol/EnforaProtocolDecoder.java b/src/org/traccar/protocol/EnforaProtocolDecoder.java
index 8f5391fd6..430693189 100644
--- a/src/org/traccar/protocol/EnforaProtocolDecoder.java
+++ b/src/org/traccar/protocol/EnforaProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class EnforaProtocolDecoder extends BaseProtocolDecoder {
- public EnforaProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public EnforaProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -101,12 +101,10 @@ public class EnforaProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Ev603ProtocolDecoder.java b/src/org/traccar/protocol/Ev603ProtocolDecoder.java
index 7c596d479..acf359daf 100644
--- a/src/org/traccar/protocol/Ev603ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Ev603ProtocolDecoder.java
@@ -33,10 +33,8 @@ import org.traccar.model.Position;
public class Ev603ProtocolDecoder extends BaseProtocolDecoder{
- private Long deviceId;
-
- public Ev603ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Ev603ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -58,25 +56,19 @@ public class Ev603ProtocolDecoder extends BaseProtocolDecoder{
// Detect device ID
if (sentence.startsWith("!1,")) {
- String imei = sentence.substring(3);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- return null;
- }
+ identify(sentence.substring(3));
}
else if (sentence.startsWith("!A,")) {
// Parse message
Matcher parser = pattern.matcher(sentence);
- if (deviceId == null || !parser.matches()) {
+ if (!hasDeviceId() || !parser.matches()) {
return null;
}
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
Integer index = 1;
diff --git a/src/org/traccar/protocol/FreedomProtocolDecoder.java b/src/org/traccar/protocol/FreedomProtocolDecoder.java
index 21e6f9abc..f8ab610b1 100644
--- a/src/org/traccar/protocol/FreedomProtocolDecoder.java
+++ b/src/org/traccar/protocol/FreedomProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class FreedomProtocolDecoder extends BaseProtocolDecoder {
- public FreedomProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public FreedomProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -63,14 +63,11 @@ public class FreedomProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identification
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Validity
position.setValid(true);
diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java
index 0fa881949..99b745175 100644
--- a/src/org/traccar/protocol/GalileoProtocolDecoder.java
+++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class GalileoProtocolDecoder extends BaseProtocolDecoder {
- public GalileoProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public GalileoProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int TAG_IMEI = 0x03;
@@ -77,9 +77,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
channel.write(reply);
}
}
-
- private Long deviceId;
-
+
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, Object msg)
@@ -113,11 +111,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
case TAG_IMEI:
String imei = buf.toString(buf.readerIndex(), 15, Charset.defaultCharset());
buf.skipBytes(imei.length());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
+ identify(imei);
break;
case TAG_DATE:
@@ -165,7 +159,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
position.setExtendedInfo(extendedInfo.toString());
positions.add(position);
- if (deviceId == null) {
+ if (!hasDeviceId()) {
Log.warning("Unknown device");
return null;
}
@@ -175,7 +169,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
for (Iterator<Position> i = positions.iterator(); i.hasNext(); ) {
Position p = i.next();
- p.setDeviceId(deviceId);
+ p.setDeviceId(getDeviceId());
if (p.getAltitude() == null) {
p.setAltitude(0.0);
diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java
index 5bc205214..33b8c501c 100644
--- a/src/org/traccar/protocol/GatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/GatorProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class GatorProtocolDecoder extends BaseProtocolDecoder {
- public GatorProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public GatorProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int PACKET_HEARTBEAT = 0x21;
@@ -75,12 +75,11 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder {
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
// Identification
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
+ return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Date and time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
diff --git a/src/org/traccar/protocol/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/Gl100ProtocolDecoder.java
index fb1e42cce..fb64d8dda 100644
--- a/src/org/traccar/protocol/Gl100ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl100ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Gl100ProtocolDecoder extends BaseProtocolDecoder {
- public Gl100ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Gl100ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -82,13 +82,10 @@ public class Gl100ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Validity
position.setValid(Integer.valueOf(parser.group(index++)) == 0);
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
index 1c20c5cc1..969be7611 100644
--- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
- public Gl200ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Gl200ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -78,13 +78,10 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Validity
position.setValid(Integer.valueOf(parser.group(index++)) < 20);
diff --git a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
index fd0c04bb4..1a0132c4a 100644
--- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
+++ b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
@@ -25,6 +25,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
import org.traccar.database.DataManager;
import org.traccar.helper.Log;
import org.traccar.model.ExtendedInfoFormatter;
@@ -36,9 +37,10 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder {
private String format0 = "TSPRXAB27GHKLMnaicz*U!";
private String format1 = "SARY*U!";
- public GlobalSatProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public GlobalSatProtocolDecoder(String protocol) {
+ super(protocol);
+ Properties properties = Context.getProps();
if (properties != null) {
if (properties.containsKey(protocol + ".format0")) {
format0 = properties.getProperty(protocol + ".format0");
@@ -97,12 +99,10 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder {
switch(format.charAt(formatIndex)) {
case 'S':
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(value).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + value);
+ if (!identify(value)) {
return null;
}
+ position.setDeviceId(getDeviceId());
break;
case 'A':
if (value.isEmpty()) {
@@ -215,13 +215,10 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identification
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Validity
position.setValid(parser.group(index++).compareTo("1") != 0);
diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
index 65f058bb6..3d981bb60 100644
--- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java
+++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
- public GoSafeProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public GoSafeProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -73,14 +73,11 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
diff --git a/src/org/traccar/protocol/GotopProtocolDecoder.java b/src/org/traccar/protocol/GotopProtocolDecoder.java
index 2e49a5dd0..80196c04a 100644
--- a/src/org/traccar/protocol/GotopProtocolDecoder.java
+++ b/src/org/traccar/protocol/GotopProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class GotopProtocolDecoder extends BaseProtocolDecoder {
- public GotopProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public GotopProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -67,13 +67,10 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Validity
position.setValid(parser.group(index++).compareTo("A") == 0);
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
index 0d8257e55..b99507ffb 100644
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
- public Gps103ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Gps103ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -99,13 +99,10 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Alarm message
extendedInfo.set("alarm", parser.group(index++));
diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
index 80e06c911..cb26d3a61 100644
--- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java
+++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
@@ -33,15 +33,10 @@ import org.traccar.model.Position;
public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public GpsGateProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public GpsGateProtocolDecoder(String protocol) {
+ super(protocol);
}
- /**
- * Regular expressions pattern
- */
private static final Pattern pattern = Pattern.compile(
"\\$GPRMC," +
"(\\d{2})(\\d{2})(\\d{2})\\.?(\\d+)?," + // Time (HHMMSS.SSS)
@@ -76,11 +71,11 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
int endIndex = sentence.indexOf(',', beginIndex);
if (endIndex != -1) {
String imei = sentence.substring(beginIndex, endIndex);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- send(channel, "$FRSES," + channel.getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (identify(imei)) {
+ if (channel != null) {
+ send(channel, "$FRSES," + channel.getId());
+ }
+ } else {
send(channel, "$FRERR,AuthError,Unknown device");
}
} else {
@@ -97,7 +92,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
}
// Process data
- else if (sentence.startsWith("$GPRMC,") && deviceId != null) {
+ else if (sentence.startsWith("$GPRMC,") && hasDeviceId()) {
// Parse message
Matcher parser = pattern.matcher(sentence);
@@ -108,7 +103,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
index 3857766c7..bab03d13f 100644
--- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
- public Gt02ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Gt02ProtocolDecoder(String protocol) {
+ super(protocol);
}
private String readImei(ChannelBuffer buf) {
@@ -84,12 +84,10 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
extendedInfo.set("index", index);
// Get device id
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Date and time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
index 1d81bb351..e94a7238b 100644
--- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -20,6 +20,7 @@ import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
import org.traccar.database.DataManager;
import org.traccar.helper.Crc;
import org.traccar.helper.Log;
@@ -32,19 +33,16 @@ import java.util.TimeZone;
public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
private boolean forceTimeZone = false;
private final TimeZone timeZone = TimeZone.getTimeZone("UTC");
- public Gt06ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
-
- if (properties != null) {
- if (properties.containsKey(protocol + ".timezone")) {
- forceTimeZone = true;
- timeZone.setRawOffset(
- Integer.valueOf(properties.getProperty(protocol + ".timezone")) * 1000);
- }
+ public Gt06ProtocolDecoder(String protocol) {
+ super(protocol);
+
+ Properties properties = Context.getProps();
+ if (properties != null && properties.containsKey(protocol + ".timezone")) {
+ forceTimeZone = true;
+ timeZone.setRawOffset(Integer.valueOf(properties.getProperty(protocol + ".timezone")) * 1000);
}
}
@@ -126,16 +124,13 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
timeZone.setRawOffset(offset);
}
}
-
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
+
+ if (identify(imei)) {
buf.skipBytes(buf.readableBytes() - 6);
sendResponse(channel, type, buf.readUnsignedShort());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
}
-
- } else if (deviceId != null && (
+
+ } else if (hasDeviceId() && (
type == MSG_GPS ||
type == MSG_GPS_LBS_1 ||
type == MSG_GPS_LBS_2 ||
@@ -147,7 +142,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
// Date and time
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index 84ddaf895..51d1ed8d0 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class H02ProtocolDecoder extends BaseProtocolDecoder {
- public H02ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public H02ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static double readCoordinate(ChannelBuffer buf, boolean lon) {
@@ -67,14 +67,11 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
buf.readByte(); // marker
// Identification
- String id = ChannelBufferTools.readHexString(buf, 10);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(ChannelBufferTools.readHexString(buf, 10))) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
@@ -141,13 +138,10 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/HaicomProtocolDecoder.java b/src/org/traccar/protocol/HaicomProtocolDecoder.java
index 078ee9ae6..ae070fd84 100644
--- a/src/org/traccar/protocol/HaicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/HaicomProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class HaicomProtocolDecoder extends BaseProtocolDecoder {
- public HaicomProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public HaicomProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -75,13 +75,10 @@ public class HaicomProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Firmware version
extendedInfo.set("version", parser.group(index++));
diff --git a/src/org/traccar/protocol/IntellitracProtocolDecoder.java b/src/org/traccar/protocol/IntellitracProtocolDecoder.java
index fa1837e50..3b03a6b2d 100644
--- a/src/org/traccar/protocol/IntellitracProtocolDecoder.java
+++ b/src/org/traccar/protocol/IntellitracProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class IntellitracProtocolDecoder extends BaseProtocolDecoder {
- public IntellitracProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public IntellitracProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -83,13 +83,10 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Detect device
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Date and time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
index 197b4103a..80c584d21 100644
--- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
- public Jt600ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Jt600ProtocolDecoder(String protocol) {
+ super(protocol);
}
private Position decodeNormalMessage(ChannelBuffer buf) throws Exception {
@@ -48,12 +48,10 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
// Get device by identifier
String id = Long.valueOf(ChannelBufferTools.readHexString(buf, 10)).toString();
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
- //return null;
+ if (!identify(id)) {
+ return null;
}
+ position.setDeviceId(getDeviceId());
// Protocol and type
int version = ChannelBufferTools.readHexInteger(buf, 1);
@@ -166,13 +164,10 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by identifier
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Longitude
Double longitude = Double.valueOf(parser.group(index++));
diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java
index 022def9eb..ed974d8ca 100644
--- a/src/org/traccar/protocol/KhdProtocolDecoder.java
+++ b/src/org/traccar/protocol/KhdProtocolDecoder.java
@@ -34,8 +34,8 @@ import org.traccar.model.Position;
public class KhdProtocolDecoder extends BaseProtocolDecoder {
- public KhdProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public KhdProtocolDecoder(String protocol) {
+ super(protocol);
}
private String readSerialNumber(ChannelBuffer buf) {
@@ -79,13 +79,11 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
// Device identification
- String id = readSerialNumber(buf);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(readSerialNumber(buf))) {
+ return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Date and time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java
index f95109b80..b868887ec 100644
--- a/src/org/traccar/protocol/LaipacProtocolDecoder.java
+++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class LaipacProtocolDecoder extends BaseProtocolDecoder {
- public LaipacProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public LaipacProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -78,12 +78,10 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identification
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
+ return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/M2mProtocolDecoder.java b/src/org/traccar/protocol/M2mProtocolDecoder.java
index 46442fb4f..0daa07422 100644
--- a/src/org/traccar/protocol/M2mProtocolDecoder.java
+++ b/src/org/traccar/protocol/M2mProtocolDecoder.java
@@ -31,12 +31,11 @@ import org.traccar.model.Position;
public class M2mProtocolDecoder extends BaseProtocolDecoder {
- public M2mProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public M2mProtocolDecoder(String protocol) {
+ super(protocol);
}
private boolean firstPacket = true;
- private Long deviceId;
@Override
protected Object decode(
@@ -68,18 +67,14 @@ public class M2mProtocolDecoder extends BaseProtocolDecoder {
}
// Identification
- try {
- deviceId = getDataManager().getDeviceByImei(imei.toString()).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
-
- } else if (deviceId != null) {
+ identify(imei.toString());
+
+ } else if (hasDeviceId()) {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// Date and time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/ManPowerProtocolDecoder.java b/src/org/traccar/protocol/ManPowerProtocolDecoder.java
index 449a1b532..dea190715 100644
--- a/src/org/traccar/protocol/ManPowerProtocolDecoder.java
+++ b/src/org/traccar/protocol/ManPowerProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class ManPowerProtocolDecoder extends BaseProtocolDecoder {
- public ManPowerProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public ManPowerProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern pattern = Pattern.compile(
@@ -72,13 +72,10 @@ public class ManPowerProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Alarm message
extendedInfo.set("status", parser.group(index++));
@@ -95,7 +92,7 @@ public class ManPowerProtocolDecoder extends BaseProtocolDecoder {
position.setTime(time.getTime());
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
diff --git a/src/org/traccar/protocol/MaxonProtocolDecoder.java b/src/org/traccar/protocol/MaxonProtocolDecoder.java
index eb1e43885..cd86e5e65 100644
--- a/src/org/traccar/protocol/MaxonProtocolDecoder.java
+++ b/src/org/traccar/protocol/MaxonProtocolDecoder.java
@@ -38,21 +38,12 @@ import org.traccar.model.Position;
*/
public class MaxonProtocolDecoder extends BaseProtocolDecoder {
- /**
- * Device ID
- */
private Position position = null;
- /**
- * Initialize
- */
- public MaxonProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public MaxonProtocolDecoder(String protocol) {
+ super(protocol);
}
- /**
- * Regular expressions pattern
- */
static private Pattern pattern = Pattern.compile(
"\\$GPRMC," +
"(\\d{2})(\\d{2})(\\d{2})\\.(\\d{2})," + // Time (HHMMSS.SSS)
@@ -66,12 +57,8 @@ public class MaxonProtocolDecoder extends BaseProtocolDecoder {
"(\\d{2})(\\d{2})(\\d{2})" + // Date (DDMMYY)
".+"); // Other (Checksumm)
- static private Pattern gpfidPattern = Pattern.compile(
- "\\$GPFID,(\\d+)$");
+ static private Pattern gpfidPattern = Pattern.compile("\\$GPFID,(\\d+)$");
- /**
- * Decode message"
- */
protected Object decode(
ChannelHandlerContext ctx, Channel channel, Object msg)
throws Exception {
@@ -102,7 +89,7 @@ public class MaxonProtocolDecoder extends BaseProtocolDecoder {
index += 1; // Skip milliseconds
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
@@ -145,13 +132,10 @@ public class MaxonProtocolDecoder extends BaseProtocolDecoder {
Matcher parser = gpfidPattern.matcher(sentence);
if (parser.matches()) {
- String imei = parser.group(1);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(1))) {
return null;
}
+ position.setDeviceId(getDeviceId());
return position;
}
}
diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java
index 2eed12fce..4a621245a 100644
--- a/src/org/traccar/protocol/MegastekProtocolDecoder.java
+++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class MegastekProtocolDecoder extends BaseProtocolDecoder {
- public MegastekProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public MegastekProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern patternGPRMC = Pattern.compile(
@@ -49,7 +49,6 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
"(\\d{2})(\\d{2})(\\d{2})" + // Date (DDMMYY)
"[^\\*]+\\*[0-9a-fA-F]{2}"); // Checksum
- //F,,imei:123456789012345,0/6,,Battery=100%,,0,,,5856,78A3;24
private static final Pattern patternSimple = Pattern.compile(
"[FL]," + // Flag
"([^,]*)," + // Alarm
@@ -200,17 +199,12 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
extendedInfo.set("alarm", parser.group(index++));
// IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception firstError) {
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception secondError) {
- Log.warning("Unknown device - " + imei + " (id - " + id + ")");
+ if (!identify(parser.group(index++), false)) {
+ if (!identify(id)) {
return null;
}
}
+ position.setDeviceId(getDeviceId());
// Satellites
extendedInfo.set("satellites", parser.group(index++));
@@ -248,13 +242,11 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
// Altitude
position.setAltitude(0.0);
-
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+
+ if (!identify(id)) {
return null;
}
+ position.setDeviceId(getDeviceId());
extendedInfo.set("mcc", parser.group(index++));
extendedInfo.set("mnc", parser.group(index++));
diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
index 9c1f5bee9..547821c69 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
@@ -29,6 +29,7 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
import org.traccar.database.DataManager;
import org.traccar.helper.Crc;
import org.traccar.helper.Log;
@@ -37,8 +38,8 @@ import org.traccar.model.Position;
public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
- public MeiligaoProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public MeiligaoProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -117,7 +118,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
}
private String getMeiligaoServer(Channel channel) {
- Properties p = getProperties();
+ Properties p = Context.getProps();
if (p != null && p.containsKey(getProtocol() + ".server")) {
return p.getProperty(getProtocol() + ".server");
@@ -179,13 +180,10 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
}
// Get device by id
- String imei = getImei(id);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(getImei(id))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Parse message
String sentence = buf.toString(
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
index cdeef155b..e213b7ddb 100644
--- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
@@ -38,8 +38,8 @@ import org.traccar.model.Position;
public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
- public MeitrackProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public MeitrackProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -91,13 +91,10 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identification
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Event
int event = Integer.valueOf(parser.group(index++));
@@ -191,22 +188,18 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
int index = ChannelBufferTools.find(buf, 0, buf.readableBytes(), ",");
// Identification
- long deviceId;
String imei = buf.toString(index + 1, 15, Charset.defaultCharset());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
-
+
buf.skipBytes(index + 1 + 15 + 1 + 3 + 1 + 2 + 2 + 4);
while (buf.readableBytes() >= 0x34) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// Event
extendedInfo.set("event", buf.readUnsignedByte());
diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
index 9a6c7396c..c37e44659 100644
--- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
+++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
@@ -32,10 +32,8 @@ import org.traccar.model.Position;
public class MiniFinderProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public MiniFinderProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public MiniFinderProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -62,16 +60,11 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder {
// Identification
if (sentence.startsWith("!1")) {
- String imei = sentence.substring(3, sentence.length());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
+ identify(sentence.substring(3, sentence.length()));
}
// Location
- else if (sentence.startsWith("!D") && deviceId != null) {
+ else if (sentence.startsWith("!D") && hasDeviceId()) {
// Parse message
Matcher parser = pattern.matcher(sentence);
@@ -82,7 +75,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
index d8d1b9f98..f09cf32f1 100644
--- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
@@ -44,8 +44,8 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
private boolean simple;
- public Mta6ProtocolDecoder(DataManager dataManager, String protocol, Properties properties, boolean simple) {
- super(dataManager, protocol, properties);
+ public Mta6ProtocolDecoder(String protocol, boolean simple) {
+ super(protocol);
this.simple = simple;
}
@@ -121,7 +121,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
}
- private List<Position> parseFormatA(ChannelBuffer buf, long deviceId) {
+ private List<Position> parseFormatA(ChannelBuffer buf) {
List<Position> positions = new LinkedList<Position>();
FloatReader latitudeReader = new FloatReader();
@@ -131,7 +131,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
try {
while (buf.readable()) {
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
short flags = buf.readUnsignedByte();
@@ -211,9 +211,9 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
return positions;
}
- private Position parseFormatA1(ChannelBuffer buf, long deviceId) {
+ private Position parseFormatA1(ChannelBuffer buf) {
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
short flags = buf.readUnsignedByte();
@@ -303,11 +303,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes("id=".length());
int index = ChannelBufferTools.find(buf, buf.readerIndex(), length, "&");
String uniqueId = buf.toString(buf.readerIndex(), index - buf.readerIndex(), Charset.defaultCharset());
- long deviceId;
- try {
- deviceId = getDataManager().getDeviceByImei(uniqueId).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + uniqueId);
+ if (!identify(uniqueId)) {
return null;
}
buf.skipBytes(uniqueId.length());
@@ -330,9 +326,9 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
// Parse data
if (packetId == 0x31 || packetId == 0x32 || packetId == 0x36) {
if (simple) {
- return parseFormatA1(buf, deviceId);
+ return parseFormatA1(buf);
} else {
- return parseFormatA(buf, deviceId);
+ return parseFormatA(buf);
}
} //else if (0x34 0x38 0x4F 0x59)
diff --git a/src/org/traccar/protocol/MtxProtocolDecoder.java b/src/org/traccar/protocol/MtxProtocolDecoder.java
index c552e3831..150e95e3b 100644
--- a/src/org/traccar/protocol/MtxProtocolDecoder.java
+++ b/src/org/traccar/protocol/MtxProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class MtxProtocolDecoder extends BaseProtocolDecoder {
- public MtxProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public MtxProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -79,13 +79,10 @@ public class MtxProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java
index eb9ad96d3..f12e15fb6 100644
--- a/src/org/traccar/protocol/NavigilProtocolDecoder.java
+++ b/src/org/traccar/protocol/NavigilProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class NavigilProtocolDecoder extends BaseProtocolDecoder {
- public NavigilProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public NavigilProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int LEAP_SECONDS_DELTA = 25;
@@ -81,13 +81,13 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
}
}
- private Position parseUnitReport(ChannelBuffer buf, long deviceId, int sequenceNumber) {
+ private Position parseUnitReport(ChannelBuffer buf, int sequenceNumber) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
position.setValid(true);
extendedInfo.set("index", sequenceNumber);
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
buf.readUnsignedShort(); // report trigger
buf.readUnsignedShort(); // flags
@@ -118,13 +118,13 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Position parseTg2Report(ChannelBuffer buf, long deviceId, int sequenceNumber) {
+ private Position parseTg2Report(ChannelBuffer buf, int sequenceNumber) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
position.setValid(true);
extendedInfo.set("index", sequenceNumber);
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
buf.readUnsignedShort(); // report trigger
buf.readUnsignedByte(); // reserved
@@ -157,12 +157,12 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Position parsePositionReport(ChannelBuffer buf, long deviceId, int sequenceNumber, long timestamp) {
+ private Position parsePositionReport(ChannelBuffer buf, int sequenceNumber, long timestamp) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
extendedInfo.set("index", sequenceNumber);
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
position.setTime(convertTimestamp(timestamp));
position.setLatitude(buf.readMedium() * 0.00002);
@@ -181,12 +181,12 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Position parsePositionReport2(ChannelBuffer buf, long deviceId, int sequenceNumber, long timestamp) {
+ private Position parsePositionReport2(ChannelBuffer buf, int sequenceNumber, long timestamp) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
extendedInfo.set("index", sequenceNumber);
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
position.setTime(convertTimestamp(timestamp));
position.setLatitude(buf.readInt() * 0.0000001);
@@ -208,12 +208,12 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Position parseSnapshot4(ChannelBuffer buf, long deviceId, int sequenceNumber) {
+ private Position parseSnapshot4(ChannelBuffer buf, int sequenceNumber) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
extendedInfo.set("index", sequenceNumber);
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
buf.readUnsignedByte(); // report trigger
buf.readUnsignedByte(); // position fix source
@@ -249,12 +249,12 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Position parseTrackingData(ChannelBuffer buf, long deviceId, int sequenceNumber, long timestamp) {
+ private Position parseTrackingData(ChannelBuffer buf, int sequenceNumber, long timestamp) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
extendedInfo.set("index", sequenceNumber);
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
position.setTime(convertTimestamp(timestamp));
buf.readUnsignedByte(); // tracking mode
@@ -296,12 +296,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedShort(); // checksum
// Get device identifier
- long deviceId;
- String navigilDeviceId = String.valueOf(buf.readUnsignedInt());
- try {
- deviceId = getDataManager().getDeviceByImei(navigilDeviceId).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + navigilDeviceId);
+ if (!identify(String.valueOf(buf.readUnsignedInt()))) {
return null;
}
@@ -315,17 +310,17 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
// Parse messages
switch (messageId) {
case MESSAGE_UNIT_REPORT:
- return parseUnitReport(buf, deviceId, sequenceNumber);
+ return parseUnitReport(buf, sequenceNumber);
case MESSAGE_TG2_REPORT:
- return parseTg2Report(buf, deviceId, sequenceNumber);
+ return parseTg2Report(buf, sequenceNumber);
case MESSAGE_POSITION_REPORT:
- return parsePositionReport(buf, deviceId, sequenceNumber, timestamp);
+ return parsePositionReport(buf, sequenceNumber, timestamp);
case MESSAGE_POSITION_REPORT_2:
- return parsePositionReport2(buf, deviceId, sequenceNumber, timestamp);
+ return parsePositionReport2(buf, sequenceNumber, timestamp);
case MESSAGE_SNAPSHOT4:
- return parseSnapshot4(buf, deviceId, sequenceNumber);
+ return parseSnapshot4(buf, sequenceNumber);
case MESSAGE_TRACKING_DATA:
- return parseTrackingData(buf, deviceId, sequenceNumber, timestamp);
+ return parseTrackingData(buf, sequenceNumber, timestamp);
}
return null;
diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java
index 4646d215f..8a5afc17f 100644
--- a/src/org/traccar/protocol/NavisProtocolDecoder.java
+++ b/src/org/traccar/protocol/NavisProtocolDecoder.java
@@ -37,15 +37,12 @@ import org.traccar.model.Position;
public class NavisProtocolDecoder extends BaseProtocolDecoder {
private String prefix;
- private long deviceId, serverId;
+ private long deviceUniqueId, serverId;
private static final Charset charset = Charset.defaultCharset();
- private String imei;
- private Long databaseDeviceId;
-
- public NavisProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public NavisProtocolDecoder(String protocol) {
+ super(protocol);
}
// Format types
@@ -88,7 +85,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(databaseDeviceId);
+ position.setDeviceId(getDeviceId());
position.setAltitude(0.0);
// Format type
@@ -262,12 +259,8 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
private Object processHandshake(Channel channel, ChannelBuffer buf) {
buf.readByte(); // semicolon symbol
- imei = buf.toString(Charset.defaultCharset());
- try {
- databaseDeviceId = getDataManager().getDeviceByImei(imei).getId();
+ if (identify(buf.toString(Charset.defaultCharset()))) {
sendReply(channel, ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<S", charset));
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
}
return null;
}
@@ -283,7 +276,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
private void sendReply(Channel channel, ChannelBuffer data) {
ChannelBuffer header = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 16);
header.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, prefix, charset));
- header.writeInt((int) deviceId);
+ header.writeInt((int) deviceUniqueId);
header.writeInt((int) serverId);
header.writeShort(data.readableBytes());
header.writeByte(checksum(data));
@@ -305,7 +298,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
prefix = buf.toString(buf.readerIndex(), 4, charset);
buf.skipBytes(prefix.length()); // prefix @NTC by default
serverId = buf.readUnsignedInt();
- deviceId = buf.readUnsignedInt();
+ deviceUniqueId = buf.readUnsignedInt();
int length = buf.readUnsignedShort();
buf.skipBytes(2); // header and data XOR checksum
diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java
index b6fa93607..bc807711d 100644
--- a/src/org/traccar/protocol/NoranProtocolDecoder.java
+++ b/src/org/traccar/protocol/NoranProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class NoranProtocolDecoder extends BaseProtocolDecoder {
- public NoranProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public NoranProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int MSG_UPLOAD_POSITION = 0x0008;
@@ -111,13 +111,11 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
// Identification
String id = buf.readBytes(11).toString(Charset.defaultCharset()).replaceAll("[^\\p{Print}]", "");
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// IO status
extendedInfo.set("io", buf.readUnsignedByte());
diff --git a/src/org/traccar/protocol/OrionProtocolDecoder.java b/src/org/traccar/protocol/OrionProtocolDecoder.java
index f20bb6d72..3b4b598b1 100644
--- a/src/org/traccar/protocol/OrionProtocolDecoder.java
+++ b/src/org/traccar/protocol/OrionProtocolDecoder.java
@@ -34,8 +34,8 @@ import org.traccar.model.Position;
public class OrionProtocolDecoder extends BaseProtocolDecoder {
- public OrionProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public OrionProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int TYPE_USERLOG = 0;
@@ -74,23 +74,18 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder {
if ((header & 0x40) != 0) {
sendResponse(channel, buf);
}
-
- String id = String.valueOf(buf.readUnsignedInt());
- long deviceId;
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+
+ if (!identify(String.valueOf(buf.readUnsignedInt()))) {
return null;
}
-
+
List<Position> positions = new LinkedList<Position>();
for (int i = 0; i < (header & 0x0f); i++) {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
extendedInfo.set("event", buf.readUnsignedByte());
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index f773a4633..85cf1219c 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -41,8 +41,8 @@ import org.traccar.model.Position;
public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
- public OsmAndProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public OsmAndProtocolDecoder(String protocol) {
+ super(protocol);
}
@Override
@@ -65,12 +65,10 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
// Identification
String id = params.get(params.containsKey("id") ? "id" : "deviceid").get(0);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Decode position
position.setValid(true);
diff --git a/src/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/org/traccar/protocol/PiligrimProtocolDecoder.java
index 02c86152d..1c0faef37 100644
--- a/src/org/traccar/protocol/PiligrimProtocolDecoder.java
+++ b/src/org/traccar/protocol/PiligrimProtocolDecoder.java
@@ -42,8 +42,8 @@ import org.traccar.model.Position;
public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
- public PiligrimProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public PiligrimProtocolDecoder(String protocol) {
+ super(protocol);
}
private void sendResponse(Channel channel, String message) {
@@ -85,13 +85,8 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
sendResponse(channel, "BINGPS: OK");
// Identification
- long deviceId;
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
- String imei = decoder.getParameters().get("imei").get(0);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(decoder.getParameters().get("imei").get(0))) {
return null;
}
@@ -108,7 +103,7 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@@ -178,9 +173,7 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
} else if (type == MSG_EVENTS) {
buf.skipBytes(13);
-
}
-
}
return positions;
diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java
index 3f120445c..04584b884 100644
--- a/src/org/traccar/protocol/ProgressProtocolDecoder.java
+++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java
@@ -34,22 +34,15 @@ import org.traccar.helper.Log;
import org.traccar.model.ExtendedInfoFormatter;
import org.traccar.model.Position;
-/**
- * Progress tracker protocol decoder
- */
public class ProgressProtocolDecoder extends BaseProtocolDecoder {
- private long deviceId;
private long lastIndex;
private long newIndex;
- public ProgressProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public ProgressProtocolDecoder(String protocol) {
+ super(protocol);
}
- /*
- * Message types
- */
private static final int MSG_NULL = 0;
private static final int MSG_IDENT = 1;
private static final int MSG_IDENT_FULL = 2;
@@ -80,9 +73,6 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder {
}*/
}
- /**
- * Request archive messages
- */
private void requestArchive(Channel channel) {
if (lastIndex == 0) {
lastIndex = newIndex;
@@ -112,16 +102,13 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(length);
length = buf.readUnsignedShort();
String imei = buf.readBytes(length).toString(Charset.defaultCharset());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
+ if (identify(imei)) {
loadLastIndex();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei + " (id - " + id + ")");
}
}
// Position
- else if (deviceId != 0 && (type == MSG_POINT || type == MSG_ALARM || type == MSG_LOGMSG)) {
+ else if (hasDeviceId() && (type == MSG_POINT || type == MSG_ALARM || type == MSG_LOGMSG)) {
List<Position> positions = new LinkedList<Position>();
int recordCount = 1;
@@ -132,7 +119,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder {
for (int j = 0; j < recordCount; j++) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// Message index
if (type == MSG_LOGMSG) {
diff --git a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
index 86c438f6c..513fdbb4b 100644
--- a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Pt3000ProtocolDecoder extends BaseProtocolDecoder {
- public Pt3000ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Pt3000ProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern pattern = Pattern.compile(
@@ -70,12 +70,10 @@ public class Pt3000ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identifier
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
+ if (!identify(parser.group(index++))) {
+ return null;
+ }
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@@ -85,7 +83,7 @@ public class Pt3000ProtocolDecoder extends BaseProtocolDecoder {
time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++)));
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java
index 72f95a0f6..2cf5ad3d6 100644
--- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
- public Pt502ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Pt502ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -71,13 +71,10 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/RitiProtocolDecoder.java b/src/org/traccar/protocol/RitiProtocolDecoder.java
index 4bc04501c..58e744f1a 100644
--- a/src/org/traccar/protocol/RitiProtocolDecoder.java
+++ b/src/org/traccar/protocol/RitiProtocolDecoder.java
@@ -35,8 +35,8 @@ import org.traccar.model.Position;
public class RitiProtocolDecoder extends BaseProtocolDecoder {
- public RitiProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public RitiProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -66,13 +66,11 @@ public class RitiProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(2); // header
// Get device id
- String id = String.valueOf(buf.readUnsignedShort());
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(String.valueOf(buf.readUnsignedShort()))) {
+ return null;
}
-
+ position.setDeviceId(getDeviceId());
+
extendedInfo.set("mode", buf.readUnsignedByte());
extendedInfo.set("command", buf.readUnsignedByte());
extendedInfo.set("power", buf.readUnsignedShort());
diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
index 0574aa2d8..b83d9f721 100644
--- a/src/org/traccar/protocol/RuptelaProtocolDecoder.java
+++ b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
- public RuptelaProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public RuptelaProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int COMMAND_RECORDS = 0x01;
@@ -49,14 +49,10 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
// Identify device
String imei = String.format("%015d", buf.readLong());
- long deviceId;
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
return null;
}
-
+
int type = buf.readUnsignedByte();
if (type == COMMAND_RECORDS) {
@@ -68,7 +64,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
for (int i = 0; i < count; i++) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// Time
position.setTime(new Date(buf.readUnsignedInt() * 1000));
diff --git a/src/org/traccar/protocol/SanavProtocolDecoder.java b/src/org/traccar/protocol/SanavProtocolDecoder.java
index 343dc87c8..abdb25d2c 100644
--- a/src/org/traccar/protocol/SanavProtocolDecoder.java
+++ b/src/org/traccar/protocol/SanavProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class SanavProtocolDecoder extends BaseProtocolDecoder {
- public SanavProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public SanavProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -69,13 +69,10 @@ public class SanavProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identification
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
index aa47e42fb..51150a8e9 100644
--- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
+++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class SkypatrolProtocolDecoder extends BaseProtocolDecoder {
- public SkypatrolProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public SkypatrolProtocolDecoder(String protocol) {
+ super(protocol);
}
private static boolean checkBit(long mask, int bit) {
@@ -98,12 +98,10 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder {
Log.warning("No device id field");
return null;
}
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
return null;
}
+ position.setDeviceId(getDeviceId());
// IO data
if (checkBit(mask, 3)) {
diff --git a/src/org/traccar/protocol/Stl060ProtocolDecoder.java b/src/org/traccar/protocol/Stl060ProtocolDecoder.java
index 51af0941e..44cf20118 100644
--- a/src/org/traccar/protocol/Stl060ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Stl060ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Stl060ProtocolDecoder extends BaseProtocolDecoder {
- public Stl060ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Stl060ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -75,13 +75,10 @@ public class Stl060ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Device identification
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java
index cdfca7905..b2bbcf573 100644
--- a/src/org/traccar/protocol/SuntechProtocolDecoder.java
+++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class SuntechProtocolDecoder extends BaseProtocolDecoder {
- public SuntechProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public SuntechProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern pattern = Pattern.compile(
@@ -70,13 +70,10 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
int index = 1;
// Identifier
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Version
extendedInfo.set("version", parser.group(index++));
diff --git a/src/org/traccar/protocol/SyrusProtocolDecoder.java b/src/org/traccar/protocol/SyrusProtocolDecoder.java
index ee11b35ef..5b7440bf9 100644
--- a/src/org/traccar/protocol/SyrusProtocolDecoder.java
+++ b/src/org/traccar/protocol/SyrusProtocolDecoder.java
@@ -35,9 +35,8 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder {
boolean sendResponse;
-
- public SyrusProtocolDecoder(DataManager dataManager, String protocol, Properties properties, boolean sendResponse) {
- super(dataManager, protocol, properties);
+ public SyrusProtocolDecoder(String protocol, boolean sendResponse) {
+ super(protocol);
this.sendResponse = sendResponse;
}
@@ -102,7 +101,6 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder {
}
// Find device ID
- Long deviceId = null;
beginIndex = sentence.indexOf(";ID=");
if (beginIndex != -1) {
beginIndex += 4;
@@ -113,13 +111,10 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder {
// Find device in database
String id = sentence.substring(beginIndex, endIndex);
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
return null;
}
-
+
// Send response
if (sendResponse && channel != null) {
channel.write(id);
@@ -137,7 +132,7 @@ public class SyrusProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java
index 25b7f367f..ccf56ea41 100644
--- a/src/org/traccar/protocol/T55ProtocolDecoder.java
+++ b/src/org/traccar/protocol/T55ProtocolDecoder.java
@@ -32,10 +32,8 @@ import org.traccar.model.Position;
public class T55ProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public T55ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public T55ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern patternGPRMC = Pattern.compile(
@@ -83,15 +81,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
"(-?\\d+\\.\\d+)," + // Altitude
"(\\d+\\.?\\d*)," + // Battery
".+");
-
- private void identify(String id) {
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
- }
- }
-
+
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, Object msg)
@@ -135,7 +125,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
}
// Location
- else if (sentence.startsWith("$GPRMC") && deviceId != null) {
+ else if (sentence.startsWith("$GPRMC") && hasDeviceId()) {
// Send response
if (channel != null) {
@@ -151,7 +141,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
@@ -207,7 +197,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
}
// Location
- else if (sentence.startsWith("$GPGGA") && deviceId != null) {
+ else if (sentence.startsWith("$GPGGA") && hasDeviceId()) {
// Parse message
Matcher parser = patternGPGGA.matcher(sentence);
@@ -218,7 +208,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
@@ -259,7 +249,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
}
// Location
- else if (sentence.startsWith("$GPRMA") && deviceId != null) {
+ else if (sentence.startsWith("$GPRMA") && hasDeviceId()) {
// Parse message
Matcher parser = patternGPRMA.matcher(sentence);
@@ -270,7 +260,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
@@ -316,7 +306,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
}
// Location
- else if (sentence.startsWith("$TRCCR") && deviceId != null) {
+ else if (sentence.startsWith("$TRCCR") && hasDeviceId()) {
// Parse message
Matcher parser = patternTRCCR.matcher(sentence);
@@ -327,7 +317,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
diff --git a/src/org/traccar/protocol/TelikProtocolDecoder.java b/src/org/traccar/protocol/TelikProtocolDecoder.java
index 84dd6fb0b..15ad77e6b 100644
--- a/src/org/traccar/protocol/TelikProtocolDecoder.java
+++ b/src/org/traccar/protocol/TelikProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class TelikProtocolDecoder extends BaseProtocolDecoder {
- public TelikProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TelikProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -70,13 +70,10 @@ public class TelikProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Message type
extendedInfo.set("type", parser.group(index++));
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index 961d4e73b..f39a81fbc 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -36,8 +36,8 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
private long deviceId;
- public TeltonikaProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TeltonikaProtocolDecoder(String protocol) {
+ super(protocol);
}
private void parseIdentification(Channel channel, ChannelBuffer buf) {
@@ -45,13 +45,8 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
int length = buf.readUnsignedShort();
String imei = buf.toString(buf.readerIndex(), length, Charset.defaultCharset());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- result = true;
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
-
+ result = identify(imei);
+
if (channel != null) {
ChannelBuffer response = ChannelBuffers.directBuffer(1);
response.writeByte(result ? 1 : 0);
diff --git a/src/org/traccar/protocol/Tk102ProtocolDecoder.java b/src/org/traccar/protocol/Tk102ProtocolDecoder.java
index bb9a5fbd2..b32b020d1 100644
--- a/src/org/traccar/protocol/Tk102ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk102ProtocolDecoder.java
@@ -32,10 +32,8 @@ import org.traccar.model.Position;
public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public Tk102ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Tk102ProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern pattern = Pattern.compile(
@@ -59,11 +57,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
// Login
if (sentence.startsWith("[!")) {
- String imei = sentence.substring(14, 14 + 15);
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(sentence.substring(14, 14 + 15))) {
return null;
}
@@ -78,7 +72,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
}
// Parse message
- else if (deviceId != null) {
+ else if (hasDeviceId()) {
// Parse message
Matcher parser = pattern.matcher(sentence);
@@ -89,7 +83,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
@@ -101,7 +95,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++)));
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index f8955b1df..fa589956a 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
- public Tk103ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Tk103ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -89,18 +89,10 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- // Compatibility mode (remove in future)
- try {
- position.setDeviceId(getDataManager().getDeviceByImei("000" + imei).getId());
- } catch(Exception error2) {
- Log.warning("Unknown device - " + imei);
- return null;
- }
+ if (!identify(parser.group(index++))) {
+ return null;
}
+ position.setDeviceId(getDeviceId());
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
index 0e17fc70c..01c1ac2aa 100644
--- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
@@ -34,8 +34,8 @@ import org.traccar.model.Position;
public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
- public Tlt2hProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Tlt2hProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern patternHeader = Pattern.compile(
@@ -75,15 +75,10 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
}
// Get device identifier
- String imei = parser.group(1);
- long deviceId;
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(1))) {
return null;
}
-
+
// Get status
String status = parser.group(2);
@@ -95,7 +90,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
if (parser.matches()) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
diff --git a/src/org/traccar/protocol/TopflytechProtocolDecoder.java b/src/org/traccar/protocol/TopflytechProtocolDecoder.java
index 9e9a7e3e3..20c4e54ad 100644
--- a/src/org/traccar/protocol/TopflytechProtocolDecoder.java
+++ b/src/org/traccar/protocol/TopflytechProtocolDecoder.java
@@ -34,8 +34,8 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder {
private Long deviceId;
- public TopflytechProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TopflytechProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern pattern = Pattern.compile(
@@ -71,13 +71,10 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identifier
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
@@ -91,7 +88,7 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder {
position.setTime(time.getTime());
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java
index 5c0cc9bec..ae8335b78 100644
--- a/src/org/traccar/protocol/TotemProtocolDecoder.java
+++ b/src/org/traccar/protocol/TotemProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class TotemProtocolDecoder extends BaseProtocolDecoder {
- public TotemProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TotemProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern patternFirst = Pattern.compile(
@@ -156,7 +156,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
} else if (format == MessageFormat.third) {
parser = patternThird.matcher(sentence);
}
- if (parser == null || !parser.matches()) {
+ if (!parser.matches()) {
return null;
}
@@ -167,13 +167,10 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Alarm type
extendedInfo.set("alarm", parser.group(index++));
diff --git a/src/org/traccar/protocol/Tr20ProtocolDecoder.java b/src/org/traccar/protocol/Tr20ProtocolDecoder.java
index fb6f319d5..9bd1ccaaf 100644
--- a/src/org/traccar/protocol/Tr20ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tr20ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Tr20ProtocolDecoder extends BaseProtocolDecoder {
- public Tr20ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Tr20ProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern patternPing = Pattern.compile(
@@ -85,16 +85,13 @@ public class Tr20ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by id
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Tr900ProtocolDecoder.java b/src/org/traccar/protocol/Tr900ProtocolDecoder.java
index da307efc9..f8890f954 100644
--- a/src/org/traccar/protocol/Tr900ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tr900ProtocolDecoder.java
@@ -31,8 +31,8 @@ import java.util.regex.Pattern;
public class Tr900ProtocolDecoder extends BaseProtocolDecoder {
- public Tr900ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Tr900ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -76,13 +76,10 @@ public class Tr900ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identification
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Validity
position.setValid(parser.group(index++).compareTo("1") == 0);
diff --git a/src/org/traccar/protocol/TrackboxProtocolDecoder.java b/src/org/traccar/protocol/TrackboxProtocolDecoder.java
index 186bc24cd..5be74b15d 100644
--- a/src/org/traccar/protocol/TrackboxProtocolDecoder.java
+++ b/src/org/traccar/protocol/TrackboxProtocolDecoder.java
@@ -32,10 +32,8 @@ import org.traccar.model.Position;
public class TrackboxProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public TrackboxProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TrackboxProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -66,11 +64,8 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder {
if (sentence.startsWith("a=connect")) {
String id = sentence.substring(sentence.indexOf("i=") + 2);
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
+ if (identify(id)) {
sendResponse(channel);
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
}
}
@@ -84,7 +79,7 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder {
// Create new position
Position position = new Position();
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
Integer index = 1;
diff --git a/src/org/traccar/protocol/TramigoProtocolDecoder.java b/src/org/traccar/protocol/TramigoProtocolDecoder.java
index a31f3294b..e0bab0483 100644
--- a/src/org/traccar/protocol/TramigoProtocolDecoder.java
+++ b/src/org/traccar/protocol/TramigoProtocolDecoder.java
@@ -37,8 +37,8 @@ import java.util.regex.Pattern;
public class TramigoProtocolDecoder extends BaseProtocolDecoder {
- public TramigoProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TramigoProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final int MSG_COMPACT = 0x0100;
@@ -68,12 +68,10 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder {
position.setValid(true);
// Get device id
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(String.valueOf(id)).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(String.valueOf(id))) {
return null;
}
+ position.setDeviceId(getDeviceId());
if (protocol == 0x01 && (type == MSG_COMPACT || type == MSG_FULL)) {
@@ -147,7 +145,6 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder {
position.setExtendedInfo(extendedInfo.toString());
return position;
-
}
return null;
diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java
index 5b3772d31..e0dc7f68e 100644
--- a/src/org/traccar/protocol/TytanProtocolDecoder.java
+++ b/src/org/traccar/protocol/TytanProtocolDecoder.java
@@ -34,13 +34,10 @@ import org.traccar.model.Position;
public class TytanProtocolDecoder extends BaseProtocolDecoder {
- public TytanProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public TytanProtocolDecoder(String protocol) {
+ super(protocol);
}
- private static final int MSG_HEARTBEAT = 0x1A;
- private static final int MSG_DATA = 0x10;
-
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, SocketAddress remoteAddress, Object msg)
@@ -58,21 +55,17 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
}
String id = String.valueOf(buf.readUnsignedInt());
- long deviceId;
- try {
- deviceId = getDataManager().getDeviceByImei(id).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
return null;
}
-
+
List<Position> positions = new LinkedList<Position>();
while (buf.readable()) {
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
int end = buf.readerIndex() + buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
index c5f63812e..48122a8f3 100644
--- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java
+++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
@@ -30,8 +30,8 @@ import java.util.Properties;
public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
- public UlbotechProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public UlbotechProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final short DATA_GPS = 0x01;
@@ -63,11 +63,10 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
// Get device id
String imei = ChannelBufferTools.readHexString(buf, 16).substring(1);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(imei)) {
+ return null;
}
+ position.setDeviceId(getDeviceId());
// Time
long seconds = buf.readUnsignedInt() & 0x7fffffffl;
@@ -82,7 +81,6 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
switch (type) {
case DATA_GPS:
-
position.setValid(true);
position.setLatitude(buf.readInt() / 1000000.0);
position.setLongitude(buf.readInt() / 1000000.0);
@@ -90,10 +88,8 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
position.setSpeed(buf.readUnsignedShort() * 0.539957);
position.setCourse((double) buf.readUnsignedShort());
extendedInfo.set("hdop", buf.readUnsignedShort());
-
break;
-
default:
buf.skipBytes(length);
break;
diff --git a/src/org/traccar/protocol/V680ProtocolDecoder.java b/src/org/traccar/protocol/V680ProtocolDecoder.java
index 95f4e101c..6e85640c0 100644
--- a/src/org/traccar/protocol/V680ProtocolDecoder.java
+++ b/src/org/traccar/protocol/V680ProtocolDecoder.java
@@ -32,10 +32,8 @@ import org.traccar.model.Position;
public class V680ProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public V680ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public V680ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -68,11 +66,7 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder {
// Detect device ID
if (sentence.length() == 16) {
String imei = sentence.substring(1, sentence.length());
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- }
+ identify(imei);
} else {
// Parse message
@@ -89,17 +83,12 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder {
// Get device by IMEI
String imei = parser.group(index++);
if (imei != null) {
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
- return null;
- }
+ identify(imei);
}
- if (deviceId == null) {
+ if (!hasDeviceId()) {
return null;
}
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
// User
extendedInfo.set("user", parser.group(index++));
diff --git a/src/org/traccar/protocol/VisiontekProtocolDecoder.java b/src/org/traccar/protocol/VisiontekProtocolDecoder.java
index 242ac1083..b61500bd9 100644
--- a/src/org/traccar/protocol/VisiontekProtocolDecoder.java
+++ b/src/org/traccar/protocol/VisiontekProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class VisiontekProtocolDecoder extends BaseProtocolDecoder {
- public VisiontekProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public VisiontekProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -81,22 +81,11 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder {
// Device identification
String id = parser.group(index++);
String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- if (imei != null) {
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error2) {
- Log.warning("Unknown device - " + id);
- return null;
- }
- } else {
- Log.warning("Unknown device - " + id);
- return null;
- }
+ if (!identify(id, false) && !identify(imei)) {
+ return null;
}
-
+ position.setDeviceId(getDeviceId());
+
// Date
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
time.clear();
diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java
index 6c4c0e8db..76cf9b924 100644
--- a/src/org/traccar/protocol/WialonProtocolDecoder.java
+++ b/src/org/traccar/protocol/WialonProtocolDecoder.java
@@ -34,10 +34,8 @@ import org.traccar.model.Position;
public class WialonProtocolDecoder extends BaseProtocolDecoder {
- private Long deviceId;
-
- public WialonProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public WialonProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -75,14 +73,14 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
// Parse message
Matcher parser = pattern.matcher(substring);
- if (deviceId == null || !parser.matches()) {
+ if (!hasDeviceId() || !parser.matches()) {
return null;
}
// Create new position
Position position = new Position();
ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter(getProtocol());
- position.setDeviceId(deviceId);
+ position.setDeviceId(getDeviceId());
Integer index = 1;
@@ -187,11 +185,8 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
// Detect device ID
if (sentence.startsWith("#L#")) {
String imei = sentence.substring(3, sentence.indexOf(';'));
- try {
- deviceId = getDataManager().getDeviceByImei(imei).getId();
+ if (identify(imei)) {
sendResponse(channel, "#AL#", 1);
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
}
}
diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java
index a9068e7be..98b75b0d2 100644
--- a/src/org/traccar/protocol/WondexProtocolDecoder.java
+++ b/src/org/traccar/protocol/WondexProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class WondexProtocolDecoder extends BaseProtocolDecoder {
- public WondexProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public WondexProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -72,13 +72,10 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder {
int index = 1;
// Device identifier
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java
index d60e48750..bfd20c64b 100644
--- a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class Xexun2ProtocolDecoder extends BaseProtocolDecoder {
- public Xexun2ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Xexun2ProtocolDecoder(String protocol) {
+ super(protocol);
}
static private Pattern pattern = Pattern.compile(
@@ -94,7 +94,7 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder {
time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++)));
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));
@@ -132,13 +132,10 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder {
extendedInfo.set("alarm", parser.group(index++));
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Satellites
extendedInfo.set("satellites", parser.group(index++).replaceFirst ("^0*(?![\\.$])", ""));
diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java
index dd9ed0528..bf119808d 100644
--- a/src/org/traccar/protocol/XexunProtocolDecoder.java
+++ b/src/org/traccar/protocol/XexunProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class XexunProtocolDecoder extends BaseProtocolDecoder {
- public XexunProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public XexunProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -116,13 +116,10 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder {
position.setTime(time.getTime());
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
position.setExtendedInfo(extendedInfo.toString());
return position;
diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java
index e6a7bd10b..cec36c866 100644
--- a/src/org/traccar/protocol/XirgoProtocolDecoder.java
+++ b/src/org/traccar/protocol/XirgoProtocolDecoder.java
@@ -33,8 +33,8 @@ import org.traccar.model.Position;
public class XirgoProtocolDecoder extends BaseProtocolDecoder {
- public XirgoProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public XirgoProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -76,13 +76,10 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Get device by IMEI
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
extendedInfo.set("event", parser.group(index++));
diff --git a/src/org/traccar/protocol/Xt013ProtocolDecoder.java b/src/org/traccar/protocol/Xt013ProtocolDecoder.java
index 389ed3b59..e471ea349 100644
--- a/src/org/traccar/protocol/Xt013ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Xt013ProtocolDecoder.java
@@ -32,8 +32,8 @@ import java.util.regex.Pattern;
public class Xt013ProtocolDecoder extends BaseProtocolDecoder {
- public Xt013ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Xt013ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -78,13 +78,10 @@ public class Xt013ProtocolDecoder extends BaseProtocolDecoder {
Integer index = 1;
// Identify device
- String imei = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + imei);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
diff --git a/src/org/traccar/protocol/Xt7ProtocolDecoder.java b/src/org/traccar/protocol/Xt7ProtocolDecoder.java
index bd46cee37..1e5396f22 100644
--- a/src/org/traccar/protocol/Xt7ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Xt7ProtocolDecoder.java
@@ -34,8 +34,8 @@ import org.traccar.model.Position;
public class Xt7ProtocolDecoder extends BaseProtocolDecoder {
- public Xt7ProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public Xt7ProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -74,13 +74,11 @@ public class Xt7ProtocolDecoder extends BaseProtocolDecoder {
// Get device by id
String id = buf.readBytes(16).toString(Charset.defaultCharset()).trim();
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(id)) {
return null;
}
-
+ position.setDeviceId(getDeviceId());
+
buf.readUnsignedByte(); // command
int length = buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/YwtProtocolDecoder.java b/src/org/traccar/protocol/YwtProtocolDecoder.java
index 5392a4ccf..fa17d6f43 100644
--- a/src/org/traccar/protocol/YwtProtocolDecoder.java
+++ b/src/org/traccar/protocol/YwtProtocolDecoder.java
@@ -32,8 +32,8 @@ import org.traccar.model.Position;
public class YwtProtocolDecoder extends BaseProtocolDecoder {
- public YwtProtocolDecoder(DataManager dataManager, String protocol, Properties properties) {
- super(dataManager, protocol, properties);
+ public YwtProtocolDecoder(String protocol) {
+ super(protocol);
}
private static final Pattern pattern = Pattern.compile(
@@ -89,13 +89,10 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder {
String type = parser.group(index++);
// Device
- String id = parser.group(index++);
- try {
- position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
- } catch(Exception error) {
- Log.warning("Unknown device - " + id);
+ if (!identify(parser.group(index++))) {
return null;
}
+ position.setDeviceId(getDeviceId());
// Time
Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));