From ecb7bb33fcec52491f917dbc65a82990dcddb808 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 8 Jun 2018 21:00:31 +1200 Subject: Migrate O and P protocols --- src/org/traccar/protocol/ObdDongleProtocol.java | 11 ++-- .../traccar/protocol/ObdDongleProtocolDecoder.java | 21 +++--- src/org/traccar/protocol/OigoProtocol.java | 9 ++- src/org/traccar/protocol/OigoProtocolDecoder.java | 24 +++---- src/org/traccar/protocol/OkoProtocol.java | 11 ++-- src/org/traccar/protocol/OkoProtocolDecoder.java | 4 +- src/org/traccar/protocol/OpenGtsProtocol.java | 13 ++-- .../traccar/protocol/OpenGtsProtocolDecoder.java | 14 ++-- src/org/traccar/protocol/OrionFrameDecoder.java | 18 +++-- src/org/traccar/protocol/OrionProtocol.java | 14 ++-- src/org/traccar/protocol/OrionProtocolDecoder.java | 29 +++++---- src/org/traccar/protocol/OwnTracksProtocol.java | 15 +++-- .../traccar/protocol/OwnTracksProtocolDecoder.java | 13 ++-- src/org/traccar/protocol/PathAwayProtocol.java | 15 +++-- .../traccar/protocol/PathAwayProtocolDecoder.java | 31 ++++----- src/org/traccar/protocol/PiligrimProtocol.java | 17 +++-- .../traccar/protocol/PiligrimProtocolDecoder.java | 41 ++++++------ src/org/traccar/protocol/PretraceProtocol.java | 13 ++-- .../traccar/protocol/PretraceProtocolDecoder.java | 4 +- src/org/traccar/protocol/PricolProtocol.java | 16 ++--- .../traccar/protocol/PricolProtocolDecoder.java | 13 ++-- src/org/traccar/protocol/ProgressProtocol.java | 18 +++-- .../traccar/protocol/ProgressProtocolDecoder.java | 76 +++++++++++----------- src/org/traccar/protocol/Pt3000Protocol.java | 13 ++-- .../traccar/protocol/Pt3000ProtocolDecoder.java | 4 +- src/org/traccar/protocol/Pt502FrameDecoder.java | 20 +++--- src/org/traccar/protocol/Pt502Protocol.java | 14 ++-- src/org/traccar/protocol/Pt502ProtocolDecoder.java | 12 ++-- src/org/traccar/protocol/Pt60Protocol.java | 11 ++-- src/org/traccar/protocol/Pt60ProtocolDecoder.java | 9 +-- 30 files changed, 256 insertions(+), 267 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/ObdDongleProtocol.java b/src/org/traccar/protocol/ObdDongleProtocol.java index 6547a31ab..5f50b16ae 100644 --- a/src/org/traccar/protocol/ObdDongleProtocol.java +++ b/src/org/traccar/protocol/ObdDongleProtocol.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.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 ObdDongleProtocol 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 LengthFieldBasedFrameDecoder(1099, 20, 2, 3, 0)); pipeline.addLast("objectDecoder", new ObdDongleProtocolDecoder(ObdDongleProtocol.this)); } diff --git a/src/org/traccar/protocol/ObdDongleProtocolDecoder.java b/src/org/traccar/protocol/ObdDongleProtocolDecoder.java index 5310c90fd..bb925ca3e 100644 --- a/src/org/traccar/protocol/ObdDongleProtocolDecoder.java +++ b/src/org/traccar/protocol/ObdDongleProtocolDecoder.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.UnitsConverter; import org.traccar.model.Position; @@ -42,9 +43,9 @@ public class ObdDongleProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_TYPE_PINGRESP = 0x0D; public static final int MSG_TYPE_DISCONNECT = 0x0E; - private static void sendResponse(Channel channel, int type, int index, String imei, ChannelBuffer content) { + private static void sendResponse(Channel channel, int type, int index, String imei, ByteBuf content) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); response.writeShort(0x5555); // header response.writeShort(index); response.writeBytes(imei.getBytes(StandardCharsets.US_ASCII)); @@ -53,7 +54,7 @@ public class ObdDongleProtocolDecoder extends BaseProtocolDecoder { response.writeBytes(content); response.writeByte(0); // checksum response.writeShort(0xAAAA); - channel.write(response); + channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress())); } } @@ -61,7 +62,7 @@ public class ObdDongleProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; buf.skipBytes(2); // header int index = buf.readUnsignedShort(); @@ -78,7 +79,7 @@ public class ObdDongleProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_TYPE_CONNECT) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); response.writeByte(1); response.writeShort(0); response.writeInt(0); @@ -112,7 +113,7 @@ public class ObdDongleProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromMph(BitUtil.from(speedCourse, 10) * 0.1)); position.setCourse(BitUtil.to(speedCourse, 10)); - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); response.writeByte(typeMajor); response.writeByte(typeMinor); sendResponse(channel, MSG_TYPE_PUBACK, index, imei, response); diff --git a/src/org/traccar/protocol/OigoProtocol.java b/src/org/traccar/protocol/OigoProtocol.java index 4b6ad0dd0..b4f2b4163 100644 --- a/src/org/traccar/protocol/OigoProtocol.java +++ b/src/org/traccar/protocol/OigoProtocol.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,9 +15,8 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ConnectionlessBootstrap; -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 OigoProtocol 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("objectDecoder", new OigoProtocolDecoder(OigoProtocol.this)); } }); diff --git a/src/org/traccar/protocol/OigoProtocolDecoder.java b/src/org/traccar/protocol/OigoProtocolDecoder.java index 2874d0455..e00079210 100644 --- a/src/org/traccar/protocol/OigoProtocolDecoder.java +++ b/src/org/traccar/protocol/OigoProtocolDecoder.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,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.helper.UnitsConverter; @@ -39,7 +41,7 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_ACKNOWLEDGEMENT = 0xE0; - private Position decodeArMessage(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { + private Position decodeArMessage(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { buf.skipBytes(1); // header buf.readUnsignedShort(); // length @@ -51,7 +53,7 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder { DeviceSession deviceSession; switch (BitUtil.to(tag, 3)) { case 0: - String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1); + String imei = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1); deviceSession = getDeviceSession(channel, remoteAddress, imei); break; case 1: @@ -159,7 +161,7 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder { return negative ? -degrees : degrees; } - private Position decodeMgMessage(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { + private Position decodeMgMessage(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { buf.readUnsignedByte(); // tag int flags = buf.getUnsignedByte(buf.readerIndex()); @@ -169,7 +171,7 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // flags deviceSession = getDeviceSession(channel, remoteAddress); } else { - String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1); + String imei = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1); deviceSession = getDeviceSession(channel, remoteAddress, imei); } @@ -211,11 +213,11 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ODOMETER, (long) (buf.readUnsignedInt() * 1609.34)); if (channel != null && BitUtil.check(flags, 7)) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); response.writeByte(MSG_ACKNOWLEDGEMENT); response.writeByte(index); response.writeByte(0x00); - channel.write(response, remoteAddress); + channel.write(new NetworkMessage(response, remoteAddress)); } return position; @@ -225,7 +227,7 @@ public class OigoProtocolDecoder 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()) == 0x7e) { return decodeArMessage(channel, remoteAddress, buf); diff --git a/src/org/traccar/protocol/OkoProtocol.java b/src/org/traccar/protocol/OkoProtocol.java index 0b38741e5..21f06cca0 100644 --- a/src/org/traccar/protocol/OkoProtocol.java +++ b/src/org/traccar/protocol/OkoProtocol.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 io.netty.handler.codec.string.StringDecoder; import org.traccar.BaseProtocol; import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -32,9 +31,9 @@ public class OkoProtocol 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("stringDecoder", new StringDecoder()); pipeline.addLast("objectDecoder", new OkoProtocolDecoder(OkoProtocol.this)); diff --git a/src/org/traccar/protocol/OkoProtocolDecoder.java b/src/org/traccar/protocol/OkoProtocolDecoder.java index 0ebe63ca3..0318c30c7 100644 --- a/src/org/traccar/protocol/OkoProtocolDecoder.java +++ b/src/org/traccar/protocol/OkoProtocolDecoder.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.DateBuilder; diff --git a/src/org/traccar/protocol/OpenGtsProtocol.java b/src/org/traccar/protocol/OpenGtsProtocol.java index a0246ba1b..afc0b0c60 100644 --- a/src/org/traccar/protocol/OpenGtsProtocol.java +++ b/src/org/traccar/protocol/OpenGtsProtocol.java @@ -15,11 +15,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.http.HttpRequestDecoder; -import org.jboss.netty.handler.codec.http.HttpResponseEncoder; +import io.netty.handler.codec.http.HttpObjectAggregator; +import io.netty.handler.codec.http.HttpRequestDecoder; +import io.netty.handler.codec.http.HttpResponseEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -32,11 +32,12 @@ public class OpenGtsProtocol 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("httpEncoder", new HttpResponseEncoder()); pipeline.addLast("httpDecoder", new HttpRequestDecoder()); + pipeline.addLast("httpAggregator", new HttpObjectAggregator(16384)); pipeline.addLast("objectDecoder", new OpenGtsProtocolDecoder(OpenGtsProtocol.this)); } }); diff --git a/src/org/traccar/protocol/OpenGtsProtocolDecoder.java b/src/org/traccar/protocol/OpenGtsProtocolDecoder.java index ba8f434d8..b61426085 100644 --- a/src/org/traccar/protocol/OpenGtsProtocolDecoder.java +++ b/src/org/traccar/protocol/OpenGtsProtocolDecoder.java @@ -15,10 +15,10 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.handler.codec.http.HttpRequest; -import org.jboss.netty.handler.codec.http.HttpResponseStatus; -import org.jboss.netty.handler.codec.http.QueryStringDecoder; +import io.netty.channel.Channel; +import io.netty.handler.codec.http.FullHttpRequest; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.handler.codec.http.QueryStringDecoder; import org.traccar.BaseHttpProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; @@ -55,9 +55,9 @@ public class OpenGtsProtocolDecoder extends BaseHttpProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - HttpRequest request = (HttpRequest) msg; - QueryStringDecoder decoder = new QueryStringDecoder(request.getUri()); - Map> params = decoder.getParameters(); + FullHttpRequest request = (FullHttpRequest) msg; + QueryStringDecoder decoder = new QueryStringDecoder(request.uri()); + Map> params = decoder.parameters(); Position position = new Position(); position.setProtocol(getProtocolName()); diff --git a/src/org/traccar/protocol/OrionFrameDecoder.java b/src/org/traccar/protocol/OrionFrameDecoder.java index f7371747a..ce5a06478 100644 --- a/src/org/traccar/protocol/OrionFrameDecoder.java +++ b/src/org/traccar/protocol/OrionFrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Anton Tananaev (anton@traccar.org) + * Copyright 2014 - 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,18 +15,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 OrionFrameDecoder extends FrameDecoder { +public class OrionFrameDecoder extends BaseFrameDecoder { @Override protected Object decode( - ChannelHandlerContext ctx, - Channel channel, - ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { int length = 6; @@ -56,7 +54,7 @@ public class OrionFrameDecoder extends FrameDecoder { } else if (type == OrionProtocolDecoder.MSG_SYSLOG && buf.readableBytes() >= length + 12) { - length += buf.getUnsignedShort(buf.readerIndex() + 8); + length += buf.getUnsignedShortLE(buf.readerIndex() + 8); if (buf.readableBytes() >= length) { return buf.readBytes(length); } diff --git a/src/org/traccar/protocol/OrionProtocol.java b/src/org/traccar/protocol/OrionProtocol.java index f4bfef985..ba7044cce 100644 --- a/src/org/traccar/protocol/OrionProtocol.java +++ b/src/org/traccar/protocol/OrionProtocol.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,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 OrionProtocol extends BaseProtocol { @@ -31,15 +29,13 @@ public class OrionProtocol extends BaseProtocol { @Override public void initTrackerServers(List 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 OrionFrameDecoder()); pipeline.addLast("objectDecoder", new OrionProtocolDecoder(OrionProtocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); + }); } } diff --git a/src/org/traccar/protocol/OrionProtocolDecoder.java b/src/org/traccar/protocol/OrionProtocolDecoder.java index ada864fba..bbc509bec 100644 --- a/src/org/traccar/protocol/OrionProtocolDecoder.java +++ b/src/org/traccar/protocol/OrionProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Anton Tananaev (anton@traccar.org) + * Copyright 2014 - 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.Position; @@ -36,13 +37,13 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_USERLOG = 0; public static final int MSG_SYSLOG = 3; - private static void sendResponse(Channel channel, ChannelBuffer buf) { + private static void sendResponse(Channel channel, ByteBuf buf) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.directBuffer(4); + ByteBuf response = Unpooled.buffer(4); response.writeByte('*'); response.writeShort(buf.getUnsignedShort(buf.writerIndex() - 2)); response.writeByte(buf.getUnsignedByte(buf.writerIndex() - 3)); - channel.write(response); + channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress())); } } @@ -56,7 +57,7 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; buf.skipBytes(2); // header int type = buf.readUnsignedByte() & 0x0f; @@ -84,13 +85,13 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_EVENT, buf.readUnsignedByte()); buf.readUnsignedByte(); // length - position.set(Position.KEY_FLAGS, buf.readUnsignedShort()); + position.set(Position.KEY_FLAGS, buf.readUnsignedShortLE()); - position.setLatitude(convertCoordinate(buf.readInt())); - position.setLongitude(convertCoordinate(buf.readInt())); - position.setAltitude(buf.readShort() / 10.0); - position.setCourse(buf.readUnsignedShort()); - position.setSpeed(buf.readUnsignedShort() * 0.0539957); + position.setLatitude(convertCoordinate(buf.readIntLE())); + position.setLongitude(convertCoordinate(buf.readIntLE())); + position.setAltitude(buf.readShortLE() / 10.0); + position.setCourse(buf.readUnsignedShortLE()); + position.setSpeed(buf.readUnsignedShortLE() * 0.0539957); DateBuilder dateBuilder = new DateBuilder() .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) diff --git a/src/org/traccar/protocol/OwnTracksProtocol.java b/src/org/traccar/protocol/OwnTracksProtocol.java index c4a6ab163..275bb739a 100644 --- a/src/org/traccar/protocol/OwnTracksProtocol.java +++ b/src/org/traccar/protocol/OwnTracksProtocol.java @@ -1,6 +1,6 @@ /* * Copyright 2017 Jan-Piet Mens (jpmens@gmail.com) - * 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. @@ -16,11 +16,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.http.HttpRequestDecoder; -import org.jboss.netty.handler.codec.http.HttpResponseEncoder; +import io.netty.handler.codec.http.HttpObjectAggregator; +import io.netty.handler.codec.http.HttpRequestDecoder; +import io.netty.handler.codec.http.HttpResponseEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -33,11 +33,12 @@ public class OwnTracksProtocol 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("httpEncoder", new HttpResponseEncoder()); pipeline.addLast("httpDecoder", new HttpRequestDecoder()); + pipeline.addLast("httpAggregator", new HttpObjectAggregator(16384)); pipeline.addLast("objectDecoder", new OwnTracksProtocolDecoder(OwnTracksProtocol.this)); } }); diff --git a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java index 120995dfb..00a63d712 100644 --- a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java +++ b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java @@ -1,6 +1,6 @@ /* * Copyright 2017 Jan-Piet Mens (jpmens@gmail.com) - * 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. @@ -16,9 +16,9 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.handler.codec.http.HttpRequest; -import org.jboss.netty.handler.codec.http.HttpResponseStatus; +import io.netty.channel.Channel; +import io.netty.handler.codec.http.FullHttpRequest; +import io.netty.handler.codec.http.HttpResponseStatus; import org.traccar.BaseHttpProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.UnitsConverter; @@ -41,9 +41,9 @@ public class OwnTracksProtocolDecoder extends BaseHttpProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - HttpRequest request = (HttpRequest) msg; + FullHttpRequest request = (FullHttpRequest) msg; JsonObject root = Json.createReader( - new StringReader(request.getContent().toString(StandardCharsets.US_ASCII))).readObject(); + new StringReader(request.content().toString(StandardCharsets.US_ASCII))).readObject(); if (!root.containsKey("_type") || !root.getString("_type").equals("location")) { sendResponse(channel, HttpResponseStatus.OK); @@ -98,4 +98,5 @@ public class OwnTracksProtocolDecoder extends BaseHttpProtocolDecoder { sendResponse(channel, HttpResponseStatus.OK); return position; } + } diff --git a/src/org/traccar/protocol/PathAwayProtocol.java b/src/org/traccar/protocol/PathAwayProtocol.java index a41692750..7cb5a3fca 100644 --- a/src/org/traccar/protocol/PathAwayProtocol.java +++ b/src/org/traccar/protocol/PathAwayProtocol.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 org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.http.HttpRequestDecoder; -import org.jboss.netty.handler.codec.http.HttpResponseEncoder; +import io.netty.handler.codec.http.HttpObjectAggregator; +import io.netty.handler.codec.http.HttpRequestDecoder; +import io.netty.handler.codec.http.HttpResponseEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -32,11 +32,12 @@ public class PathAwayProtocol 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("httpEncoder", new HttpResponseEncoder()); pipeline.addLast("httpDecoder", new HttpRequestDecoder()); + pipeline.addLast("httpAggregator", new HttpObjectAggregator(16384)); pipeline.addLast("objectDecoder", new PathAwayProtocolDecoder(PathAwayProtocol.this)); } }); diff --git a/src/org/traccar/protocol/PathAwayProtocolDecoder.java b/src/org/traccar/protocol/PathAwayProtocolDecoder.java index 845a5e892..40e68a5d2 100644 --- a/src/org/traccar/protocol/PathAwayProtocolDecoder.java +++ b/src/org/traccar/protocol/PathAwayProtocolDecoder.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,16 +15,17 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelFutureListener; -import org.jboss.netty.handler.codec.http.DefaultHttpResponse; -import org.jboss.netty.handler.codec.http.HttpRequest; -import org.jboss.netty.handler.codec.http.HttpResponse; -import org.jboss.netty.handler.codec.http.HttpResponseStatus; -import org.jboss.netty.handler.codec.http.HttpVersion; -import org.jboss.netty.handler.codec.http.QueryStringDecoder; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFutureListener; +import io.netty.handler.codec.http.DefaultFullHttpResponse; +import io.netty.handler.codec.http.FullHttpRequest; +import io.netty.handler.codec.http.FullHttpResponse; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.handler.codec.http.HttpVersion; +import io.netty.handler.codec.http.QueryStringDecoder; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.NetworkMessage; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -58,16 +59,16 @@ public class PathAwayProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - HttpRequest request = (HttpRequest) msg; - QueryStringDecoder decoder = new QueryStringDecoder(request.getUri()); + FullHttpRequest request = (FullHttpRequest) msg; + QueryStringDecoder decoder = new QueryStringDecoder(request.uri()); DeviceSession deviceSession = getDeviceSession( - channel, remoteAddress, decoder.getParameters().get("UserName").get(0)); + channel, remoteAddress, decoder.parameters().get("UserName").get(0)); if (deviceSession == null) { return null; } - Parser parser = new Parser(PATTERN, decoder.getParameters().get("LOC").get(0)); + Parser parser = new Parser(PATTERN, decoder.parameters().get("LOC").get(0)); if (!parser.matches()) { return null; } @@ -85,8 +86,8 @@ public class PathAwayProtocolDecoder extends BaseProtocolDecoder { position.setCourse(parser.nextDouble(0)); if (channel != null) { - HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); - channel.write(response).addListener(ChannelFutureListener.CLOSE); + FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)).addListener(ChannelFutureListener.CLOSE); } return position; diff --git a/src/org/traccar/protocol/PiligrimProtocol.java b/src/org/traccar/protocol/PiligrimProtocol.java index a2960f762..ff602d366 100644 --- a/src/org/traccar/protocol/PiligrimProtocol.java +++ b/src/org/traccar/protocol/PiligrimProtocol.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.http.HttpChunkAggregator; -import org.jboss.netty.handler.codec.http.HttpRequestDecoder; -import org.jboss.netty.handler.codec.http.HttpResponseEncoder; +import io.netty.handler.codec.http.HttpObjectAggregator; +import io.netty.handler.codec.http.HttpRequestDecoder; +import io.netty.handler.codec.http.HttpResponseEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -33,12 +32,12 @@ public class PiligrimProtocol 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("httpEncoder", new HttpResponseEncoder()); pipeline.addLast("httpDecoder", new HttpRequestDecoder()); - pipeline.addLast("httpAggregator", new HttpChunkAggregator(16384)); + pipeline.addLast("httpAggregator", new HttpObjectAggregator(16384)); pipeline.addLast("objectDecoder", new PiligrimProtocolDecoder(PiligrimProtocol.this)); } }); diff --git a/src/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/org/traccar/protocol/PiligrimProtocolDecoder.java index f2ec16c59..a1850df54 100644 --- a/src/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Anton Tananaev (anton@traccar.org) + * Copyright 2014 - 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,23 +15,23 @@ */ 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.handler.codec.http.DefaultHttpResponse; -import org.jboss.netty.handler.codec.http.HttpRequest; -import org.jboss.netty.handler.codec.http.HttpResponse; -import org.jboss.netty.handler.codec.http.HttpResponseStatus; -import org.jboss.netty.handler.codec.http.HttpVersion; -import org.jboss.netty.handler.codec.http.QueryStringDecoder; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.handler.codec.http.DefaultFullHttpResponse; +import io.netty.handler.codec.http.FullHttpRequest; +import io.netty.handler.codec.http.FullHttpResponse; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.handler.codec.http.HttpVersion; +import io.netty.handler.codec.http.QueryStringDecoder; 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.Position; import java.net.SocketAddress; -import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.util.LinkedList; import java.util.List; @@ -44,11 +44,10 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder { private void sendResponse(Channel channel, String message) { if (channel != null) { - HttpResponse response = new DefaultHttpResponse( - HttpVersion.HTTP_1_1, HttpResponseStatus.OK); - response.setContent(ChannelBuffers.copiedBuffer( - ByteOrder.BIG_ENDIAN, message, StandardCharsets.US_ASCII)); - channel.write(response); + FullHttpResponse response = new DefaultFullHttpResponse( + HttpVersion.HTTP_1_1, HttpResponseStatus.OK, + Unpooled.copiedBuffer(message, StandardCharsets.US_ASCII)); + channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress())); } } @@ -60,8 +59,8 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - HttpRequest request = (HttpRequest) msg; - String uri = request.getUri(); + FullHttpRequest request = (FullHttpRequest) msg; + String uri = request.uri(); if (uri.startsWith("/config")) { @@ -79,15 +78,15 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, "BINGPS: OK"); - QueryStringDecoder decoder = new QueryStringDecoder(request.getUri()); + QueryStringDecoder decoder = new QueryStringDecoder(request.uri()); DeviceSession deviceSession = getDeviceSession( - channel, remoteAddress, decoder.getParameters().get("imei").get(0)); + channel, remoteAddress, decoder.parameters().get("imei").get(0)); if (deviceSession == null) { return null; } List positions = new LinkedList<>(); - ChannelBuffer buf = request.getContent(); + ByteBuf buf = request.content(); while (buf.readableBytes() > 2) { diff --git a/src/org/traccar/protocol/PretraceProtocol.java b/src/org/traccar/protocol/PretraceProtocol.java index 8f0a22851..456807c1b 100644 --- a/src/org/traccar/protocol/PretraceProtocol.java +++ b/src/org/traccar/protocol/PretraceProtocol.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,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 PretraceProtocol 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/PretraceProtocolDecoder.java b/src/org/traccar/protocol/PretraceProtocolDecoder.java index 24d707a1c..e4306a429 100644 --- a/src/org/traccar/protocol/PretraceProtocolDecoder.java +++ b/src/org/traccar/protocol/PretraceProtocolDecoder.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.Parser; diff --git a/src/org/traccar/protocol/PricolProtocol.java b/src/org/traccar/protocol/PricolProtocol.java index 0005dc3c1..ca52e2734 100644 --- a/src/org/traccar/protocol/PricolProtocol.java +++ b/src/org/traccar/protocol/PricolProtocol.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,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.FixedLengthFrameDecoder; +import io.netty.handler.codec.FixedLengthFrameDecoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -32,16 +30,16 @@ public class PricolProtocol 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 FixedLengthFrameDecoder(64)); pipeline.addLast("objectDecoder", new PricolProtocolDecoder(PricolProtocol.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 PricolProtocolDecoder(PricolProtocol.this)); } }); diff --git a/src/org/traccar/protocol/PricolProtocolDecoder.java b/src/org/traccar/protocol/PricolProtocolDecoder.java index 577665dcc..901639501 100644 --- a/src/org/traccar/protocol/PricolProtocolDecoder.java +++ b/src/org/traccar/protocol/PricolProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,11 +15,12 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.NetworkMessage; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @@ -37,7 +38,7 @@ public class PricolProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; buf.readUnsignedByte(); // header @@ -86,7 +87,7 @@ public class PricolProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_RPM, buf.readUnsignedShort()); if (channel != null) { - channel.write(ChannelBuffers.copiedBuffer("ACK", StandardCharsets.US_ASCII), remoteAddress); + channel.write(new NetworkMessage(Unpooled.copiedBuffer("ACK", StandardCharsets.US_ASCII), remoteAddress)); } return position; diff --git a/src/org/traccar/protocol/ProgressProtocol.java b/src/org/traccar/protocol/ProgressProtocol.java index 6e2093346..22fdfbd48 100644 --- a/src/org/traccar/protocol/ProgressProtocol.java +++ b/src/org/traccar/protocol/ProgressProtocol.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 ProgressProtocol extends BaseProtocol { @Override public void initTrackerServers(List 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 ProgressProtocolDecoder(ProgressProtocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); + }); } } diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java index d85b6acb3..d7e67df30 100644 --- a/src/org/traccar/protocol/ProgressProtocolDecoder.java +++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2014 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,16 +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.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.model.Position; import java.net.SocketAddress; -import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.LinkedList; @@ -53,12 +54,12 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { if (lastIndex == 0) { lastIndex = newIndex; } else if (newIndex > lastIndex) { - ChannelBuffer request = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 12); - request.writeShort(MSG_LOG_SYNC); - request.writeShort(4); - request.writeInt((int) lastIndex); - request.writeInt(0); - channel.write(request); + ByteBuf request = Unpooled.buffer(12); + request.writeShortLE(MSG_LOG_SYNC); + request.writeShortLE(4); + request.writeIntLE((int) lastIndex); + request.writeIntLE(0); + channel.writeAndFlush(new NetworkMessage(request, channel.remoteAddress())); } } @@ -66,18 +67,18 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; - int type = buf.readUnsignedShort(); - buf.readUnsignedShort(); // length + ByteBuf buf = (ByteBuf) msg; + int type = buf.readUnsignedShortLE(); + buf.readUnsignedShortLE(); // length if (type == MSG_IDENT || type == MSG_IDENT_FULL) { - buf.readUnsignedInt(); // id - int length = buf.readUnsignedShort(); + buf.readUnsignedIntLE(); // id + int length = buf.readUnsignedShortLE(); buf.skipBytes(length); - length = buf.readUnsignedShort(); + length = buf.readUnsignedShortLE(); buf.skipBytes(length); - length = buf.readUnsignedShort(); + length = buf.readUnsignedShortLE(); String imei = buf.readBytes(length).toString(StandardCharsets.US_ASCII); getDeviceSession(channel, remoteAddress, imei); @@ -92,7 +93,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { int recordCount = 1; if (type == MSG_LOGMSG) { - recordCount = buf.readUnsignedShort(); + recordCount = buf.readUnsignedShortLE(); } for (int j = 0; j < recordCount; j++) { @@ -101,61 +102,60 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_LOGMSG) { position.set(Position.KEY_ARCHIVE, true); - int subtype = buf.readUnsignedShort(); + int subtype = buf.readUnsignedShortLE(); if (subtype == MSG_ALARM) { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } - if (buf.readUnsignedShort() > buf.readableBytes()) { + if (buf.readUnsignedShortLE() > buf.readableBytes()) { lastIndex += 1; break; // workaround for device bug } - lastIndex = buf.readUnsignedInt(); + lastIndex = buf.readUnsignedIntLE(); position.set(Position.KEY_INDEX, lastIndex); } else { - newIndex = buf.readUnsignedInt(); + newIndex = buf.readUnsignedIntLE(); } - position.setTime(new Date(buf.readUnsignedInt() * 1000)); - position.setLatitude(buf.readInt() * 180.0 / 0x7FFFFFFF); - position.setLongitude(buf.readInt() * 180.0 / 0x7FFFFFFF); - position.setSpeed(buf.readUnsignedInt() * 0.01); - position.setCourse(buf.readUnsignedShort() * 0.01); - position.setAltitude(buf.readUnsignedShort() * 0.01); + position.setTime(new Date(buf.readUnsignedIntLE() * 1000)); + position.setLatitude(buf.readIntLE() * 180.0 / 0x7FFFFFFF); + position.setLongitude(buf.readIntLE() * 180.0 / 0x7FFFFFFF); + position.setSpeed(buf.readUnsignedIntLE() * 0.01); + position.setCourse(buf.readUnsignedShortLE() * 0.01); + position.setAltitude(buf.readUnsignedShortLE() * 0.01); int satellites = buf.readUnsignedByte(); position.setValid(satellites >= 3); position.set(Position.KEY_SATELLITES, satellites); position.set(Position.KEY_RSSI, buf.readUnsignedByte()); - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); - long extraFlags = buf.readLong(); + long extraFlags = buf.readLongLE(); if (BitUtil.check(extraFlags, 0)) { - int count = buf.readUnsignedShort(); + int count = buf.readUnsignedShortLE(); for (int i = 1; i <= count; i++) { - position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort()); + position.set(Position.PREFIX_ADC + i, buf.readUnsignedShortLE()); } } if (BitUtil.check(extraFlags, 1)) { - int size = buf.readUnsignedShort(); + int size = buf.readUnsignedShortLE(); position.set("can", buf.toString(buf.readerIndex(), size, StandardCharsets.US_ASCII)); buf.skipBytes(size); } if (BitUtil.check(extraFlags, 2)) { - position.set("passenger", - ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedShort()))); + position.set("passenger", ByteBufUtil.hexDump(buf.readBytes(buf.readUnsignedShortLE()))); } if (type == MSG_ALARM) { position.set(Position.KEY_ALARM, true); byte[] response = {(byte) 0xC9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - channel.write(ChannelBuffers.wrappedBuffer(response)); + channel.write(Unpooled.wrappedBuffer(response)); } - buf.readUnsignedInt(); // crc + buf.readUnsignedIntLE(); // crc positions.add(position); } diff --git a/src/org/traccar/protocol/Pt3000Protocol.java b/src/org/traccar/protocol/Pt3000Protocol.java index 9c9da3301..03cc493d9 100644 --- a/src/org/traccar/protocol/Pt3000Protocol.java +++ b/src/org/traccar/protocol/Pt3000Protocol.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.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 Pt3000Protocol 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, 'd')); // probably wrong pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java index f4540afe8..8e9d99d14 100644 --- a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2015 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,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/Pt502FrameDecoder.java b/src/org/traccar/protocol/Pt502FrameDecoder.java index 4d3e9b4d5..9c7989446 100644 --- a/src/org/traccar/protocol/Pt502FrameDecoder.java +++ b/src/org/traccar/protocol/Pt502FrameDecoder.java @@ -15,20 +15,20 @@ */ 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; import java.nio.charset.StandardCharsets; -public class Pt502FrameDecoder extends FrameDecoder { +public class Pt502FrameDecoder extends BaseFrameDecoder { private static final int BINARY_HEADER = 5; @Override protected Object decode( - ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() < 10) { return null; @@ -37,10 +37,10 @@ public class Pt502FrameDecoder extends FrameDecoder { if (buf.getUnsignedByte(buf.readerIndex()) == 0xbf && buf.toString(buf.readerIndex() + BINARY_HEADER, 4, StandardCharsets.US_ASCII).equals("$PHD")) { - int length = buf.getUnsignedShort(buf.readerIndex() + 3); + int length = buf.getUnsignedShortLE(buf.readerIndex() + 3); if (buf.readableBytes() >= length) { buf.skipBytes(BINARY_HEADER); - ChannelBuffer result = buf.readBytes(length - BINARY_HEADER - 2); + ByteBuf result = buf.readBytes(length - BINARY_HEADER - 2); buf.skipBytes(2); // line break return result; } @@ -57,8 +57,8 @@ public class Pt502FrameDecoder extends FrameDecoder { } if (index > 0) { - ChannelBuffer result = buf.readBytes(index - buf.readerIndex()); - while (buf.readable() + ByteBuf result = buf.readBytes(index - buf.readerIndex()); + while (buf.isReadable() && (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n')) { buf.skipBytes(1); } diff --git a/src/org/traccar/protocol/Pt502Protocol.java b/src/org/traccar/protocol/Pt502Protocol.java index f7d0d04a2..fe8a0bb6c 100644 --- a/src/org/traccar/protocol/Pt502Protocol.java +++ b/src/org/traccar/protocol/Pt502Protocol.java @@ -15,14 +15,12 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import org.traccar.model.Command; -import java.nio.ByteOrder; import java.util.List; public class Pt502Protocol extends BaseProtocol { @@ -39,17 +37,15 @@ public class Pt502Protocol extends BaseProtocol { @Override public void initTrackerServers(List 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 Pt502FrameDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("objectEncoder", new Pt502ProtocolEncoder()); pipeline.addLast("objectDecoder", new Pt502ProtocolDecoder(Pt502Protocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); + }); } } diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index 76e7ee1bf..4f75666ae 100644 --- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java @@ -16,9 +16,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.Unpooled; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; @@ -35,7 +35,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { private static final int MAX_CHUNK_SIZE = 960; - private ChannelBuffer photo; + private ByteBuf photo; public Pt502ProtocolDecoder(Pt502Protocol protocol) { super(protocol); @@ -152,7 +152,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; int typeEndIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ','); String type = buf.toString(buf.readerIndex(), typeEndIndex - buf.readerIndex(), StandardCharsets.US_ASCII); @@ -195,7 +195,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { if (type.startsWith("$PHO")) { int size = Integer.parseInt(type.split("-")[0].substring(4)); if (size > 0) { - photo = ChannelBuffers.buffer(size); + photo = Unpooled.buffer(size); requestPhotoFragment(channel); } } diff --git a/src/org/traccar/protocol/Pt60Protocol.java b/src/org/traccar/protocol/Pt60Protocol.java index 857790efd..6c03f209e 100644 --- a/src/org/traccar/protocol/Pt60Protocol.java +++ b/src/org/traccar/protocol/Pt60Protocol.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; @@ -33,9 +32,9 @@ public class Pt60Protocol 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, "@R#@")); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/Pt60ProtocolDecoder.java b/src/org/traccar/protocol/Pt60ProtocolDecoder.java index 26f07a0a9..24dc72332 100644 --- a/src/org/traccar/protocol/Pt60ProtocolDecoder.java +++ b/src/org/traccar/protocol/Pt60ProtocolDecoder.java @@ -15,9 +15,10 @@ */ 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.NetworkMessage; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.model.Position; @@ -49,10 +50,10 @@ public class Pt60ProtocolDecoder extends BaseProtocolDecoder { .expression("(.*)") // data .compile(); - private void sendResponse(Channel channel) { + private void sendResponse(Channel channel, SocketAddress remoteAddress) { if (channel != null) { DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); - channel.write("@G#@,V01,38," + dateFormat.format(new Date()) + ",@R#@"); + channel.write(new NetworkMessage("@G#@,V01,38," + dateFormat.format(new Date()) + ",@R#@", remoteAddress)); } } @@ -60,7 +61,7 @@ public class Pt60ProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - sendResponse(channel); + sendResponse(channel, remoteAddress); Parser parser = new Parser(PATTERN, (String) msg); if (!parser.matches()) { -- cgit v1.2.3