aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-04-28 14:59:53 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-04-28 14:59:53 +1200
commitc14f99819add0971a82ced01bf6d54ed77aedb74 (patch)
tree4a2991429fd91e4d3c2a18e04cbb6776cdfc3fc7
parentac88c14d7982ef7571ae6f09ec50267ea4f1062a (diff)
downloadtrackermap-server-c14f99819add0971a82ced01bf6d54ed77aedb74.tar.gz
trackermap-server-c14f99819add0971a82ced01bf6d54ed77aedb74.tar.bz2
trackermap-server-c14f99819add0971a82ced01bf6d54ed77aedb74.zip
Implement Aplicom CAN extension
-rw-r--r--default.cfg1
-rw-r--r--src/org/traccar/Context.java4
-rw-r--r--src/org/traccar/protocol/AplicomProtocolDecoder.java103
-rw-r--r--test/org/traccar/protocol/AplicomProtocolDecoderTest.java4
4 files changed, 108 insertions, 4 deletions
diff --git a/default.cfg b/default.cfg
index 841d2168e..5401b93da 100644
--- a/default.cfg
+++ b/default.cfg
@@ -270,6 +270,7 @@
<!-- Aplicom server configuration -->
<entry key='aplicom.enable'>true</entry>
<entry key='aplicom.port'>5049</entry>
+ <entry key='aplicom.can'>false</entry>
<!-- Gotop server configuration -->
<entry key='gotop.enable'>true</entry>
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index af32267c9..a180a64ab 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -110,7 +110,11 @@ public class Context {
serverManager.init();
}
+ /**
+ * Initialize context for unit testing
+ */
public static void init(DataManager dataManager) {
+ properties = new Properties();
Context.dataManager = dataManager;
}
diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java
index d29548088..2234b6e19 100644
--- a/src/org/traccar/protocol/AplicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java
@@ -15,13 +15,17 @@
*/
package org.traccar.protocol;
+import java.util.ArrayList;
import java.util.Date;
import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
+import org.traccar.helper.ChannelBufferTools;
import org.traccar.model.ExtendedInfoFormatter;
import org.traccar.model.Position;
@@ -98,7 +102,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
}
private static final int DEFAULT_SELECTOR = 0x0002FC;
-
+
private static final int EVENT_DATA = 119;
@Override
@@ -134,7 +138,8 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
position.setDeviceId(getDeviceId());
// Event
- extendedInfo.set("event", buf.readUnsignedByte());
+ int event = buf.readUnsignedByte();
+ extendedInfo.set("event", event);
buf.readUnsignedByte();
// Validity
@@ -225,6 +230,100 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
position.setAltitude(buf.readShort());
}
+ // Snapshot counter
+ if ((selector & 0x2000) != 0) {
+ buf.readUnsignedShort();
+ }
+
+ // State flags
+ if ((selector & 0x4000) != 0) {
+ buf.skipBytes(8);
+ }
+
+ // Event specific data
+ if ((selector & 0x1000) != 0) {
+ switch (event) {
+ case 2:
+ case 40:
+ buf.readUnsignedByte();
+ break;
+ case 9:
+ buf.readUnsignedMedium();
+ break;
+ case 31:
+ case 32:
+ buf.readUnsignedShort();
+ break;
+ case 38:
+ buf.skipBytes(4 * 9);
+ break;
+ case 113:
+ buf.readUnsignedInt();
+ buf.readUnsignedByte();
+ break;
+ case 121:
+ case 142:
+ buf.readLong();
+ break;
+ case 130:
+ buf.readUnsignedInt(); // incorrect
+ break;
+ }
+ }
+
+ // CAN data
+ if (buf.readable() && (selector & 0x1000) != 0 && event == EVENT_DATA &&
+ Boolean.parseBoolean(Context.getProps().getProperty(getProtocol() + ".can"))) {
+
+ buf.readUnsignedMedium(); // packet identifier
+ buf.readUnsignedByte(); // version
+ int count = buf.readUnsignedByte();
+ buf.readUnsignedByte(); // batch count
+ buf.readUnsignedShort(); // selector bit
+ buf.readUnsignedInt(); // timestamp
+
+ buf.skipBytes(8);
+
+ ArrayList<ChannelBuffer> values = new ArrayList<ChannelBuffer>(count);
+
+ for (int i = 0; i < count; i++) {
+ values.add(buf.readBytes(8));
+ }
+
+ for (int i = 0; i < count; i++) {
+ ChannelBuffer value = values.get(i);
+ switch (buf.readInt()) {
+ case 0x40C:
+ extendedInfo.set("suction-temperature1", ChannelBuffers.swapShort(value.readShort()) * 0.1);
+ extendedInfo.set("suction-temperature2", ChannelBuffers.swapShort(value.readShort()) * 0.1);
+ extendedInfo.set("suction-temperature3", ChannelBuffers.swapShort(value.readShort()) * 0.1);
+ extendedInfo.set("evaporator-fan", ChannelBuffers.swapShort(value.readShort()));
+ break;
+ case 0x50C:
+ extendedInfo.set("evaporator-temperature1", ChannelBuffers.swapShort(value.readShort()) * 0.1);
+ extendedInfo.set("evaporator-temperature2", ChannelBuffers.swapShort(value.readShort()) * 0.1);
+ extendedInfo.set("evaporator-temperature3", ChannelBuffers.swapShort(value.readShort()) * 0.1);
+ break;
+ case 0x20D:
+ extendedInfo.set("diesel-rpm", ChannelBuffers.swapShort(value.readShort()));
+ extendedInfo.set("diesel-temperature", ChannelBuffers.swapShort(value.readShort()) * 0.1);
+ extendedInfo.set("battery", ChannelBuffers.swapShort(value.readShort()) * 0.01);
+ extendedInfo.set("air-temperature", ChannelBuffers.swapShort(value.readShort()) * 0.1);
+ break;
+ case 0x30D:
+ extendedInfo.set("alarms", ChannelBufferTools.readHexString(value, 16));
+ break;
+ case 0x40D:
+ extendedInfo.set("cold-unit-status", ChannelBufferTools.readHexString(value, 16));
+ break;
+ case 0x50D:
+ extendedInfo.set("coolant-pressure", ChannelBuffers.swapShort(value.readShort()) * 0.1);
+ extendedInfo.set("suction-pressure", ChannelBuffers.swapShort(value.readShort()) * 0.1);
+ break;
+ }
+ }
+ }
+
position.setExtendedInfo(extendedInfo.toString());
return position;
}
diff --git a/test/org/traccar/protocol/AplicomProtocolDecoderTest.java b/test/org/traccar/protocol/AplicomProtocolDecoderTest.java
index 6d4bc65bd..eb064812c 100644
--- a/test/org/traccar/protocol/AplicomProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/AplicomProtocolDecoderTest.java
@@ -13,10 +13,10 @@ public class AplicomProtocolDecoderTest extends ProtocolDecoderTest {
AplicomProtocolDecoder decoder = new AplicomProtocolDecoder(null);
verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
- "44C20146B710C158DA002100B09F0700C054CA0EA254CA0E9C03BE0BF6015D7069070000142A600000000000000001"))));
+ "44C20146B710C158DA009500B09F7700C054CA0EA454CA0EA403BE0BF6015D706B070000142A600000000000000002434946010801000754CA0EA4000000000000008400000000000000000000000000000000300000FE00FE0000000000000000000000000000000000000000000000000000000000000000000040502035000000000000020D0000030D0000040C0000040D0000050C0000050D0000058C0000060C"))));
verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
- "44C20146B710C158DA009500B09F7700C054CA0EA454CA0EA403BE0BF6015D706B070000142A600000000000000002434946010801000754CA0EA4000000000000008400000000000000000000000000000000300000FE00FE0000000000000000000000000000000000000000000000000000000000000000000040502035000000000000020D0000030D0000040C0000040D0000050C0000050D0000058C0000060C"))));
+ "44C20146B710C158DA002100B09F0700C054CA0EA254CA0E9C03BE0BF6015D7069070000142A600000000000000001"))));
verify(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
"44C20143720729D6840043031fff7191C0450ef906450ef90603b20b8003b20b80066465b3870ce30f010ce30ce3003200001520000000030aa200003b13000000320300000bcb17acff0099000186a002"))));