From ecaa84400f3b088e89b92d3331e183d7cf262d46 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 17 Mar 2019 09:45:20 -0700 Subject: Implement Huabao engine cut --- .../traccar/protocol/HuabaoProtocolDecoder.java | 1 + .../traccar/protocol/HuabaoProtocolEncoder.java | 32 +++++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3