aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/HuabaoProtocolEncoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol/HuabaoProtocolEncoder.java')
-rw-r--r--src/org/traccar/protocol/HuabaoProtocolEncoder.java39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/org/traccar/protocol/HuabaoProtocolEncoder.java b/src/org/traccar/protocol/HuabaoProtocolEncoder.java
index a622fdb9a..a2702fec7 100644
--- a/src/org/traccar/protocol/HuabaoProtocolEncoder.java
+++ b/src/org/traccar/protocol/HuabaoProtocolEncoder.java
@@ -30,24 +30,27 @@ public class HuabaoProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- ByteBuf id = Unpooled.wrappedBuffer(
- DataConverter.parseHex(getUniqueId(command.getDeviceId()))); // TODO ref count
-
- ByteBuf data = Unpooled.buffer();
- byte[] time = DataConverter.parseHex(new SimpleDateFormat("yyMMddHHmmss").format(new Date()));
-
- switch (command.getType()) {
- case Command.TYPE_ENGINE_STOP:
- data.writeByte(0x01);
- data.writeBytes(time);
- return HuabaoProtocolDecoder.formatMessage(HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data);
- case Command.TYPE_ENGINE_RESUME:
- data.writeByte(0x00);
- data.writeBytes(time);
- return HuabaoProtocolDecoder.formatMessage(HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- return null;
+ ByteBuf id = Unpooled.wrappedBuffer(
+ DataConverter.parseHex(getUniqueId(command.getDeviceId())));
+ try {
+ ByteBuf data = Unpooled.buffer();
+ byte[] time = DataConverter.parseHex(new SimpleDateFormat("yyMMddHHmmss").format(new Date()));
+
+ switch (command.getType()) {
+ case Command.TYPE_ENGINE_STOP:
+ data.writeByte(0x01);
+ data.writeBytes(time);
+ return HuabaoProtocolDecoder.formatMessage(HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data);
+ case Command.TYPE_ENGINE_RESUME:
+ data.writeByte(0x00);
+ data.writeBytes(time);
+ return HuabaoProtocolDecoder.formatMessage(HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data);
+ default:
+ Log.warning(new UnsupportedOperationException(command.getType()));
+ return null;
+ }
+ } finally {
+ id.release();
}
}