aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-10-17 10:51:03 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-10-17 10:51:03 +1300
commit91d6491b438ecddbe63a49de26a76cd8f7309650 (patch)
tree8253667cd658bc919fa33c3097e95d42f33bb52a
parenta5b4ba98656bba77854b0fa5e4de2ca0d4f839b5 (diff)
downloadtraccar-server-91d6491b438ecddbe63a49de26a76cd8f7309650.tar.gz
traccar-server-91d6491b438ecddbe63a49de26a76cd8f7309650.tar.bz2
traccar-server-91d6491b438ecddbe63a49de26a76cd8f7309650.zip
Properly decode pseudo IP address
-rw-r--r--src/org/traccar/protocol/GatorProtocolDecoder.java21
-rw-r--r--test/org/traccar/protocol/GatorProtocolDecoderTest.java10
2 files changed, 22 insertions, 9 deletions
diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java
index b8431003b..f132e82d2 100644
--- a/src/org/traccar/protocol/GatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/GatorProtocolDecoder.java
@@ -18,10 +18,8 @@ package org.traccar.protocol;
import java.net.SocketAddress;
import java.util.Calendar;
import java.util.TimeZone;
-
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
-
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.ChannelBufferTools;
import org.traccar.helper.UnitsConverter;
@@ -45,6 +43,17 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_PICTURE_FRAME = 0x54;
public static final int MSG_CAMERA_RESPONSE = 0x56;
public static final int MSG_PICTURE_DATA = 0x57;
+
+ public static String decodeId(int b1, int b2, int b3, int b4) {
+
+ int d1 = 30 + ((b1 >> 7) << 3) + ((b2 >> 7) << 2) + ((b3 >> 7) << 1) + (b4 >> 7);
+ int d2 = b1 & 0x7f;
+ int d3 = b2 & 0x7f;
+ int d4 = b3 & 0x7f;
+ int d5 = b4 & 0x7f;
+
+ return String.format("%02d%02d%02d%02d%02d", d1, d2, d3, d4, d5);
+ }
@Override
protected Object decode(
@@ -57,21 +66,17 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder {
int type = buf.readUnsignedByte();
buf.readUnsignedShort(); // length
- // Pseudo IP address
- String id = String.format("%02d%02d%02d%02d",
+ String id = decodeId(
buf.readUnsignedByte(), buf.readUnsignedByte(),
buf.readUnsignedByte(), buf.readUnsignedByte());
- id = id.replaceFirst("^0+(?!$)", "");
if (type == MSG_POSITION_DATA || type == MSG_ROLLCALL_RESPONSE
|| type == MSG_ALARM_DATA || type == MSG_BLIND_AREA) {
- // Create new position
Position position = new Position();
position.setProtocol(getProtocolName());
- // Identification
- if (!identify(id, channel)) {
+ if (!identify("1" + id, channel, null, false) && !identify(id, channel)) {
return null;
}
position.setDeviceId(getDeviceId());
diff --git a/test/org/traccar/protocol/GatorProtocolDecoderTest.java b/test/org/traccar/protocol/GatorProtocolDecoderTest.java
index cecf70527..606f58942 100644
--- a/test/org/traccar/protocol/GatorProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/GatorProtocolDecoderTest.java
@@ -1,11 +1,19 @@
package org.traccar.protocol;
import org.jboss.netty.buffer.ChannelBuffers;
-import static org.traccar.helper.DecoderVerifier.verify;
+import org.junit.Assert;
import org.junit.Test;
import org.traccar.helper.ChannelBufferTools;
+import static org.traccar.helper.DecoderVerifier.verify;
public class GatorProtocolDecoderTest extends ProtocolDecoderTest {
+
+ @Test
+ public void testDecodeId() {
+
+ Assert.assertEquals("3512345006", GatorProtocolDecoder.decodeId(12, 162, 50, 134));
+
+ }
@Test
public void testDecode() throws Exception {