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 --- src/org/traccar/protocol/Mta6ProtocolDecoder.java | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/org/traccar/protocol/Mta6ProtocolDecoder.java') 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 parseFormatA(ChannelBuffer buf, long deviceId) { + private List parseFormatA(ChannelBuffer buf) { List positions = new LinkedList(); 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) -- cgit v1.2.3