diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-17 09:45:20 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-17 09:45:20 -0700 |
commit | ecaa84400f3b088e89b92d3331e183d7cf262d46 (patch) | |
tree | 908aea14881a1367158a45e1249b85580850c07e /src/org/traccar/protocol/HuabaoProtocolEncoder.java | |
parent | 9d7219db111c85d8f113460b231eff31a252971c (diff) | |
download | trackermap-server-ecaa84400f3b088e89b92d3331e183d7cf262d46.tar.gz trackermap-server-ecaa84400f3b088e89b92d3331e183d7cf262d46.tar.bz2 trackermap-server-ecaa84400f3b088e89b92d3331e183d7cf262d46.zip |
Implement Huabao engine cut
Diffstat (limited to 'src/org/traccar/protocol/HuabaoProtocolEncoder.java')
-rw-r--r-- | src/org/traccar/protocol/HuabaoProtocolEncoder.java | 32 |
1 files changed, 25 insertions, 7 deletions
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; } |