aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/NavisProtocolDecoder.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/NavisProtocolDecoder.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/NavisProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/NavisProtocolDecoder.java21
1 files changed, 7 insertions, 14 deletions
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