diff options
48 files changed, 341 insertions, 362 deletions
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java index 2cc24d3d9..1729edd54 100644 --- a/src/org/traccar/BaseProtocol.java +++ b/src/org/traccar/BaseProtocol.java @@ -16,7 +16,6 @@ package org.traccar; import io.netty.buffer.Unpooled; -import io.netty.handler.codec.string.StringEncoder; import org.traccar.database.ActiveDevice; import org.traccar.helper.DataConverter; import org.traccar.model.Command; diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java index 31bf47e3f..fe41bd857 100644 --- a/src/org/traccar/BaseProtocolDecoder.java +++ b/src/org/traccar/BaseProtocolDecoder.java @@ -17,7 +17,6 @@ package org.traccar; import io.netty.channel.Channel; import io.netty.channel.socket.DatagramChannel; -import io.netty.handler.codec.http.HttpRequestDecoder; import org.traccar.helper.Log; import org.traccar.helper.UnitsConverter; import org.traccar.model.Device; diff --git a/src/org/traccar/EventLoopGroupFactory.java b/src/org/traccar/EventLoopGroupFactory.java index 806a3a1dc..482559253 100644 --- a/src/org/traccar/EventLoopGroupFactory.java +++ b/src/org/traccar/EventLoopGroupFactory.java @@ -23,6 +23,9 @@ public final class EventLoopGroupFactory { private static EventLoopGroup bossGroup = new NioEventLoopGroup(); private static EventLoopGroup workerGroup = new NioEventLoopGroup(); + private EventLoopGroupFactory() { + } + public static EventLoopGroup getBossGroup() { return bossGroup; } diff --git a/src/org/traccar/WrapperOutboundHandler.java b/src/org/traccar/WrapperOutboundHandler.java index ad342fa6c..b14cdb75a 100644 --- a/src/org/traccar/WrapperOutboundHandler.java +++ b/src/org/traccar/WrapperOutboundHandler.java @@ -35,7 +35,9 @@ public class WrapperOutboundHandler implements ChannelOutboundHandler { } @Override - public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception { + public void connect( + ChannelHandlerContext ctx, SocketAddress remoteAddress, + SocketAddress localAddress, ChannelPromise promise) throws Exception { handler.connect(ctx, remoteAddress, localAddress, promise); } diff --git a/src/org/traccar/helper/BufferUtil.java b/src/org/traccar/helper/BufferUtil.java index b2768dbfd..c046fcaf5 100644 --- a/src/org/traccar/helper/BufferUtil.java +++ b/src/org/traccar/helper/BufferUtil.java @@ -22,7 +22,10 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; -public class BufferUtil { +public final class BufferUtil { + + private BufferUtil() { + } public static int indexOf(String needle, ByteBuf haystack) { return ByteBufUtil.indexOf( diff --git a/src/org/traccar/protocol/GalileoFrameDecoder.java b/src/org/traccar/protocol/GalileoFrameDecoder.java index 6d02ce744..5a57c3a95 100644 --- a/src/org/traccar/protocol/GalileoFrameDecoder.java +++ b/src/org/traccar/protocol/GalileoFrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 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,28 +15,24 @@ */ 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 GalileoFrameDecoder extends FrameDecoder { +public class GalileoFrameDecoder extends BaseFrameDecoder { private static final int MESSAGE_MINIMUM_LENGTH = 5; @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() < MESSAGE_MINIMUM_LENGTH) { return null; } - // Read packet - int length = buf.getUnsignedShort(buf.readerIndex() + 1) & 0x7fff; + int length = buf.getUnsignedShortLE(buf.readerIndex() + 1) & 0x7fff; if (buf.readableBytes() >= (length + MESSAGE_MINIMUM_LENGTH)) { return buf.readBytes(length + MESSAGE_MINIMUM_LENGTH); } diff --git a/src/org/traccar/protocol/GalileoProtocol.java b/src/org/traccar/protocol/GalileoProtocol.java index f76de04a0..93178ea52 100644 --- a/src/org/traccar/protocol/GalileoProtocol.java +++ b/src/org/traccar/protocol/GalileoProtocol.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,13 +15,11 @@ */ 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 org.traccar.model.Command; -import java.nio.ByteOrder; import java.util.List; public class GalileoProtocol extends BaseProtocol { @@ -35,16 +33,14 @@ public class GalileoProtocol 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 GalileoFrameDecoder()); pipeline.addLast("objectEncoder", new GalileoProtocolEncoder()); pipeline.addLast("objectDecoder", new GalileoProtocolDecoder(GalileoProtocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); + }); } } diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java index d8a1651bb..9beb93e4c 100644 --- a/src/org/traccar/protocol/GalileoProtocolDecoder.java +++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2017 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,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.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.HashMap; @@ -92,15 +93,15 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { } private void sendReply(Channel channel, int checksum) { - ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 3); + ByteBuf reply = Unpooled.buffer(3); reply.writeByte(0x02); - reply.writeShort((short) checksum); + reply.writeShortLE((short) checksum); if (channel != null) { - channel.write(reply); + channel.write(new NetworkMessage(reply, channel.remoteAddress())); } } - private void decodeTag(Position position, ChannelBuffer buf, int tag) { + private void decodeTag(Position position, ByteBuf buf, int tag) { switch (tag) { case 0x01: position.set(Position.KEY_VERSION_HW, buf.readUnsignedByte()); @@ -109,41 +110,41 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte()); break; case 0x04: - position.set("deviceId", buf.readUnsignedShort()); + position.set("deviceId", buf.readUnsignedShortLE()); break; case 0x10: - position.set(Position.KEY_INDEX, buf.readUnsignedShort()); + position.set(Position.KEY_INDEX, buf.readUnsignedShortLE()); break; case 0x20: - position.setTime(new Date(buf.readUnsignedInt() * 1000)); + position.setTime(new Date(buf.readUnsignedIntLE() * 1000)); break; case 0x33: - position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1)); - position.setCourse(buf.readUnsignedShort() * 0.1); + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE() * 0.1)); + position.setCourse(buf.readUnsignedShortLE() * 0.1); break; case 0x34: - position.setAltitude(buf.readShort()); + position.setAltitude(buf.readShortLE()); break; case 0x40: - position.set(Position.KEY_STATUS, buf.readUnsignedShort()); + position.set(Position.KEY_STATUS, buf.readUnsignedShortLE()); break; case 0x41: - position.set(Position.KEY_POWER, buf.readUnsignedShort()); + position.set(Position.KEY_POWER, buf.readUnsignedShortLE()); break; case 0x42: - position.set(Position.KEY_BATTERY, buf.readUnsignedShort()); + position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE()); break; case 0x43: position.set(Position.KEY_DEVICE_TEMP, buf.readByte()); break; case 0x44: - position.set(Position.KEY_ACCELERATION, buf.readUnsignedInt()); + position.set(Position.KEY_ACCELERATION, buf.readUnsignedIntLE()); break; case 0x45: - position.set(Position.KEY_OUTPUT, buf.readUnsignedShort()); + position.set(Position.KEY_OUTPUT, buf.readUnsignedShortLE()); break; case 0x46: - position.set(Position.KEY_INPUT, buf.readUnsignedShort()); + position.set(Position.KEY_INPUT, buf.readUnsignedShortLE()); break; case 0x50: case 0x51: @@ -153,27 +154,27 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { case 0x55: case 0x56: case 0x57: - position.set(Position.PREFIX_ADC + (tag - 0x50), buf.readUnsignedShort()); + position.set(Position.PREFIX_ADC + (tag - 0x50), buf.readUnsignedShortLE()); break; case 0x58: - position.set("rs2320", buf.readUnsignedShort()); + position.set("rs2320", buf.readUnsignedShortLE()); break; case 0x59: - position.set("rs2321", buf.readUnsignedShort()); + position.set("rs2321", buf.readUnsignedShortLE()); break; case 0xc0: - position.set("fuelTotal", buf.readUnsignedInt() * 0.5); + position.set("fuelTotal", buf.readUnsignedIntLE() * 0.5); break; case 0xc1: position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4); position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedByte() - 40); - position.set(Position.KEY_RPM, buf.readUnsignedShort() * 0.125); + position.set(Position.KEY_RPM, buf.readUnsignedShortLE() * 0.125); break; case 0xc2: - position.set("canB0", buf.readUnsignedInt()); + position.set("canB0", buf.readUnsignedIntLE()); break; case 0xc3: - position.set("canB1", buf.readUnsignedInt()); + position.set("canB1", buf.readUnsignedIntLE()); break; case 0xc4: case 0xc5: @@ -197,20 +198,20 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { case 0xd8: case 0xd9: case 0xda: - position.set("can16Bit" + (tag - 0xd6), buf.readUnsignedShort()); + position.set("can16Bit" + (tag - 0xd6), buf.readUnsignedShortLE()); break; case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf: - position.set("can32Bit" + (tag - 0xdb), buf.readUnsignedInt()); + position.set("can32Bit" + (tag - 0xdb), buf.readUnsignedIntLE()); break; case 0xd4: - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); break; case 0xe0: - position.set(Position.KEY_INDEX, buf.readUnsignedInt()); + position.set(Position.KEY_INDEX, buf.readUnsignedIntLE()); break; case 0xe1: position.set(Position.KEY_RESULT, @@ -224,10 +225,11 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { case 0xe7: case 0xe8: case 0xe9: - position.set("userData" + (tag - 0xe2), buf.readUnsignedInt()); + position.set("userData" + (tag - 0xe2), buf.readUnsignedIntLE()); break; case 0xea: - position.set("userDataArray", ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte()))); + position.set("userDataArray", ByteBufUtil.hexDump(buf.readBytes(buf.readUnsignedByte()))); + position.set("userDataArray", ByteBufUtil.hexDump(buf.readBytes(buf.readUnsignedByte()))); break; default: buf.skipBytes(getTagLength(tag)); @@ -239,10 +241,10 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; buf.readUnsignedByte(); // header - int length = (buf.readUnsignedShort() & 0x7fff) + 3; + int length = (buf.readUnsignedShortLE() & 0x7fff) + 3; List<Position> positions = new LinkedList<>(); Set<Integer> tags = new HashSet<>(); @@ -270,8 +272,8 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { } else if (tag == 0x30) { hasLocation = true; position.setValid((buf.readUnsignedByte() & 0xf0) == 0x00); - position.setLatitude(buf.readInt() / 1000000.0); - position.setLongitude(buf.readInt() / 1000000.0); + position.setLatitude(buf.readIntLE() / 1000000.0); + position.setLongitude(buf.readIntLE() / 1000000.0); } else { decodeTag(position, buf, tag); } @@ -293,7 +295,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { positions.add(position); } - sendReply(channel, buf.readUnsignedShort()); + sendReply(channel, buf.readUnsignedShortLE()); for (Position p : positions) { p.setDeviceId(deviceSession.getDeviceId()); diff --git a/src/org/traccar/protocol/GalileoProtocolEncoder.java b/src/org/traccar/protocol/GalileoProtocolEncoder.java index cb6028abb..47fbc3f9c 100644 --- a/src/org/traccar/protocol/GalileoProtocolEncoder.java +++ b/src/org/traccar/protocol/GalileoProtocolEncoder.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,39 +15,38 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.Checksum; import org.traccar.helper.Log; import org.traccar.model.Command; -import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; public class GalileoProtocolEncoder extends BaseProtocolEncoder { - private ChannelBuffer encodeText(String uniqueId, String text) { + private ByteBuf encodeText(String uniqueId, String text) { - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 256); + ByteBuf buf = Unpooled.buffer(256); buf.writeByte(0x01); - buf.writeShort(uniqueId.length() + text.length() + 11); // TODO + buf.writeShortLE(uniqueId.length() + text.length() + 11); // TODO buf.writeByte(0x03); // imei tag buf.writeBytes(uniqueId.getBytes(StandardCharsets.US_ASCII)); buf.writeByte(0x04); // device id tag - buf.writeShort(0); // not needed if imei provided + buf.writeShortLE(0); // not needed if imei provided buf.writeByte(0xE0); // index tag - buf.writeInt(0); // index + buf.writeIntLE(0); // index buf.writeByte(0xE1); // command text tag buf.writeByte(text.length()); buf.writeBytes(text.getBytes(StandardCharsets.US_ASCII)); - buf.writeShort(Checksum.crc16(Checksum.CRC16_MODBUS, buf.toByteBuffer(0, buf.writerIndex()))); + buf.writeShortLE(Checksum.crc16(Checksum.CRC16_MODBUS, buf.nioBuffer(0, buf.writerIndex()))); return buf; } diff --git a/src/org/traccar/protocol/GatorProtocol.java b/src/org/traccar/protocol/GatorProtocol.java index 7fa4854d3..531f1238c 100644 --- a/src/org/traccar/protocol/GatorProtocol.java +++ b/src/org/traccar/protocol/GatorProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2016 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,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 GatorProtocol 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, 3, 2)); pipeline.addLast("objectDecoder", new GatorProtocolDecoder(GatorProtocol.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 GatorProtocolDecoder(GatorProtocol.this)); } }); diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java index b38214457..5841f6fad 100644 --- a/src/org/traccar/protocol/GatorProtocolDecoder.java +++ b/src/org/traccar/protocol/GatorProtocolDecoder.java @@ -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.BcdUtil; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; @@ -58,7 +59,7 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder { private void sendResponse(Channel channel, SocketAddress remoteAddress, byte calibration) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); response.writeByte(0x24); response.writeByte(0x24); // header response.writeByte(MSG_HEARTBEAT); // size response.writeShort(5); @@ -67,7 +68,7 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder { response.writeByte(0); // slave order response.writeByte(1); // calibration response.writeByte(0x0D); - channel.write(response, remoteAddress); + channel.write(new NetworkMessage(response, remoteAddress)); } } @@ -75,7 +76,7 @@ public class GatorProtocolDecoder 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(); diff --git a/src/org/traccar/protocol/GenxProtocol.java b/src/org/traccar/protocol/GenxProtocol.java index 2b5b1a43d..2c3c4f7a0 100644 --- a/src/org/traccar/protocol/GenxProtocol.java +++ b/src/org/traccar/protocol/GenxProtocol.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.frame.LineBasedFrameDecoder; -import org.jboss.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.LineBasedFrameDecoder; +import io.netty.handler.codec.string.StringDecoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -32,9 +31,9 @@ public class GenxProtocol 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("objectDecoder", new GenxProtocolDecoder(GenxProtocol.this)); diff --git a/src/org/traccar/protocol/GenxProtocolDecoder.java b/src/org/traccar/protocol/GenxProtocolDecoder.java index d4a348ce1..399a42109 100644 --- a/src/org/traccar/protocol/GenxProtocolDecoder.java +++ b/src/org/traccar/protocol/GenxProtocolDecoder.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.Context; import org.traccar.DeviceSession; diff --git a/src/org/traccar/protocol/Gl100Protocol.java b/src/org/traccar/protocol/Gl100Protocol.java index 0fd18d44f..90beab23a 100644 --- a/src/org/traccar/protocol/Gl100Protocol.java +++ b/src/org/traccar/protocol/Gl100Protocol.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,13 +15,11 @@ */ 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.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; @@ -34,18 +32,18 @@ public class Gl100Protocol 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, '\0')); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("objectDecoder", new Gl100ProtocolDecoder(Gl100Protocol.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("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("objectDecoder", new Gl100ProtocolDecoder(Gl100Protocol.this)); diff --git a/src/org/traccar/protocol/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/Gl100ProtocolDecoder.java index 405090695..13ed7120e 100644 --- a/src/org/traccar/protocol/Gl100ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl100ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2015 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,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; @@ -64,7 +65,7 @@ public class Gl100ProtocolDecoder extends BaseProtocolDecoder { String response = "+RESP:GTHBD,GPRS ACTIVE,"; response += sentence.substring(9, sentence.lastIndexOf(',')); response += '\0'; - channel.write(response); // heartbeat response + channel.write(new NetworkMessage(response, remoteAddress)); // heartbeat response } Parser parser = new Parser(PATTERN, sentence); diff --git a/src/org/traccar/protocol/GlobalSatProtocol.java b/src/org/traccar/protocol/GlobalSatProtocol.java index f3d07fc96..dddf07d55 100644 --- a/src/org/traccar/protocol/GlobalSatProtocol.java +++ b/src/org/traccar/protocol/GlobalSatProtocol.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 GlobalSatProtocol 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/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java index 4361e0c2f..dd1ede9a4 100644 --- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java +++ b/src/org/traccar/protocol/GlobalSatProtocolDecoder.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,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.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; @@ -51,7 +52,7 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder { private Position decodeOriginal(Channel channel, SocketAddress remoteAddress, String sentence) { if (channel != null) { - channel.write("ACK\r"); + channel.write(new NetworkMessage("ACK\r", remoteAddress)); } String format; diff --git a/src/org/traccar/protocol/GnxProtocol.java b/src/org/traccar/protocol/GnxProtocol.java index 84af24000..985f200eb 100644 --- a/src/org/traccar/protocol/GnxProtocol.java +++ b/src/org/traccar/protocol/GnxProtocol.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 GnxProtocol 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, "\n\r")); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/GnxProtocolDecoder.java b/src/org/traccar/protocol/GnxProtocolDecoder.java index b3a636d14..36bcba2dc 100644 --- a/src/org/traccar/protocol/GnxProtocolDecoder.java +++ b/src/org/traccar/protocol/GnxProtocolDecoder.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/GoSafeProtocol.java b/src/org/traccar/protocol/GoSafeProtocol.java index bfd473df9..e4c6cc66f 100644 --- a/src/org/traccar/protocol/GoSafeProtocol.java +++ b/src/org/traccar/protocol/GoSafeProtocol.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 GoSafeProtocol 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/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java index ae00ad71a..38224f16d 100644 --- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java +++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.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.BitUtil; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; @@ -205,7 +206,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder { Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { if (channel != null) { - channel.write("1234"); + channel.write(new NetworkMessage("1234", remoteAddress)); } String sentence = (String) msg; diff --git a/src/org/traccar/protocol/GotopProtocol.java b/src/org/traccar/protocol/GotopProtocol.java index 5d522adf5..272c38cd0 100644 --- a/src/org/traccar/protocol/GotopProtocol.java +++ b/src/org/traccar/protocol/GotopProtocol.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 GotopProtocol 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/GotopProtocolDecoder.java b/src/org/traccar/protocol/GotopProtocolDecoder.java index 29e8d87dd..728c2a8d6 100644 --- a/src/org/traccar/protocol/GotopProtocolDecoder.java +++ b/src/org/traccar/protocol/GotopProtocolDecoder.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.Parser; diff --git a/src/org/traccar/protocol/Gps056FrameDecoder.java b/src/org/traccar/protocol/Gps056FrameDecoder.java index 4ce83dc0a..7cfd54c4e 100644 --- a/src/org/traccar/protocol/Gps056FrameDecoder.java +++ b/src/org/traccar/protocol/Gps056FrameDecoder.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,26 +15,26 @@ */ 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 Gps056FrameDecoder extends FrameDecoder { +public class Gps056FrameDecoder extends BaseFrameDecoder { private static final int MESSAGE_HEADER = 4; @Override protected Object decode( - ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() >= MESSAGE_HEADER) { int length = Integer.parseInt(buf.toString(2, 2, StandardCharsets.US_ASCII)) + 5; if (buf.readableBytes() >= length) { - ChannelBuffer frame = buf.readBytes(length); - while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != '$') { + ByteBuf frame = buf.readBytes(length); + while (buf.isReadable() && buf.getUnsignedByte(buf.readerIndex()) != '$') { buf.readByte(); } return frame; diff --git a/src/org/traccar/protocol/Gps056Protocol.java b/src/org/traccar/protocol/Gps056Protocol.java index 33c190ad2..f5122830d 100644 --- a/src/org/traccar/protocol/Gps056Protocol.java +++ b/src/org/traccar/protocol/Gps056Protocol.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,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 Gps056Protocol 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 Gps056FrameDecoder()); pipeline.addLast("objectDecoder", new Gps056ProtocolDecoder(Gps056Protocol.this)); } diff --git a/src/org/traccar/protocol/Gps056ProtocolDecoder.java b/src/org/traccar/protocol/Gps056ProtocolDecoder.java index ccb389250..d8d63cce2 100644 --- a/src/org/traccar/protocol/Gps056ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps056ProtocolDecoder.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; @@ -33,20 +34,20 @@ public class Gps056ProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private static void sendResponse(Channel channel, String type, String imei, ChannelBuffer content) { + private static void sendResponse(Channel channel, String type, String imei, ByteBuf content) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); String header = "*" + type + imei; response.writeBytes(header.getBytes(StandardCharsets.US_ASCII)); if (content != null) { response.writeBytes(content); } response.writeByte('#'); - channel.write(response); + channel.write(new NetworkMessage(response, channel.remoteAddress())); } } - private static double decodeCoordinate(ChannelBuffer buf) { + private static double decodeCoordinate(ByteBuf buf) { double degrees = buf.getUnsignedShort(buf.readerIndex()) / 100; double minutes = buf.readUnsignedShort() % 100 + buf.readUnsignedShort() * 0.0001; degrees += minutes / 60; @@ -57,12 +58,12 @@ public class Gps056ProtocolDecoder extends BaseProtocolDecoder { return degrees; } - private static void decodeStatus(ChannelBuffer buf, Position position) { + private static void decodeStatus(ByteBuf buf, Position position) { position.set(Position.KEY_INPUT, buf.readUnsignedByte()); position.set(Position.KEY_OUTPUT, buf.readUnsignedByte()); - position.set(Position.PREFIX_ADC + 1, ChannelBuffers.swapShort(buf.readShort()) * 5.06); // mV + position.set(Position.PREFIX_ADC + 1, buf.readShortLE() * 5.06); // mV position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.set(Position.KEY_RSSI, buf.readUnsignedByte()); @@ -73,7 +74,7 @@ public class Gps056ProtocolDecoder 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 buf.skipBytes(2); // length @@ -89,7 +90,7 @@ public class Gps056ProtocolDecoder extends BaseProtocolDecoder { if (type.startsWith("LOGN")) { sendResponse(channel, "LGSA" + type.substring(4), imei, - ChannelBuffers.copiedBuffer("1", StandardCharsets.US_ASCII)); + Unpooled.copiedBuffer("1", StandardCharsets.US_ASCII)); } else if (type.startsWith("GPSL")) { diff --git a/src/org/traccar/protocol/GpsGateProtocol.java b/src/org/traccar/protocol/GpsGateProtocol.java index c7dc2c4f3..4685e40b7 100644 --- a/src/org/traccar/protocol/GpsGateProtocol.java +++ b/src/org/traccar/protocol/GpsGateProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2016 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 GpsGateProtocol 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, "\0", "\n", "\r\n")); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java index 5c7096276..b4357ff64 100644 --- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2016 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,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.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; @@ -65,9 +66,9 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); - private void send(Channel channel, String message) { + private void send(Channel channel, SocketAddress remoteAddress, String message) { if (channel != null) { - channel.write(message + Checksum.nmea(message) + "\r\n"); + channel.write(new NetworkMessage(message + Checksum.nmea(message) + "\r\n", remoteAddress)); } } @@ -79,7 +80,6 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { if (sentence.startsWith("$FRLIN,")) { - // Login int beginIndex = sentence.indexOf(',', 7); if (beginIndex != -1) { beginIndex += 1; @@ -89,22 +89,21 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession != null) { if (channel != null) { - send(channel, "$FRSES," + channel.getId()); + send(channel, remoteAddress, "$FRSES," + channel.id().asShortText()); } } else { - send(channel, "$FRERR,AuthError,Unknown device"); + send(channel, remoteAddress, "$FRERR,AuthError,Unknown device"); } } else { - send(channel, "$FRERR,AuthError,Parse error"); + send(channel, remoteAddress, "$FRERR,AuthError,Parse error"); } } else { - send(channel, "$FRERR,AuthError,Parse error"); + send(channel, remoteAddress, "$FRERR,AuthError,Parse error"); } } else if (sentence.startsWith("$FRVER,")) { - // Version check - send(channel, "$FRVER,1,0,GpsGate Server 1.0"); + send(channel, remoteAddress, "$FRVER,1,0,GpsGate Server 1.0"); } else if (sentence.startsWith("$GPRMC,")) { diff --git a/src/org/traccar/protocol/GpsMarkerProtocol.java b/src/org/traccar/protocol/GpsMarkerProtocol.java index 5c64d16b2..0655d2c88 100644 --- a/src/org/traccar/protocol/GpsMarkerProtocol.java +++ b/src/org/traccar/protocol/GpsMarkerProtocol.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 GpsMarkerProtocol 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/GpsMarkerProtocolDecoder.java b/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java index ca5bdcbed..a6e39e353 100644 --- a/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2016 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/GpsmtaProtocol.java b/src/org/traccar/protocol/GpsmtaProtocol.java index 2d1181bec..b2720cb8a 100644 --- a/src/org/traccar/protocol/GpsmtaProtocol.java +++ b/src/org/traccar/protocol/GpsmtaProtocol.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,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 GpsmtaProtocol 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 GpsmtaProtocolDecoder(GpsmtaProtocol.this)); diff --git a/src/org/traccar/protocol/GpsmtaProtocolDecoder.java b/src/org/traccar/protocol/GpsmtaProtocolDecoder.java index c71162078..a4e732ed9 100644 --- a/src/org/traccar/protocol/GpsmtaProtocolDecoder.java +++ b/src/org/traccar/protocol/GpsmtaProtocolDecoder.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,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; @@ -81,7 +82,7 @@ public class GpsmtaProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_CHARGE, parser.nextInt(0) == 1); if (channel != null) { - channel.write(time, remoteAddress); + channel.write(new NetworkMessage(time, remoteAddress)); } return position; diff --git a/src/org/traccar/protocol/GranitFrameDecoder.java b/src/org/traccar/protocol/GranitFrameDecoder.java index 7e8f4a3f5..5e555fb15 100644 --- a/src/org/traccar/protocol/GranitFrameDecoder.java +++ b/src/org/traccar/protocol/GranitFrameDecoder.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,29 +15,29 @@ */ 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.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import org.traccar.BaseFrameDecoder; +import org.traccar.helper.BufferUtil; -public class GranitFrameDecoder extends FrameDecoder { +public class GranitFrameDecoder extends BaseFrameDecoder { @Override protected Object decode( - ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { - int indexEnd = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n")); + int indexEnd = BufferUtil.indexOf("\r\n", buf); if (indexEnd != -1) { - int indexTilde = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("~")); + int indexTilde = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '~'); if (indexTilde != -1 && indexTilde < indexEnd) { - int length = buf.getUnsignedShort(indexTilde + 1); - indexEnd = buf.indexOf(indexTilde + 2 + length, buf.writerIndex(), new StringFinder("\r\n")); + int length = buf.getUnsignedShortLE(indexTilde + 1); + indexEnd = BufferUtil.indexOf("\r\n", buf, indexTilde + 2 + length, buf.writerIndex()); if (indexEnd == -1) { return null; } } - ChannelBuffer frame = buf.readBytes(indexEnd - buf.readerIndex()); + ByteBuf frame = buf.readBytes(indexEnd - buf.readerIndex()); buf.skipBytes(2); return frame; } diff --git a/src/org/traccar/protocol/GranitProtocol.java b/src/org/traccar/protocol/GranitProtocol.java index 32e8e00b0..5855d34ee 100644 --- a/src/org/traccar/protocol/GranitProtocol.java +++ b/src/org/traccar/protocol/GranitProtocol.java @@ -1,6 +1,6 @@ /* - * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) - * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org) + * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2018 Andrey Kunitsyn (andrey@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,13 +16,11 @@ */ 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 org.traccar.model.Command; -import java.nio.ByteOrder; import java.util.List; public class GranitProtocol extends BaseProtocol { @@ -41,16 +39,14 @@ public class GranitProtocol 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 GranitFrameDecoder()); pipeline.addLast("objectEncoder", new GranitProtocolEncoder()); pipeline.addLast("objectDecoder", new GranitProtocolDecoder(GranitProtocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); + }); } } diff --git a/src/org/traccar/protocol/GranitProtocolDecoder.java b/src/org/traccar/protocol/GranitProtocolDecoder.java index 50d879bb4..d9e7b62d8 100644 --- a/src/org/traccar/protocol/GranitProtocolDecoder.java +++ b/src/org/traccar/protocol/GranitProtocolDecoder.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,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 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.BitUtil; import org.traccar.helper.Checksum; -import org.traccar.helper.StringFinder; import org.traccar.model.Position; import java.net.SocketAddress; -import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Date; @@ -50,35 +49,35 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { adc4Ratio = Context.getConfig().getDouble("granit.adc4Ratio", 1); } - public static void appendChecksum(ChannelBuffer buffer, int length) { + public static void appendChecksum(ByteBuf buffer, int length) { buffer.writeByte('*'); - int checksum = Checksum.xor(buffer.toByteBuffer(0, length)) & 0xFF; + int checksum = Checksum.xor(buffer.nioBuffer(0, length)) & 0xFF; String checksumString = String.format("%02X", checksum); buffer.writeBytes(checksumString.getBytes(StandardCharsets.US_ASCII)); buffer.writeByte('\r'); buffer.writeByte('\n'); } private static void sendResponseCurrent(Channel channel, int deviceId, long time) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); + ByteBuf response = Unpooled.buffer(0); response.writeBytes("BB+UGRC~".getBytes(StandardCharsets.US_ASCII)); - response.writeShort(6); // length + response.writeShortLE(6); // length response.writeInt((int) time); - response.writeShort(deviceId); + response.writeShortLE(deviceId); appendChecksum(response, 16); - channel.write(response); + channel.write(new NetworkMessage(response, channel.remoteAddress())); } private static void sendResponseArchive(Channel channel, int deviceId, int packNum) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); + ByteBuf response = Unpooled.buffer(0); response.writeBytes("BB+ARCF~".getBytes(StandardCharsets.US_ASCII)); - response.writeShort(4); // length - response.writeShort(packNum); - response.writeShort(deviceId); + response.writeShortLE(4); // length + response.writeShortLE(packNum); + response.writeShortLE(deviceId); appendChecksum(response, 14); - channel.write(response); + channel.write(new NetworkMessage(response, channel.remoteAddress())); } - private void decodeStructure(ChannelBuffer buf, Position position) { + private void decodeStructure(ByteBuf buf, Position position) { short flags = buf.readUnsignedByte(); position.setValid(BitUtil.check(flags, 7)); if (BitUtil.check(flags, 1)) { @@ -93,8 +92,8 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { int lonDegrees = buf.readUnsignedByte(); int latDegrees = buf.readUnsignedByte(); - int lonMinutes = buf.readUnsignedShort(); - int latMinutes = buf.readUnsignedShort(); + int lonMinutes = buf.readUnsignedShortLE(); + int latMinutes = buf.readUnsignedShortLE(); double latitude = latDegrees + latMinutes / 60000.0; double longitude = lonDegrees + lonMinutes / 60000.0; @@ -119,7 +118,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { } position.setCourse(course); - position.set(Position.KEY_DISTANCE, buf.readShort()); + position.set(Position.KEY_DISTANCE, buf.readShortLE()); int analogIn1 = buf.readUnsignedByte(); int analogIn2 = buf.readUnsignedByte(); @@ -150,9 +149,9 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { @Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; - int indexTilde = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("~")); + int indexTilde = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '~'); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); @@ -175,13 +174,13 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { if (header.equals("+RRCB~")) { - buf.skipBytes(2); //binary length 26 - int deviceId = buf.readUnsignedShort(); + buf.skipBytes(2); // binary length 26 + int deviceId = buf.readUnsignedShortLE(); deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(deviceId)); if (deviceSession == null) { return null; } - long unixTime = buf.readUnsignedInt(); + long unixTime = buf.readUnsignedIntLE(); if (channel != null) { sendResponseCurrent(channel, deviceId, unixTime); } @@ -195,8 +194,8 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { } else if (header.equals("+DDAT~")) { - buf.skipBytes(2); //binary length - int deviceId = buf.readUnsignedShort(); + buf.skipBytes(2); // binary length + int deviceId = buf.readUnsignedShortLE(); deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(deviceId)); if (deviceSession == null) { return null; @@ -206,15 +205,15 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder { return null; } byte nblocks = buf.readByte(); - int packNum = buf.readUnsignedShort(); + int packNum = buf.readUnsignedShortLE(); if (channel != null) { sendResponseArchive(channel, deviceId, packNum); } List<Position> positions = new ArrayList<>(); while (nblocks > 0) { nblocks--; - long unixTime = buf.readUnsignedInt(); - int timeIncrement = buf.getUnsignedShort(buf.readerIndex() + 120); + long unixTime = buf.readUnsignedIntLE(); + int timeIncrement = buf.getUnsignedShortLE(buf.readerIndex() + 120); for (int i = 0; i < 6; i++) { if (buf.getUnsignedByte(buf.readerIndex()) != 0xFE) { Position position = new Position(getProtocolName()); diff --git a/src/org/traccar/protocol/GranitProtocolEncoder.java b/src/org/traccar/protocol/GranitProtocolEncoder.java index dbfd30ff1..bde267ee6 100644 --- a/src/org/traccar/protocol/GranitProtocolEncoder.java +++ b/src/org/traccar/protocol/GranitProtocolEncoder.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. @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.traccar.protocol; +package org.traccar.protocol; import java.nio.charset.StandardCharsets; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; import org.traccar.helper.Log; import org.traccar.model.Command; @@ -44,7 +44,7 @@ public class GranitProtocolEncoder extends BaseProtocolEncoder { return null; } if (!commandString.isEmpty()) { - ChannelBuffer commandBuf = ChannelBuffers.dynamicBuffer(); + ByteBuf commandBuf = Unpooled.buffer(); commandBuf.writeBytes(commandString.getBytes(StandardCharsets.US_ASCII)); GranitProtocolDecoder.appendChecksum(commandBuf, commandString.length()); return commandBuf; diff --git a/src/org/traccar/protocol/Gt02Protocol.java b/src/org/traccar/protocol/Gt02Protocol.java index 0abd4021b..f44cb3979 100644 --- a/src/org/traccar/protocol/Gt02Protocol.java +++ b/src/org/traccar/protocol/Gt02Protocol.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,9 @@ */ package org.traccar.protocol; -import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.LengthFieldBasedFrameDecoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -32,7 +32,7 @@ public class Gt02Protocol 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 LengthFieldBasedFrameDecoder(256, 2, 1, 2, 0)); pipeline.addLast("objectDecoder", new Gt02ProtocolDecoder(Gt02Protocol.this)); } diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java index 3eb3e193a..d222acaab 100644 --- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2016 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. diff --git a/src/org/traccar/protocol/Gt06FrameDecoder.java b/src/org/traccar/protocol/Gt06FrameDecoder.java index c8b5e56ae..41e56415a 100644 --- a/src/org/traccar/protocol/Gt06FrameDecoder.java +++ b/src/org/traccar/protocol/Gt06FrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 - 2017 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,16 +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 Gt06FrameDecoder extends FrameDecoder { +public class Gt06FrameDecoder extends BaseFrameDecoder { @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; diff --git a/src/org/traccar/protocol/Gt06Protocol.java b/src/org/traccar/protocol/Gt06Protocol.java index f45ac95ee..e00a585ca 100644 --- a/src/org/traccar/protocol/Gt06Protocol.java +++ b/src/org/traccar/protocol/Gt06Protocol.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 org.traccar.model.Command; @@ -35,9 +34,9 @@ public class Gt06Protocol 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 Gt06FrameDecoder()); pipeline.addLast("objectEncoder", new Gt06ProtocolEncoder()); pipeline.addLast("objectDecoder", new Gt06ProtocolDecoder(Gt06Protocol.this)); diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 3e5ebc8c5..44dbf9d8b 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -15,9 +15,10 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; @@ -44,7 +45,7 @@ import java.util.regex.Pattern; public class Gt06ProtocolDecoder extends BaseProtocolDecoder { - private final Map<Integer, ChannelBuffer> photos = new HashMap<>(); + private final Map<Integer, ByteBuf> photos = new HashMap<>(); public Gt06ProtocolDecoder(Gt06Protocol protocol) { super(protocol); @@ -162,9 +163,9 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } } - private void sendResponse(Channel channel, boolean extended, int type, int index, ChannelBuffer content) { + private void sendResponse(Channel channel, boolean extended, int type, int index, ByteBuf content) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); int length = 5 + (content != null ? content.readableBytes() : 0); if (extended) { response.writeShort(0x7979); @@ -179,22 +180,22 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } response.writeShort(index); response.writeShort(Checksum.crc16(Checksum.CRC16_X25, - response.toByteBuffer(2, response.writerIndex() - 2))); + response.nioBuffer(2, response.writerIndex() - 2))); response.writeByte('\r'); response.writeByte('\n'); // ending channel.write(response); } } private void sendPhotoRequest(Channel channel, int pictureId) { - ChannelBuffer photo = photos.get(pictureId); - ChannelBuffer content = ChannelBuffers.dynamicBuffer(); + ByteBuf photo = photos.get(pictureId); + ByteBuf content = Unpooled.buffer(); content.writeInt(pictureId); content.writeInt(photo.writerIndex()); content.writeShort(Math.min(photo.writableBytes(), 1024)); sendResponse(channel, false, MSG_X1_PHOTO_DATA, 0, content); } - private boolean decodeGps(Position position, ChannelBuffer buf, boolean hasLength, TimeZone timezone) { + private boolean decodeGps(Position position, ByteBuf buf, boolean hasLength, TimeZone timezone) { DateBuilder dateBuilder = new DateBuilder(timezone) .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) @@ -232,7 +233,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return true; } - private boolean decodeLbs(Position position, ChannelBuffer buf, boolean hasLength) { + private boolean decodeLbs(Position position, ByteBuf buf, boolean hasLength) { int length = 0; if (hasLength) { @@ -255,7 +256,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return true; } - private boolean decodeStatus(Position position, ChannelBuffer buf) { + private boolean decodeStatus(Position position, ByteBuf buf) { int status = buf.readUnsignedByte(); @@ -367,7 +368,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return position; } - private Object decodeBasic(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception { + private Object decodeBasic(Channel channel, SocketAddress remoteAddress, ByteBuf buf) throws Exception { int length = buf.readUnsignedByte(); int dataLength = length - 5; @@ -386,7 +387,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_LOGIN) { - String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1); + String imei = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1); buf.readUnsignedShort(); // type deviceSession = getDeviceSession(channel, remoteAddress, imei); @@ -435,7 +436,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } else if (type == MSG_ADDRESS_REQUEST) { String response = "NA&&NA&&0##"; - ChannelBuffer content = ChannelBuffers.dynamicBuffer(); + ByteBuf content = Unpooled.buffer(); content.writeByte(response.length()); content.writeInt(0); content.writeBytes(response.getBytes(StandardCharsets.US_ASCII)); @@ -444,7 +445,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } else if (type == MSG_TIME_REQUEST) { Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - ChannelBuffer content = ChannelBuffers.dynamicBuffer(); + ByteBuf content = Unpooled.buffer(); content.writeByte(calendar.get(Calendar.YEAR) - 2000); content.writeByte(calendar.get(Calendar.MONTH) + 1); content.writeByte(calendar.get(Calendar.DAY_OF_MONTH)); @@ -482,7 +483,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // photo source buf.readUnsignedByte(); // picture format - ChannelBuffer photo = ChannelBuffers.buffer(buf.readInt()); + ByteBuf photo = Unpooled.buffer(buf.readInt()); int pictureId = buf.readInt(); photos.put(pictureId, photo); sendPhotoRequest(channel, pictureId); @@ -500,7 +501,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return null; } - private Object decodeWifi(ChannelBuffer buf, DeviceSession deviceSession) throws Exception { + private Object decodeWifi(ByteBuf buf, DeviceSession deviceSession) throws Exception { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); @@ -537,7 +538,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return position; } - private Object decodeBasicOther(Channel channel, ChannelBuffer buf, + private Object decodeBasicOther(Channel channel, ByteBuf buf, DeviceSession deviceSession, int type, int dataLength) throws Exception { Position position = new Position(getProtocolName()); @@ -571,7 +572,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { if (type != MSG_LBS_MULTIPLE && type != MSG_LBS_2) { int wifiCount = buf.readUnsignedByte(); for (int i = 0; i < wifiCount; i++) { - String mac = ChannelBuffers.hexDump(buf.readBytes(6)).replaceAll("(..)", "$1:"); + String mac = ByteBufUtil.hexDump(buf.readBytes(6)).replaceAll("(..)", "$1:"); network.addWifiAccessPoint(WifiAccessPoint.from( mac.substring(0, mac.length() - 1), buf.readUnsignedByte())); } @@ -619,7 +620,9 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } else { - buf.skipBytes(dataLength); + if (dataLength > 0) { + buf.skipBytes(dataLength); + } if (type != MSG_COMMAND_0 && type != MSG_COMMAND_1 && type != MSG_COMMAND_2) { sendResponse(channel, false, type, buf.getShort(buf.writerIndex() - 6), null); } @@ -640,7 +643,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return position; } - private Object decodeExtended(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception { + private Object decodeExtended(Channel channel, SocketAddress remoteAddress, ByteBuf buf) throws Exception { DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession == null) { @@ -704,7 +707,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { int pictureId = buf.readInt(); - ChannelBuffer photo = photos.get(pictureId); + ByteBuf photo = photos.get(pictureId); buf.readUnsignedInt(); // offset buf.readBytes(photo, buf.readUnsignedShort()); @@ -772,7 +775,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; int header = buf.readShort(); diff --git a/src/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/org/traccar/protocol/Gt06ProtocolEncoder.java index daf045f4f..46b4fa5a4 100644 --- a/src/org/traccar/protocol/Gt06ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolEncoder.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,8 +15,8 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import org.traccar.BaseProtocolEncoder; import org.traccar.Context; import org.traccar.helper.Checksum; @@ -27,11 +27,11 @@ import java.nio.charset.StandardCharsets; public class Gt06ProtocolEncoder extends BaseProtocolEncoder { - private ChannelBuffer encodeContent(long deviceId, String content) { + private ByteBuf encodeContent(long deviceId, String content) { boolean language = Context.getIdentityManager().lookupAttributeBoolean(deviceId, "gt06.language", false, true); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); + ByteBuf buf = Unpooled.buffer(); buf.writeByte(0x78); buf.writeByte(0x78); @@ -50,7 +50,7 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { buf.writeShort(0); // message index - buf.writeShort(Checksum.crc16(Checksum.CRC16_X25, buf.toByteBuffer(2, buf.writerIndex() - 2))); + buf.writeShort(Checksum.crc16(Checksum.CRC16_X25, buf.nioBuffer(2, buf.writerIndex() - 2))); buf.writeByte('\r'); buf.writeByte('\n'); diff --git a/src/org/traccar/protocol/Gt30Protocol.java b/src/org/traccar/protocol/Gt30Protocol.java index 186002a35..43bb5a70b 100644 --- a/src/org/traccar/protocol/Gt30Protocol.java +++ b/src/org/traccar/protocol/Gt30Protocol.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.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 Gt30Protocol 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("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/Gt30ProtocolDecoder.java b/src/org/traccar/protocol/Gt30ProtocolDecoder.java index 27081a108..ac1557994 100644 --- a/src/org/traccar/protocol/Gt30ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt30ProtocolDecoder.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/test/org/traccar/protocol/GalileoFrameDecoderTest.java b/test/org/traccar/protocol/GalileoFrameDecoderTest.java index 7a7c97ba6..defd39499 100644 --- a/test/org/traccar/protocol/GalileoFrameDecoderTest.java +++ b/test/org/traccar/protocol/GalileoFrameDecoderTest.java @@ -15,12 +15,12 @@ public class GalileoFrameDecoderTest extends ProtocolTest { GalileoFrameDecoder decoder = new GalileoFrameDecoder(); assertEquals( - binary(ByteOrder.LITTLE_ENDIAN, "011780011102e603383633353931303238393630323437043200801c"), - decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "011780011102e603383633353931303238393630323437043200801c"))); + binary("011780011102e603383633353931303238393630323437043200801c"), + decoder.decode(null, null, binary("011780011102e603383633353931303238393630323437043200801c"))); assertEquals( - binary(ByteOrder.LITTLE_ENDIAN, "01d48304320010020520a5829f58300f50dc8a024c0965013300000000344102350740003a41e14b426610431b4459fa672a4500004601a050364c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e293000000043200100105202d829f58300f50dc8a024c0965013300000000344102350740003a41d04b426110431b445702882a4500004601a050374c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29400000004320010000520b5819f58300f50dc8a024c0965013300000000344102350740003a419e4b426a10431c4456fab72a4500004601a050434c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010ff04203d819f58300f50dc8a024c0965013300000000344102350740003a41874b426310431c4454fe572a4500004601a050334c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29600000004320010fe0420c5809f58300f50dc8a024c0965013300000000344102350840003a41a24b426710431c4457fea72a4500004601a050214c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fd04204d809f58300f50dc8a024c0965013300000000344102350840003a41a34b426310431c4455f6772a4500004601a0502e4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29900000004320010fc0420d57f9f58300f50dc8a024c0965013300000000344102350840003a41bd4b426510431d4458fe672a4500004601a0501f4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fb04205d7f9f58300f50dc8a024c0965013300000000344102350840003a41b54b426310431d4456fa772a4500004601a0502d4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010fa0420e57e9f58300f50dc8a024c0965013300000000344102350840003a41b24b426210431e4454fa872a4500004601a050fe4b510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29000000004320010f904206d7e9f58300f50dc8a024c0965013300000000344102350a40003a41af4b426710431f4458fea72a4500004601a0500a4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e28900000067c5"), - decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "01d48304320010020520a5829f58300f50dc8a024c0965013300000000344102350740003a41e14b426610431b4459fa672a4500004601a050364c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e293000000043200100105202d829f58300f50dc8a024c0965013300000000344102350740003a41d04b426110431b445702882a4500004601a050374c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29400000004320010000520b5819f58300f50dc8a024c0965013300000000344102350740003a419e4b426a10431c4456fab72a4500004601a050434c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010ff04203d819f58300f50dc8a024c0965013300000000344102350740003a41874b426310431c4454fe572a4500004601a050334c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29600000004320010fe0420c5809f58300f50dc8a024c0965013300000000344102350840003a41a24b426710431c4457fea72a4500004601a050214c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fd04204d809f58300f50dc8a024c0965013300000000344102350840003a41a34b426310431c4455f6772a4500004601a0502e4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29900000004320010fc0420d57f9f58300f50dc8a024c0965013300000000344102350840003a41bd4b426510431d4458fe672a4500004601a0501f4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fb04205d7f9f58300f50dc8a024c0965013300000000344102350840003a41b54b426310431d4456fa772a4500004601a0502d4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010fa0420e57e9f58300f50dc8a024c0965013300000000344102350840003a41b24b426210431e4454fa872a4500004601a050fe4b510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29000000004320010f904206d7e9f58300f50dc8a024c0965013300000000344102350a40003a41af4b426710431f4458fea72a4500004601a0500a4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e28900000067c5"))); + binary("01d48304320010020520a5829f58300f50dc8a024c0965013300000000344102350740003a41e14b426610431b4459fa672a4500004601a050364c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e293000000043200100105202d829f58300f50dc8a024c0965013300000000344102350740003a41d04b426110431b445702882a4500004601a050374c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29400000004320010000520b5819f58300f50dc8a024c0965013300000000344102350740003a419e4b426a10431c4456fab72a4500004601a050434c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010ff04203d819f58300f50dc8a024c0965013300000000344102350740003a41874b426310431c4454fe572a4500004601a050334c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29600000004320010fe0420c5809f58300f50dc8a024c0965013300000000344102350840003a41a24b426710431c4457fea72a4500004601a050214c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fd04204d809f58300f50dc8a024c0965013300000000344102350840003a41a34b426310431c4455f6772a4500004601a0502e4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29900000004320010fc0420d57f9f58300f50dc8a024c0965013300000000344102350840003a41bd4b426510431d4458fe672a4500004601a0501f4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fb04205d7f9f58300f50dc8a024c0965013300000000344102350840003a41b54b426310431d4456fa772a4500004601a0502d4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010fa0420e57e9f58300f50dc8a024c0965013300000000344102350840003a41b24b426210431e4454fa872a4500004601a050fe4b510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29000000004320010f904206d7e9f58300f50dc8a024c0965013300000000344102350a40003a41af4b426710431f4458fea72a4500004601a0500a4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e28900000067c5"), + decoder.decode(null, null, binary("01d48304320010020520a5829f58300f50dc8a024c0965013300000000344102350740003a41e14b426610431b4459fa672a4500004601a050364c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e293000000043200100105202d829f58300f50dc8a024c0965013300000000344102350740003a41d04b426110431b445702882a4500004601a050374c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29400000004320010000520b5819f58300f50dc8a024c0965013300000000344102350740003a419e4b426a10431c4456fab72a4500004601a050434c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010ff04203d819f58300f50dc8a024c0965013300000000344102350740003a41874b426310431c4454fe572a4500004601a050334c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29600000004320010fe0420c5809f58300f50dc8a024c0965013300000000344102350840003a41a24b426710431c4457fea72a4500004601a050214c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fd04204d809f58300f50dc8a024c0965013300000000344102350840003a41a34b426310431c4455f6772a4500004601a0502e4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29900000004320010fc0420d57f9f58300f50dc8a024c0965013300000000344102350840003a41bd4b426510431d4458fe672a4500004601a0501f4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fb04205d7f9f58300f50dc8a024c0965013300000000344102350840003a41b54b426310431d4456fa772a4500004601a0502d4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010fa0420e57e9f58300f50dc8a024c0965013300000000344102350840003a41b24b426210431e4454fa872a4500004601a050fe4b510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29000000004320010f904206d7e9f58300f50dc8a024c0965013300000000344102350a40003a41af4b426710431f4458fea72a4500004601a0500a4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e28900000067c5"))); } diff --git a/test/org/traccar/protocol/GalileoProtocolDecoderTest.java b/test/org/traccar/protocol/GalileoProtocolDecoderTest.java index 6f2f1f90a..d6563453a 100644 --- a/test/org/traccar/protocol/GalileoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GalileoProtocolDecoderTest.java @@ -1,7 +1,5 @@ package org.traccar.protocol; -import java.nio.ByteOrder; - import org.junit.Test; import org.traccar.ProtocolTest; @@ -12,25 +10,25 @@ public class GalileoProtocolDecoderTest extends ProtocolTest { GalileoProtocolDecoder decoder = new GalileoProtocolDecoder(new GalileoProtocol()); - verifyPositions(decoder, false, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, false, binary( "01560003383636303530303338343337353836044701e000000000e13c494e414c4c3a696e303d31313230362c696e313d302c696e323d302c696e333d302c696e343d302c696e353d302c4163633d3536363932343732353bfdef")); - verifyPositions(decoder, false, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, false, binary( "012a0003383633353931303233353137333732046600e000000000e1104f555428332e2e3029203d2031313130bb29")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "0144030338363832303430303132363939333404320010ee0f20f5a86c57300570172f03bc7dfd023363002604343e00351c40092a414a6842af0e432445000046030050246b51666a524c055300000338363832303430303132363939333404320010ed0f20f4a86c57300570172f03b47dfd023363000d05343e00351140090a41c56742a60e432445000046030050b56a514f6a521b045300000338363832303430303132363939333404320010ec0f20e6a86c57300b34172f03287efd023300000000344900350d40290a41562742030b43234500004603205023455190445295005300000338363832303430303132363939333404320010eb0f20e4a86c57300b34172f03287efd023300000000344900350d40290b41000042bd0b432345000046032050dc31518c315200005300000338363832303430303132363939333404320010ea0f20c7a86c57300b34172f03287efd023300000000344900350d40a90b41000042050d43234500004600205000005100005200005300000338363832303430303132363939333404320010e90f204fa86c57300b34172f03287efd023300000000344900350d40a90b41000042ff0c43244500004600205000005100005200005300000338363832303430303132363939333404320010e80f20d7a76c57300b34172f03287efd023300000000344900350d40a90b41000042fd0c43244500004600205000005100005200005300000338363832303430303132363939333404320010e70f205fa76c57300b34172f03287efd023300000000344900350d40a90b41000042fd0c43254500004600205000005100005200005300000338363832303430303132363939333404320010e60f20e7a66c57300b34172f03287efd023300000000344900350d40a90b41000042fd0c43264500004600205000005100005200005300000338363832303430303132363939333404320010e50f206fa66c57300468172f03907cfd023300007a0a343600352b40a90b41000042030d43274500004600205000005100005200005300000338363832303430303132363939333404320010e40f2051a66c5730048c172f03ac7cfd02335300980a341600352b40a12b41000042040d43274500004600e0500000510000520000530000abde")); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "011380033836383230343030313534393038370432008590")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "01cf030446ba10630320a7054c533008f86c8e0310062c043347049e02344000350940013241506b428f10432244aeea572045f9004604a0500000510000529a6b5300000446ba10712420ce1c4b533009b4f06703043df4033381037b0a343800350a40093241db6b428f10432544c05ef81f45f9004604a050000051000052886b5300000446ba10702420c11c4b53300a54f16703c450f403336e034e0a343900350840093241dd6b428f1043254491eaf71f45f9004604a050000051000052c26b5300000446ba106f2420b31c4b53300cecf267033865f403336a03300a343800350740093241e66b429010432544b446582045f9004604a050000051000052f76b5300000446ba106e2420a61c4b53300c9cf467038878f403337b03370a343800350740093241b56b428f10432544ba46f81f45f9004604a050000051000052c66b5300000446ba106d2420991c4b53300bc8f56703508cf403338d036e0a343700350840093241d66b428f10432544b4ea572045f9004604a050000051000052846b5300000446ba106c24208c1c4b533008c8f5670370a0f403338703920a343a00350e40093241c76b428f10432544c0fef71f45f9004604a0500000510000528d6b5300000446ba106b24207f1c4b533009a4f5670338b4f403337603920a343c00350a40093241d06b428f104325449146a81f45f9004604a0500000510000528a6b5300000446ba106a2420721c4b53300b9cf56703ecc7f403337103810a343a00350840093241ca6b428f10432544d12e582045f9004604a050000051000052996b5300000446ba10692420651c4b53300a64f6670358dbf403337a03490a343900350840093241e56b429010432544aed2f71f45f9004604a050000051000052b26b5300000446ba10682420581c4b5330094cf86703e0eef4033381030c0a343a00350940093241f96b428f10432544cb2e182145f9004604a050000051000052926b5300000446ba106724204b1c4b533009f8fa67032802f503337b03fc09343b00350a40093241d86b428f10432544c0ea772145f9004604a0500000510000529e6b5300000446ba106624203e1c4b533009a0fd67036815f503338403fd09343c00350a40093241a86b428f10432544ae2e582045f9004604a050000051000052a86b5300000446ba10652420311c4b53300944006803b028f503338003ff09343d00350940093241dc6b428e10432544a8fea71f45f9004604a050000051000052e26b5300000446ba10642420241c4b533008f0026803083cf503338b03f909343c00350d40093241d36b428f10432544c0eaa71f45f9004604a050000051000052ab6b530000ff3f")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "011e8304320010270220dbd2f051300a90cf740328ac59033300000000347600351240012a41e92e42500f431f440006c814450f00460020500000510000520000530000540000550000560000570000580000600000610000620000a000a100a200a300a400a500a600a700a800a900aa00ab00ac00ad00ae00af00b00000b10000b20000b30000b40000b50000b60000b70000b80000b90000c000000000c100000000c200000000c300000000c400c500c600c700c800c900ca00cb00cc00cd00ce00cf00d000d100d200d471020000d60000d70000d80000d90000da0000db00000000dc00000000dd00000000de00000000df00000000f000000000f100000000f200000000f30000000004320010260220bdd2f051300590cf740328ac59033300000000347600351440090a41f02e427b0f431f44ff0db814450f00460000500000510000520000530000540000550000560000570000580000600000610000620000a000a100a200a300a400a500a600a700a800a900aa00ab00ac00ad00ae00af00b00000b10000b20000b30000b40000b50000b60000b70000b80000b90000c000000000c100000000c200000000c300000000c400c500c600c700c800c900ca00cb00cc00cd00ce00cf00d000d100d200d471020000d60000d70000d80000d90000da0000db00000000dc00000000dd00000000de00000000df00000000f000000000f100000000f200000000f300000000043200102502208ed2f051300ed8d0740304ac5903330000000034a500350a40012a41ec2e422d0f431f440016b814450f00460020500000510000520000530000540000550000560000570000580000600000610000620000a000a100a200a300a400a500a600a700a800a900aa00ab00ac00ad00ae00af00b00000b10000b20000b30000b40000b50000b60000b70000b80000b90000c000000000c100000000c200000000c300000000c400c500c600c700c800c900ca00cb00cc00cd00ce00cf00d000d100d200d44d020000d60000d70000d80000d90000da0000db00000000dc00000000dd00000000de00000000df00000000f000000000f100000000f200000000f300000000622e")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "01d48304320010020520a5829f58300f50dc8a024c0965013300000000344102350740003a41e14b426610431b4459fa672a4500004601a050364c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e293000000043200100105202d829f58300f50dc8a024c0965013300000000344102350740003a41d04b426110431b445702882a4500004601a050374c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29400000004320010000520b5819f58300f50dc8a024c0965013300000000344102350740003a419e4b426a10431c4456fab72a4500004601a050434c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010ff04203d819f58300f50dc8a024c0965013300000000344102350740003a41874b426310431c4454fe572a4500004601a050334c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29600000004320010fe0420c5809f58300f50dc8a024c0965013300000000344102350840003a41a24b426710431c4457fea72a4500004601a050214c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fd04204d809f58300f50dc8a024c0965013300000000344102350840003a41a34b426310431c4455f6772a4500004601a0502e4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29900000004320010fc0420d57f9f58300f50dc8a024c0965013300000000344102350840003a41bd4b426510431d4458fe672a4500004601a0501f4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fb04205d7f9f58300f50dc8a024c0965013300000000344102350840003a41b54b426310431d4456fa772a4500004601a0502d4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010fa0420e57e9f58300f50dc8a024c0965013300000000344102350840003a41b24b426210431e4454fa872a4500004601a050fe4b510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29000000004320010f904206d7e9f58300f50dc8a024c0965013300000000344102350a40003a41af4b426710431f4458fea72a4500004601a0500a4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e28900000067c5")); } diff --git a/test/org/traccar/protocol/GranitFrameDecoderTest.java b/test/org/traccar/protocol/GranitFrameDecoderTest.java index 130b9dbd7..7c4bb06c2 100644 --- a/test/org/traccar/protocol/GranitFrameDecoderTest.java +++ b/test/org/traccar/protocol/GranitFrameDecoderTest.java @@ -1,7 +1,5 @@ package org.traccar.protocol; -import java.nio.ByteOrder; - import org.junit.Test; import org.traccar.ProtocolTest; @@ -16,33 +14,31 @@ public class GranitFrameDecoderTest extends ProtocolTest { assertEquals( binary("2b525243427e1a003e2934757c57b8b03c38d279b4e61e9bd7006b000000001c00002a4533"), - decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "2b525243427e1a003e2934757c57b8b03c38d279b4e61e9bd7006b000000001c00002a45330d0a"))); + decoder.decode(null, null, binary("2b525243427e1a003e2934757c57b8b03c38d279b4e61e9bd7006b000000001c00002a45330d0a"))); assertEquals( binary("2b525243427e1a000d0a34757c57b8b03c38d279b4e61e9bd7006b000000001c00002a4533"), - decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "2b525243427e1a000d0a34757c57b8b03c38d279b4e61e9bd7006b000000001c00002a45330d0a"))); + decoder.decode(null, null, binary("2b525243427e1a000d0a34757c57b8b03c38d279b4e61e9bd7006b000000001c00002a45330d0a"))); assertEquals( binary("4f4b"), - decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "4f4b0d0a2b525243427e1a000d0a34757c57b8b03c38d279b4e61e9bd7006b000000001c00002a45330d0a"))); + decoder.decode(null, null, binary("4f4b0d0a2b525243427e1a000d0a34757c57b8b03c38d279b4e61e9bd7006b000000001c00002a45330d0a"))); assertEquals( binary("2b444441547e84003e290401d01690737c57b8903c383c7fa0e5081b64006b000000001c0000b8803c388e7fe7e5102197006c000000001c0000b8813c38ad7f02e6042035006c000000001d0000b8813c38bf7f13e6001d1e006c000000001d0000b8813c38bf7f13e6001d00006c000000001d0000b8903c38977f34e6091065006c000000001e000014002a3932"), - decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, - "2b444441547e84003e290401d01690737c57b8903c383c7fa0e5081b64006b000000001c0000b8803c388e7fe7e5102197006c000000001c0000b8813c38ad7f02e6042035006c000000001d0000b8813c38bf7f13e6001d1e006c000000001d0000b8813c38bf7f13e6001d00006c000000001d0000b8903c38977f34e6091065006c000000001e000014002a39320d0a"))); + decoder.decode(null, null, binary("2b444441547e84003e290401d01690737c57b8903c383c7fa0e5081b64006b000000001c0000b8803c388e7fe7e5102197006c000000001c0000b8813c38ad7f02e6042035006c000000001d0000b8813c38bf7f13e6001d1e006c000000001d0000b8813c38bf7f13e6001d00006c000000001d0000b8903c38977f34e6091065006c000000001e000014002a39320d0a"))); assertEquals( binary("2b444441547e84003e290401d41680747c57f8a03c38987f50e6005300006c000000001c0000f8b03c38987f50e6005300006c000000001c0000fefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefe14002a4346"), - decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, - "2b444441547e84003e290401d41680747c57f8a03c38987f50e6005300006c000000001c0000f8b03c38987f50e6005300006c000000001c0000fefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefe14002a43460d0a"))); + decoder.decode(null, null, binary("2b444441547e84003e290401d41680747c57f8a03c38987f50e6005300006c000000001c0000f8b03c38987f50e6005300006c000000001c0000fefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefe14002a43460d0a"))); assertEquals( binary("2b49444e543a204e6176696761746f722e30347820204669726d776172652076657273696f6e202030373132474c4e202a3231"), - decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "2b49444e543a204e6176696761746f722e30347820204669726d776172652076657273696f6e202030373132474c4e202a32310d0a"))); + decoder.decode(null, null, binary("2b49444e543a204e6176696761746f722e30347820204669726d776172652076657273696f6e202030373132474c4e202a32310d0a"))); assertEquals( binary("4552524f522057524f4e4720434845434b53554d5f31"), - decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "4552524f522057524f4e4720434845434b53554d5f310d0a"))); + decoder.decode(null, null, binary("4552524f522057524f4e4720434845434b53554d5f310d0a"))); } diff --git a/test/org/traccar/protocol/GranitProtocolDecoderTest.java b/test/org/traccar/protocol/GranitProtocolDecoderTest.java index 6e85b5cfc..21f913dbe 100644 --- a/test/org/traccar/protocol/GranitProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GranitProtocolDecoderTest.java @@ -1,7 +1,5 @@ package org.traccar.protocol; -import java.nio.ByteOrder; - import org.junit.Test; import org.traccar.ProtocolTest; @@ -12,38 +10,38 @@ public class GranitProtocolDecoderTest extends ProtocolTest { GranitProtocolDecoder decoder = new GranitProtocolDecoder(new GranitProtocol()); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "2b444441547e8400c500040130050c43495808002839aee3150200000000640000000000000008002839aee3150200000000640000000000000008002839aee3150200000000640000000000000008002839aee3150200000000640000000000000008002839aee3150200000000640000000000000008002839aee3150200000000640000000000000014002a37420d0a")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "2b525243427e1a00c5008443495808002839aee315020000000064000000000000002a37410d0a"), position("2016-12-08 11:27:00.000", false, 57.00888, 40.97143)); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "2b525243427e1a00c500ec904858b842283997e30002000000005e000000000d00002a32390d0a"), position("2016-12-07 22:45:00.000", true, 57.00853, 40.97105)); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "2b525243427e1a00c500009148580800283997e30002000000005f000000000000002a33410d0a")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "2b444441547e84003b6d0401b10e9217445800b051398f35d34a313b000072000000010b000080b051398f35d34a313b000072000000010b0000f0b051390f33314c303b900371000000010b0000f0b05139cd31e54c2f3cd0016f000000010b0000f0b051396831204d303d950071000000010b0000f0b051397530aa4d323c610171000000010b00000a002a30420d0a")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "2b525243427e1a003e2934757c57b8b03c38d279b4e61e9bd7006b000000001c00002a4533")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "2b444441547e84003e290401d01690737c57b8903c383c7fa0e5081b64006b000000001c0000b8803c388e7fe7e5102197006c000000001c0000b8813c38ad7f02e6042035006c000000001d0000b8813c38bf7f13e6001d1e006c000000001d0000b8813c38bf7f13e6001d00006c000000001d0000b8903c38977f34e6091065006c000000001e000014002a3932")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "2b444441547e84003e290401d41680747c57f8a03c38987f50e6005300006c000000001c0000f8b03c38987f50e6005300006c000000001c0000fefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefe14002a4346")); // +IDNT: Navigator.04x Firmware version 0712GLN *21 - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "2b49444e543a204e6176696761746f722e30347820204669726d776172652076657273696f6e202030373132474c4e202a3231")); // ERROR WRONG CHECKSUM_1 - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "4552524f522057524f4e4720434845434b53554d5f31")); } |