aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-03-17 09:45:20 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-03-17 09:45:20 -0700
commitecaa84400f3b088e89b92d3331e183d7cf262d46 (patch)
tree908aea14881a1367158a45e1249b85580850c07e
parent9d7219db111c85d8f113460b231eff31a252971c (diff)
downloadtrackermap-server-ecaa84400f3b088e89b92d3331e183d7cf262d46.tar.gz
trackermap-server-ecaa84400f3b088e89b92d3331e183d7cf262d46.tar.bz2
trackermap-server-ecaa84400f3b088e89b92d3331e183d7cf262d46.zip
Implement Huabao engine cut
-rw-r--r--src/org/traccar/protocol/HuabaoProtocolDecoder.java1
-rw-r--r--src/org/traccar/protocol/HuabaoProtocolEncoder.java32
-rw-r--r--test/org/traccar/protocol/HuabaoProtocolEncoderTest.java2
3 files changed, 27 insertions, 8 deletions
diff --git a/src/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/org/traccar/protocol/HuabaoProtocolDecoder.java
index f5e73c1f9..4e39d42eb 100644
--- a/src/org/traccar/protocol/HuabaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/HuabaoProtocolDecoder.java
@@ -44,6 +44,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_GENERAL_RESPONSE = 0x8001;
public static final int MSG_TERMINAL_REGISTER = 0x0100;
public static final int MSG_TERMINAL_REGISTER_RESPONSE = 0x8100;
+ public static final int MSG_TERMINAL_CONTROL = 8105;
public static final int MSG_TERMINAL_AUTH = 0x0102;
public static final int MSG_LOCATION_REPORT = 0x0200;
public static final int MSG_LOCATION_BATCH = 0x0704;
diff --git a/src/org/traccar/protocol/HuabaoProtocolEncoder.java b/src/org/traccar/protocol/HuabaoProtocolEncoder.java
index 056597b50..7759790c4 100644
--- a/src/org/traccar/protocol/HuabaoProtocolEncoder.java
+++ b/src/org/traccar/protocol/HuabaoProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.traccar.BaseProtocolEncoder;
+import org.traccar.Context;
import org.traccar.helper.DataConverter;
import org.traccar.model.Command;
@@ -29,6 +30,9 @@ public class HuabaoProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
+ boolean alternative = Context.getIdentityManager().lookupAttributeBoolean(
+ command.getDeviceId(), "huabao.alternative", false, true);
+
ByteBuf id = Unpooled.wrappedBuffer(
DataConverter.parseHex(getUniqueId(command.getDeviceId())));
try {
@@ -37,13 +41,27 @@ public class HuabaoProtocolEncoder extends BaseProtocolEncoder {
switch (command.getType()) {
case Command.TYPE_ENGINE_STOP:
- data.writeByte(0x01);
- data.writeBytes(time);
- return HuabaoProtocolDecoder.formatMessage(HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data);
+ if (alternative) {
+ data.writeByte(0x01);
+ data.writeBytes(time);
+ return HuabaoProtocolDecoder.formatMessage(
+ HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data);
+ } else {
+ data.writeByte(0xf0);
+ return HuabaoProtocolDecoder.formatMessage(
+ HuabaoProtocolDecoder.MSG_TERMINAL_CONTROL, id, data);
+ }
case Command.TYPE_ENGINE_RESUME:
- data.writeByte(0x00);
- data.writeBytes(time);
- return HuabaoProtocolDecoder.formatMessage(HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data);
+ if (alternative) {
+ data.writeByte(0x00);
+ data.writeBytes(time);
+ return HuabaoProtocolDecoder.formatMessage(
+ HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data);
+ } else {
+ data.writeByte(0xf1);
+ return HuabaoProtocolDecoder.formatMessage(
+ HuabaoProtocolDecoder.MSG_TERMINAL_CONTROL, id, data);
+ }
default:
return null;
}
diff --git a/test/org/traccar/protocol/HuabaoProtocolEncoderTest.java b/test/org/traccar/protocol/HuabaoProtocolEncoderTest.java
index c29147a26..771e6d28c 100644
--- a/test/org/traccar/protocol/HuabaoProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/HuabaoProtocolEncoderTest.java
@@ -17,7 +17,7 @@ public class HuabaoProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_ENGINE_STOP);
- verifyCommand(encoder, command, binary("7EA0060007001403305278017701150424154610AD7E"));
+ verifyCommand(encoder, command, binary("7e81050001080201000027001ff0467e"));
}