aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolDecoder.java19
-rw-r--r--test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java3
2 files changed, 15 insertions, 7 deletions
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());
diff --git a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java
index 1c4252c0f..f48c9ef39 100644
--- a/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/MeiligaoProtocolDecoderTest.java
@@ -14,6 +14,9 @@ public class MeiligaoProtocolDecoderTest extends ProtocolDecoderTest {
MeiligaoProtocolDecoder decoder = new MeiligaoProtocolDecoder(new MeiligaoProtocol());
verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
+ "242400706796502079108999553131333131382e3030302c412c313033372e393637382c4e2c30363132312e353637392c572c302e35342c322e34322c3330303931352c2c2c412a37307c302e37377c392e397c303030307c303030302c303161327c3030313138373132374cae0d0a"))));
+
+ verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
"24240074630700194707719966009E1F7F00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007C3132303334302C3238303630362C323430302E303030302C4E2C31323130302E303030302C458F7E0D0A"))));
verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(