aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/Tk102ProtocolDecoder.java
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/Tk102ProtocolDecoder.java
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/Tk102ProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/Tk102ProtocolDecoder.java18
1 files changed, 6 insertions, 12 deletions
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++));