aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/NavigilProtocolDecoder.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/NavigilProtocolDecoder.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/NavigilProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/NavigilProtocolDecoder.java47
1 files changed, 21 insertions, 26 deletions
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;