diff options
37 files changed, 365 insertions, 414 deletions
diff --git a/src/org/traccar/protocol/BceFrameDecoder.java b/src/org/traccar/protocol/BceFrameDecoder.java index 4fac79f85..15ae40148 100644 --- a/src/org/traccar/protocol/BceFrameDecoder.java +++ b/src/org/traccar/protocol/BceFrameDecoder.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,18 +15,18 @@ */ 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 BceFrameDecoder extends FrameDecoder { +public class BceFrameDecoder extends BaseFrameDecoder { private static final int HANDSHAKE_LENGTH = 7; // "#BCE#\r\n" private boolean header = true; - private static byte checksum(ChannelBuffer buf, int end) { + private static byte checksum(ByteBuf buf, int end) { byte result = 0; for (int i = 0; i < end; i++) { result += buf.getByte(buf.readerIndex() + i); @@ -36,9 +36,7 @@ public class BceFrameDecoder extends FrameDecoder { @Override protected Object decode( - ChannelHandlerContext ctx, - Channel channel, - ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (header && buf.readableBytes() >= HANDSHAKE_LENGTH) { buf.skipBytes(HANDSHAKE_LENGTH); @@ -48,7 +46,7 @@ public class BceFrameDecoder extends FrameDecoder { int end = 8; // IMEI while (buf.readableBytes() >= end + 2 + 1 + 1 + 1) { - end += buf.getUnsignedShort(buf.readerIndex() + end) + 2; + end += buf.getUnsignedShortLE(buf.readerIndex() + end) + 2; if (buf.readableBytes() > end && checksum(buf, end) == buf.getByte(buf.readerIndex() + end)) { return buf.readBytes(end + 1); diff --git a/src/org/traccar/protocol/BceProtocol.java b/src/org/traccar/protocol/BceProtocol.java index 5374fd0e1..880a4df70 100644 --- a/src/org/traccar/protocol/BceProtocol.java +++ b/src/org/traccar/protocol/BceProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,12 +15,10 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; -import java.nio.ByteOrder; import java.util.List; public class BceProtocol extends BaseProtocol { @@ -31,15 +29,13 @@ public class BceProtocol 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 BceFrameDecoder()); pipeline.addLast("objectDecoder", new BceProtocolDecoder(BceProtocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); + }); } } diff --git a/src/org/traccar/protocol/BceProtocolDecoder.java b/src/org/traccar/protocol/BceProtocolDecoder.java index f48757a4f..301be7847 100644 --- a/src/org/traccar/protocol/BceProtocolDecoder.java +++ b/src/org/traccar/protocol/BceProtocolDecoder.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.BitUtil; import org.traccar.helper.UnitsConverter; import org.traccar.model.CellTower; @@ -27,7 +28,6 @@ import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; -import java.nio.ByteOrder; import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -50,9 +50,9 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; - String imei = String.format("%015d", buf.readLong()); + String imei = String.format("%015d", buf.readLongLE()); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { return null; @@ -62,7 +62,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { while (buf.readableBytes() > 1) { - int dataEnd = buf.readUnsignedShort() + buf.readerIndex(); + int dataEnd = buf.readUnsignedShortLE() + buf.readerIndex(); int type = buf.readUnsignedByte(); int confirmKey = buf.readUnsignedByte() & 0x7F; @@ -73,7 +73,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { int structEnd = buf.readUnsignedByte() + buf.readerIndex(); - long time = buf.readUnsignedInt(); + long time = buf.readUnsignedIntLE(); if ((time & 0x0f) == DATA_TYPE) { time = time >> 4 << 1; @@ -84,7 +84,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { int mask; List<Integer> masks = new LinkedList<>(); do { - mask = buf.readUnsignedShort(); + mask = buf.readUnsignedShortLE(); masks.add(mask); } while (BitUtil.check(mask, 15)); @@ -92,8 +92,8 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(mask, 0)) { position.setValid(true); - position.setLongitude(buf.readFloat()); - position.setLatitude(buf.readFloat()); + position.setLongitude(buf.readFloatLE()); + position.setLatitude(buf.readFloatLE()); position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); int status = buf.readUnsignedByte(); @@ -101,18 +101,18 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_HDOP, BitUtil.from(status, 4)); position.setCourse(buf.readUnsignedByte() * 2); - position.setAltitude(buf.readUnsignedShort()); + position.setAltitude(buf.readUnsignedShortLE()); - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); } if (BitUtil.check(mask, 1)) { - position.set(Position.KEY_INPUT, buf.readUnsignedShort()); + position.set(Position.KEY_INPUT, buf.readUnsignedShortLE()); } for (int i = 1; i <= 8; i++) { if (BitUtil.check(mask, i + 1)) { - position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort()); + position.set(Position.PREFIX_ADC + i, buf.readUnsignedShortLE()); } } @@ -131,8 +131,8 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(mask, 14)) { position.setNetwork(new Network(CellTower.from( - buf.readUnsignedShort(), buf.readUnsignedByte(), - buf.readUnsignedShort(), buf.readUnsignedShort(), + buf.readUnsignedShortLE(), buf.readUnsignedByte(), + buf.readUnsignedShortLE(), buf.readUnsignedShortLE(), buf.readUnsignedByte()))); buf.readUnsignedByte(); } @@ -147,9 +147,9 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { // Send response if (type == MSG_ASYNC_STACK && channel != null) { - ChannelBuffer response = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, 8 + 2 + 2 + 1); - response.writeLong(Long.parseLong(imei)); - response.writeShort(2); + ByteBuf response = Unpooled.buffer(8 + 2 + 2 + 1); + response.writeLongLE(Long.parseLong(imei)); + response.writeShortLE(2); response.writeByte(MSG_STACK_COFIRM); response.writeByte(confirmKey); @@ -159,7 +159,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder { } response.writeByte(checksum); - channel.write(response); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } } diff --git a/src/org/traccar/protocol/BlackKiteProtocol.java b/src/org/traccar/protocol/BlackKiteProtocol.java index db32f5328..3e0b918f8 100644 --- a/src/org/traccar/protocol/BlackKiteProtocol.java +++ b/src/org/traccar/protocol/BlackKiteProtocol.java @@ -1,6 +1,6 @@ /* * Copyright 2015 Vijay Kumar (vijaykumar@zilogic.com) - * 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. @@ -16,12 +16,10 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; -import java.nio.ByteOrder; import java.util.List; public class BlackKiteProtocol extends BaseProtocol { @@ -32,15 +30,13 @@ public class BlackKiteProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new GalileoFrameDecoder()); + protected void addProtocolHandlers(PipelineBuilder pipeline) { + // pipeline.addLast("frameDecoder", new GalileoFrameDecoder()); TODO uncomment pipeline.addLast("objectDecoder", new BlackKiteProtocolDecoder(BlackKiteProtocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); + }); } } diff --git a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java index 7fc39fc7c..9701a8059 100644 --- a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java +++ b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org) * Copyright 2015 Vijay Kumar (vijaykumar@zilogic.com) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,16 +16,16 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.NetworkMessage; import org.traccar.helper.BitUtil; import org.traccar.model.Position; import java.net.SocketAddress; -import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.HashSet; @@ -56,11 +56,11 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder { private static final int TAG_XT3 = 0x62; 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.writeAndFlush(new NetworkMessage(reply, channel.remoteAddress())); } } @@ -68,10 +68,10 @@ public class BlackKiteProtocolDecoder 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<>(); @@ -99,27 +99,27 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder { break; case TAG_DATE: - position.setTime(new Date(buf.readUnsignedInt() * 1000)); + position.setTime(new Date(buf.readUnsignedIntLE() * 1000)); break; case TAG_COORDINATES: 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); break; case TAG_SPEED_COURSE: - position.setSpeed(buf.readUnsignedShort() * 0.0539957); - position.setCourse(buf.readUnsignedShort() * 0.1); + position.setSpeed(buf.readUnsignedShortLE() * 0.0539957); + position.setCourse(buf.readUnsignedShortLE() * 0.1); break; case TAG_ALTITUDE: - position.setAltitude(buf.readShort()); + position.setAltitude(buf.readShortLE()); break; case TAG_STATUS: - int status = buf.readUnsignedShort(); + int status = buf.readUnsignedShortLE(); position.set(Position.KEY_IGNITION, BitUtil.check(status, 9)); if (BitUtil.check(status, 15)) { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); @@ -128,33 +128,33 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder { break; case TAG_DIGITAL_INPUTS: - int input = buf.readUnsignedShort(); + int input = buf.readUnsignedShortLE(); for (int i = 0; i < 16; i++) { position.set(Position.PREFIX_IO + (i + 1), BitUtil.check(input, i)); } break; case TAG_DIGITAL_OUTPUTS: - int output = buf.readUnsignedShort(); + int output = buf.readUnsignedShortLE(); for (int i = 0; i < 16; i++) { position.set(Position.PREFIX_IO + (i + 17), BitUtil.check(output, i)); } break; case TAG_INPUT_VOLTAGE1: - position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort() / 1000.0); + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE() / 1000.0); break; case TAG_INPUT_VOLTAGE2: - position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort() / 1000.0); + position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShortLE() / 1000.0); break; case TAG_INPUT_VOLTAGE3: - position.set(Position.PREFIX_ADC + 3, buf.readUnsignedShort() / 1000.0); + position.set(Position.PREFIX_ADC + 3, buf.readUnsignedShortLE() / 1000.0); break; case TAG_INPUT_VOLTAGE4: - position.set(Position.PREFIX_ADC + 4, buf.readUnsignedShort() / 1000.0); + position.set(Position.PREFIX_ADC + 4, buf.readUnsignedShortLE() / 1000.0); break; case TAG_XT1: @@ -178,7 +178,7 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder { return null; } - sendReply(channel, buf.readUnsignedShort()); + sendReply(channel, buf.readUnsignedShortLE()); for (Position p : positions) { p.setDeviceId(deviceSession.getDeviceId()); diff --git a/src/org/traccar/protocol/BoxProtocol.java b/src/org/traccar/protocol/BoxProtocol.java index 36e7790f0..6e76ee635 100644 --- a/src/org/traccar/protocol/BoxProtocol.java +++ b/src/org/traccar/protocol/BoxProtocol.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 BoxProtocol 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("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/BoxProtocolDecoder.java b/src/org/traccar/protocol/BoxProtocolDecoder.java index 63238bcef..ef18f1555 100644 --- a/src/org/traccar/protocol/BoxProtocolDecoder.java +++ b/src/org/traccar/protocol/BoxProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 - 2015 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,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.helper.UnitsConverter; @@ -62,7 +63,7 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder { } else if (sentence.startsWith("E,")) { if (channel != null) { - channel.write("A," + sentence.substring(2) + "\r"); + channel.write(new NetworkMessage("A," + sentence.substring(2) + "\r", remoteAddress)); } } else if (sentence.startsWith("L,")) { diff --git a/src/org/traccar/protocol/CalAmpProtocol.java b/src/org/traccar/protocol/CalAmpProtocol.java index a3577f10c..29cb2974f 100644 --- a/src/org/traccar/protocol/CalAmpProtocol.java +++ b/src/org/traccar/protocol/CalAmpProtocol.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.ConnectionlessBootstrap; -import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -30,9 +29,9 @@ public class CalAmpProtocol 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("objectDecoder", new CalAmpProtocolDecoder(CalAmpProtocol.this)); } }); diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java index f717d3c5d..9e9bd1336 100644 --- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java +++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.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,13 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.NetworkMessage; import org.traccar.helper.BitUtil; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; @@ -52,7 +54,7 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { private void sendResponse(Channel channel, SocketAddress remoteAddress, int type, int index, int result) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.directBuffer(10); + ByteBuf response = Unpooled.buffer(10); response.writeByte(SERVICE_RESPONSE); response.writeByte(MSG_ACK); response.writeShort(index); @@ -60,11 +62,11 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { response.writeByte(result); response.writeByte(0); response.writeMedium(0); - channel.write(response, remoteAddress); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } } - private Position decodePosition(DeviceSession deviceSession, int type, ChannelBuffer buf) { + private Position decodePosition(DeviceSession deviceSession, int type, ByteBuf buf) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); @@ -143,14 +145,14 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; if (BitUtil.check(buf.getByte(buf.readerIndex()), 7)) { int content = buf.readUnsignedByte(); if (BitUtil.check(content, 0)) { - String id = ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte())); + String id = ByteBufUtil.hexDump(buf.readBytes(buf.readUnsignedByte())); getDeviceSession(channel, remoteAddress, id); } diff --git a/src/org/traccar/protocol/CarTrackProtocol.java b/src/org/traccar/protocol/CarTrackProtocol.java index d235c92be..2ac6598a4 100644 --- a/src/org/traccar/protocol/CarTrackProtocol.java +++ b/src/org/traccar/protocol/CarTrackProtocol.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 CarTrackProtocol 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/CarTrackProtocolDecoder.java b/src/org/traccar/protocol/CarTrackProtocolDecoder.java index 94215379d..87c4ae345 100644 --- a/src/org/traccar/protocol/CarTrackProtocolDecoder.java +++ b/src/org/traccar/protocol/CarTrackProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 - 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2014 - 2018 Anton Tananaev (anton@traccar.org) * Copyright 2014 Rohit * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,7 +16,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; diff --git a/src/org/traccar/protocol/CarcellProtocol.java b/src/org/traccar/protocol/CarcellProtocol.java index c9fedad65..40ecfbbe7 100644 --- a/src/org/traccar/protocol/CarcellProtocol.java +++ b/src/org/traccar/protocol/CarcellProtocol.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. @@ -17,12 +17,11 @@ package org.traccar.protocol; import java.util.List; -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 org.traccar.model.Command; @@ -37,9 +36,9 @@ public class CarcellProtocol 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("stringEncoder", new StringEncoder()); pipeline.addLast("stringDecoder", new StringDecoder()); diff --git a/src/org/traccar/protocol/CarcellProtocolDecoder.java b/src/org/traccar/protocol/CarcellProtocolDecoder.java index 52b777b81..a4da7982e 100644 --- a/src/org/traccar/protocol/CarcellProtocolDecoder.java +++ b/src/org/traccar/protocol/CarcellProtocolDecoder.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. @@ -18,7 +18,7 @@ package org.traccar.protocol; import java.net.SocketAddress; import java.util.regex.Pattern; -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/CarscopProtocol.java b/src/org/traccar/protocol/CarscopProtocol.java index 01a754027..c52b025bc 100644 --- a/src/org/traccar/protocol/CarscopProtocol.java +++ b/src/org/traccar/protocol/CarscopProtocol.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 CarscopProtocol 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/CarscopProtocolDecoder.java b/src/org/traccar/protocol/CarscopProtocolDecoder.java index 7f9dcc3b7..d8634b512 100644 --- a/src/org/traccar/protocol/CarscopProtocolDecoder.java +++ b/src/org/traccar/protocol/CarscopProtocolDecoder.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,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; diff --git a/src/org/traccar/protocol/CastelProtocol.java b/src/org/traccar/protocol/CastelProtocol.java index d5ba5cd55..3e3c5699e 100644 --- a/src/org/traccar/protocol/CastelProtocol.java +++ b/src/org/traccar/protocol/CastelProtocol.java @@ -15,15 +15,12 @@ */ 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 org.traccar.model.Command; -import java.nio.ByteOrder; import java.util.List; public class CastelProtocol extends BaseProtocol { @@ -37,26 +34,21 @@ public class CastelProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0)); + protected void addProtocolHandlers(PipelineBuilder pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0)); // TODO LE frame decoder pipeline.addLast("objectEncoder", new CastelProtocolEncoder()); pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - - server = new TrackerServer(new ConnectionlessBootstrap(), getName()) { + }); + serverList.add(new TrackerServer(true, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("objectEncoder", new CastelProtocolEncoder()); pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); + }); } } diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index 2ac79f9cf..296309989 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -15,11 +15,13 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.NetworkMessage; import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.ObdDecoder; @@ -29,7 +31,6 @@ import org.traccar.model.Network; import org.traccar.model.Position; import java.net.SocketAddress; -import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.LinkedList; @@ -100,7 +101,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { public static final short MSG_CC_PETROL_CONTROL = 0x4583; public static final short MSG_CC_HEARTBEAT_RESPONSE = (short) 0x8206; - private Position readPosition(DeviceSession deviceSession, ChannelBuffer buf) { + private Position readPosition(DeviceSession deviceSession, ByteBuf buf) { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); @@ -110,10 +111,10 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()); position.setTime(dateBuilder.getDate()); - double lat = buf.readUnsignedInt() / 3600000.0; - double lon = buf.readUnsignedInt() / 3600000.0; - position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShort())); - position.setCourse(buf.readUnsignedShort() * 0.1); + double lat = buf.readUnsignedIntLE() / 3600000.0; + double lon = buf.readUnsignedIntLE() / 3600000.0; + position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShortLE())); + position.setCourse(buf.readUnsignedShortLE() * 0.1); int flags = buf.readUnsignedByte(); if ((flags & 0x02) == 0) { @@ -140,13 +141,13 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { return position; } - private void decodeObd(Position position, ChannelBuffer buf, boolean groups) { + private void decodeObd(Position position, ByteBuf buf, boolean groups) { int count = buf.readUnsignedByte(); int[] pids = new int[count]; for (int i = 0; i < count; i++) { - pids[i] = buf.readUnsignedShort() & 0xff; + pids[i] = buf.readUnsignedShortLE() & 0xff; } if (groups) { @@ -161,10 +162,10 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { value = buf.readUnsignedByte(); break; case 2: - value = buf.readUnsignedShort(); + value = buf.readUnsignedShortLE(); break; case 4: - value = buf.readInt(); + value = buf.readIntLE(); break; default: value = 0; @@ -174,21 +175,21 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { } } - private void decodeStat(Position position, ChannelBuffer buf) { + private void decodeStat(Position position, ByteBuf buf) { - buf.readUnsignedInt(); // ACC ON time - buf.readUnsignedInt(); // UTC time - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); - position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt()); - position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt()); - buf.readUnsignedShort(); // current fuel consumption - position.set(Position.KEY_STATUS, buf.readUnsignedInt()); + buf.readUnsignedIntLE(); // ACC ON time + buf.readUnsignedIntLE(); // UTC time + position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); + position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedIntLE()); + position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedIntLE()); + buf.readUnsignedShortLE(); // current fuel consumption + position.set(Position.KEY_STATUS, buf.readUnsignedIntLE()); buf.skipBytes(8); } private void sendResponse( Channel channel, SocketAddress remoteAddress, - int version, ChannelBuffer id, short type, ChannelBuffer content) { + int version, ByteBuf id, short type, ByteBuf content) { if (channel != null) { int length = 2 + 2 + 1 + id.readableBytes() + 2 + 2 + 2; @@ -196,41 +197,41 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { length += content.readableBytes(); } - ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, length); + ByteBuf response = Unpooled.buffer(length); response.writeByte('@'); response.writeByte('@'); - response.writeShort(length); + response.writeShortLE(length); response.writeByte(version); response.writeBytes(id); - response.writeShort(ChannelBuffers.swapShort(type)); + response.writeShort(type); if (content != null) { response.writeBytes(content); } - response.writeShort( - Checksum.crc16(Checksum.CRC16_X25, response.toByteBuffer(0, response.writerIndex()))); + response.writeShortLE( + Checksum.crc16(Checksum.CRC16_X25, response.nioBuffer(0, response.writerIndex()))); response.writeByte(0x0D); response.writeByte(0x0A); - channel.write(response, remoteAddress); + channel.write(new NetworkMessage(response, remoteAddress)); } } private void sendResponse( - Channel channel, SocketAddress remoteAddress, ChannelBuffer id, short type) { + Channel channel, SocketAddress remoteAddress, ByteBuf id, short type) { if (channel != null) { int length = 2 + 2 + id.readableBytes() + 2 + 4 + 8 + 2 + 2; - ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, length); + ByteBuf response = Unpooled.buffer(length); response.writeByte('@'); response.writeByte('@'); - response.writeShort(length); + response.writeShortLE(length); response.writeBytes(id); - response.writeShort(ChannelBuffers.swapShort(type)); - response.writeInt(0); + response.writeShort(type); + response.writeIntLE(0); for (int i = 0; i < 8; i++) { response.writeByte(0xff); } - response.writeShort( - Checksum.crc16(Checksum.CRC16_X25, response.toByteBuffer(0, response.writerIndex()))); + response.writeShortLE( + Checksum.crc16(Checksum.CRC16_X25, response.nioBuffer(0, response.writerIndex()))); response.writeByte(0x0D); response.writeByte(0x0A); - channel.write(response, remoteAddress); + channel.write(new NetworkMessage(response, remoteAddress)); } } @@ -284,8 +285,8 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { } private Object decodeSc( - Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, - int version, ChannelBuffer id, short type, DeviceSession deviceSession) { + Channel channel, SocketAddress remoteAddress, ByteBuf buf, + int version, ByteBuf id, short type, DeviceSession deviceSession) { if (type == MSG_SC_HEARTBEAT) { @@ -295,28 +296,28 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { || type == MSG_SC_ALARM || type == MSG_SC_CURRENT_LOCATION || type == MSG_SC_FUEL) { if (type == MSG_SC_LOGIN) { - ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 10); - response.writeInt(0xFFFFFFFF); - response.writeShort(0); - response.writeInt((int) (System.currentTimeMillis() / 1000)); + ByteBuf response = Unpooled.buffer(10); + response.writeIntLE(0xFFFFFFFF); + response.writeShortLE(0); + response.writeIntLE((int) (System.currentTimeMillis() / 1000)); sendResponse(channel, remoteAddress, version, id, MSG_SC_LOGIN_RESPONSE, response); } if (type == MSG_SC_GPS) { buf.readUnsignedByte(); // historical } else if (type == MSG_SC_ALARM) { - buf.readUnsignedInt(); // alarm + buf.readUnsignedIntLE(); // alarm } else if (type == MSG_SC_CURRENT_LOCATION) { - buf.readUnsignedShort(); + buf.readUnsignedShortLE(); } - buf.readUnsignedInt(); // ACC ON time - buf.readUnsignedInt(); // UTC time - long odometer = buf.readUnsignedInt(); - long tripOdometer = buf.readUnsignedInt(); - long fuelConsumption = buf.readUnsignedInt(); - buf.readUnsignedShort(); // current fuel consumption - long status = buf.readUnsignedInt(); + buf.readUnsignedIntLE(); // ACC ON time + buf.readUnsignedIntLE(); // UTC time + long odometer = buf.readUnsignedIntLE(); + long tripOdometer = buf.readUnsignedIntLE(); + long fuelConsumption = buf.readUnsignedIntLE(); + buf.readUnsignedShortLE(); // current fuel consumption + long status = buf.readUnsignedIntLE(); buf.skipBytes(8); int count = buf.readUnsignedByte(); @@ -340,13 +341,13 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { for (Position position : positions) { decodeAlarm(position, alarm); } - buf.readUnsignedShort(); // description - buf.readUnsignedShort(); // threshold + buf.readUnsignedShortLE(); // description + buf.readUnsignedShortLE(); // threshold } } } else if (type == MSG_SC_FUEL) { for (Position position : positions) { - position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort()); + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE()); } } @@ -356,7 +357,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { } else if (type == MSG_SC_GPS_SLEEP) { - buf.readUnsignedInt(); // device time + buf.readUnsignedIntLE(); // device time return readPosition(deviceSession, buf); @@ -370,7 +371,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { decodeStat(position, buf); - buf.readUnsignedShort(); // sample rate + buf.readUnsignedShortLE(); // sample rate decodeObd(position, buf, true); return position; @@ -382,7 +383,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { decodeStat(position, buf); buf.readUnsignedByte(); // flag - position.add(ObdDecoder.decodeCodes(ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte())))); + position.add(ObdDecoder.decodeCodes(ByteBufUtil.hexDump(buf.readBytes(buf.readUnsignedByte())))); return position; @@ -404,7 +405,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { decodeStat(position, buf); position.setNetwork(new Network( - CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort()))); + CellTower.fromLacCid(buf.readUnsignedShortLE(), buf.readUnsignedShortLE()))); return position; @@ -412,20 +413,20 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { Position position = createPosition(deviceSession); - buf.readUnsignedShort(); // index + buf.readUnsignedShortLE(); // index buf.readUnsignedByte(); // response count buf.readUnsignedByte(); // response index int failureCount = buf.readUnsignedByte(); for (int i = 0; i < failureCount; i++) { - buf.readUnsignedShort(); // tag + buf.readUnsignedShortLE(); // tag } int successCount = buf.readUnsignedByte(); for (int i = 0; i < successCount; i++) { - buf.readUnsignedShort(); // tag + buf.readUnsignedShortLE(); // tag position.set(Position.KEY_RESULT, - buf.readBytes(buf.readUnsignedShort()).toString(StandardCharsets.US_ASCII)); + buf.readBytes(buf.readUnsignedShortLE()).toString(StandardCharsets.US_ASCII)); } return position; @@ -436,8 +437,8 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { } private Object decodeCc( - Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, - int version, ChannelBuffer id, short type, DeviceSession deviceSession) { + Channel channel, SocketAddress remoteAddress, ByteBuf buf, + int version, ByteBuf id, short type, DeviceSession deviceSession) { if (type == MSG_CC_HEARTBEAT) { @@ -451,16 +452,16 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { for (int i = 0; i < count; i++) { Position position = readPosition(deviceSession, buf); - position.set(Position.KEY_STATUS, buf.readUnsignedInt()); + position.set(Position.KEY_STATUS, buf.readUnsignedIntLE()); position.set(Position.KEY_BATTERY, buf.readUnsignedByte()); - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); buf.readUnsignedByte(); // geo-fencing id buf.readUnsignedByte(); // geo-fencing flags buf.readUnsignedByte(); // additional flags position.setNetwork(new Network( - CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort()))); + CellTower.fromLacCid(buf.readUnsignedShortLE(), buf.readUnsignedShortLE()))); positions.add(position); } @@ -473,9 +474,9 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { Position position = readPosition(deviceSession, buf); - position.set(Position.KEY_STATUS, buf.readUnsignedInt()); + position.set(Position.KEY_STATUS, buf.readUnsignedIntLE()); position.set(Position.KEY_BATTERY, buf.readUnsignedByte()); - position.set(Position.KEY_ODOMETER, buf.readUnsignedInt()); + position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE()); buf.readUnsignedByte(); // geo-fencing id buf.readUnsignedByte(); // geo-fencing flags @@ -493,8 +494,8 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { } private Object decodeMpip( - Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, - int version, ChannelBuffer id, short type, DeviceSession deviceSession) { + Channel channel, SocketAddress remoteAddress, ByteBuf buf, + int version, ByteBuf id, short type, DeviceSession deviceSession) { if (type == 0x4001) { @@ -506,8 +507,8 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { sendResponse(channel, remoteAddress, id, (short) 0x1001); - buf.readUnsignedInt(); // index - buf.readUnsignedInt(); // unix time + buf.readUnsignedIntLE(); // index + buf.readUnsignedIntLE(); // unix time buf.readUnsignedByte(); return readPosition(deviceSession, buf); @@ -537,18 +538,18 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; - int header = buf.readUnsignedShort(); - buf.readUnsignedShort(); // length + int header = buf.readUnsignedShortLE(); + buf.readUnsignedShortLE(); // length int version = -1; if (header == 0x4040) { version = buf.readUnsignedByte(); } - ChannelBuffer id = buf.readBytes(20); - short type = ChannelBuffers.swapShort(buf.readShort()); + ByteBuf id = buf.readBytes(20); + short type = buf.readShort(); DeviceSession deviceSession = getDeviceSession( channel, remoteAddress, id.toString(StandardCharsets.US_ASCII).trim()); diff --git a/src/org/traccar/protocol/CastelProtocolEncoder.java b/src/org/traccar/protocol/CastelProtocolEncoder.java index 806dac19e..dde8ac11f 100644 --- a/src/org/traccar/protocol/CastelProtocolEncoder.java +++ b/src/org/traccar/protocol/CastelProtocolEncoder.java @@ -15,37 +15,36 @@ */ 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; import org.traccar.helper.Log; import org.traccar.model.Command; -import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; public class CastelProtocolEncoder extends BaseProtocolEncoder { - private ChannelBuffer encodeContent(long deviceId, short type, ChannelBuffer content) { - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); + private ByteBuf encodeContent(long deviceId, short type, ByteBuf content) { + ByteBuf buf = Unpooled.buffer(0); String uniqueId = Context.getIdentityManager().getById(deviceId).getUniqueId(); buf.writeByte('@'); buf.writeByte('@'); - buf.writeShort(2 + 2 + 1 + 20 + 2 + content.readableBytes() + 2 + 2); // length + buf.writeShortLE(2 + 2 + 1 + 20 + 2 + content.readableBytes() + 2 + 2); // length buf.writeByte(1); // protocol version buf.writeBytes(uniqueId.getBytes(StandardCharsets.US_ASCII)); buf.writeZero(20 - uniqueId.length()); - buf.writeShort(ChannelBuffers.swapShort(type)); + buf.writeShort(type); buf.writeBytes(content); - buf.writeShort(Checksum.crc16(Checksum.CRC16_X25, buf.toByteBuffer())); + buf.writeShortLE(Checksum.crc16(Checksum.CRC16_X25, buf.nioBuffer())); buf.writeByte('\r'); buf.writeByte('\n'); @@ -55,7 +54,7 @@ public class CastelProtocolEncoder extends BaseProtocolEncoder { @Override protected Object encodeCommand(Command command) { - ChannelBuffer content = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); + ByteBuf content = Unpooled.buffer(0); switch (command.getType()) { case Command.TYPE_ENGINE_STOP: content.writeByte(1); diff --git a/src/org/traccar/protocol/CautelaProtocol.java b/src/org/traccar/protocol/CautelaProtocol.java index 89ab7a1d0..dc5c82193 100644 --- a/src/org/traccar/protocol/CautelaProtocol.java +++ b/src/org/traccar/protocol/CautelaProtocol.java @@ -15,12 +15,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.LineBasedFrameDecoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -33,9 +32,9 @@ public class CautelaProtocol 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/CautelaProtocolDecoder.java b/src/org/traccar/protocol/CautelaProtocolDecoder.java index 7c48ff690..ce231591e 100644 --- a/src/org/traccar/protocol/CautelaProtocolDecoder.java +++ b/src/org/traccar/protocol/CautelaProtocolDecoder.java @@ -15,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; diff --git a/src/org/traccar/protocol/CellocatorFrameDecoder.java b/src/org/traccar/protocol/CellocatorFrameDecoder.java index b4708f5db..8cdba18e0 100644 --- a/src/org/traccar/protocol/CellocatorFrameDecoder.java +++ b/src/org/traccar/protocol/CellocatorFrameDecoder.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,29 +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; import org.traccar.helper.Log; -public class CellocatorFrameDecoder extends FrameDecoder { +public class CellocatorFrameDecoder extends BaseFrameDecoder { private static final int MESSAGE_MINIMUM_LENGTH = 15; @Override protected Object decode( - ChannelHandlerContext ctx, - Channel channel, - ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { - // Check minimum length - int available = buf.readableBytes(); - if (available < MESSAGE_MINIMUM_LENGTH) { + if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) { return null; } - // Size depending on message type int length = 0; int type = buf.getUnsignedByte(4); switch (type) { @@ -51,8 +46,8 @@ public class CellocatorFrameDecoder extends FrameDecoder { length = 70; break; case CellocatorProtocolDecoder.MSG_CLIENT_SERIAL: - if (available >= 19) { - length = 19 + buf.getUnsignedShort(16); + if (buf.readableBytes() >= 19) { + length = 19 + buf.getUnsignedShortLE(16); } break; case CellocatorProtocolDecoder.MSG_CLIENT_MODULAR: @@ -63,8 +58,7 @@ public class CellocatorFrameDecoder extends FrameDecoder { break; } - // Read packet - if (length > 0 && available >= length) { + if (length > 0 && buf.readableBytes() >= length) { return buf.readBytes(length); } diff --git a/src/org/traccar/protocol/CellocatorProtocol.java b/src/org/traccar/protocol/CellocatorProtocol.java index 4a20bc977..bf186e67f 100644 --- a/src/org/traccar/protocol/CellocatorProtocol.java +++ b/src/org/traccar/protocol/CellocatorProtocol.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,14 +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.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 CellocatorProtocol extends BaseProtocol { @@ -35,26 +32,21 @@ public class CellocatorProtocol 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 CellocatorFrameDecoder()); pipeline.addLast("objectEncoder", new CellocatorProtocolEncoder()); pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); - - server = new TrackerServer(new ConnectionlessBootstrap(), getName()) { + }); + serverList.add(new TrackerServer(true, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("objectEncoder", new CellocatorProtocolEncoder()); pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this)); } - }; - server.setEndianness(ByteOrder.LITTLE_ENDIAN); - serverList.add(server); + }); } } diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java index 67db9aa7d..426b6bf3b 100644 --- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java +++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.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,17 +15,17 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.NetworkMessage; import org.traccar.helper.DateBuilder; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import java.net.SocketAddress; -import java.nio.ByteOrder; public class CellocatorProtocolDecoder extends BaseProtocolDecoder { @@ -44,15 +44,15 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { private byte commandCount; private void sendReply(Channel channel, SocketAddress remoteAddress, long deviceId, byte packetNumber) { - ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 28); + ByteBuf reply = Unpooled.buffer(28); reply.writeByte('M'); reply.writeByte('C'); reply.writeByte('G'); reply.writeByte('P'); reply.writeByte(MSG_SERVER_ACKNOWLEDGE); - reply.writeInt((int) deviceId); + reply.writeIntLE((int) deviceId); reply.writeByte(commandCount++); - reply.writeInt(0); // authentication code + reply.writeIntLE(0); // authentication code reply.writeByte(0); reply.writeByte(packetNumber); reply.writeZero(11); @@ -64,7 +64,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { reply.writeByte(checksum); if (channel != null) { - channel.write(reply, remoteAddress); + channel.write(new NetworkMessage(reply, remoteAddress)); } } @@ -85,14 +85,14 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; buf.skipBytes(4); // system code int type = buf.readUnsignedByte(); - long deviceUniqueId = buf.readUnsignedInt(); + long deviceUniqueId = buf.readUnsignedIntLE(); if (type != MSG_CLIENT_SERIAL) { - buf.readUnsignedShort(); // communication control + buf.readUnsignedShortLE(); // communication control } byte packetNumber = buf.readByte(); @@ -121,17 +121,17 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); position.set("mode", buf.readUnsignedByte()); - position.set(Position.PREFIX_IO + 1, buf.readUnsignedInt()); + position.set(Position.PREFIX_IO + 1, buf.readUnsignedIntLE()); operator <<= 8; operator += buf.readUnsignedByte(); position.set(Position.KEY_OPERATOR, operator); - position.set(Position.PREFIX_ADC + 1, buf.readUnsignedInt()); - position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium()); + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedIntLE()); + position.set(Position.KEY_ODOMETER, buf.readUnsignedMediumLE()); buf.skipBytes(6); // multi-purpose data - position.set(Position.KEY_GPS, buf.readUnsignedShort()); + position.set(Position.KEY_GPS, buf.readUnsignedShortLE()); position.set("locationStatus", buf.readUnsignedByte()); position.set("mode1", buf.readUnsignedByte()); position.set("mode2", buf.readUnsignedByte()); @@ -139,15 +139,15 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.setValid(true); - position.setLongitude(buf.readInt() / Math.PI * 180 / 100000000); - position.setLatitude(buf.readInt() / Math.PI * 180 / 100000000.0); - position.setAltitude(buf.readInt() * 0.01); - position.setSpeed(UnitsConverter.knotsFromMps(buf.readInt() * 0.01)); - position.setCourse(buf.readUnsignedShort() / Math.PI * 180.0 / 1000.0); + position.setLongitude(buf.readIntLE() / Math.PI * 180 / 100000000); + position.setLatitude(buf.readIntLE() / Math.PI * 180 / 100000000.0); + position.setAltitude(buf.readIntLE() * 0.01); + position.setSpeed(UnitsConverter.knotsFromMps(buf.readIntLE() * 0.01)); + position.setCourse(buf.readUnsignedShortLE() / Math.PI * 180.0 / 1000.0); DateBuilder dateBuilder = new DateBuilder() .setTimeReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) - .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedShort()); + .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedShortLE()); position.setTime(dateBuilder.getDate()); return position; diff --git a/src/org/traccar/protocol/CellocatorProtocolEncoder.java b/src/org/traccar/protocol/CellocatorProtocolEncoder.java index bb143d349..4eef42128 100644 --- a/src/org/traccar/protocol/CellocatorProtocolEncoder.java +++ b/src/org/traccar/protocol/CellocatorProtocolEncoder.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,34 +15,32 @@ */ 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.Log; import org.traccar.model.Command; -import java.nio.ByteOrder; - public class CellocatorProtocolEncoder extends BaseProtocolEncoder { - private ChannelBuffer encodeContent(long deviceId, int command, int data1, int data2) { + private ByteBuf encodeContent(long deviceId, int command, int data1, int data2) { - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0); + ByteBuf buf = Unpooled.buffer(0); buf.writeByte('M'); buf.writeByte('C'); buf.writeByte('G'); buf.writeByte('P'); buf.writeByte(0); - buf.writeInt(Integer.parseInt(getUniqueId(deviceId))); + buf.writeIntLE(Integer.parseInt(getUniqueId(deviceId))); buf.writeByte(0); // command numerator - buf.writeInt(0); // authentication code + buf.writeIntLE(0); // authentication code buf.writeByte(command); buf.writeByte(command); buf.writeByte(data1); buf.writeByte(data1); buf.writeByte(data2); buf.writeByte(data2); - buf.writeInt(0); // command specific data + buf.writeIntLE(0); // command specific data byte checksum = 0; for (int i = 4; i < buf.writerIndex(); i++) { diff --git a/src/org/traccar/protocol/CguardProtocol.java b/src/org/traccar/protocol/CguardProtocol.java index 460bd331f..5d2ffb6fd 100644 --- a/src/org/traccar/protocol/CguardProtocol.java +++ b/src/org/traccar/protocol/CguardProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,12 +15,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.LineBasedFrameDecoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -33,9 +32,9 @@ public class CguardProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/CguardProtocolDecoder.java b/src/org/traccar/protocol/CguardProtocolDecoder.java index 2e20537c8..806f500ab 100644 --- a/src/org/traccar/protocol/CguardProtocolDecoder.java +++ b/src/org/traccar/protocol/CguardProtocolDecoder.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/CityeasyProtocol.java b/src/org/traccar/protocol/CityeasyProtocol.java index 7e5ca0ba0..82b33e0f4 100644 --- a/src/org/traccar/protocol/CityeasyProtocol.java +++ b/src/org/traccar/protocol/CityeasyProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,9 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import io.netty.handler.codec.LengthFieldBasedFrameDecoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import org.traccar.model.Command; @@ -37,9 +36,9 @@ public class CityeasyProtocol 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, 2, 2, -4, 0)); pipeline.addLast("objectEncoder", new CityeasyProtocolEncoder()); pipeline.addLast("objectDecoder", new CityeasyProtocolDecoder(CityeasyProtocol.this)); diff --git a/src/org/traccar/protocol/CityeasyProtocolDecoder.java b/src/org/traccar/protocol/CityeasyProtocolDecoder.java index 7a1d8119d..5e5568402 100644 --- a/src/org/traccar/protocol/CityeasyProtocolDecoder.java +++ b/src/org/traccar/protocol/CityeasyProtocolDecoder.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 org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.Checksum; @@ -69,12 +69,12 @@ public class CityeasyProtocolDecoder 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.readUnsignedShort(); // length - String imei = ChannelBuffers.hexDump(buf.readBytes(7)); + String imei = ByteBufUtil.hexDump(buf.readBytes(7)); DeviceSession deviceSession = getDeviceSession( channel, remoteAddress, imei, imei + Checksum.luhn(Long.parseLong(imei))); if (deviceSession == null) { diff --git a/src/org/traccar/protocol/CityeasyProtocolEncoder.java b/src/org/traccar/protocol/CityeasyProtocolEncoder.java index 387926e03..e143563f0 100644 --- a/src/org/traccar/protocol/CityeasyProtocolEncoder.java +++ b/src/org/traccar/protocol/CityeasyProtocolEncoder.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. @@ -17,8 +17,8 @@ package org.traccar.protocol; import java.util.TimeZone; -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; @@ -26,9 +26,9 @@ import org.traccar.model.Command; public class CityeasyProtocolEncoder extends BaseProtocolEncoder { - private ChannelBuffer encodeContent(int type, ChannelBuffer content) { + private ByteBuf encodeContent(int type, ByteBuf content) { - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); + ByteBuf buf = Unpooled.buffer(); buf.writeByte('S'); buf.writeByte('S'); @@ -36,7 +36,7 @@ public class CityeasyProtocolEncoder extends BaseProtocolEncoder { buf.writeShort(type); buf.writeBytes(content); buf.writeInt(0x0B); - buf.writeShort(Checksum.crc16(Checksum.CRC16_KERMIT, buf.toByteBuffer())); + buf.writeShort(Checksum.crc16(Checksum.CRC16_KERMIT, buf.nioBuffer())); buf.writeByte('\r'); buf.writeByte('\n'); @@ -46,7 +46,7 @@ public class CityeasyProtocolEncoder extends BaseProtocolEncoder { @Override protected Object encodeCommand(Command command) { - ChannelBuffer content = ChannelBuffers.dynamicBuffer(); + ByteBuf content = Unpooled.buffer(); switch (command.getType()) { case Command.TYPE_POSITION_SINGLE: diff --git a/src/org/traccar/protocol/ContinentalProtocol.java b/src/org/traccar/protocol/ContinentalProtocol.java index 5f43a51f7..540128120 100644 --- a/src/org/traccar/protocol/ContinentalProtocol.java +++ b/src/org/traccar/protocol/ContinentalProtocol.java @@ -15,10 +15,9 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import io.netty.handler.codec.LengthFieldBasedFrameDecoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -31,9 +30,9 @@ public class ContinentalProtocol 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, 2, 2, -4, 0)); pipeline.addLast("objectDecoder", new ContinentalProtocolDecoder(ContinentalProtocol.this)); } diff --git a/src/org/traccar/protocol/ContinentalProtocolDecoder.java b/src/org/traccar/protocol/ContinentalProtocolDecoder.java index 5ea1d3246..20134fc1f 100644 --- a/src/org/traccar/protocol/ContinentalProtocolDecoder.java +++ b/src/org/traccar/protocol/ContinentalProtocolDecoder.java @@ -15,8 +15,8 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.Channel; +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; @@ -41,7 +41,7 @@ public class ContinentalProtocolDecoder 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.readUnsignedShort(); // length diff --git a/src/org/traccar/protocol/CradlepointProtocol.java b/src/org/traccar/protocol/CradlepointProtocol.java index 6ed54aa17..51de43bd9 100644 --- a/src/org/traccar/protocol/CradlepointProtocol.java +++ b/src/org/traccar/protocol/CradlepointProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,12 +15,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.LineBasedFrameDecoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -33,9 +32,9 @@ public class CradlepointProtocol extends BaseProtocol { @Override public void initTrackerServers(List<TrackerServer> serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/CradlepointProtocolDecoder.java b/src/org/traccar/protocol/CradlepointProtocolDecoder.java index 48bd67021..222f73ec3 100644 --- a/src/org/traccar/protocol/CradlepointProtocolDecoder.java +++ b/src/org/traccar/protocol/CradlepointProtocolDecoder.java @@ -15,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; diff --git a/test/org/traccar/protocol/BceProtocolDecoderTest.java b/test/org/traccar/protocol/BceProtocolDecoderTest.java index 53daf5ff3..e2a5aa213 100644 --- a/test/org/traccar/protocol/BceProtocolDecoderTest.java +++ b/test/org/traccar/protocol/BceProtocolDecoderTest.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 BceProtocolDecoderTest extends ProtocolTest { BceProtocolDecoder decoder = new BceProtocolDecoder(new BceProtocol()); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "789622d1cb1303003401a53365b70f4a9babc0ffd700c04400f0b6c741e63933428f1c431c015468de43f18221341b007e0ae20001430a698f003f008d000000000031f85900000000f0831c018400000000000000000000000000000000000209000000000000000000000000000000030065f70f4a9babc0ffd700c0440069bcc741e73733427f1c431a01a9378343f1829c391b00a80be2000170056da7003e007c000000000031c04e00000000f0831c01810000000000000000000000000000000000060100000000000000000000000000000003006537104a9babc0ffd700c0440051c1c74129363342721c421801e4809543f18210341b00710ae2000170056da7003e0072000000000031c04800000000b8841c017e00000000000000000000000000000000000306000000000000000000000000000000030069")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "be76619c834601004200a0003fd769c568ffc3db0079161d420683a9414918b1150000000000d102660167040000000000009f06357f0000a401042ea415e10232000000000000000000000051")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "be76619c834601004200a0003ff76cc568ffc3db00bd151d423c8ca9410a18af150000000000d1023a0160040000000000009f06427f0000a401042ea416e1003e00000000000000000000009a")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "be76619c834601004202a5863f57f8b868ffc3db0001712642b70b9d41221946200246d23342d1023e016404000000000000a0065a7f0000a4010496f277e3064300000000000000000000003f97f8b868ffc3db0074712642ae0a9d412919452102fff19042d102a4026304000000000000a006487f0000a4010496f277e3064300000000000000000000003fb7f8b868ffc3db00c6712642000a9d413019442002a6074542d102300165040000000000009f064f7f0000a4010496f277e3064300000000000000000000003fd7f8b868ffc3db002872264245099d413518421f02bea35e42d1021e0164040000000000009f06377f0000a4010496f277e3064300000000000000000000003fe7f8b868ffc3db0061722642e3089d413a28421f02a05ff641d102580163040000000000009f06577f0000a4010496f277e3064300000000000000000000003f17f9b868ffc3db0021732642a3079d414119411d02d69fcc42d102440165040000000000009f06437f0000a4010496f277e3064300000000000000000000003f37f9b868ffc3db00ae732642b4069d414628421b02e0629742d1024c0167040000000000009f06557f0000a4010496f277e3064300000000000000000000003f57f9b868ffc3db0044742642ae059d414c28421a027540a342d102860163040000000000009f065b7f0000a4010496f277e3064300000000000000000000003f97f9b868ffc3db007275264256039d4153284417029e1f2f43d1024a016704000000000000a0064e7f0000a4010496f277e306430000000000000000000000db")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "2d41abfa2e4501004e02a5a0068609f96a009106260af96a00a006260af96a009106960af96a00a306a60af96a008f06b60af96a009106960cf96a00a03e0715f96affc300804000e6a23a4230ccc441001f47850200000000a0000000bd6542651a110d004b1000000000a401045a56bf4d02480000000000000000061623f96a00a0062623f96a00913ea728f96affc300804000e6a23a4230ccc441001f7f850200000000a0000000bd6542651a110d004a1000000000a401045a56bf4d02480000000000000000069639f96a00a006a639f96a00913e373cf96affc300804000e6a23a4230ccc441001f7f850200000000a0000000ad6534651a110d004a1000000000a401045a56bf4d024800000000000000003ed74ff96affc300804000e6a23a4230ccc441001f7f850200000000a0000000ad6534651a111b004a1000000000a401045a56bf4d01480000000000000000061650f96a00a0062650f96a00913e6763f96affc300804000e6a23a4230ccc441001f7f850200000000a0000000ad6534651a110d004a1000000000a401045a56bf4d01480000000000000000069666f96a00a006a666f96a00913e0777f96affc300804000e6a23a4230ccc441001f7f850200000000a0000000ad6534651a110d004a1000000000a401045a56bf4d0148000000000000000006067df96a00a006167df96a0091063687f96a00a3064687f96a008f065687f96a0091063689f96a00a03e978af96affc300804000e6a23a4230ccc441001f87850200000000a0000000ad6527651a110d004a1000000000a401045a56bf4d024800000000000000000e")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "be76619c834601003302a5e8327764726bff432fc52a420e2c93410028afd2070000000080024a0005040000000000008e06547f0000a401043cf21f390e54328764726bff432fc52a420e2c93410028afd2070000000080024c0005040000000000008e064f7f0000a401043cf21f390e54329764726bff432fc52a420e2c93410028afd2070000000080024e0002040000000000008d064f7f0000a401043cf21f390e5432a764726bff432fc52a420e2c93410028afd2070000000080024e0004040000000000008e06587f0000a401043cf21f390e5432b764726bff432fc52a420e2c93410028afd207000000008002460005040000000000008e06557f0000a401043cf21f390e5432c764726bff432fc52a420e2c93410028afd2070000000080024e0004040000000000008e06347f0000a401043cf21f390e5432d764726bff432fc52a420e2c93410028afd2070000000080024e0002040000000000008e06547f0000a401043cf21f390e5432e764726bff432fc52a420e2c93410028afd207000000008002540002040000000000008e06477f0000a401043cf21f390e5432f764726bff432fc52a420e2c93410028afd207000000008002540004040000000000008d064f7f0000a401043cf21f390e54320765726bff432fc52a420e2c93410028afd207000000008002540004040000000000008e064d7f0000a401043cf21f390e54321765726bff432fc52a420e2c93410028afd207000000008002540004040000000000008e06467f0000a401043cf21f390e544200a0003f3743c96bffc3db0060c81c42d885ab41002aaf060000000000d102380167040000000000008a064f7f0000a4010412a46b330033000000000000000000000025")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "ca07629c834601002702a58f3c278ff96a0bc000a0c00140bc3a42508bc541002a70a905000000009000c101a40103d904440e003000000000000000000000000000000000000001013c878ff96a0bc000a0c00140bc3a42508bc541002970a905000000009000c301a40103d904440e003000000000000000000000000000000000000001013cb7d2f96a0bc000a0c00124bc3a426b8fc5410428000404000000009000c401a40103d904440e003500000000000000000000000000000000000001013cc7d2f96a0bc000a0c00124bc3a426b8fc5410428000404000000009000c301a40103d904440e003500000000000000000000000000000000000001013cd7f2f96a0bc000a0c00114bc3a42a48fc5410029027e03000000009000c301a40103d904440e003000000000000000000000000000000000000001013c670dfa6a0bc000a0c001f1bb3a42418dc541002a484904000000009000c001a40103d904440e003a00000000000000000000000000000000000001013c770dfa6a0bc000a0c001f1bb3a42418dc5410028484904000000009000bf01a40103d904440e003a00000000000000000000000000000000000001013c470efa6a0bc000a0c001f1bb3a42418dc5410029484904000000009000bf01a40103d904440e003a00000000000000000000000000000000000001013c5711fa6a0bc000a0c001f1bb3a42418dc5410029484904000000009000c101a40103d904440e003000000000000000000000000000000000000001013f00a0003cc795866b0bc000a0c00144bc3a423a90c541003697cb03000000008000cf01a40103d9040d0f0030000000000000000000000000000000000000010100")); } diff --git a/test/org/traccar/protocol/BlackKiteProtocolDecoderTest.java b/test/org/traccar/protocol/BlackKiteProtocolDecoderTest.java index 503f51f3a..0a4d44150 100644 --- a/test/org/traccar/protocol/BlackKiteProtocolDecoderTest.java +++ b/test/org/traccar/protocol/BlackKiteProtocolDecoderTest.java @@ -1,7 +1,5 @@ package org.traccar.protocol; -import java.nio.ByteOrder; - import org.junit.Test; import org.traccar.ProtocolTest; @@ -12,10 +10,10 @@ public class BlackKiteProtocolDecoderTest extends ProtocolTest { BlackKiteProtocolDecoder decoder = new BlackKiteProtocolDecoder(new BlackKiteProtocol()); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "01150003313131313131313131313131313131209836055605BA")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "0136000331313131313131313131313131313120523905563000010000000100000033000000003400004000004500004600005000005100009F76")); } diff --git a/test/org/traccar/protocol/CastelProtocolDecoderTest.java b/test/org/traccar/protocol/CastelProtocolDecoderTest.java index 2baee5494..826ac7d2e 100644 --- a/test/org/traccar/protocol/CastelProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CastelProtocolDecoderTest.java @@ -1,7 +1,5 @@ package org.traccar.protocol; -import java.nio.ByteOrder; - import org.junit.Test; import org.traccar.ProtocolTest; @@ -12,133 +10,133 @@ public class CastelProtocolDecoderTest extends ProtocolTest { CastelProtocolDecoder decoder = new CastelProtocolDecoder(new CastelProtocol()); - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "40403a00043231335750323031373030363135360000000000a00200000100000101201100344a474446364545374a4230373632363056ff0d0a")); - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "4040560004323133474c3230313630303033363400000000004002a122a05a5423a05abe0f2a000000000007f1f90014000000040001640011170003001e000505210b210c210d210f2101062b58ef02001a25950d0a")); - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "404057000431303031313132353239393837000000000000004002C1F06952F0F169529C9111000000000069830000470000000400036401014C01030078000505210C210D210F21102101073BE8030064280AEB930D0A")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "40405f000536303331353030303335313200000000000000004001040212102a2f72b29302a0af8512b40787018e000000000043e4ae000000007ca0f7224d5049503632305f56312e312e30004d5049502d3632302056322e300072140d0a")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "24245000363137313135313243333133360000000000000040011b011207133ac49a390464514a15000000008e480c00000917000000000000ffafffaf00010000ffff7800ffffffffffffff003c0d0a")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "40408200033231334c32303137303031313039000000000000100136477b5964477b590400000000000000dc410f000000000204000709207910008304011c07110e110dd41a160714a95a0f00001e058c4944442d3231334c2056312e312e3120323031372d30352d3038004944442d3231334c2056312e312e300000006da10d0a")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "40408200033231334c323031373030303131370000000000001001000c6759a10d67590a9e1200000000000e3e0000000000020000000e4e791c000004010d0711060515083017086cd1181f000040067d4944442d3231334c2056312e312e3120323031372d30352d3038004944442d3231334c2056312e312e3000000066e30d0a")); - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "404043000432313345503230313630303035383500000000004006a2021d5810031d58ae940400da050000f6040000070000000400076401680000000001001bd20d0a")); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "4040d0000432313345503230313630303035383500000000001001831c1c58b1fc1c58ae94040012220000f60400005800000000000763016800008484004944445f3231335730315f532056312e302e37004944445f3231335730315f482056312e302e370032000110021003100410051006100710081009100a100b100c100d100e1011100111021103110411051106110711011202120312041201130213031301160216011701180218011b011c011d011e011f021f031f041f051f061f071f0121022101260127012861780d0a")); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "404029000432313345503230313630303035383500000000009001ffffffff0000b4fc1c582b6e0d0a")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "40406000043231334550323031363030303538350000000000400708000000831c1c58f4fb1c58ae94040012220000f604000058000000200007630168000084c401040b10090c3532db3f07f07f7520090100000101010e00000000c7920d0a")); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "404042000432313345503230313630303035383500000000001002831c1c58b7fc1c58ae94040012220000f604000058000000000007630168000084840072a20d0a")); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "4040d0000432313345503230313630303035383500000000001001831c1c5805fe1c58ae94040012220000f60400005800000000000763016800008484004944445f3231335730315f532056312e302e37004944445f3231335730315f482056312e302e370032000110021003100410051006100710081009100a100b100c100d100e1011100111021103110411051106110711011202120312041201130213031301160216011701180218011b011c011d011e011f021f031f041f051f061f071f012102210126012701284eb10d0a")); - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "40405700043231334e583230313630303131373700000000004002c458ce572159ce57a9e2020082030000500c00000f0000000400036401240e0403023c000505210c210d210f21102101075b14030121330269430d0a")); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "40407800043231334e583230313630303131373700000000004004fa52ce574b53ce57cad1020041020000050c00000d0000000400036401240b0503001b042105210c210d210f211021112113211c211f212121232124212c212d213021312133213e2141214221452149214a214c214f215021384e0d0a")); - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "4040a600043231334e583230313630303131373700000000004005fa52ce575053ce57cad102006b020000050c00000d0000000400036401240b050300001b042105210c210d210f211021112113211c211f212121232124212c212d213021312133213e2141214221452149214a214c214f215021015bd604301f500600000653000000bc0bffff78250000ff2d98642401000f8080e038000f0f0000000000000077b10d0a")); - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "40404300043231334e583230313630303131373700000000004006fa52ce574e53ce57cad1020053020000050c00000d0000000400036401240b0503000000feec0d0a")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "40403600043231334e583230313630303033343600000000004009ad31a457050810061a35b29bf80ae6da83180300320bbe32580d0a40403600043231334e583230313630303033343600000000004009ad31a457050810061a35b29bf80ae6da83180300320bbe32580d0a")); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "4040d400043535333133350000000000000000000000000000100196d499574bd899570000000000000000010000000000000000000000002410000000004944445f3231334730325f532056322e332e345f4e004944445f3231334730325f482056322e332e345f4e0032000110021003100410051006100710081009100a100b100c100d100e1011100111021103110411051106110711011202120312041201130213031301160216011701180218011b011c011d011e011f021f031f041f051f061f071f012102210126012701285b410d0a")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "24243f00676e6768656636313031313132393030313734002001840d0000d2deb556020602100b35360456cf09e6ebac0200000000030000000001abc10d0a")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "24243f00676e6768656636313031313132393030313734002001840d000000dfb556020602100b36298256cf0956ebac020000990c7f0000000001b4830d0a")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "4040590004313030303030303030303800000000000000000040010072f53f56c25240560000000078b00900000000009c3100000000030100011900030001090b0f080106c04fe40b4037310c0060e001ff018d01e05e0d0a")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "40405900043231334e5832303135303030303336000000000040010073dd735600df7356b9220000270b000000000000000000000400000000240e03000201120c0f0a19050c1e5808ca35530dd902540d9c010000e5300d0a")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "404055000431303031313132353239393837000000000000001002C1F0695230086A529C911100000000000F890000A60500000000036301014CFF000001190A0D0539191480D60488C5721800000000BF8A640D0A")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "40406000043130303131313235323939383700000000000000400705000000C1F0695249F469529C9111000000000069830000D80040000400036401014C04030001190A0D04201E1480D60488C5721800000000AF0101060F000F00EA1E0D0A")); - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "404057000431303031313132353239393837000000000000004002C1F06952F0F169529C9111000000000069830000470000000400036401014C01030078000505210C210D210F21102101073BE8030064280AEB930D0A")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "40405900043130303131313235323939383700000000000000400101C1F06952E7F069529C9111000000000069830000070000000400036401014C00030001190A0D0412041480D60488C57218000000009F01E803ED9A0D0A")); - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "4040B9000431303031313132353239393837000000000000004005C1F069521BF169529C9111000000000069830000130000000400036401014C0003000022032104210521062107210C210D210E210F2110211121132115211C211F21212124212E212F2130213121322133213C214221432144214521472149214A214C214D214E210100643B6232E803003E64280A3C24FE00010E010F00D5805A483C640000000000010000E02E000000066400000500000000A7710D0A")); - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "404043000431303031313132353239393837000000000000004006C1F0695209F169529C91110000000000698300000D0000000400036401014C00030000009AF40D0A")); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "404086000431303031313132353239393837000000000000004004C1F0695200F169529C91110000000000698300000D0000000400036401014C00030022032104210521062107210C210D210E210F2110211121132115211C211F21212124212E212F2130213121322133213C214221432144214521472149214A214C214D214E219AE90D0A")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "40407F000431303031313132353239393837000000000000001001C1F06952FDF069529C91110000000000698300000C0000000000036401014C00030001190A0D04121A1480D60488C5721800000000AF4944445F3231364730325F532056312E322E31004944445F3231364730325F482056312E322E31000000DF640D0A")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "404044000c3631313135303030303935360000000000000000420600011e0a0f0b1312864fcd08c07a13030100640acf000004000a000000000000007ba083a66ad80d0a")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "40405c000c363131313530303030393536000000000000000040011c0a0f0e362dca53cd0860831303000000000300000000ff000000000000007ba083a650542d3639305f56312e312e320050542d3639302056312e32008a020d0a")); - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "4040450004323132474c31313433303035303033000000000040082ca89b55a6a99b555c57000000000000c40200000b0000001400036401111f000302f5533bd653f10d0a")); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "40404d0004323132474c3131343330303530303300000000004007120000002ca89b55cba99b555c57000000000000c40200000b0000000000036401111f000102000101170000000068850d0a")); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "4040420004323132474c31313433303035303033000000000010022ca89b55cca99b555c57000000000000cf0200000b0000000000036401111f0000020013be0d0a")); - verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyAttributes(decoder, binary( "4040870004323132474c31313433303035303033000000000040052ca89b55e3a89b555c57000000000000c4020000040000001400036401111f0003000012042105210b210c210d210f211021112113211c2121212321242133213421422146214f212b50663603003ce9030dff060000600dffffc25865ffff9e02b43624000000003cbc0d0a")); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "4040d00004323132474c31313433303035303033000000000010013ec09b5596c29b555c57000000000000de0200000f0000000000036401111f000000004944445f3231334730325f532056322e322e36004944445f3231334730325f482056322e322e360032000110021003100410051006100710081009100a100b100c100d100e1011100111021103110411051106110711011202120312041201130213031301160216011701180218011b011c011d011e011f021f031f041f051f061f071f012102210126012701288a690d0a")); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "40404d0004323132474c3131343330303530303300000000004007050000003ec09b5564c29b555c57000000000000de0200000f0000002000036401111f0000020001010e00000000237e0d0a")); - verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyNull(decoder, binary( "40401F00043130303131313235323939383700000000000000100303320D0A")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "40407F000431303031313132353239393837000000000000001001C1F06952FDF069529C91110000000000698300000C0000000000036401014C00030001190A0D04121A1480D60488C5721800000000AF4944445F3231364730325F532056312E322E31004944445F3231364730325F482056312E322E31000000DF640D0A")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "40405900043130303131313235323939383700000000000000400101C1F06952E7F069529C9111000000000069830000070000000400036401014C00030001190A0D0412041480D60488C57218000000009F01E803ED9A0D0A")); - verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPositions(decoder, binary( "40405900043335343034333035303834343134330000000000400100f61a7355c11b7355710000000b00000000000000000000000400000000240e0200020106060f100b2d5a78a7076ec0fb1d00008c065f010000ac220d0a")); } diff --git a/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java b/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java index cdda0fca7..17854c824 100644 --- a/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java @@ -1,7 +1,5 @@ package org.traccar.protocol; -import java.nio.ByteOrder; - import org.junit.Test; import org.traccar.ProtocolTest; @@ -12,19 +10,19 @@ public class CellocatorProtocolDecoderTest extends ProtocolTest { CellocatorProtocolDecoder decoder = new CellocatorProtocolDecoder(new CellocatorProtocol()); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "4D434750008AD01500080103011804000000460020000000005E750000000000000000000000C34300040204DA4DA30367195703E803000000000000000001030F0802E10778")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "4D434750008AD01500080102011804000000360060000000005E750000000000000000000000C24300040204DA4DA30367195703E80300000000000000003B020F0802E107DF")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "4D4347500006000000081A02021204000000210062300000006B00E100000000000000000000E5A100040206614EA303181A57034E1200000000000000001525071403D60749")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "4d434750000101000008011f041804000000200100000000005e750000000000000000000000548500040204da4da30367195703e80300000000000000002014151007dd07f7")); - verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN, + verifyPosition(decoder, binary( "4d434750005e930100080102041804000000200f20000000005e7500000000000000000000005af400040204da4da30367195703e8030000000000000000021a111e08dd0760")); } |