diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-05 23:16:21 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-05 23:16:21 +1200 |
commit | 9c99076dc2416c4e0725007af0e5f2f2f444c05c (patch) | |
tree | 55068f2ab5dbe99fcd60acc01c1bb05fc365aa43 /src | |
parent | b8f4fc8888aaad7fe384c1dc2b80f44c1683bb03 (diff) | |
download | trackermap-server-9c99076dc2416c4e0725007af0e5f2f2f444c05c.tar.gz trackermap-server-9c99076dc2416c4e0725007af0e5f2f2f444c05c.tar.bz2 trackermap-server-9c99076dc2416c4e0725007af0e5f2f2f444c05c.zip |
Migrate more protocols
Diffstat (limited to 'src')
51 files changed, 397 insertions, 414 deletions
diff --git a/src/org/traccar/BaseFrameDecoder.java b/src/org/traccar/BaseFrameDecoder.java new file mode 100644 index 000000000..f90f90e4b --- /dev/null +++ b/src/org/traccar/BaseFrameDecoder.java @@ -0,0 +1,37 @@ +/* + * Copyright 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; + +import java.util.List; + +public abstract class BaseFrameDecoder extends ByteToMessageDecoder { + + @Override + protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { + Object decoded = decode(ctx, ctx != null ? ctx.channel() : null, in); + if (decoded != null) { + out.add(decoded); + } + } + + protected abstract Object decode(ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception; + +} diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java index c33270fc6..2cc24d3d9 100644 --- a/src/org/traccar/BaseProtocol.java +++ b/src/org/traccar/BaseProtocol.java @@ -76,7 +76,7 @@ public abstract class BaseProtocol implements Protocol { activeDevice.write(command); } else if (command.getType().equals(Command.TYPE_CUSTOM)) { String data = command.getString(Command.KEY_DATA); - if (activeDevice.getChannel().pipeline().get(StringEncoder.class) != null) { // TODO change + if (activeDevice.getChannel().pipeline().get("stringEncoder") != null) { activeDevice.write(data); } else { activeDevice.write(Unpooled.wrappedBuffer(DataConverter.parseHex(data))); diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java index 9c0b51c79..31bf47e3f 100644 --- a/src/org/traccar/BaseProtocolDecoder.java +++ b/src/org/traccar/BaseProtocolDecoder.java @@ -145,7 +145,7 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { } public DeviceSession getDeviceSession(Channel channel, SocketAddress remoteAddress, String... uniqueIds) { - if (channel != null && channel.pipeline().get(HttpRequestDecoder.class) != null // TODO change + if (channel != null && channel.pipeline().get("httpDecoder") != null || Context.getConfig().getBoolean("decoder.ignoreSessionCache")) { long deviceId = findDeviceId(remoteAddress, uniqueIds); if (deviceId != 0) { diff --git a/src/org/traccar/GlobalChannelFactory.java b/src/org/traccar/EventLoopGroupFactory.java index 7bc0f4f03..806a3a1dc 100644 --- a/src/org/traccar/GlobalChannelFactory.java +++ b/src/org/traccar/EventLoopGroupFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 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. @@ -18,7 +18,7 @@ package org.traccar; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; -public final class GlobalChannelFactory { // TODO rename class +public final class EventLoopGroupFactory { private static EventLoopGroup bossGroup = new NioEventLoopGroup(); private static EventLoopGroup workerGroup = new NioEventLoopGroup(); diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java index fb643c958..c3d36b04c 100644 --- a/src/org/traccar/TrackerServer.java +++ b/src/org/traccar/TrackerServer.java @@ -19,7 +19,6 @@ import io.netty.bootstrap.AbstractBootstrap; import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; -import io.netty.channel.ChannelPipeline; import io.netty.channel.group.ChannelGroup; import io.netty.channel.group.DefaultChannelGroup; import io.netty.channel.socket.nio.NioDatagramChannel; @@ -53,14 +52,14 @@ public abstract class TrackerServer { if (datagram) { this.bootstrap = new Bootstrap() - .group(GlobalChannelFactory.getWorkerGroup()) + .group(EventLoopGroupFactory.getWorkerGroup()) .channel(NioDatagramChannel.class) .handler(pipelineFactory); } else { this.bootstrap = new ServerBootstrap() - .group(GlobalChannelFactory.getBossGroup(), GlobalChannelFactory.getWorkerGroup()) + .group(EventLoopGroupFactory.getBossGroup(), EventLoopGroupFactory.getWorkerGroup()) .channel(NioServerSocketChannel.class) .childHandler(pipelineFactory); diff --git a/src/org/traccar/helper/StringFinder.java b/src/org/traccar/helper/StringFinder.java deleted file mode 100644 index 53e9bd68a..000000000 --- a/src/org/traccar/helper/StringFinder.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.helper; - -import java.nio.charset.StandardCharsets; - -public class StringFinder /*implements ChannelBufferIndexFinder*/ { // TODO handle this - - /*private String string; - - public StringFinder(String string) { - this.string = string; - } - - @Override - public boolean find(ChannelBuffer buffer, int guessedIndex) { - - if (buffer.writerIndex() - guessedIndex < string.length()) { - return false; - } - - return string.equals(buffer.toString(guessedIndex, string.length(), StandardCharsets.US_ASCII)); - }*/ - -} diff --git a/src/org/traccar/protocol/AdmProtocol.java b/src/org/traccar/protocol/AdmProtocol.java index 4d2cbe7b3..994661af2 100644 --- a/src/org/traccar/protocol/AdmProtocol.java +++ b/src/org/traccar/protocol/AdmProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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,10 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.LengthFieldBasedFrameDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import org.traccar.model.Command; @@ -37,17 +36,16 @@ public class AdmProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 1, -3, 0)); + protected void addProtocolHandlers(PipelineBuilder pipeline) { + pipeline.addLast("frameDecoder", + new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, 1024, 2, 1, -3, 0, true)); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("objectEncoder", new AdmProtocolEncoder()); pipeline.addLast("objectDecoder", new AdmProtocolDecoder(AdmProtocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); + }); } } diff --git a/src/org/traccar/protocol/AdmProtocolDecoder.java b/src/org/traccar/protocol/AdmProtocolDecoder.java index 4ae16017a..04a607749 100644 --- a/src/org/traccar/protocol/AdmProtocolDecoder.java +++ b/src/org/traccar/protocol/AdmProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 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,8 +15,8 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.Channel; +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; @@ -38,7 +38,7 @@ public class AdmProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_PHOTO = 0x0A; public static final int MSG_ADM5 = 0x01; - private Position decodeData(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, int type) { + private Position decodeData(Channel channel, SocketAddress remoteAddress, ByteBuf buf, int type) { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession == null) { @@ -50,25 +50,25 @@ public class AdmProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte()); - position.set(Position.KEY_INDEX, buf.readUnsignedShort()); + position.set(Position.KEY_INDEX, buf.readUnsignedShortLE()); - int status = buf.readUnsignedShort(); + int status = buf.readUnsignedShortLE(); position.set(Position.KEY_STATUS, status); position.setValid(!BitUtil.check(status, 5)); - position.setLatitude(buf.readFloat()); - position.setLongitude(buf.readFloat()); - position.setCourse(buf.readUnsignedShort() * 0.1); - position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1)); + position.setLatitude(buf.readFloatLE()); + position.setLongitude(buf.readFloatLE()); + position.setCourse(buf.readUnsignedShortLE() * 0.1); + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE() * 0.1)); position.set(Position.KEY_ACCELERATION, buf.readUnsignedByte() * 0.1); - position.setAltitude(buf.readUnsignedShort()); + position.setAltitude(buf.readUnsignedShortLE()); position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1); position.set(Position.KEY_SATELLITES, buf.readUnsignedByte() & 0x0f); - position.setTime(new Date(buf.readUnsignedInt() * 1000)); + position.setTime(new Date(buf.readUnsignedIntLE() * 1000)); - position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001); - position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001); + position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.001); + position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001); if (BitUtil.check(type, 2)) { buf.readUnsignedByte(); // vib @@ -84,19 +84,19 @@ public class AdmProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(type, 3)) { for (int i = 1; i <= 6; i++) { - position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort() * 0.001); + position.set(Position.PREFIX_ADC + i, buf.readUnsignedShortLE() * 0.001); } } if (BitUtil.check(type, 4)) { for (int i = 1; i <= 2; i++) { - position.set(Position.PREFIX_COUNT + i, buf.readUnsignedInt()); + position.set(Position.PREFIX_COUNT + i, buf.readUnsignedIntLE()); } } if (BitUtil.check(type, 5)) { for (int i = 1; i <= 3; i++) { - buf.readUnsignedShort(); // fuel level + buf.readUnsignedShortLE(); // fuel level } for (int i = 1; i <= 3; i++) { position.set(Position.PREFIX_TEMP + i, buf.readUnsignedByte()); @@ -108,7 +108,7 @@ public class AdmProtocolDecoder extends BaseProtocolDecoder { } if (BitUtil.check(type, 7)) { - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); } return position; @@ -117,7 +117,7 @@ public class AdmProtocolDecoder extends BaseProtocolDecoder { return null; } - private Position parseCommandResponse(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { + private Position parseCommandResponse(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession == null) { return null; @@ -139,9 +139,9 @@ public class AdmProtocolDecoder extends BaseProtocolDecoder { @Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; - buf.readUnsignedShort(); // device id + buf.readUnsignedShortLE(); // device id int size = buf.readUnsignedByte(); if (size != CMD_RESPONSE_SIZE) { diff --git a/src/org/traccar/protocol/AdmProtocolEncoder.java b/src/org/traccar/protocol/AdmProtocolEncoder.java index 8cbd8618d..bcbf8a2f1 100644 --- a/src/org/traccar/protocol/AdmProtocolEncoder.java +++ b/src/org/traccar/protocol/AdmProtocolEncoder.java @@ -39,4 +39,5 @@ public class AdmProtocolEncoder extends StringProtocolEncoder { return null; } + } diff --git a/src/org/traccar/protocol/AisProtocol.java b/src/org/traccar/protocol/AisProtocol.java index 4b2e1719e..ff81db45c 100644 --- a/src/org/traccar/protocol/AisProtocol.java +++ b/src/org/traccar/protocol/AisProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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,10 +15,9 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ConnectionlessBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringDecoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -31,9 +30,9 @@ public class AisProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("objectDecoder", new AisProtocolDecoder(AisProtocol.this)); } diff --git a/src/org/traccar/protocol/AisProtocolDecoder.java b/src/org/traccar/protocol/AisProtocolDecoder.java index 842260e98..7954ef5f9 100644 --- a/src/org/traccar/protocol/AisProtocolDecoder.java +++ b/src/org/traccar/protocol/AisProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitBuffer; diff --git a/src/org/traccar/protocol/AlematicsFrameDecoder.java b/src/org/traccar/protocol/AlematicsFrameDecoder.java index b8b3e3403..daac868c0 100644 --- a/src/org/traccar/protocol/AlematicsFrameDecoder.java +++ b/src/org/traccar/protocol/AlematicsFrameDecoder.java @@ -15,10 +15,10 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.LineBasedFrameDecoder; +import org.traccar.NetworkMessage; public class AlematicsFrameDecoder extends LineBasedFrameDecoder { @@ -31,20 +31,20 @@ public class AlematicsFrameDecoder extends LineBasedFrameDecoder { // example of heartbeat: FA F8 00 07 00 03 15 AD 4E 78 3A D2 @Override - protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { + protected Object decode(ChannelHandlerContext ctx, ByteBuf buf) throws Exception { if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) { return null; } if (buf.getUnsignedShort(buf.readerIndex()) == 0xFAF8) { - ChannelBuffer heartbeat = buf.readBytes(12); - if (channel != null) { - channel.write(heartbeat); + ByteBuf heartbeat = buf.readBytes(12); + if (ctx != null && ctx.channel() != null) { + ctx.channel().writeAndFlush(new NetworkMessage(heartbeat, ctx.channel().remoteAddress())); } } - return super.decode(ctx, channel, buf); + return super.decode(ctx, buf); } } diff --git a/src/org/traccar/protocol/AlematicsProtocol.java b/src/org/traccar/protocol/AlematicsProtocol.java index 241ce8bf9..a8bb124f9 100644 --- a/src/org/traccar/protocol/AlematicsProtocol.java +++ b/src/org/traccar/protocol/AlematicsProtocol.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,10 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -32,9 +31,9 @@ public class AlematicsProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new AlematicsFrameDecoder(1024)); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/AlematicsProtocolDecoder.java b/src/org/traccar/protocol/AlematicsProtocolDecoder.java index b83081cc1..794588f5f 100644 --- a/src/org/traccar/protocol/AlematicsProtocolDecoder.java +++ b/src/org/traccar/protocol/AlematicsProtocolDecoder.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,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; diff --git a/src/org/traccar/protocol/ApelProtocol.java b/src/org/traccar/protocol/ApelProtocol.java index 690b5ed99..6b18c2fb8 100644 --- a/src/org/traccar/protocol/ApelProtocol.java +++ b/src/org/traccar/protocol/ApelProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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,10 +15,9 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import io.netty.handler.codec.LengthFieldBasedFrameDecoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.nio.ByteOrder; @@ -32,15 +31,14 @@ public class ApelProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, 4, 0)); + protected void addProtocolHandlers(PipelineBuilder pipeline) { + pipeline.addLast("frameDecoder", + new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, 1024, 2, 2, 4, 0, true)); pipeline.addLast("objectDecoder", new ApelProtocolDecoder(ApelProtocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); + }); } } diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java index a107f7d6f..bb99783f0 100644 --- a/src/org/traccar/protocol/ApelProtocolDecoder.java +++ b/src/org/traccar/protocol/ApelProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2014 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 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,17 +15,17 @@ */ 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.Checksum; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; -import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.LinkedList; @@ -66,24 +66,24 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { public static final short MSG_GPRS_COMMAND = 180; private void sendSimpleMessage(Channel channel, short type) { - ChannelBuffer request = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 8); - request.writeShort(type); - request.writeShort(0); - request.writeInt(Checksum.crc32(request.toByteBuffer(0, 4))); - channel.write(request); + ByteBuf request = Unpooled.buffer(8); + request.writeShortLE(type); + request.writeShortLE(0); + request.writeIntLE(Checksum.crc32(request.nioBuffer(0, 4))); + channel.writeAndFlush(new NetworkMessage(request, channel.remoteAddress())); } private void requestArchive(Channel channel) { if (lastIndex == 0) { lastIndex = newIndex; } else if (newIndex > lastIndex) { - ChannelBuffer request = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 14); - request.writeShort(MSG_REQUEST_LOG_RECORDS); - request.writeShort(6); - request.writeInt((int) lastIndex); - request.writeShort(512); - request.writeInt(Checksum.crc32(request.toByteBuffer(0, 10))); - channel.write(request); + ByteBuf request = Unpooled.buffer(14); + request.writeShortLE(MSG_REQUEST_LOG_RECORDS); + request.writeShortLE(6); + request.writeIntLE((int) lastIndex); + request.writeShortLE(512); + request.writeIntLE(Checksum.crc32(request.nioBuffer(0, 10))); + channel.writeAndFlush(new NetworkMessage(request, channel.remoteAddress())); } } @@ -91,11 +91,11 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; - int type = buf.readUnsignedShort(); + ByteBuf buf = (ByteBuf) msg; + int type = buf.readUnsignedShortLE(); boolean alarm = (type & 0x8000) != 0; type = type & 0x7FFF; - buf.readUnsignedShort(); // length + buf.readUnsignedShortLE(); // length if (alarm) { sendSimpleMessage(channel, MSG_ACK_ALARM); @@ -107,15 +107,15 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_TRACKER_ID_EXT) { - buf.readUnsignedInt(); // id - int length = buf.readUnsignedShort(); + buf.readUnsignedIntLE(); // id + int length = buf.readUnsignedShortLE(); buf.skipBytes(length); - length = buf.readUnsignedShort(); + length = buf.readUnsignedShortLE(); getDeviceSession(channel, remoteAddress, buf.readBytes(length).toString(StandardCharsets.US_ASCII)); } else if (type == MSG_LAST_LOG_INDEX) { - long index = buf.readUnsignedInt(); + long index = buf.readUnsignedIntLE(); if (index > 0) { newIndex = index; requestArchive(channel); @@ -132,7 +132,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { int recordCount = 1; if (type == MSG_LOG_RECORDS) { - recordCount = buf.readUnsignedShort(); + recordCount = buf.readUnsignedShortLE(); } for (int j = 0; j < recordCount; j++) { @@ -142,20 +142,20 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { int subtype = type; if (type == MSG_LOG_RECORDS) { position.set(Position.KEY_ARCHIVE, true); - lastIndex = buf.readUnsignedInt() + 1; + lastIndex = buf.readUnsignedIntLE() + 1; position.set(Position.KEY_INDEX, lastIndex); - subtype = buf.readUnsignedShort(); + subtype = buf.readUnsignedShortLE(); if (subtype != MSG_CURRENT_GPS_DATA && subtype != MSG_STATE_FULL_INFO_T104) { - buf.skipBytes(buf.readUnsignedShort()); + buf.skipBytes(buf.readUnsignedShortLE()); continue; } - buf.readUnsignedShort(); // length + buf.readUnsignedShortLE(); // length } - position.setTime(new Date(buf.readUnsignedInt() * 1000)); - position.setLatitude(buf.readInt() * 180.0 / 0x7FFFFFFF); - position.setLongitude(buf.readInt() * 180.0 / 0x7FFFFFFF); + position.setTime(new Date(buf.readUnsignedIntLE() * 1000)); + position.setLatitude(buf.readIntLE() * 180.0 / 0x7FFFFFFF); + position.setLongitude(buf.readIntLE() * 180.0 / 0x7FFFFFFF); if (subtype == MSG_STATE_FULL_INFO_T104) { int speed = buf.readUnsignedByte(); @@ -163,36 +163,36 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromKph(speed)); position.set(Position.KEY_HDOP, buf.readByte()); } else { - int speed = buf.readShort(); + int speed = buf.readShortLE(); position.setValid(speed != -1); position.setSpeed(UnitsConverter.knotsFromKph(speed * 0.01)); } - position.setCourse(buf.readShort() * 0.01); - position.setAltitude(buf.readShort()); + position.setCourse(buf.readShortLE() * 0.01); + position.setAltitude(buf.readShortLE()); if (subtype == MSG_STATE_FULL_INFO_T104) { position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.set(Position.KEY_RSSI, buf.readUnsignedByte()); - position.set(Position.KEY_EVENT, buf.readUnsignedShort()); - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + position.set(Position.KEY_EVENT, buf.readUnsignedShortLE()); + position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); position.set(Position.KEY_INPUT, buf.readUnsignedByte()); position.set(Position.KEY_OUTPUT, buf.readUnsignedByte()); for (int i = 1; i <= 8; i++) { - position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort()); + position.set(Position.PREFIX_ADC + i, buf.readUnsignedShortLE()); } - position.set(Position.PREFIX_COUNT + 1, buf.readUnsignedInt()); - position.set(Position.PREFIX_COUNT + 2, buf.readUnsignedInt()); - position.set(Position.PREFIX_COUNT + 3, buf.readUnsignedInt()); + position.set(Position.PREFIX_COUNT + 1, buf.readUnsignedIntLE()); + position.set(Position.PREFIX_COUNT + 2, buf.readUnsignedIntLE()); + position.set(Position.PREFIX_COUNT + 3, buf.readUnsignedIntLE()); } positions.add(position); } - buf.readUnsignedInt(); // crc + buf.readUnsignedIntLE(); // crc if (type == MSG_LOG_RECORDS) { requestArchive(channel); diff --git a/src/org/traccar/protocol/AplicomFrameDecoder.java b/src/org/traccar/protocol/AplicomFrameDecoder.java index 083025077..813bd49c6 100644 --- a/src/org/traccar/protocol/AplicomFrameDecoder.java +++ b/src/org/traccar/protocol/AplicomFrameDecoder.java @@ -1,5 +1,5 @@ /*
- * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 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.
@@ -16,15 +16,15 @@ package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
+import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.ByteToMessageDecoder;
+import org.traccar.BaseFrameDecoder;
-import java.util.List;
-
-public class AplicomFrameDecoder extends ByteToMessageDecoder {
+public class AplicomFrameDecoder extends BaseFrameDecoder {
@Override
- protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
+ protected Object decode(
+ ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
// Skip Alive message
while (buf.isReadable() && Character.isDigit(buf.getByte(buf.readerIndex()))) {
@@ -33,7 +33,7 @@ public class AplicomFrameDecoder extends ByteToMessageDecoder { // Check minimum length
if (buf.readableBytes() < 11) {
- return;
+ return null;
}
// Read flags
@@ -53,8 +53,10 @@ public class AplicomFrameDecoder extends ByteToMessageDecoder { // Return buffer
if (buf.readableBytes() >= length) {
- out.add(buf.readBytes(length));
+ return buf.readBytes(length);
}
+
+ return null;
}
}
diff --git a/src/org/traccar/protocol/AplicomProtocol.java b/src/org/traccar/protocol/AplicomProtocol.java index 80f6f528f..6b9074163 100644 --- a/src/org/traccar/protocol/AplicomProtocol.java +++ b/src/org/traccar/protocol/AplicomProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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,9 +15,8 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -30,9 +29,9 @@ public class AplicomProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new AplicomFrameDecoder()); pipeline.addLast("objectDecoder", new AplicomProtocolDecoder(AplicomProtocol.this)); } diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java index e649b52a6..b9da609ed 100644 --- a/src/org/traccar/protocol/AplicomProtocolDecoder.java +++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java @@ -15,9 +15,9 @@ */ 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.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; @@ -82,7 +82,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { private static final int EVENT_DATA = 119; - private void decodeEventData(Position position, ChannelBuffer buf, int event) { + private void decodeEventData(Position position, ByteBuf buf, int event) { switch (event) { case 2: case 40: @@ -117,7 +117,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeCanData(ChannelBuffer buf, Position position) { + private void decodeCanData(ByteBuf buf, Position position) { buf.readUnsignedMedium(); // packet identifier position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte()); @@ -128,63 +128,63 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(8); - ArrayList<ChannelBuffer> values = new ArrayList<>(count); + ArrayList<ByteBuf> values = new ArrayList<>(count); for (int i = 0; i < count; i++) { values.add(buf.readBytes(8)); } for (int i = 0; i < count; i++) { - ChannelBuffer value = values.get(i); + ByteBuf value = values.get(i); switch (buf.readInt()) { case 0x20D: - position.set(Position.KEY_RPM, ChannelBuffers.swapShort(value.readShort())); - position.set("dieselTemperature", ChannelBuffers.swapShort(value.readShort()) * 0.1); - position.set("batteryVoltage", ChannelBuffers.swapShort(value.readShort()) * 0.01); - position.set("supplyAirTempDep1", ChannelBuffers.swapShort(value.readShort()) * 0.1); + position.set(Position.KEY_RPM, value.readShortLE()); + position.set("dieselTemperature", value.readShortLE() * 0.1); + position.set("batteryVoltage", value.readShortLE() * 0.01); + position.set("supplyAirTempDep1", value.readShortLE() * 0.1); break; case 0x30D: - position.set("activeAlarm", ChannelBuffers.hexDump(value)); + position.set("activeAlarm", ByteBufUtil.hexDump(value)); break; case 0x40C: - position.set("airTempDep1", ChannelBuffers.swapShort(value.readShort()) * 0.1); - position.set("airTempDep2", ChannelBuffers.swapShort(value.readShort()) * 0.1); + position.set("airTempDep1", value.readShortLE() * 0.1); + position.set("airTempDep2", value.readShortLE() * 0.1); break; case 0x40D: - position.set("coldUnitState", ChannelBuffers.hexDump(value)); + position.set("coldUnitState", ByteBufUtil.hexDump(value)); break; case 0x50C: - position.set("defrostTempDep1", ChannelBuffers.swapShort(value.readShort()) * 0.1); - position.set("defrostTempDep2", ChannelBuffers.swapShort(value.readShort()) * 0.1); + position.set("defrostTempDep1", value.readShortLE() * 0.1); + position.set("defrostTempDep2", value.readShortLE() * 0.1); break; case 0x50D: - position.set("condenserPressure", ChannelBuffers.swapShort(value.readShort()) * 0.1); - position.set("suctionPressure", ChannelBuffers.swapShort(value.readShort()) * 0.1); + position.set("condenserPressure", value.readShortLE() * 0.1); + position.set("suctionPressure", value.readShortLE() * 0.1); break; case 0x58C: value.readByte(); value.readShort(); // index switch (value.readByte()) { case 0x01: - position.set("setpointZone1", ChannelBuffers.swapInt(value.readInt()) * 0.1); + position.set("setpointZone1", value.readIntLE() * 0.1); break; case 0x02: - position.set("setpointZone2", ChannelBuffers.swapInt(value.readInt()) * 0.1); + position.set("setpointZone2", value.readIntLE() * 0.1); break; case 0x05: - position.set("unitType", ChannelBuffers.swapInt(value.readInt())); + position.set("unitType", value.readIntLE()); break; case 0x13: - position.set("dieselHours", ChannelBuffers.swapInt(value.readInt()) / 60 / 60); + position.set("dieselHours", value.readIntLE() / 60 / 60); break; case 0x14: - position.set("electricHours", ChannelBuffers.swapInt(value.readInt()) / 60 / 60); + position.set("electricHours", value.readIntLE() / 60 / 60); break; case 0x17: - position.set("serviceIndicator", ChannelBuffers.swapInt(value.readInt())); + position.set("serviceIndicator", value.readIntLE()); break; case 0x18: - position.set("softwareVersion", ChannelBuffers.swapInt(value.readInt()) * 0.01); + position.set("softwareVersion", value.readIntLE() * 0.01); break; default: break; @@ -197,7 +197,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeD(Position position, ChannelBuffer buf, int selector, int event) { + private void decodeD(Position position, ByteBuf buf, int selector, int event) { if ((selector & 0x0008) != 0) { position.setValid((buf.readUnsignedByte() & 0x40) != 0); @@ -292,12 +292,12 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } if (Context.getConfig().getBoolean(getProtocolName() + ".can") - && buf.readable() && (selector & 0x1000) != 0 && event == EVENT_DATA) { + && buf.isReadable() && (selector & 0x1000) != 0 && event == EVENT_DATA) { decodeCanData(buf, position); } } - private void decodeE(Position position, ChannelBuffer buf, int selector) { + private void decodeE(Position position, ByteBuf buf, int selector) { if ((selector & 0x0008) != 0) { position.set("tachographEvent", buf.readUnsignedShort()); @@ -379,7 +379,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeH(Position position, ChannelBuffer buf, int selector) { + private void decodeH(Position position, ByteBuf buf, int selector) { if ((selector & 0x0004) != 0) { getLastLocation(position, new Date(buf.readUnsignedInt() * 1000)); @@ -457,7 +457,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeEB(Position position, ChannelBuffer buf) { + private void decodeEB(Position position, ByteBuf buf) { if (buf.readByte() != (byte) 'E' || buf.readByte() != (byte) 'B') { return; @@ -477,7 +477,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { switch (type) { case 0x01: - position.set("brakeFlags", ChannelBuffers.hexDump(buf.readBytes(length))); + position.set("brakeFlags", ByteBufUtil.hexDump(buf.readBytes(length))); break; case 0x02: position.set("wheelSpeed", buf.readUnsignedShort() / 256.0); @@ -507,10 +507,10 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { position.set("vdcActiveCounter", buf.readUnsignedShort()); break; case 0x0B: - position.set("brakeMinMaxData", ChannelBuffers.hexDump(buf.readBytes(length))); + position.set("brakeMinMaxData", ByteBufUtil.hexDump(buf.readBytes(length))); break; case 0x0C: - position.set("missingPgn", ChannelBuffers.hexDump(buf.readBytes(length))); + position.set("missingPgn", ByteBufUtil.hexDump(buf.readBytes(length))); break; case 0x0D: buf.readUnsignedByte(); @@ -526,7 +526,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeF(Position position, ChannelBuffer buf, int selector) { + private void decodeF(Position position, ByteBuf buf, int selector) { getLastLocation(position, null); @@ -636,7 +636,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder { @Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; char protocol = (char) buf.readByte(); int version = buf.readUnsignedByte(); diff --git a/src/org/traccar/protocol/AppelloProtocol.java b/src/org/traccar/protocol/AppelloProtocol.java index 8581850a1..33c7bbeed 100644 --- a/src/org/traccar/protocol/AppelloProtocol.java +++ b/src/org/traccar/protocol/AppelloProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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,12 +15,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.LineBasedFrameDecoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -33,9 +32,9 @@ public class AppelloProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/AppelloProtocolDecoder.java b/src/org/traccar/protocol/AppelloProtocolDecoder.java index bf95b4068..ea0a2e243 100644 --- a/src/org/traccar/protocol/AppelloProtocolDecoder.java +++ b/src/org/traccar/protocol/AppelloProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.Parser; diff --git a/src/org/traccar/protocol/AquilaProtocol.java b/src/org/traccar/protocol/AquilaProtocol.java index c1de71cd3..b8c8e45d9 100644 --- a/src/org/traccar/protocol/AquilaProtocol.java +++ b/src/org/traccar/protocol/AquilaProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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,12 +15,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.LineBasedFrameDecoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -33,9 +32,9 @@ public class AquilaProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/AquilaProtocolDecoder.java b/src/org/traccar/protocol/AquilaProtocolDecoder.java index 9963ead34..ca6d2e48f 100644 --- a/src/org/traccar/protocol/AquilaProtocolDecoder.java +++ b/src/org/traccar/protocol/AquilaProtocolDecoder.java @@ -15,10 +15,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +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.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; @@ -302,7 +303,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder { if (channel != null) { String password = Context.getIdentityManager().lookupAttributeString( position.getDeviceId(), getProtocolName() + ".language", "aquila123", true); - channel.write("#set$" + id + "@" + password + "#EMR_MODE:0*"); + channel.write(new NetworkMessage("#set$" + id + "@" + password + "#EMR_MODE:0*", remoteAddress)); } } diff --git a/src/org/traccar/protocol/Ardi01Protocol.java b/src/org/traccar/protocol/Ardi01Protocol.java index 3bcff8608..5242df08c 100644 --- a/src/org/traccar/protocol/Ardi01Protocol.java +++ b/src/org/traccar/protocol/Ardi01Protocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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,11 @@ */ package org.traccar.protocol; -import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.LineBasedFrameDecoder; import io.netty.handler.codec.string.StringDecoder; import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -34,7 +34,7 @@ public class Ardi01Protocol extends BaseProtocol { public void initTrackerServers(List<TrackerServer> serverList) { serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java index 9ae50df86..7e25159b1 100644 --- a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java +++ b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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. diff --git a/src/org/traccar/protocol/ArknavProtocol.java b/src/org/traccar/protocol/ArknavProtocol.java index c22e5f443..3497ab8bb 100644 --- a/src/org/traccar/protocol/ArknavProtocol.java +++ b/src/org/traccar/protocol/ArknavProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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,12 +15,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -33,9 +32,9 @@ public class ArknavProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\r')); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/ArknavProtocolDecoder.java b/src/org/traccar/protocol/ArknavProtocolDecoder.java index aeea4a734..c1a297e97 100644 --- a/src/org/traccar/protocol/ArknavProtocolDecoder.java +++ b/src/org/traccar/protocol/ArknavProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.Parser; diff --git a/src/org/traccar/protocol/ArknavX8Protocol.java b/src/org/traccar/protocol/ArknavX8Protocol.java index e759b5294..f5ad81660 100644 --- a/src/org/traccar/protocol/ArknavX8Protocol.java +++ b/src/org/traccar/protocol/ArknavX8Protocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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,12 +15,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -33,9 +32,9 @@ public class ArknavX8Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ';')); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java index 47cc267fe..60d7fe0db 100644 --- a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java +++ b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.Parser; diff --git a/src/org/traccar/protocol/ArnaviProtocol.java b/src/org/traccar/protocol/ArnaviProtocol.java index 956f2329a..88203fdbe 100644 --- a/src/org/traccar/protocol/ArnaviProtocol.java +++ b/src/org/traccar/protocol/ArnaviProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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,12 +15,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.LineBasedFrameDecoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -33,9 +32,9 @@ public class ArnaviProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/ArnaviProtocolDecoder.java b/src/org/traccar/protocol/ArnaviProtocolDecoder.java index ec96343fe..7649dddf6 100644 --- a/src/org/traccar/protocol/ArnaviProtocolDecoder.java +++ b/src/org/traccar/protocol/ArnaviProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; diff --git a/src/org/traccar/protocol/AstraProtocol.java b/src/org/traccar/protocol/AstraProtocol.java index 87c562a9d..301afa532 100644 --- a/src/org/traccar/protocol/AstraProtocol.java +++ b/src/org/traccar/protocol/AstraProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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,9 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ConnectionlessBootstrap; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import io.netty.handler.codec.LengthFieldBasedFrameDecoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -32,16 +30,16 @@ public class AstraProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 1, 2, -3, 0)); pipeline.addLast("objectDecoder", new AstraProtocolDecoder(AstraProtocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { + serverList.add(new TrackerServer(true, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("objectDecoder", new AstraProtocolDecoder(AstraProtocol.this)); } }); diff --git a/src/org/traccar/protocol/AstraProtocolDecoder.java b/src/org/traccar/protocol/AstraProtocolDecoder.java index 7f247251d..7a4e1ee85 100644 --- a/src/org/traccar/protocol/AstraProtocolDecoder.java +++ b/src/org/traccar/protocol/AstraProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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.BitUtil; import org.traccar.helper.DateBuilder; import org.traccar.helper.Log; @@ -44,10 +45,10 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; if (channel != null) { - channel.write(ChannelBuffers.wrappedBuffer(new byte[] {0x06}), remoteAddress); + channel.writeAndFlush(new NetworkMessage(Unpooled.wrappedBuffer(new byte[] {0x06}), remoteAddress)); } buf.readUnsignedByte(); // protocol diff --git a/src/org/traccar/protocol/At2000FrameDecoder.java b/src/org/traccar/protocol/At2000FrameDecoder.java index af257d0fb..9d5524ec1 100644 --- a/src/org/traccar/protocol/At2000FrameDecoder.java +++ b/src/org/traccar/protocol/At2000FrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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,38 +15,37 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.FrameDecoder; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import org.traccar.BaseFrameDecoder; +import org.traccar.NetworkMessage; -import java.nio.ByteOrder; - -public class At2000FrameDecoder extends FrameDecoder { +public class At2000FrameDecoder extends BaseFrameDecoder { private static final int BLOCK_LENGTH = 16; private static final int ACK_LENGTH = 496; private boolean firstPacket = true; - private ChannelBuffer currentBuffer; + private ByteBuf currentBuffer; private int acknowledgedBytes; private void sendResponse(Channel channel) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 2 * BLOCK_LENGTH); + ByteBuf response = Unpooled.buffer(2 * BLOCK_LENGTH); response.writeByte(At2000ProtocolDecoder.MSG_ACKNOWLEDGEMENT); - response.writeMedium(ChannelBuffers.swapMedium(1)); + response.writeMedium(1); response.writeByte(0x00); // success response.writerIndex(2 * BLOCK_LENGTH); - channel.write(response); + channel.write(new NetworkMessage(response, channel.remoteAddress())); } } @Override protected Object decode( - ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() < 5) { return null; @@ -55,9 +54,9 @@ public class At2000FrameDecoder extends FrameDecoder { int length; if (firstPacket) { firstPacket = false; - length = buf.getUnsignedMedium(buf.readerIndex() + 2); + length = buf.getUnsignedMediumLE(buf.readerIndex() + 2); } else { - length = buf.getUnsignedMedium(buf.readerIndex() + 1); + length = buf.getUnsignedMediumLE(buf.readerIndex() + 1); } length += BLOCK_LENGTH; diff --git a/src/org/traccar/protocol/At2000Protocol.java b/src/org/traccar/protocol/At2000Protocol.java index 35aa0b469..1aca8bb13 100644 --- a/src/org/traccar/protocol/At2000Protocol.java +++ b/src/org/traccar/protocol/At2000Protocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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,12 +15,10 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; -import java.nio.ByteOrder; import java.util.List; public class At2000Protocol extends BaseProtocol { @@ -31,15 +29,13 @@ public class At2000Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new At2000FrameDecoder()); pipeline.addLast("objectDecoder", new At2000ProtocolDecoder(At2000Protocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); + }); } } diff --git a/src/org/traccar/protocol/At2000ProtocolDecoder.java b/src/org/traccar/protocol/At2000ProtocolDecoder.java index e0f2b4278..bd75e12b9 100644 --- a/src/org/traccar/protocol/At2000ProtocolDecoder.java +++ b/src/org/traccar/protocol/At2000ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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.DataConverter; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @@ -28,7 +29,6 @@ import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import java.net.SocketAddress; -import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.LinkedList; @@ -52,11 +52,11 @@ public class At2000ProtocolDecoder extends BaseProtocolDecoder { private static void sendRequest(Channel channel) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, BLOCK_LENGTH); + ByteBuf response = Unpooled.buffer(BLOCK_LENGTH); response.writeByte(MSG_TRACK_REQUEST); - response.writeMedium(ChannelBuffers.swapMedium(0)); + response.writeMedium(0); response.writerIndex(BLOCK_LENGTH); - channel.write(response); + channel.write(new NetworkMessage(response, channel.remoteAddress())); } } @@ -64,14 +64,14 @@ public class At2000ProtocolDecoder 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()) == 0x01) { buf.readUnsignedByte(); // codec id } int type = buf.readUnsignedByte(); - buf.readUnsignedMedium(); // length + buf.readUnsignedMediumLE(); // length buf.skipBytes(BLOCK_LENGTH - 1 - 3); if (type == MSG_DEVICE_ID) { @@ -108,7 +108,7 @@ public class At2000ProtocolDecoder extends BaseProtocolDecoder { byte[] data = new byte[buf.capacity() - BLOCK_LENGTH]; buf.readBytes(data); - buf = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, cipher.update(data)); + buf = Unpooled.wrappedBuffer(cipher.update(data)); List<Position> positions = new LinkedList<>(); @@ -117,31 +117,31 @@ public class At2000ProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - buf.readUnsignedShort(); // index - buf.readUnsignedShort(); // reserved + buf.readUnsignedShortLE(); // index + buf.readUnsignedShortLE(); // reserved position.setValid(true); - position.setTime(new Date(buf.readLong() * 1000)); + position.setTime(new Date(buf.readLongLE() * 1000)); - position.setLatitude(buf.readFloat()); - position.setLongitude(buf.readFloat()); - position.setAltitude(buf.readFloat()); - position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloat())); - position.setCourse(buf.readFloat()); + position.setLatitude(buf.readFloatLE()); + position.setLongitude(buf.readFloatLE()); + position.setAltitude(buf.readFloatLE()); + position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloatLE())); + position.setCourse(buf.readFloatLE()); - buf.readUnsignedInt(); // geozone event - buf.readUnsignedInt(); // io events - buf.readUnsignedInt(); // geozone value - buf.readUnsignedInt(); // io values - buf.readUnsignedShort(); // operator + buf.readUnsignedIntLE(); // geozone event + buf.readUnsignedIntLE(); // io events + buf.readUnsignedIntLE(); // geozone value + buf.readUnsignedIntLE(); // io values + buf.readUnsignedShortLE(); // operator - position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort()); - position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort()); + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE()); + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE()); - position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001); + position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.001); - buf.readUnsignedShort(); // cid + buf.readUnsignedShortLE(); // cid position.set(Position.KEY_RSSI, buf.readUnsignedByte()); buf.readUnsignedByte(); // current profile diff --git a/src/org/traccar/protocol/AtrackFrameDecoder.java b/src/org/traccar/protocol/AtrackFrameDecoder.java index 224679bde..a37b5d0f8 100644 --- a/src/org/traccar/protocol/AtrackFrameDecoder.java +++ b/src/org/traccar/protocol/AtrackFrameDecoder.java @@ -15,19 +15,22 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.FrameDecoder; -import org.traccar.helper.StringFinder; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import org.traccar.BaseFrameDecoder; -public class AtrackFrameDecoder extends FrameDecoder { +import java.nio.charset.StandardCharsets; + +public class AtrackFrameDecoder extends BaseFrameDecoder { private static final int KEEPALIVE_LENGTH = 12; @Override protected Object decode( - ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() >= 2) { @@ -48,7 +51,8 @@ public class AtrackFrameDecoder extends FrameDecoder { } else { - int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n")); + ByteBuf delimiter = Unpooled.wrappedBuffer("\r\n".getBytes(StandardCharsets.US_ASCII)); + int endIndex = ByteBufUtil.indexOf(delimiter, buf); if (endIndex > 0) { return buf.readBytes(endIndex - buf.readerIndex() + 2); } diff --git a/src/org/traccar/protocol/AtrackProtocol.java b/src/org/traccar/protocol/AtrackProtocol.java index 5104e5587..74840a1f5 100644 --- a/src/org/traccar/protocol/AtrackProtocol.java +++ b/src/org/traccar/protocol/AtrackProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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,10 +15,8 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ConnectionlessBootstrap; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import org.traccar.model.Command; @@ -34,17 +32,17 @@ public class AtrackProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new AtrackFrameDecoder()); pipeline.addLast("objectEncoder", new AtrackProtocolEncoder()); pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(AtrackProtocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { + serverList.add(new TrackerServer(true, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("objectEncoder", new AtrackProtocolEncoder()); pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(AtrackProtocol.this)); } diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java index ac208c0f2..19746f31e 100644 --- a/src/org/traccar/protocol/AtrackProtocolDecoder.java +++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java @@ -15,12 +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.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.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; @@ -80,15 +81,15 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { private static void sendResponse(Channel channel, SocketAddress remoteAddress, long rawId, int index) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.directBuffer(12); + ByteBuf response = Unpooled.buffer(12); response.writeShort(0xfe02); response.writeLong(rawId); response.writeShort(index); - channel.write(response, remoteAddress); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } } - private static String readString(ChannelBuffer buf) { + private static String readString(ByteBuf buf) { String result = null; int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0); if (index > buf.readerIndex()) { @@ -98,7 +99,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { return result; } - private void readCustomData(Position position, ChannelBuffer buf, String form) { + private void readCustomData(Position position, ByteBuf buf, String form) { CellTower cellTower = new CellTower(); String[] keys = form.substring(1).split("%"); for (String key : keys) { @@ -321,7 +322,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { return position; } - private List<Position> decodeBinary(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { + private List<Position> decodeBinary(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { buf.skipBytes(2); // prefix buf.readUnsignedShort(); // checksum @@ -414,11 +415,11 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; if (buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) { if (channel != null) { - channel.write(buf, remoteAddress); // keep-alive message + channel.writeAndFlush(new NetworkMessage(buf, remoteAddress)); // keep-alive message } return null; } else if (buf.getByte(buf.readerIndex()) == '$') { diff --git a/src/org/traccar/protocol/AtrackProtocolEncoder.java b/src/org/traccar/protocol/AtrackProtocolEncoder.java index 77f16527f..1aa580435 100644 --- a/src/org/traccar/protocol/AtrackProtocolEncoder.java +++ b/src/org/traccar/protocol/AtrackProtocolEncoder.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,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffers; +import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.Log; import org.traccar.model.Command; @@ -29,7 +29,7 @@ public class AtrackProtocolEncoder extends BaseProtocolEncoder { switch (command.getType()) { case Command.TYPE_CUSTOM: - return ChannelBuffers.copiedBuffer( + return Unpooled.copiedBuffer( command.getString(Command.KEY_DATA) + "\r\n", StandardCharsets.US_ASCII); default: Log.warning(new UnsupportedOperationException(command.getType())); diff --git a/src/org/traccar/protocol/AuroProtocol.java b/src/org/traccar/protocol/AuroProtocol.java index e1b23478f..99affeba1 100644 --- a/src/org/traccar/protocol/AuroProtocol.java +++ b/src/org/traccar/protocol/AuroProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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,12 +15,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.LineBasedFrameDecoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -33,9 +32,9 @@ public class AuroProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/AuroProtocolDecoder.java b/src/org/traccar/protocol/AuroProtocolDecoder.java index 3cb3a440c..e84b65bf3 100644 --- a/src/org/traccar/protocol/AuroProtocolDecoder.java +++ b/src/org/traccar/protocol/AuroProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.Parser; diff --git a/src/org/traccar/protocol/AustinNbProtocol.java b/src/org/traccar/protocol/AustinNbProtocol.java index 7f6739495..1ffb6e4ad 100644 --- a/src/org/traccar/protocol/AustinNbProtocol.java +++ b/src/org/traccar/protocol/AustinNbProtocol.java @@ -15,11 +15,10 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ConnectionlessBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -32,9 +31,9 @@ public class AustinNbProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { + serverList.add(new TrackerServer(true, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("objectDecoder", new AustinNbProtocolDecoder(AustinNbProtocol.this)); diff --git a/src/org/traccar/protocol/AustinNbProtocolDecoder.java b/src/org/traccar/protocol/AustinNbProtocolDecoder.java index c8f4baf78..5e2ee6178 100644 --- a/src/org/traccar/protocol/AustinNbProtocolDecoder.java +++ b/src/org/traccar/protocol/AustinNbProtocolDecoder.java @@ -15,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.Parser; diff --git a/src/org/traccar/protocol/AutoFonFrameDecoder.java b/src/org/traccar/protocol/AutoFonFrameDecoder.java index 2fa1b4072..517f4b124 100644 --- a/src/org/traccar/protocol/AutoFonFrameDecoder.java +++ b/src/org/traccar/protocol/AutoFonFrameDecoder.java @@ -16,18 +16,16 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.FrameDecoder; +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import org.traccar.BaseFrameDecoder; -public class AutoFonFrameDecoder extends FrameDecoder { +public class AutoFonFrameDecoder extends BaseFrameDecoder { @Override protected Object decode( - ChannelHandlerContext ctx, - Channel channel, - ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { // Check minimum length if (buf.readableBytes() < 12) { diff --git a/src/org/traccar/protocol/AutoFonProtocol.java b/src/org/traccar/protocol/AutoFonProtocol.java index 927bda120..993f8610c 100644 --- a/src/org/traccar/protocol/AutoFonProtocol.java +++ b/src/org/traccar/protocol/AutoFonProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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,9 +15,8 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -30,9 +29,9 @@ public class AutoFonProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new AutoFonFrameDecoder()); pipeline.addLast("objectDecoder", new AutoFonProtocolDecoder(AutoFonProtocol.this)); } diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java index e243b93ea..cb1ddaca9 100644 --- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java @@ -16,11 +16,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.DateBuilder; import org.traccar.model.CellTower; @@ -60,7 +62,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { } } - private Position decodePosition(DeviceSession deviceSession, ChannelBuffer buf, boolean history) { + private Position decodePosition(DeviceSession deviceSession, ByteBuf buf, boolean history) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); @@ -118,7 +120,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; int type = buf.readUnsignedByte(); @@ -129,14 +131,14 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // software version } - 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 && channel != null) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); response.writeBytes("resp_crc=".getBytes(StandardCharsets.US_ASCII)); response.writeByte(buf.getByte(buf.writerIndex() - 1)); - channel.write(response); + channel.write(new NetworkMessage(response, remoteAddress)); } return null; diff --git a/src/org/traccar/protocol/AutoGradeProtocol.java b/src/org/traccar/protocol/AutoGradeProtocol.java index 41bb8d9ad..ba51c2bfc 100644 --- a/src/org/traccar/protocol/AutoGradeProtocol.java +++ b/src/org/traccar/protocol/AutoGradeProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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,12 +15,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -33,9 +32,9 @@ public class AutoGradeProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ')')); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/AutoGradeProtocolDecoder.java b/src/org/traccar/protocol/AutoGradeProtocolDecoder.java index b98c68cbd..9b9ef7d46 100644 --- a/src/org/traccar/protocol/AutoGradeProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoGradeProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 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,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; diff --git a/src/org/traccar/protocol/Avl301Protocol.java b/src/org/traccar/protocol/Avl301Protocol.java index 4a217bad6..98a9b8edc 100644 --- a/src/org/traccar/protocol/Avl301Protocol.java +++ b/src/org/traccar/protocol/Avl301Protocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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,10 +15,9 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import io.netty.handler.codec.LengthFieldBasedFrameDecoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -31,9 +30,9 @@ public class Avl301Protocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 1, -3, 0)); pipeline.addLast("objectDecoder", new Avl301ProtocolDecoder(Avl301Protocol.this)); } diff --git a/src/org/traccar/protocol/Avl301ProtocolDecoder.java b/src/org/traccar/protocol/Avl301ProtocolDecoder.java index 056395d35..a473f9a5b 100644 --- a/src/org/traccar/protocol/Avl301ProtocolDecoder.java +++ b/src/org/traccar/protocol/Avl301ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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.DateBuilder; import org.traccar.model.CellTower; import org.traccar.model.Network; @@ -33,7 +34,7 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private String readImei(ChannelBuffer buf) { + private String readImei(ByteBuf buf) { int b = buf.readUnsignedByte(); StringBuilder imei = new StringBuilder(); imei.append(b & 0x0F); @@ -51,12 +52,12 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder { private void sendResponse(Channel channel, int type) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.directBuffer(5); + ByteBuf response = Unpooled.buffer(5); response.writeByte('$'); response.writeByte(type); response.writeByte('#'); response.writeByte('\r'); response.writeByte('\n'); - channel.write(response); + channel.write(new NetworkMessage(response, channel.remoteAddress())); } } @@ -64,7 +65,7 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; buf.skipBytes(1); // header int type = buf.readUnsignedByte(); |