From 757cdb82c9109541ee5e7dc8d8ddca31c8507ca3 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 7 Jun 2018 15:38:00 +0500 Subject: Migrate U,V protocols --- src/org/traccar/protocol/UlbotechFrameDecoder.java | 19 +++++----- src/org/traccar/protocol/UlbotechProtocol.java | 9 +++-- .../traccar/protocol/UlbotechProtocolDecoder.java | 40 ++++++++++++---------- src/org/traccar/protocol/UproProtocol.java | 11 +++--- src/org/traccar/protocol/UproProtocolDecoder.java | 22 ++++++------ src/org/traccar/protocol/V680Protocol.java | 18 +++++----- src/org/traccar/protocol/V680ProtocolDecoder.java | 4 +-- src/org/traccar/protocol/VisiontekProtocol.java | 13 ++++--- .../traccar/protocol/VisiontekProtocolDecoder.java | 4 +-- src/org/traccar/protocol/Vt200FrameDecoder.java | 19 +++++----- src/org/traccar/protocol/Vt200Protocol.java | 9 +++-- src/org/traccar/protocol/Vt200ProtocolDecoder.java | 14 ++++---- src/org/traccar/protocol/VtfmsFrameDecoder.java | 15 ++++---- src/org/traccar/protocol/VtfmsProtocol.java | 17 +++++---- src/org/traccar/protocol/VtfmsProtocolDecoder.java | 4 +-- 15 files changed, 108 insertions(+), 110 deletions(-) diff --git a/src/org/traccar/protocol/UlbotechFrameDecoder.java b/src/org/traccar/protocol/UlbotechFrameDecoder.java index 8e7b497c5..e64791324 100644 --- a/src/org/traccar/protocol/UlbotechFrameDecoder.java +++ b/src/org/traccar/protocol/UlbotechFrameDecoder.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,19 +15,20 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.FrameDecoder; +import org.traccar.BaseFrameDecoder; -public class UlbotechFrameDecoder extends FrameDecoder { +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; + +public class UlbotechFrameDecoder extends BaseFrameDecoder { @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, - ChannelBuffer buf) throws Exception { + ByteBuf buf) throws Exception { if (buf.readableBytes() < 2) { return null; @@ -37,7 +38,7 @@ public class UlbotechFrameDecoder extends FrameDecoder { int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0xF8); if (index != -1) { - ChannelBuffer result = ChannelBuffers.buffer(index + 1 - buf.readerIndex()); + ByteBuf result = Unpooled.buffer(index + 1 - buf.readerIndex()); while (buf.readerIndex() <= index) { int b = buf.readUnsignedByte(); diff --git a/src/org/traccar/protocol/UlbotechProtocol.java b/src/org/traccar/protocol/UlbotechProtocol.java index 40f4594a5..7d6d95706 100644 --- a/src/org/traccar/protocol/UlbotechProtocol.java +++ b/src/org/traccar/protocol/UlbotechProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,8 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -30,9 +29,9 @@ public class UlbotechProtocol extends BaseProtocol { @Override public void initTrackerServers(List serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new UlbotechFrameDecoder()); pipeline.addLast("objectDecoder", new UlbotechProtocolDecoder(UlbotechProtocol.this)); } diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index 5499518a1..0c3ea6391 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.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.BitUtil; import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; @@ -58,18 +60,18 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { private static final short DATA_RFID = 0x0E; private static final short DATA_EVENT = 0x10; - private void decodeObd(Position position, ChannelBuffer buf, int length) { + private void decodeObd(Position position, ByteBuf buf, int length) { int end = buf.readerIndex() + length; while (buf.readerIndex() < end) { int parameterLength = buf.getUnsignedByte(buf.readerIndex()) >> 4; int mode = buf.readUnsignedByte() & 0x0F; - position.add(ObdDecoder.decode(mode, ChannelBuffers.hexDump(buf.readBytes(parameterLength - 1)))); + position.add(ObdDecoder.decode(mode, ByteBufUtil.hexDump(buf.readBytes(parameterLength - 1)))); } } - private void decodeJ1708(Position position, ChannelBuffer buf, int length) { + private void decodeJ1708(Position position, ByteBuf buf, int length) { int end = buf.readerIndex() + length; @@ -81,14 +83,14 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { if (type == 3) { id += 256; } - String value = ChannelBuffers.hexDump(buf.readBytes(len - 1)); + String value = ByteBufUtil.hexDump(buf.readBytes(len - 1)); if (type == 2 || type == 3) { position.set("pid" + id, value); } } } - private void decodeDriverBehavior(Position position, ChannelBuffer buf) { + private void decodeDriverBehavior(Position position, ByteBuf buf) { int value = buf.readUnsignedByte(); @@ -137,7 +139,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { return null; } - private void decodeAdc(Position position, ChannelBuffer buf, int length) { + private void decodeAdc(Position position, ByteBuf buf, int length) { for (int i = 0; i < length / 2; i++) { int value = buf.readUnsignedShort(); int id = BitUtil.from(value, 12); @@ -198,13 +200,13 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { return position; } - private Object decodeBinary(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { + private Object decodeBinary(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { buf.readUnsignedByte(); // header buf.readUnsignedByte(); // version buf.readUnsignedByte(); // type - String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1); + String imei = ByteBufUtil.hexDump(buf.readBytes(8)).substring(1); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { @@ -294,7 +296,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { break; case DATA_CANBUS: - position.set("can", ChannelBuffers.hexDump(buf.readBytes(length))); + position.set("can", ByteBufUtil.hexDump(buf.readBytes(length))); break; case DATA_J1708: @@ -337,28 +339,28 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; if (buf.getUnsignedByte(buf.readerIndex()) == 0xF8) { if (channel != null) { - ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + ByteBuf response = Unpooled.buffer(); response.writeByte(0xF8); response.writeByte(DATA_GPS); response.writeByte(0xFE); response.writeShort(buf.getShort(response.writerIndex() - 1 - 2)); - response.writeShort(Checksum.crc16(Checksum.CRC16_XMODEM, response.toByteBuffer(1, 4))); + response.writeShort(Checksum.crc16(Checksum.CRC16_XMODEM, response.nioBuffer(1, 4))); response.writeByte(0xF8); - channel.write(response); + channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } return decodeBinary(channel, remoteAddress, buf); } else { if (channel != null) { - channel.write(ChannelBuffers.copiedBuffer(String.format("*TS01,ACK:%04X#", - Checksum.crc16(Checksum.CRC16_XMODEM, buf.toByteBuffer(1, buf.writerIndex() - 2))), - StandardCharsets.US_ASCII)); + channel.writeAndFlush(new NetworkMessage(Unpooled.copiedBuffer(String.format("*TS01,ACK:%04X#", + Checksum.crc16(Checksum.CRC16_XMODEM, buf.nioBuffer(1, buf.writerIndex() - 2))), + StandardCharsets.US_ASCII), remoteAddress)); } return decodeText(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII)); diff --git a/src/org/traccar/protocol/UproProtocol.java b/src/org/traccar/protocol/UproProtocol.java index c00f859ee..832121ec1 100644 --- a/src/org/traccar/protocol/UproProtocol.java +++ b/src/org/traccar/protocol/UproProtocol.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,10 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -32,9 +31,9 @@ public class UproProtocol extends BaseProtocol { @Override public void initTrackerServers(List serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#')); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("objectDecoder", new UproProtocolDecoder(UproProtocol.this)); diff --git a/src/org/traccar/protocol/UproProtocolDecoder.java b/src/org/traccar/protocol/UproProtocolDecoder.java index 28f3d0249..9bbf6eb93 100644 --- a/src/org/traccar/protocol/UproProtocolDecoder.java +++ b/src/org/traccar/protocol/UproProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -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.BitUtil; @@ -92,7 +92,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; if (buf.getByte(buf.readerIndex()) != '*') { throw new ParseException(null, 0); @@ -126,7 +126,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { channel.write("*MG20Y" + type + subtype + "#"); } - while (buf.readable()) { + while (buf.isReadable()) { buf.readByte(); // skip delimiter @@ -137,7 +137,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { delimiterIndex = buf.writerIndex(); } - ChannelBuffer data = buf.readBytes(delimiterIndex - buf.readerIndex()); + ByteBuf data = buf.readBytes(delimiterIndex - buf.readerIndex()); switch (dataType) { case 'A': @@ -148,7 +148,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { break; case 'C': long odometer = 0; - while (data.readable()) { + while (data.isReadable()) { odometer <<= 4; odometer += data.readByte() - (byte) '0'; } @@ -162,13 +162,13 @@ public class UproProtocolDecoder extends BaseProtocolDecoder { Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII), 16)))); break; case 'Q': - position.set("obd-pid", ChannelBuffers.hexDump(data)); + position.set("obd-pid", ByteBufUtil.hexDump(data)); break; case 'R': - position.set("odb-travel", ChannelBuffers.hexDump(data)); + position.set("odb-travel", ByteBufUtil.hexDump(data)); break; case 'S': - position.set("obd-traffic", ChannelBuffers.hexDump(data)); + position.set("obd-traffic", ByteBufUtil.hexDump(data)); break; default: break; diff --git a/src/org/traccar/protocol/V680Protocol.java b/src/org/traccar/protocol/V680Protocol.java index 98c64830b..eb9111578 100644 --- a/src/org/traccar/protocol/V680Protocol.java +++ b/src/org/traccar/protocol/V680Protocol.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,13 +15,11 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ConnectionlessBootstrap; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; import org.traccar.CharacterDelimiterFrameDecoder; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -34,18 +32,18 @@ public class V680Protocol extends BaseProtocol { @Override public void initTrackerServers(List serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "##")); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("objectDecoder", new V680ProtocolDecoder(V680Protocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { + serverList.add(new TrackerServer(true, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("objectDecoder", new V680ProtocolDecoder(V680Protocol.this)); diff --git a/src/org/traccar/protocol/V680ProtocolDecoder.java b/src/org/traccar/protocol/V680ProtocolDecoder.java index caa06a863..05095e8ba 100644 --- a/src/org/traccar/protocol/V680ProtocolDecoder.java +++ b/src/org/traccar/protocol/V680ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -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/VisiontekProtocol.java b/src/org/traccar/protocol/VisiontekProtocol.java index c6dd09562..897c7e6f7 100644 --- a/src/org/traccar/protocol/VisiontekProtocol.java +++ b/src/org/traccar/protocol/VisiontekProtocol.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 VisiontekProtocol extends BaseProtocol { @Override public void initTrackerServers(List serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#')); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("stringEncoder", new StringEncoder()); diff --git a/src/org/traccar/protocol/VisiontekProtocolDecoder.java b/src/org/traccar/protocol/VisiontekProtocolDecoder.java index 33c555c6b..57ccb5100 100644 --- a/src/org/traccar/protocol/VisiontekProtocolDecoder.java +++ b/src/org/traccar/protocol/VisiontekProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 - 2016 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,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/Vt200FrameDecoder.java b/src/org/traccar/protocol/Vt200FrameDecoder.java index adde12118..0fd83e715 100644 --- a/src/org/traccar/protocol/Vt200FrameDecoder.java +++ b/src/org/traccar/protocol/Vt200FrameDecoder.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,22 +15,23 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.FrameDecoder; +import org.traccar.BaseFrameDecoder; -public class Vt200FrameDecoder extends FrameDecoder { +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; + +public class Vt200FrameDecoder extends BaseFrameDecoder { @Override protected Object decode( - ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')') + 1; if (endIndex > 0) { - ChannelBuffer frame = ChannelBuffers.dynamicBuffer(); + ByteBuf frame = Unpooled.buffer(); while (buf.readerIndex() < endIndex) { int b = buf.readByte(); diff --git a/src/org/traccar/protocol/Vt200Protocol.java b/src/org/traccar/protocol/Vt200Protocol.java index 59c61cb61..b227020c2 100644 --- a/src/org/traccar/protocol/Vt200Protocol.java +++ b/src/org/traccar/protocol/Vt200Protocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,8 @@ */ package org.traccar.protocol; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipeline; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; import java.util.List; @@ -30,9 +29,9 @@ public class Vt200Protocol extends BaseProtocol { @Override public void initTrackerServers(List serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new Vt200FrameDecoder()); pipeline.addLast("objectDecoder", new Vt200ProtocolDecoder(Vt200Protocol.this)); } diff --git a/src/org/traccar/protocol/Vt200ProtocolDecoder.java b/src/org/traccar/protocol/Vt200ProtocolDecoder.java index d08107b16..d0ee32c5d 100644 --- a/src/org/traccar/protocol/Vt200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Vt200ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,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.BcdUtil; @@ -42,7 +42,7 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { return degrees + minutes * 0.0001 / 60; } - protected Date decodeDate(ChannelBuffer buf) { + protected Date decodeDate(ByteBuf buf) { DateBuilder dateBuilder = new DateBuilder() .setDateReverse(BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2)) .setTime(BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2)); @@ -53,11 +53,11 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - ChannelBuffer buf = (ChannelBuffer) msg; + ByteBuf buf = (ByteBuf) msg; buf.skipBytes(1); // header - String id = ChannelBuffers.hexDump(buf.readBytes(6)); + String id = ByteBufUtil.hexDump(buf.readBytes(6)); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); if (deviceSession == null) { return null; diff --git a/src/org/traccar/protocol/VtfmsFrameDecoder.java b/src/org/traccar/protocol/VtfmsFrameDecoder.java index 2e6033fcc..98072711f 100644 --- a/src/org/traccar/protocol/VtfmsFrameDecoder.java +++ b/src/org/traccar/protocol/VtfmsFrameDecoder.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,16 +15,17 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.FrameDecoder; +import org.traccar.BaseFrameDecoder; -public class VtfmsFrameDecoder extends FrameDecoder { +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; + +public class VtfmsFrameDecoder extends BaseFrameDecoder { @Override protected Object decode( - ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')'); if (endIndex > 0) { diff --git a/src/org/traccar/protocol/VtfmsProtocol.java b/src/org/traccar/protocol/VtfmsProtocol.java index 61e0bf2b9..dee72aaa8 100644 --- a/src/org/traccar/protocol/VtfmsProtocol.java +++ b/src/org/traccar/protocol/VtfmsProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,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.string.StringDecoder; import org.traccar.BaseProtocol; +import org.traccar.PipelineBuilder; import org.traccar.TrackerServer; +import io.netty.handler.codec.string.StringDecoder; + import java.util.List; public class VtfmsProtocol extends BaseProtocol { @@ -32,17 +31,17 @@ public class VtfmsProtocol extends BaseProtocol { @Override public void initTrackerServers(List serverList) { - serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { + serverList.add(new TrackerServer(false, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("frameDecoder", new VtfmsFrameDecoder()); pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("objectDecoder", new VtfmsProtocolDecoder(VtfmsProtocol.this)); } }); - serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { + serverList.add(new TrackerServer(true, getName()) { @Override - protected void addSpecificHandlers(ChannelPipeline pipeline) { + protected void addProtocolHandlers(PipelineBuilder pipeline) { pipeline.addLast("stringDecoder", new StringDecoder()); pipeline.addLast("objectDecoder", new VtfmsProtocolDecoder(VtfmsProtocol.this)); } diff --git a/src/org/traccar/protocol/VtfmsProtocolDecoder.java b/src/org/traccar/protocol/VtfmsProtocolDecoder.java index 736a27a64..5e5e5c9b5 100644 --- a/src/org/traccar/protocol/VtfmsProtocolDecoder.java +++ b/src/org/traccar/protocol/VtfmsProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ package org.traccar.protocol; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.helper.Parser; -- cgit v1.2.3