aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-09-29 09:40:57 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-09-29 09:40:57 +1300
commitd6f63ef1ac9e1b66205d3671d63058b2684b34ab (patch)
tree9b563c1519c29ede854e4c1a81b9db74e7ea7a85
parent6d8c8f3b9570ecb3fc359071b23a8fa0ecf836ab (diff)
downloadtraccar-server-d6f63ef1ac9e1b66205d3671d63058b2684b34ab.tar.gz
traccar-server-d6f63ef1ac9e1b66205d3671d63058b2684b34ab.tar.bz2
traccar-server-d6f63ef1ac9e1b66205d3671d63058b2684b34ab.zip
Clean up BlackKite protocol code
-rw-r--r--setup/unix/traccar.xml1
-rw-r--r--setup/windows/traccar.xml1
-rw-r--r--src/org/traccar/model/Event.java2
-rw-r--r--src/org/traccar/protocol/BlackKiteProtocol.java2
-rw-r--r--src/org/traccar/protocol/BlackKiteProtocolDecoder.java86
-rw-r--r--test/org/traccar/protocol/BlackKiteProtocolDecoderTest.java2
-rw-r--r--tools/opengts.xml1
7 files changed, 26 insertions, 69 deletions
diff --git a/setup/unix/traccar.xml b/setup/unix/traccar.xml
index 06dd293ea..70270b7d1 100644
--- a/setup/unix/traccar.xml
+++ b/setup/unix/traccar.xml
@@ -317,6 +317,5 @@
<entry key='castel.port'>5086</entry>
<entry key='mxt.port'>5087</entry>
<entry key='cityeasy.port'>5088</entry>
- <entry key='blackkite.port'>5091</entry>
</properties>
diff --git a/setup/windows/traccar.xml b/setup/windows/traccar.xml
index ce3f4ebdc..bf0dc3efa 100644
--- a/setup/windows/traccar.xml
+++ b/setup/windows/traccar.xml
@@ -317,6 +317,5 @@
<entry key='castel.port'>5086</entry>
<entry key='mxt.port'>5087</entry>
<entry key='cityeasy.port'>5088</entry>
- <entry key='blackkite.port'>5091</entry>
</properties>
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
index cfa51e82e..cadca767b 100644
--- a/src/org/traccar/model/Event.java
+++ b/src/org/traccar/model/Event.java
@@ -81,9 +81,9 @@ public abstract class Event {
public static final String KEY_DISTANCE = "distance";
public static final String KEY_DOOR = "door";
public static final String KEY_RPM = "rpm";
+
public static final String KEY_OBD_SPEED = "speed";
public static final String KEY_OBD_ODOMETER = "odometer";
- public static final String KEY_VBATT = "vehicle-battery";
// Starts with 1 not 0
public static final String PREFIX_TEMP = "temp";
diff --git a/src/org/traccar/protocol/BlackKiteProtocol.java b/src/org/traccar/protocol/BlackKiteProtocol.java
index 0bdafd750..3f1890f88 100644
--- a/src/org/traccar/protocol/BlackKiteProtocol.java
+++ b/src/org/traccar/protocol/BlackKiteProtocol.java
@@ -1,7 +1,5 @@
/*
* Copyright 2015 Vijay Kumar (vijaykumar@zilogic.com)
- *
- * Based on GalileoProtocol.java
* Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
index 4f63dbafa..4b78cf647 100644
--- a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
+++ b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
@@ -1,7 +1,5 @@
/*
* Copyright 2015 Vijay Kumar (vijaykumar@zilogic.com)
- *
- * Based on GalileoProtocolDecoder.java
* Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,11 +20,9 @@ import java.net.SocketAddress;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.util.Date;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
@@ -37,14 +33,6 @@ import org.traccar.helper.BitUtil;
import org.traccar.model.Event;
import org.traccar.model.Position;
-
-class DecodeError extends Exception {
- public DecodeError(String message) {
- super(message);
- }
-}
-
-
public class BlackKiteProtocolDecoder extends BaseProtocolDecoder {
public BlackKiteProtocolDecoder(BlackKiteProtocol protocol) {
@@ -66,34 +54,6 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder {
private static final int TAG_XT1 = 0x60;
private static final int TAG_XT2 = 0x61;
private static final int TAG_XT3 = 0x62;
-
- private static final Map<Integer, Integer> tagLengthMap = new HashMap<>();
-
- static {
- tagLengthMap.put(TAG_IMEI, 15);
- tagLengthMap.put(TAG_DATE, 4);
- tagLengthMap.put(TAG_COORDINATES, 9);
- tagLengthMap.put(TAG_SPEED_COURSE, 4);
- tagLengthMap.put(TAG_ALTITUDE, 2);
- tagLengthMap.put(TAG_STATUS, 2);
- tagLengthMap.put(TAG_DIGITAL_INPUTS, 2);
- tagLengthMap.put(TAG_DIGITAL_OUTPUTS, 2);
- tagLengthMap.put(TAG_INPUT_VOLTAGE1, 2);
- tagLengthMap.put(TAG_INPUT_VOLTAGE2, 2);
- tagLengthMap.put(TAG_INPUT_VOLTAGE3, 2);
- tagLengthMap.put(TAG_INPUT_VOLTAGE4, 2);
- tagLengthMap.put(TAG_XT1, 16);
- tagLengthMap.put(TAG_XT2, 16);
- tagLengthMap.put(TAG_XT3, 16);
- }
-
- private static int getTagLength(int tag) throws DecodeError {
- Integer length = tagLengthMap.get(tag);
- if (length == null)
- throw new DecodeError(String.format("invalid tag '%d'", tag));
-
- return length;
- }
private void sendReply(Channel channel, int checksum) {
ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 3);
@@ -114,8 +74,8 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // header
int length = (buf.readUnsignedShort() & 0x7fff) + 3;
- List<Position> positions = new LinkedList<Position>();
- Set<Integer> tags = new HashSet<Integer>();
+ List<Position> positions = new LinkedList<>();
+ Set<Integer> tags = new HashSet<>();
boolean hasLocation = false;
Position position = new Position();
position.setProtocol(getProtocolName());
@@ -164,50 +124,51 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder {
case TAG_STATUS:
int status = buf.readUnsignedShort();
- position.set(Event.KEY_IGNITION, BitUtil.check(status, 9));
- position.set(Event.KEY_ALARM, BitUtil.check(status, 15));
- position.set(Event.KEY_VBATT, BitUtil.check(status, 2));
+ position.set(Event.KEY_IGNITION, BitUtil.check(status, 9));
+ position.set(Event.KEY_ALARM, BitUtil.check(status, 15));
+ position.set(Event.KEY_POWER, BitUtil.check(status, 2));
break;
case TAG_DIGITAL_INPUTS:
- int input = buf.readUnsignedShort();
- for (int i = 0; i < 16; i++)
- position.set(Event.PREFIX_IO + (i + 1), BitUtil.check(input, i));
+ int input = buf.readUnsignedShort();
+ for (int i = 0; i < 16; i++)
+ position.set(Event.PREFIX_IO + (i + 1), BitUtil.check(input, i));
break;
case TAG_DIGITAL_OUTPUTS:
- int output = buf.readUnsignedShort();
- for (int i = 0; i < 16; i++)
- position.set(Event.PREFIX_IO + (i + 17), BitUtil.check(output, i));
+ int output = buf.readUnsignedShort();
+ for (int i = 0; i < 16; i++)
+ position.set(Event.PREFIX_IO + (i + 17), BitUtil.check(output, i));
break;
case TAG_INPUT_VOLTAGE1:
- position.set(Event.PREFIX_ADC + 1, buf.readUnsignedShort() / 1000.0);
+ position.set(Event.PREFIX_ADC + 1, buf.readUnsignedShort() / 1000.0);
break;
case TAG_INPUT_VOLTAGE2:
- position.set(Event.PREFIX_ADC + 2, buf.readUnsignedShort() / 1000.0);
+ position.set(Event.PREFIX_ADC + 2, buf.readUnsignedShort() / 1000.0);
break;
case TAG_INPUT_VOLTAGE3:
- position.set(Event.PREFIX_ADC + 3, buf.readUnsignedShort() / 1000.0);
+ position.set(Event.PREFIX_ADC + 3, buf.readUnsignedShort() / 1000.0);
break;
case TAG_INPUT_VOLTAGE4:
- position.set(Event.PREFIX_ADC + 4, buf.readUnsignedShort() / 1000.0);
+ position.set(Event.PREFIX_ADC + 4, buf.readUnsignedShort() / 1000.0);
+ break;
+
+ case TAG_XT1:
+ case TAG_XT2:
+ case TAG_XT3:
+ buf.skipBytes(16);
break;
-
+
default:
- try {
- buf.skipBytes(getTagLength(tag));
- } catch (DecodeError e) {
- Log.warning("Error decoding packet: " + e.getMessage());
- return null;
- }
break;
}
}
+
if (hasLocation && position.getFixTime() != null) {
positions.add(position);
}
@@ -226,6 +187,7 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder {
if (positions.isEmpty()) {
return null;
}
+
return positions;
}
diff --git a/test/org/traccar/protocol/BlackKiteProtocolDecoderTest.java b/test/org/traccar/protocol/BlackKiteProtocolDecoderTest.java
index 3060bb3f8..8ccf9f6a8 100644
--- a/test/org/traccar/protocol/BlackKiteProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/BlackKiteProtocolDecoderTest.java
@@ -1,6 +1,5 @@
package org.traccar.protocol;
-import org.traccar.helper.TestIdentityManager;
import java.nio.ByteOrder;
import org.jboss.netty.buffer.ChannelBuffers;
import static org.junit.Assert.assertNull;
@@ -20,6 +19,7 @@ public class BlackKiteProtocolDecoderTest extends ProtocolDecoderTest {
verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertHexString(
"0136000331313131313131313131313131313120523905563000010000000100000033000000003400004000004500004600005000005100009F76"))));
+
}
}
diff --git a/tools/opengts.xml b/tools/opengts.xml
index a1144d593..b1bfa197b 100644
--- a/tools/opengts.xml
+++ b/tools/opengts.xml
@@ -124,6 +124,5 @@
<entry key='tytan.port'>5084</entry>
<entry key='avl301.port'>5085</entry>
<entry key='castel.port'>5086</entry>
- <entry key='blackkite.port'>5091</entry>
</properties>