diff options
Diffstat (limited to 'src/org/traccar/protocol/TlvProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/TlvProtocolDecoder.java | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/org/traccar/protocol/TlvProtocolDecoder.java b/src/org/traccar/protocol/TlvProtocolDecoder.java index 0cf68acb8..d3ce4e072 100644 --- a/src/org/traccar/protocol/TlvProtocolDecoder.java +++ b/src/org/traccar/protocol/TlvProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2018 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. @@ -15,11 +15,12 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.NetworkMessage; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @@ -33,43 +34,43 @@ public class TlvProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private void sendResponse(Channel channel, String type, String... arguments) { + private void sendResponse(Channel channel, SocketAddress remoteAddress, String type, String... arguments) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); - response.writeBytes(ChannelBuffers.copiedBuffer(type, StandardCharsets.US_ASCII)); + ByteBuf response = Unpooled.buffer(); + response.writeCharSequence(type, StandardCharsets.US_ASCII); for (String argument : arguments) { response.writeByte(argument.length()); - response.writeBytes(ChannelBuffers.copiedBuffer(argument, StandardCharsets.US_ASCII)); + response.writeCharSequence(argument, StandardCharsets.US_ASCII); } response.writeByte(0); - channel.write(response); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } } - private String readArgument(ChannelBuffer buf) { - return buf.readBytes(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII); + private String readArgument(ByteBuf buf) { + return buf.readSlice(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII); } @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; - String type = buf.readBytes(2).toString(StandardCharsets.US_ASCII); + String type = buf.readSlice(2).toString(StandardCharsets.US_ASCII); if (channel != null) { switch (type) { case "0A": case "0C": - sendResponse(channel, type); + sendResponse(channel, remoteAddress, type); break; case "0B": - sendResponse(channel, type, "1482202689", "10", "20", "15"); + sendResponse(channel, remoteAddress, type, "1482202689", "10", "20", "15"); break; case "0E": case "0F": - sendResponse(channel, type, "30", "Unknown"); + sendResponse(channel, remoteAddress, type, "30", "Unknown"); break; default: break; |