From 1fe468bf5b004845e8904b66198597d28d37a029 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 12 Jun 2018 13:57:19 +1200 Subject: Migrate new protocols --- src/org/traccar/protocol/EsealProtocol.java | 13 +++++----- src/org/traccar/protocol/EsealProtocolDecoder.java | 6 +++-- src/org/traccar/protocol/FreematicsProtocol.java | 9 ++++--- .../protocol/FreematicsProtocolDecoder.java | 2 +- src/org/traccar/protocol/L100ProtocolDecoder.java | 3 ++- .../traccar/protocol/RetranslatorFrameDecoder.java | 15 ++++++------ src/org/traccar/protocol/RetranslatorProtocol.java | 7 +++--- .../protocol/RetranslatorProtocolDecoder.java | 28 +++++++++------------- src/org/traccar/protocol/SviasProtocol.java | 11 ++++----- src/org/traccar/protocol/SviasProtocolDecoder.java | 5 ++-- 10 files changed, 46 insertions(+), 53 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/EsealProtocol.java b/src/org/traccar/protocol/EsealProtocol.java index c778021ec..54be201d1 100644 --- a/src/org/traccar/protocol/EsealProtocol.java +++ b/src/org/traccar/protocol/EsealProtocol.java @@ -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 org.traccar.model.Command; @@ -38,9 +37,9 @@ public class EsealProtocol extends BaseProtocol { @Override public void initTrackerServers(List 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("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/EsealProtocolDecoder.java b/src/org/traccar/protocol/EsealProtocolDecoder.java index 90f360d66..39c0d94c2 100644 --- a/src/org/traccar/protocol/EsealProtocolDecoder.java +++ b/src/org/traccar/protocol/EsealProtocolDecoder.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; @@ -62,7 +63,8 @@ public class EsealProtocolDecoder extends BaseProtocolDecoder { private void sendResponse(Channel channel, String prefix, String type, String payload) { if (channel != null) { - channel.write(prefix + type + "," + payload + ",E##\r\n"); + channel.writeAndFlush(new NetworkMessage( + prefix + type + "," + payload + ",E##\r\n", channel.remoteAddress())); } } diff --git a/src/org/traccar/protocol/FreematicsProtocol.java b/src/org/traccar/protocol/FreematicsProtocol.java index 551c7e619..3bcd5bfd1 100644 --- a/src/org/traccar/protocol/FreematicsProtocol.java +++ b/src/org/traccar/protocol/FreematicsProtocol.java @@ -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 FreematicsProtocol extends BaseProtocol { @Override public void initTrackerServers(List 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("stringDecoder", new StringDecoder()); pipeline.addLast("objectDecoder", new FreematicsProtocolDecoder(FreematicsProtocol.this)); } diff --git a/src/org/traccar/protocol/FreematicsProtocolDecoder.java b/src/org/traccar/protocol/FreematicsProtocolDecoder.java index 66e451d6d..2cab45189 100644 --- a/src/org/traccar/protocol/FreematicsProtocolDecoder.java +++ b/src/org/traccar/protocol/FreematicsProtocolDecoder.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.DateBuilder; diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java index 7c652c95a..d9f830ec5 100644 --- a/src/org/traccar/protocol/L100ProtocolDecoder.java +++ b/src/org/traccar/protocol/L100ProtocolDecoder.java @@ -18,6 +18,7 @@ package org.traccar.protocol; 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.DateBuilder; import org.traccar.helper.Parser; @@ -169,7 +170,7 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder { if (channel != null) { String response = "@" + imei + ",00," + index + ","; response += "*" + (char) Checksum.xor(response); - channel.write(response, remoteAddress); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } return null; } diff --git a/src/org/traccar/protocol/RetranslatorFrameDecoder.java b/src/org/traccar/protocol/RetranslatorFrameDecoder.java index 1836fb26e..1ad07b8da 100644 --- a/src/org/traccar/protocol/RetranslatorFrameDecoder.java +++ b/src/org/traccar/protocol/RetranslatorFrameDecoder.java @@ -15,19 +15,18 @@ */ 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.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import org.traccar.BaseFrameDecoder; -public class RetranslatorFrameDecoder extends FrameDecoder { +public class RetranslatorFrameDecoder extends BaseFrameDecoder { @Override protected Object decode( - ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { - int length = 4 + ChannelBuffers.swapInt(buf.getInt(buf.readerIndex())); + int length = 4 + buf.getIntLE(buf.readerIndex()); if (buf.readableBytes() >= length) { return buf.readBytes(length); } else { diff --git a/src/org/traccar/protocol/RetranslatorProtocol.java b/src/org/traccar/protocol/RetranslatorProtocol.java index 0421390b2..725e37bd2 100644 --- a/src/org/traccar/protocol/RetranslatorProtocol.java +++ b/src/org/traccar/protocol/RetranslatorProtocol.java @@ -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 RetranslatorProtocol extends BaseProtocol { @Override public void initTrackerServers(List 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 RetranslatorFrameDecoder()); pipeline.addLast("objectDecoder", new RetranslatorProtocolDecoder(RetranslatorProtocol.this)); } diff --git a/src/org/traccar/protocol/RetranslatorProtocolDecoder.java b/src/org/traccar/protocol/RetranslatorProtocolDecoder.java index 756b0bcaf..b31dce5d7 100644 --- a/src/org/traccar/protocol/RetranslatorProtocolDecoder.java +++ b/src/org/traccar/protocol/RetranslatorProtocolDecoder.java @@ -15,15 +15,15 @@ */ 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.model.Position; import java.net.SocketAddress; -import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.util.Date; @@ -33,21 +33,15 @@ public class RetranslatorProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private double readDouble(ChannelBuffer buf) { - byte[] bytes = new byte[8]; - buf.readBytes(bytes); - return ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, bytes).readDouble(); - } - @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { if (channel != null) { - channel.write(ChannelBuffers.wrappedBuffer(new byte[]{0x11})); + channel.writeAndFlush(new NetworkMessage(Unpooled.wrappedBuffer(new byte[]{0x11}), remoteAddress)); } - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; buf.readUnsignedInt(); // length @@ -65,7 +59,7 @@ public class RetranslatorProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedInt(); // bit flags - while (buf.readable()) { + while (buf.isReadable()) { buf.readUnsignedShort(); // block type int blockEnd = buf.readInt() + buf.readerIndex(); @@ -78,9 +72,9 @@ public class RetranslatorProtocolDecoder extends BaseProtocolDecoder { if (name.equals("posinfo")) { position.setValid(true); - position.setLongitude(readDouble(buf)); - position.setLatitude(readDouble(buf)); - position.setAltitude(readDouble(buf)); + position.setLongitude(buf.readDoubleLE()); + position.setLatitude(buf.readDoubleLE()); + position.setAltitude(buf.readDoubleLE()); position.setSpeed(buf.readShort()); position.setCourse(buf.readShort()); position.set(Position.KEY_SATELLITES, buf.readByte()); @@ -95,7 +89,7 @@ public class RetranslatorProtocolDecoder extends BaseProtocolDecoder { position.set(name, buf.readInt()); break; case 4: - position.set(name, readDouble(buf)); + position.set(name, buf.readDoubleLE()); break; case 5: position.set(name, buf.readLong()); diff --git a/src/org/traccar/protocol/SviasProtocol.java b/src/org/traccar/protocol/SviasProtocol.java index badf3d091..a811ddc9a 100644 --- a/src/org/traccar/protocol/SviasProtocol.java +++ b/src/org/traccar/protocol/SviasProtocol.java @@ -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; @@ -43,9 +42,9 @@ public class SviasProtocol extends BaseProtocol { @Override public void initTrackerServers(List 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/SviasProtocolDecoder.java b/src/org/traccar/protocol/SviasProtocolDecoder.java index c2ea33ae9..d6d755e19 100644 --- a/src/org/traccar/protocol/SviasProtocolDecoder.java +++ b/src/org/traccar/protocol/SviasProtocolDecoder.java @@ -15,8 +15,9 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.NetworkMessage; import org.traccar.helper.BitUtil; import org.traccar.helper.PatternBuilder; @@ -62,7 +63,7 @@ public class SviasProtocolDecoder extends BaseProtocolDecoder { throws Exception { if (channel != null) { - channel.write("@"); + channel.writeAndFlush(new NetworkMessage("@", remoteAddress)); } Parser parser = new Parser(PATTERN, (String) msg); -- cgit v1.2.3