diff options
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java | 20 | ||||
-rw-r--r-- | src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java | 10 |
2 files changed, 17 insertions, 13 deletions
diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java index f67cc3d8f..0d574203c 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -57,13 +57,17 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { public static final int RESULT_SUCCESS = 0; - public static ByteBuf formatMessage(int type, ByteBuf id, ByteBuf data) { + public static ByteBuf formatMessage(int type, ByteBuf id, boolean shortIndex, ByteBuf data) { ByteBuf buf = Unpooled.buffer(); buf.writeByte(0x7e); buf.writeShort(type); buf.writeShort(data.readableBytes()); buf.writeBytes(id); - buf.writeShort(0); // index + if (shortIndex) { + buf.writeByte(1); + } else { + buf.writeShort(1); + } buf.writeBytes(data); data.release(); buf.writeByte(Checksum.xor(buf.nioBuffer(1, buf.readableBytes() - 1))); @@ -79,18 +83,18 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { response.writeShort(type); response.writeByte(RESULT_SUCCESS); channel.writeAndFlush(new NetworkMessage( - formatMessage(MSG_GENERAL_RESPONSE, id, response), remoteAddress)); + formatMessage(MSG_GENERAL_RESPONSE, id, false, response), remoteAddress)); } } private void sendGeneralResponse2( - Channel channel, SocketAddress remoteAddress, ByteBuf id, int index) { + Channel channel, SocketAddress remoteAddress, ByteBuf id, int type) { if (channel != null) { ByteBuf response = Unpooled.buffer(); - response.writeShort(index); + response.writeShort(type); response.writeByte(RESULT_SUCCESS); channel.writeAndFlush(new NetworkMessage( - formatMessage(MSG_GENERAL_RESPONSE_2, id, response), remoteAddress)); + formatMessage(MSG_GENERAL_RESPONSE_2, id, true, response), remoteAddress)); } } @@ -161,7 +165,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { response.writeByte(RESULT_SUCCESS); response.writeBytes(ByteBufUtil.hexDump(id).getBytes(StandardCharsets.US_ASCII)); channel.writeAndFlush(new NetworkMessage( - formatMessage(MSG_TERMINAL_REGISTER_RESPONSE, id, response), remoteAddress)); + formatMessage(MSG_TERMINAL_REGISTER_RESPONSE, id, false, response), remoteAddress)); } } else if (type == MSG_TERMINAL_AUTH) { @@ -175,7 +179,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { } else if (type == MSG_LOCATION_REPORT_2 || type == MSG_LOCATION_REPORT_BLIND) { if (BitUtil.check(attribute, 15)) { - sendGeneralResponse2(channel, remoteAddress, id, index); + sendGeneralResponse2(channel, remoteAddress, id, type); } return decodeLocation2(deviceSession, buf, type); diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java index 40d07230d..55c1e0c3b 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2020 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. @@ -50,22 +50,22 @@ public class HuabaoProtocolEncoder extends BaseProtocolEncoder { data.writeByte(0x01); data.writeBytes(time); return HuabaoProtocolDecoder.formatMessage( - HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data); + HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, false, data); } else { data.writeByte(0xf0); return HuabaoProtocolDecoder.formatMessage( - HuabaoProtocolDecoder.MSG_TERMINAL_CONTROL, id, data); + HuabaoProtocolDecoder.MSG_TERMINAL_CONTROL, id, false, data); } case Command.TYPE_ENGINE_RESUME: if (alternative) { data.writeByte(0x00); data.writeBytes(time); return HuabaoProtocolDecoder.formatMessage( - HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data); + HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, false, data); } else { data.writeByte(0xf1); return HuabaoProtocolDecoder.formatMessage( - HuabaoProtocolDecoder.MSG_TERMINAL_CONTROL, id, data); + HuabaoProtocolDecoder.MSG_TERMINAL_CONTROL, id, false, data); } default: return null; |