diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-07 23:03:50 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-07 23:03:50 +1200 |
commit | e26b25c7c35cb99f3e0fb114bcedd76f090e0c3b (patch) | |
tree | 2a6a6ad9018e1de675fdadaadc6929f1163e37f7 /src/org/traccar/protocol/UlbotechProtocolDecoder.java | |
parent | 7e324a9dfb2bcde08d1524a9f3dc5114c0d49bdc (diff) | |
parent | 757cdb82c9109541ee5e7dc8d8ddca31c8507ca3 (diff) | |
download | trackermap-server-e26b25c7c35cb99f3e0fb114bcedd76f090e0c3b.tar.gz trackermap-server-e26b25c7c35cb99f3e0fb114bcedd76f090e0c3b.tar.bz2 trackermap-server-e26b25c7c35cb99f3e0fb114bcedd76f090e0c3b.zip |
Merge pull request #3917 from Abyss777/netty4_uv
Migrate U,V protocols
Diffstat (limited to 'src/org/traccar/protocol/UlbotechProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/UlbotechProtocolDecoder.java | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index 5499518a1..0c3ea6391 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -15,11 +15,13 @@ */ 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.ByteBufUtil; +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.BitUtil; import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; @@ -58,18 +60,18 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { private static final short DATA_RFID = 0x0E; private static final short DATA_EVENT = 0x10; - private void decodeObd(Position position, ChannelBuffer buf, int length) { + private void decodeObd(Position position, ByteBuf buf, int length) { int end = buf.readerIndex() + length; while (buf.readerIndex() < end) { int parameterLength = buf.getUnsignedByte(buf.readerIndex()) >> 4; int mode = buf.readUnsignedByte() & 0x0F; - position.add(ObdDecoder.decode(mode, ChannelBuffers.hexDump(buf.readBytes(parameterLength - 1)))); + position.add(ObdDecoder.decode(mode, ByteBufUtil.hexDump(buf.readBytes(parameterLength - 1)))); } } - private void decodeJ1708(Position position, ChannelBuffer buf, int length) { + private void decodeJ1708(Position position, ByteBuf buf, int length) { int end = buf.readerIndex() + length; @@ -81,14 +83,14 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { if (type == 3) { id += 256; } - String value = ChannelBuffers.hexDump(buf.readBytes(len - 1)); + String value = ByteBufUtil.hexDump(buf.readBytes(len - 1)); if (type == 2 || type == 3) { position.set("pid" + id, value); } } } - private void decodeDriverBehavior(Position position, ChannelBuffer buf) { + private void decodeDriverBehavior(Position position, ByteBuf buf) { int value = buf.readUnsignedByte(); @@ -137,7 +139,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { return null; } - private void decodeAdc(Position position, ChannelBuffer buf, int length) { + private void decodeAdc(Position position, ByteBuf buf, int length) { for (int i = 0; i < length / 2; i++) { int value = buf.readUnsignedShort(); int id = BitUtil.from(value, 12); @@ -198,13 +200,13 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { return position; } - private Object decodeBinary(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { + private Object decodeBinary(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { buf.readUnsignedByte(); // header buf.readUnsignedByte(); // version buf.readUnsignedByte(); // type - String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1); + String imei = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { @@ -294,7 +296,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { break; case DATA_CANBUS: - position.set("can", ChannelBuffers.hexDump(buf.readBytes(length))); + position.set("can", ByteBufUtil.hexDump(buf.readBytes(length))); break; case DATA_J1708: @@ -337,28 +339,28 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; if (buf.getUnsignedByte(buf.readerIndex()) == 0xF8) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); response.writeByte(0xF8); response.writeByte(DATA_GPS); response.writeByte(0xFE); response.writeShort(buf.getShort(response.writerIndex() - 1 - 2)); - response.writeShort(Checksum.crc16(Checksum.CRC16_XMODEM, response.toByteBuffer(1, 4))); + response.writeShort(Checksum.crc16(Checksum.CRC16_XMODEM, response.nioBuffer(1, 4))); response.writeByte(0xF8); - channel.write(response); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } return decodeBinary(channel, remoteAddress, buf); } else { if (channel != null) { - channel.write(ChannelBuffers.copiedBuffer(String.format("*TS01,ACK:%04X#", - Checksum.crc16(Checksum.CRC16_XMODEM, buf.toByteBuffer(1, buf.writerIndex() - 2))), - StandardCharsets.US_ASCII)); + channel.writeAndFlush(new NetworkMessage(Unpooled.copiedBuffer(String.format("*TS01,ACK:%04X#", + Checksum.crc16(Checksum.CRC16_XMODEM, buf.nioBuffer(1, buf.writerIndex() - 2))), + StandardCharsets.US_ASCII), remoteAddress)); } return decodeText(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII)); |