diff options
author | Abyss777 <abyss@fox5.ru> | 2018-06-06 11:01:59 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2018-06-06 11:01:59 +0500 |
commit | e091e61f54cabd2442927700d9c689f81fc1ed8b (patch) | |
tree | 97e5414d9eeb41fc0c4545c26b5098ac727c2de7 /src/org/traccar/protocol/TeltonikaProtocolDecoder.java | |
parent | eb6475d5087345b7f355fcd55362b955ba5df715 (diff) | |
download | trackermap-server-e091e61f54cabd2442927700d9c689f81fc1ed8b.tar.gz trackermap-server-e091e61f54cabd2442927700d9c689f81fc1ed8b.tar.bz2 trackermap-server-e091e61f54cabd2442927700d9c689f81fc1ed8b.zip |
Migrate gl200 and teltonika to netty 4
Diffstat (limited to 'src/org/traccar/protocol/TeltonikaProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/TeltonikaProtocolDecoder.java | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index 230db5dde..ac51239db 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -15,12 +15,14 @@ */ 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.Context; import org.traccar.DeviceSession; +import org.traccar.NetworkMessage; import org.traccar.helper.BitUtil; import org.traccar.helper.UnitsConverter; import org.traccar.model.CellTower; @@ -48,20 +50,20 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { this.extended = Context.getConfig().getBoolean(getProtocolName() + ".extended"); } - private DeviceSession parseIdentification(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { + private DeviceSession parseIdentification(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { int length = buf.readUnsignedShort(); String imei = buf.toString(buf.readerIndex(), length, StandardCharsets.US_ASCII); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (channel != null) { - ChannelBuffer response = ChannelBuffers.directBuffer(1); + ByteBuf response = Unpooled.directBuffer(1); if (deviceSession != null) { response.writeByte(1); } else { response.writeByte(0); } - channel.write(response); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } return deviceSession; } @@ -71,7 +73,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { public static final int CODEC_12 = 0x0C; public static final int CODEC_16 = 0x10; - private void decodeSerial(Position position, ChannelBuffer buf) { + private void decodeSerial(Position position, ByteBuf buf) { getLastLocation(position, null); @@ -81,7 +83,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } - private long readValue(ChannelBuffer buf, int length, boolean signed) { + private long readValue(ByteBuf buf, int length, boolean signed) { switch (length) { case 1: return signed ? buf.readByte() : buf.readUnsignedByte(); @@ -94,7 +96,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeOtherParameter(Position position, int id, ChannelBuffer buf, int length) { + private void decodeOtherParameter(Position position, int id, ByteBuf buf, int length) { switch (id) { case 1: case 2: @@ -201,7 +203,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeGh3000Parameter(Position position, int id, ChannelBuffer buf, int length) { + private void decodeGh3000Parameter(Position position, int id, ByteBuf buf, int length) { switch (id) { case 1: position.set(Position.KEY_BATTERY_LEVEL, readValue(buf, length, false)); @@ -244,7 +246,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeParameter(Position position, int id, ChannelBuffer buf, int length, int codec) { + private void decodeParameter(Position position, int id, ByteBuf buf, int length, int codec) { if (codec == CODEC_GH3000) { decodeGh3000Parameter(position, id, buf, length); } else { @@ -265,7 +267,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeLocation(Position position, ChannelBuffer buf, int codec) { + private void decodeLocation(Position position, ByteBuf buf, int codec) { int globalMask = 0x0f; @@ -392,7 +394,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (extended) { int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - position.set(Position.PREFIX_IO + buf.readUnsignedByte(), ChannelBuffers.hexDump(buf.readBytes(16))); + position.set(Position.PREFIX_IO + buf.readUnsignedByte(), ByteBufUtil.hexDump(buf.readBytes(16))); } } @@ -401,7 +403,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } private List<Position> parseData( - Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, int locationPacketId, String... imei) { + Channel channel, SocketAddress remoteAddress, ByteBuf buf, int locationPacketId, String... imei) { List<Position> positions = new LinkedList<>(); if (!connectionless) { @@ -433,17 +435,17 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { if (channel != null) { if (connectionless) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); response.writeShort(5); response.writeShort(0); response.writeByte(0x01); response.writeByte(locationPacketId); response.writeByte(count); - channel.write(response, remoteAddress); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } else { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); response.writeInt(count); - channel.write(response); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } } @@ -453,7 +455,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { @Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; if (connectionless) { return decodeUdp(channel, remoteAddress, buf); @@ -462,7 +464,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } } - private Object decodeTcp(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception { + private Object decodeTcp(Channel channel, SocketAddress remoteAddress, ByteBuf buf) throws Exception { if (buf.getUnsignedShort(0) > 0) { parseIdentification(channel, remoteAddress, buf); @@ -474,7 +476,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { return null; } - private Object decodeUdp(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception { + private Object decodeUdp(Channel channel, SocketAddress remoteAddress, ByteBuf buf) throws Exception { buf.readUnsignedShort(); // length buf.readUnsignedShort(); // packet id |