From e84f02c3bffda311e86fab584d7c40702b5223be Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 1 Oct 2015 14:45:47 +1300 Subject: Improve Meiligao device identification --- src/org/traccar/protocol/MeiligaoProtocolDecoder.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index 43142744c..c660107ca 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -80,7 +80,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { private static final int MSG_RFID = 0x9966; - private String getImei(ChannelBuffer buf) { + private boolean identify(ChannelBuffer buf, Channel channel) { String id = ""; for (int i = 0; i < 7; i++) { @@ -98,12 +98,17 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } if (id.length() == 14) { - id += Crc.luhnChecksum(Long.valueOf(id)); // IMEI checksum - } - if (id.length() > 15) { - id = id.substring(0, 15); + // Sometimes first digit is cut, so this won't work + if (identify(id + Crc.luhnChecksum(Long.valueOf(id)), channel, null, false)) { + return true; + } + } else if (id.length() > 15) { + if (identify(id.substring(0, 15), channel, null, false)) { + return true; + } } - return id; + + return identify(id, channel); } private static void sendResponse( @@ -189,7 +194,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } // Get device by id - if (!identify(getImei(id), channel)) { + if (!identify(id, channel)) { return null; } position.setDeviceId(getDeviceId()); -- cgit v1.2.3