From 206600cd599e03eaa095619fc8a52b742d3413a1 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 4 Dec 2012 22:22:07 +1300 Subject: Added unknown device logging (fix #102) --- src/org/traccar/protocol/Avl08ProtocolDecoder.java | 8 +++++++- src/org/traccar/protocol/EnforaProtocolDecoder.java | 7 ++++++- src/org/traccar/protocol/Ev603ProtocolDecoder.java | 8 +++++++- src/org/traccar/protocol/Gl100ProtocolDecoder.java | 8 +++++++- src/org/traccar/protocol/Gl200ProtocolDecoder.java | 8 +++++++- src/org/traccar/protocol/Gps103ProtocolDecoder.java | 7 ++++++- src/org/traccar/protocol/H02ProtocolDecoder.java | 8 +++++++- src/org/traccar/protocol/Jt600ProtocolDecoder.java | 15 +++++++++++++-- src/org/traccar/protocol/MaxonProtocolDecoder.java | 8 +++++++- src/org/traccar/protocol/MeiligaoProtocolDecoder.java | 9 ++++++++- src/org/traccar/protocol/NavisProtocolDecoder.java | 3 +-- src/org/traccar/protocol/ProgressProtocolDecoder.java | 7 ++++++- src/org/traccar/protocol/Pt502ProtocolDecoder.java | 7 ++++++- src/org/traccar/protocol/T55ProtocolDecoder.java | 7 ++++++- src/org/traccar/protocol/Tk103ProtocolDecoder.java | 8 +++++++- src/org/traccar/protocol/Tr20ProtocolDecoder.java | 8 +++++++- src/org/traccar/protocol/V680ProtocolDecoder.java | 8 +++++++- src/org/traccar/protocol/Xexun2ProtocolDecoder.java | 8 +++++++- src/org/traccar/protocol/XexunProtocolDecoder.java | 8 +++++++- 19 files changed, 129 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/Avl08ProtocolDecoder.java b/src/org/traccar/protocol/Avl08ProtocolDecoder.java index c8766b642..a01771c35 100644 --- a/src/org/traccar/protocol/Avl08ProtocolDecoder.java +++ b/src/org/traccar/protocol/Avl08ProtocolDecoder.java @@ -22,6 +22,7 @@ import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.GenericProtocolDecoder; +import org.traccar.helper.Log; import org.traccar.model.DataManager; import org.traccar.model.Position; @@ -88,7 +89,12 @@ public class Avl08ProtocolDecoder extends GenericProtocolDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + try { + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + } catch(Exception error) { + Log.warning("Unknown device - " + imei); + return null; + } // Alarm type extendedInfo.append(""); diff --git a/src/org/traccar/protocol/EnforaProtocolDecoder.java b/src/org/traccar/protocol/EnforaProtocolDecoder.java index fc40dcbba..aa6dbaf13 100644 --- a/src/org/traccar/protocol/EnforaProtocolDecoder.java +++ b/src/org/traccar/protocol/EnforaProtocolDecoder.java @@ -107,7 +107,12 @@ public class EnforaProtocolDecoder extends GenericProtocolDecoder { Integer index = 1; // Get device by IMEI - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + try { + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + } catch(Exception error) { + Log.warning("Unknown device - " + imei); + return null; + } // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); diff --git a/src/org/traccar/protocol/Ev603ProtocolDecoder.java b/src/org/traccar/protocol/Ev603ProtocolDecoder.java index 83689f760..6d89120a8 100644 --- a/src/org/traccar/protocol/Ev603ProtocolDecoder.java +++ b/src/org/traccar/protocol/Ev603ProtocolDecoder.java @@ -23,6 +23,7 @@ import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.GenericProtocolDecoder; +import org.traccar.helper.Log; import org.traccar.model.DataManager; import org.traccar.model.Position; @@ -68,7 +69,12 @@ public class Ev603ProtocolDecoder extends GenericProtocolDecoder{ // Detect device ID if (sentence.startsWith("!1,")) { String imei = sentence.substring(3); - deviceId = getDataManager().getDeviceByImei(imei).getId(); + try { + deviceId = getDataManager().getDeviceByImei(imei).getId(); + } catch(Exception error) { + Log.warning("Unknown device - " + imei); + return null; + } } else if (sentence.startsWith("!A,")) { diff --git a/src/org/traccar/protocol/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/Gl100ProtocolDecoder.java index 2e8b40a61..760e91f68 100644 --- a/src/org/traccar/protocol/Gl100ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl100ProtocolDecoder.java @@ -22,6 +22,7 @@ import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.GenericProtocolDecoder; +import org.traccar.helper.Log; import org.traccar.model.DataManager; import org.traccar.model.Position; @@ -88,7 +89,12 @@ public class Gl100ProtocolDecoder extends GenericProtocolDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + try { + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + } catch(Exception error) { + Log.warning("Unknown device - " + imei); + return null; + } // Validity position.setValid(Integer.valueOf(parser.group(index++)) == 0 ? false : true); diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index c109ea4c7..019c839cd 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -22,6 +22,7 @@ import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.GenericProtocolDecoder; +import org.traccar.helper.Log; import org.traccar.model.DataManager; import org.traccar.model.Position; @@ -81,7 +82,12 @@ public class Gl200ProtocolDecoder extends GenericProtocolDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + try { + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + } catch(Exception error) { + Log.warning("Unknown device - " + imei); + return null; + } // Validity position.setValid(Integer.valueOf(parser.group(index++)) == 0 ? false : true); diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 1f19b56e4..9c9f56b2f 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -94,7 +94,12 @@ public class Gps103ProtocolDecoder extends GenericProtocolDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + try { + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + } catch(Exception error) { + Log.warning("Unknown device - " + imei); + return null; + } // Alarm message extendedInfo.append(""); diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index bfdfc3758..2d4fb9a21 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -22,6 +22,7 @@ import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.GenericProtocolDecoder; +import org.traccar.helper.Log; import org.traccar.model.DataManager; import org.traccar.model.Position; @@ -77,7 +78,12 @@ public class H02ProtocolDecoder extends GenericProtocolDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + try { + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + } catch(Exception error) { + Log.warning("Unknown device - " + imei); + return null; + } // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index 907eabb4b..d765c1b42 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -25,6 +25,7 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.GenericProtocolDecoder; import org.traccar.helper.ChannelBufferTools; +import org.traccar.helper.Log; import org.traccar.model.DataManager; import org.traccar.model.Position; @@ -51,7 +52,12 @@ public class Jt600ProtocolDecoder extends GenericProtocolDecoder { // Get device by identifier String id = Long.valueOf(ChannelBufferTools.readHexString(buf, 10)).toString(); - position.setDeviceId(getDataManager().getDeviceByImei(id).getId()); + try { + position.setDeviceId(getDataManager().getDeviceByImei(id).getId()); + } catch(Exception error) { + Log.warning("Unknown device - " + id); + return null; + } buf.readByte(); // protocol version + data type @@ -157,7 +163,12 @@ public class Jt600ProtocolDecoder extends GenericProtocolDecoder { // Get device by identifier String id = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(id).getId()); + try { + position.setDeviceId(getDataManager().getDeviceByImei(id).getId()); + } catch(Exception error) { + Log.warning("Unknown device - " + id); + return null; + } // Longitude Double lonlitude = Double.valueOf(parser.group(index++)); diff --git a/src/org/traccar/protocol/MaxonProtocolDecoder.java b/src/org/traccar/protocol/MaxonProtocolDecoder.java index e05ef0e30..9bad2c965 100644 --- a/src/org/traccar/protocol/MaxonProtocolDecoder.java +++ b/src/org/traccar/protocol/MaxonProtocolDecoder.java @@ -22,6 +22,7 @@ import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.GenericProtocolDecoder; +import org.traccar.helper.Log; import org.traccar.model.DataManager; import org.traccar.model.Position; @@ -142,7 +143,12 @@ public class MaxonProtocolDecoder extends GenericProtocolDecoder { if (parser.matches()) { String imei = parser.group(1); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + try { + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + } catch(Exception error) { + Log.warning("Unknown device - " + imei); + return null; + } return position; } } diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index b658c74e8..d5658b9a2 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -27,6 +27,7 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.GenericProtocolDecoder; import org.traccar.helper.Crc; +import org.traccar.helper.Log; import org.traccar.model.DataManager; import org.traccar.model.Position; @@ -133,7 +134,13 @@ public class MeiligaoProtocolDecoder extends GenericProtocolDecoder { // Get device by id // TODO: change imei to unique id - position.setDeviceId(getDataManager().getDeviceByImei(getId(buf)).getId()); + String id = getId(buf); + try { + position.setDeviceId(getDataManager().getDeviceByImei(id).getId()); + } catch(Exception error) { + Log.warning("Unknown device - " + id); + return null; + } // Parse message String sentence = buf.toString(offset, buf.readableBytes() - offset - 4, Charset.defaultCharset()); diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java index 1b3cd80f7..291d2b87c 100644 --- a/src/org/traccar/protocol/NavisProtocolDecoder.java +++ b/src/org/traccar/protocol/NavisProtocolDecoder.java @@ -277,12 +277,11 @@ public class NavisProtocolDecoder extends GenericProtocolDecoder { private Object processHandshake(Channel channel, ChannelBuffer buf) { buf.readByte(); // semicolon symbol imei = buf.toString(Charset.defaultCharset()); - try { databaseDeviceId = getDataManager().getDeviceByImei(imei).getId(); sendReply(channel, ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*"); diff --git a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java index e7b29b728..6edb3733e 100644 --- a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java +++ b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java @@ -22,6 +22,7 @@ import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.GenericProtocolDecoder; +import org.traccar.helper.Log; import org.traccar.model.DataManager; import org.traccar.model.Position; @@ -148,7 +149,12 @@ public class Xexun2ProtocolDecoder extends GenericProtocolDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + try { + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + } catch(Exception error) { + Log.warning("Unknown device - " + imei); + return null; + } // Satellites extendedInfo.append(""); diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java index cbff2dee3..2da1c68ac 100644 --- a/src/org/traccar/protocol/XexunProtocolDecoder.java +++ b/src/org/traccar/protocol/XexunProtocolDecoder.java @@ -23,6 +23,7 @@ import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.GenericProtocolDecoder; +import org.traccar.helper.Log; import org.traccar.model.DataManager; import org.traccar.model.Position; @@ -119,7 +120,12 @@ public class XexunProtocolDecoder extends GenericProtocolDecoder { // Get device by IMEI String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + try { + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + } catch(Exception error) { + Log.warning("Unknown device - " + imei); + return null; + } return position; } -- cgit v1.2.3