From 2a3fad9496decd83f06ae5abf067f8d4337ec741 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 23 Apr 2015 15:49:56 +1200 Subject: Major code refacroting --- .../traccar/protocol/CalAmpProtocolDecoder.java | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'src/org/traccar/protocol/CalAmpProtocolDecoder.java') 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)); -- cgit v1.2.3