aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2018-06-08 17:04:44 +0500
committerAbyss777 <abyss@fox5.ru>2018-06-08 17:04:44 +0500
commitc176b7b4bf4eef6f71767f92ada2591ef27c1cfa (patch)
treefd7ef0e30a4644760154ffc14101749311040d85
parentecb7bb33fcec52491f917dbc65a82990dcddb808 (diff)
downloadtrackermap-server-c176b7b4bf4eef6f71767f92ada2591ef27c1cfa.tar.gz
trackermap-server-c176b7b4bf4eef6f71767f92ada2591ef27c1cfa.tar.bz2
trackermap-server-c176b7b4bf4eef6f71767f92ada2591ef27c1cfa.zip
Migrate part of T protocols
-rw-r--r--src/org/traccar/protocol/TelicFrameDecoder.java21
-rw-r--r--src/org/traccar/protocol/TelicProtocol.java18
-rw-r--r--src/org/traccar/protocol/TelicProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/Tlt2hProtocol.java13
-rw-r--r--src/org/traccar/protocol/Tlt2hProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/TlvProtocol.java9
-rw-r--r--src/org/traccar/protocol/TlvProtocolDecoder.java29
-rw-r--r--src/org/traccar/protocol/TmgFrameDecoder.java45
-rw-r--r--src/org/traccar/protocol/TmgProtocol.java13
-rw-r--r--src/org/traccar/protocol/TmgProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/TopflytechProtocol.java13
-rw-r--r--src/org/traccar/protocol/TopflytechProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/TotemFrameDecoder.java19
-rw-r--r--src/org/traccar/protocol/TotemProtocol.java13
-rw-r--r--src/org/traccar/protocol/TotemProtocolDecoder.java7
-rw-r--r--src/org/traccar/protocol/Tr20Protocol.java15
-rw-r--r--src/org/traccar/protocol/Tr20ProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/Tr900Protocol.java20
-rw-r--r--src/org/traccar/protocol/Tr900ProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/TrackboxProtocol.java15
-rw-r--r--src/org/traccar/protocol/TrackboxProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/TrakMateProtocol.java13
-rw-r--r--src/org/traccar/protocol/TrakMateProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/TrvProtocol.java13
-rw-r--r--src/org/traccar/protocol/TrvProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/Tt8850Protocol.java13
-rw-r--r--src/org/traccar/protocol/Tt8850ProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/TytanProtocol.java9
-rw-r--r--src/org/traccar/protocol/TytanProtocolDecoder.java22
-rw-r--r--src/org/traccar/protocol/TzoneProtocol.java12
-rw-r--r--src/org/traccar/protocol/TzoneProtocolDecoder.java18
-rw-r--r--test/org/traccar/protocol/TelicFrameDecoderTest.java28
32 files changed, 213 insertions, 221 deletions
diff --git a/src/org/traccar/protocol/TelicFrameDecoder.java b/src/org/traccar/protocol/TelicFrameDecoder.java
index 245be28fb..b99ef98bf 100644
--- a/src/org/traccar/protocol/TelicFrameDecoder.java
+++ b/src/org/traccar/protocol/TelicFrameDecoder.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,32 +15,33 @@
*/
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 TelicFrameDecoder extends FrameDecoder {
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+
+public class TelicFrameDecoder extends BaseFrameDecoder {
@Override
protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
+ ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
if (buf.readableBytes() < 4) {
return null;
}
- long length = buf.getUnsignedInt(buf.readerIndex());
+ long length = buf.getUnsignedIntLE(buf.readerIndex());
if (length < 1024) {
if (buf.readableBytes() >= length + 4) {
- buf.readUnsignedInt();
+ buf.readUnsignedIntLE();
return buf.readBytes((int) length);
}
} else {
int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0);
if (endIndex >= 0) {
- ChannelBuffer frame = buf.readBytes(endIndex - buf.readerIndex());
+ ByteBuf frame = buf.readBytes(endIndex - buf.readerIndex());
buf.readByte();
if (frame.readableBytes() > 0) {
return frame;
diff --git a/src/org/traccar/protocol/TelicProtocol.java b/src/org/traccar/protocol/TelicProtocol.java
index fdd0b94c6..0ee4cf165 100644
--- a/src/org/traccar/protocol/TelicProtocol.java
+++ b/src/org/traccar/protocol/TelicProtocol.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,14 +15,12 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
-import java.nio.ByteOrder;
import java.util.List;
public class TelicProtocol extends BaseProtocol {
@@ -33,17 +31,15 @@ public class TelicProtocol 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 TelicFrameDecoder());
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("objectDecoder", new TelicProtocolDecoder(TelicProtocol.this));
}
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
+ });
}
}
diff --git a/src/org/traccar/protocol/TelicProtocolDecoder.java b/src/org/traccar/protocol/TelicProtocolDecoder.java
index 197db059b..3a9962361 100644
--- a/src/org/traccar/protocol/TelicProtocolDecoder.java
+++ b/src/org/traccar/protocol/TelicProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2014 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,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/Tlt2hProtocol.java b/src/org/traccar/protocol/Tlt2hProtocol.java
index 752b0d8ef..1a23dee40 100644
--- a/src/org/traccar/protocol/Tlt2hProtocol.java
+++ b/src/org/traccar/protocol/Tlt2hProtocol.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 Tlt2hProtocol 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(32 * 1024, "##\r\n"));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
index a5a195afa..780785247 100644
--- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.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,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/TlvProtocol.java b/src/org/traccar/protocol/TlvProtocol.java
index da8d88b8a..ddc8d2a6e 100644
--- a/src/org/traccar/protocol/TlvProtocol.java
+++ b/src/org/traccar/protocol/TlvProtocol.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,10 +15,9 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
import org.traccar.BaseProtocol;
import org.traccar.CharacterDelimiterFrameDecoder;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -31,9 +30,9 @@ public class TlvProtocol 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('\0'));
pipeline.addLast("objectDecoder", new TlvProtocolDecoder(TlvProtocol.this));
}
diff --git a/src/org/traccar/protocol/TlvProtocolDecoder.java b/src/org/traccar/protocol/TlvProtocolDecoder.java
index 0cf68acb8..ae1a3346a 100644
--- a/src/org/traccar/protocol/TlvProtocolDecoder.java
+++ b/src/org/traccar/protocol/TlvProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,11 +15,12 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
@@ -33,20 +34,20 @@ public class TlvProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private void sendResponse(Channel channel, String type, String... arguments) {
+ private void sendResponse(Channel channel, SocketAddress remoteAddress, String type, String... arguments) {
if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeBytes(ChannelBuffers.copiedBuffer(type, StandardCharsets.US_ASCII));
+ ByteBuf response = Unpooled.buffer();
+ response.writeBytes(Unpooled.copiedBuffer(type, StandardCharsets.US_ASCII));
for (String argument : arguments) {
response.writeByte(argument.length());
- response.writeBytes(ChannelBuffers.copiedBuffer(argument, StandardCharsets.US_ASCII));
+ response.writeBytes(Unpooled.copiedBuffer(argument, StandardCharsets.US_ASCII));
}
response.writeByte(0);
- channel.write(response);
+ channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
}
- private String readArgument(ChannelBuffer buf) {
+ private String readArgument(ByteBuf buf) {
return buf.readBytes(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII);
}
@@ -54,7 +55,7 @@ public class TlvProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
String type = buf.readBytes(2).toString(StandardCharsets.US_ASCII);
@@ -62,14 +63,14 @@ public class TlvProtocolDecoder extends BaseProtocolDecoder {
switch (type) {
case "0A":
case "0C":
- sendResponse(channel, type);
+ sendResponse(channel, remoteAddress, type);
break;
case "0B":
- sendResponse(channel, type, "1482202689", "10", "20", "15");
+ sendResponse(channel, remoteAddress, type, "1482202689", "10", "20", "15");
break;
case "0E":
case "0F":
- sendResponse(channel, type, "30", "Unknown");
+ sendResponse(channel, remoteAddress, type, "30", "Unknown");
break;
default:
break;
diff --git a/src/org/traccar/protocol/TmgFrameDecoder.java b/src/org/traccar/protocol/TmgFrameDecoder.java
index c39cf03ac..a2039ff52 100644
--- a/src/org/traccar/protocol/TmgFrameDecoder.java
+++ b/src/org/traccar/protocol/TmgFrameDecoder.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,37 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBufferIndexFinder;
-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 TmgFrameDecoder extends FrameDecoder {
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+
+public class TmgFrameDecoder extends BaseFrameDecoder {
private boolean isLetter(byte c) {
return c >= 'a' && c <= 'z';
}
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- int beginIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new ChannelBufferIndexFinder() {
- @Override
- public boolean find(ChannelBuffer buffer, int guessedIndex) {
- if (buffer.getByte(guessedIndex) != (byte) '$' || buffer.writerIndex() - guessedIndex < 5) {
- return false;
- }
- return buffer.getByte(guessedIndex + 4) == ','
+ private int findHeader(ByteBuf buffer) {
+ int guessedIndex = buffer.indexOf(buffer.readerIndex(), buffer.writerIndex(), (byte) '$');
+ while (guessedIndex != -1 && buffer.writerIndex() - guessedIndex >= 5) {
+ if (buffer.getByte(guessedIndex + 4) == ','
&& isLetter(buffer.getByte(guessedIndex + 1))
&& isLetter(buffer.getByte(guessedIndex + 2))
- && isLetter(buffer.getByte(guessedIndex + 3));
+ && isLetter(buffer.getByte(guessedIndex + 3))) {
+ return guessedIndex;
}
- });
+ guessedIndex = buffer.indexOf(guessedIndex, buffer.writerIndex(), (byte) '$');
+ }
+ return -1;
+ }
+
+ @Override
+ protected Object decode(
+ ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
+
+ int beginIndex = findHeader(buf);
if (beginIndex >= 0) {
@@ -51,7 +54,7 @@ public class TmgFrameDecoder extends FrameDecoder {
int endIndex = buf.indexOf(beginIndex, buf.writerIndex(), (byte) '\n');
if (endIndex >= 0) {
- ChannelBuffer frame = buf.readBytes(endIndex - beginIndex);
+ ByteBuf frame = buf.readBytes(endIndex - beginIndex);
buf.readByte(); // delimiter
return frame;
}
diff --git a/src/org/traccar/protocol/TmgProtocol.java b/src/org/traccar/protocol/TmgProtocol.java
index c11762cac..192891100 100644
--- a/src/org/traccar/protocol/TmgProtocol.java
+++ b/src/org/traccar/protocol/TmgProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,11 +15,10 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -32,9 +31,9 @@ public class TmgProtocol 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 TmgFrameDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("stringDecoder", new StringDecoder());
diff --git a/src/org/traccar/protocol/TmgProtocolDecoder.java b/src/org/traccar/protocol/TmgProtocolDecoder.java
index cb10eedd7..7ac443d5c 100644
--- a/src/org/traccar/protocol/TmgProtocolDecoder.java
+++ b/src/org/traccar/protocol/TmgProtocolDecoder.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.BitUtil;
diff --git a/src/org/traccar/protocol/TopflytechProtocol.java b/src/org/traccar/protocol/TopflytechProtocol.java
index 7d4b13ee6..03eb4b3ea 100644
--- a/src/org/traccar/protocol/TopflytechProtocol.java
+++ b/src/org/traccar/protocol/TopflytechProtocol.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 TopflytechProtocol 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/TopflytechProtocolDecoder.java b/src/org/traccar/protocol/TopflytechProtocolDecoder.java
index b3a8fa845..4ce161b1c 100644
--- a/src/org/traccar/protocol/TopflytechProtocolDecoder.java
+++ b/src/org/traccar/protocol/TopflytechProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.Parser;
diff --git a/src/org/traccar/protocol/TotemFrameDecoder.java b/src/org/traccar/protocol/TotemFrameDecoder.java
index 70dc5db3b..a7e134c09 100644
--- a/src/org/traccar/protocol/TotemFrameDecoder.java
+++ b/src/org/traccar/protocol/TotemFrameDecoder.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,25 +15,26 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-import org.traccar.helper.StringFinder;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
import java.nio.charset.StandardCharsets;
-public class TotemFrameDecoder extends FrameDecoder {
+import org.traccar.BaseFrameDecoder;
+import org.traccar.helper.BufferUtil;
+
+public class TotemFrameDecoder extends BaseFrameDecoder {
@Override
protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
+ ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
if (buf.readableBytes() < 10) {
return null;
}
- int beginIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("$$"));
+ int beginIndex = BufferUtil.indexOf("$$", buf);
if (beginIndex == -1) {
return null;
} else if (beginIndex > buf.readerIndex()) {
diff --git a/src/org/traccar/protocol/TotemProtocol.java b/src/org/traccar/protocol/TotemProtocol.java
index 1c5cf5b02..c533268cc 100644
--- a/src/org/traccar/protocol/TotemProtocol.java
+++ b/src/org/traccar/protocol/TotemProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,11 +15,10 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.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.PipelineBuilder;
import org.traccar.TrackerServer;
import org.traccar.model.Command;
@@ -37,9 +36,9 @@ public class TotemProtocol 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 TotemFrameDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("stringDecoder", new StringDecoder());
diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java
index c200129d2..c1ee8bf20 100644
--- a/src/org/traccar/protocol/TotemProtocolDecoder.java
+++ b/src/org/traccar/protocol/TotemProtocolDecoder.java
@@ -15,9 +15,10 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.BitUtil;
import org.traccar.helper.Checksum;
import org.traccar.helper.DateBuilder;
@@ -411,9 +412,9 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
if (pattern == PATTERN4) {
String response = "$$0014AA" + sentence.substring(sentence.length() - 6, sentence.length() - 2);
response += String.format("%02X", Checksum.xor(response)).toUpperCase();
- channel.write(response);
+ channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
} else {
- channel.write("ACK OK\r\n");
+ channel.writeAndFlush(new NetworkMessage("ACK OK\r\n", remoteAddress));
}
}
diff --git a/src/org/traccar/protocol/Tr20Protocol.java b/src/org/traccar/protocol/Tr20Protocol.java
index 8de004be9..629d8b961 100644
--- a/src/org/traccar/protocol/Tr20Protocol.java
+++ b/src/org/traccar/protocol/Tr20Protocol.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.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 Tr20Protocol 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/Tr20ProtocolDecoder.java b/src/org/traccar/protocol/Tr20ProtocolDecoder.java
index 579d575b0..1e3f8e8b2 100644
--- a/src/org/traccar/protocol/Tr20ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tr20ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,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/Tr900Protocol.java b/src/org/traccar/protocol/Tr900Protocol.java
index 40f287efa..80ad76087 100644
--- a/src/org/traccar/protocol/Tr900Protocol.java
+++ b/src/org/traccar/protocol/Tr900Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,13 +15,11 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.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;
@@ -34,18 +32,18 @@ public class Tr900Protocol 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());
pipeline.addLast("objectDecoder", new Tr900ProtocolDecoder(Tr900Protocol.this));
}
});
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
+ serverList.add(new TrackerServer(true, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("objectDecoder", new Tr900ProtocolDecoder(Tr900Protocol.this));
diff --git a/src/org/traccar/protocol/Tr900ProtocolDecoder.java b/src/org/traccar/protocol/Tr900ProtocolDecoder.java
index 0ce4158e4..8200884ac 100644
--- a/src/org/traccar/protocol/Tr900ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tr900ProtocolDecoder.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,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/TrackboxProtocol.java b/src/org/traccar/protocol/TrackboxProtocol.java
index c1aa5ac6a..c86870aec 100644
--- a/src/org/traccar/protocol/TrackboxProtocol.java
+++ b/src/org/traccar/protocol/TrackboxProtocol.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.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 TrackboxProtocol 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/TrackboxProtocolDecoder.java b/src/org/traccar/protocol/TrackboxProtocolDecoder.java
index 2c113fb76..fff60ae70 100644
--- a/src/org/traccar/protocol/TrackboxProtocolDecoder.java
+++ b/src/org/traccar/protocol/TrackboxProtocolDecoder.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.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
@@ -46,9 +47,9 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder {
.number("(d+)") // satellites
.compile();
- private void sendResponse(Channel channel) {
+ private void sendResponse(Channel channel, SocketAddress remoteAddress) {
if (channel != null) {
- channel.write("=OK=\r\n");
+ channel.writeAndFlush(new NetworkMessage("=OK=\r\n", remoteAddress));
}
}
@@ -61,7 +62,7 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder {
if (sentence.startsWith("a=connect")) {
String id = sentence.substring(sentence.indexOf("i=") + 2);
if (getDeviceSession(channel, remoteAddress, id) != null) {
- sendResponse(channel);
+ sendResponse(channel, remoteAddress);
}
return null;
}
@@ -75,7 +76,7 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder {
if (!parser.matches()) {
return null;
}
- sendResponse(channel);
+ sendResponse(channel, remoteAddress);
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
diff --git a/src/org/traccar/protocol/TrakMateProtocol.java b/src/org/traccar/protocol/TrakMateProtocol.java
index f6d9bf457..506408d65 100644
--- a/src/org/traccar/protocol/TrakMateProtocol.java
+++ b/src/org/traccar/protocol/TrakMateProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,11 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.CharacterDelimiterFrameDecoder;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -33,9 +32,9 @@ public class TrakMateProtocol 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/TrakMateProtocolDecoder.java b/src/org/traccar/protocol/TrakMateProtocolDecoder.java
index 293c13fad..9fd7af542 100644
--- a/src/org/traccar/protocol/TrakMateProtocolDecoder.java
+++ b/src/org/traccar/protocol/TrakMateProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2017 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/TrvProtocol.java b/src/org/traccar/protocol/TrvProtocol.java
index 348ccd92a..7167ab674 100644
--- a/src/org/traccar/protocol/TrvProtocol.java
+++ b/src/org/traccar/protocol/TrvProtocol.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 TrvProtocol 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/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java
index e0cebc9a5..9c4968974 100644
--- a/src/org/traccar/protocol/TrvProtocolDecoder.java
+++ b/src/org/traccar/protocol/TrvProtocolDecoder.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,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.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
@@ -119,11 +120,11 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
String responseHeader = id + (char) (type.charAt(0) + 1) + type.substring(1);
if (type.equals("AP00") && id.equals("IW")) {
String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
- channel.write(responseHeader + "," + time + ",0#");
+ channel.writeAndFlush(new NetworkMessage(responseHeader + "," + time + ",0#", remoteAddress));
} else if (type.equals("AP14")) {
- channel.write(responseHeader + ",0.000,0.000#");
+ channel.writeAndFlush(new NetworkMessage(responseHeader + ",0.000,0.000#", remoteAddress));
} else {
- channel.write(responseHeader + "#");
+ channel.writeAndFlush(new NetworkMessage(responseHeader + "#", remoteAddress));
}
}
diff --git a/src/org/traccar/protocol/Tt8850Protocol.java b/src/org/traccar/protocol/Tt8850Protocol.java
index 79dc031bc..7d3c6a437 100644
--- a/src/org/traccar/protocol/Tt8850Protocol.java
+++ b/src/org/traccar/protocol/Tt8850Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,11 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.CharacterDelimiterFrameDecoder;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -33,9 +32,9 @@ public class Tt8850Protocol 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/Tt8850ProtocolDecoder.java b/src/org/traccar/protocol/Tt8850ProtocolDecoder.java
index 0134f4764..46220e143 100644
--- a/src/org/traccar/protocol/Tt8850ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tt8850ProtocolDecoder.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/TytanProtocol.java b/src/org/traccar/protocol/TytanProtocol.java
index 0c27fb12b..7c424981b 100644
--- a/src/org/traccar/protocol/TytanProtocol.java
+++ b/src/org/traccar/protocol/TytanProtocol.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 TytanProtocol 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 TytanProtocolDecoder(TytanProtocol.this));
}
});
diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java
index a65ad4cfc..221df6081 100644
--- a/src/org/traccar/protocol/TytanProtocolDecoder.java
+++ b/src/org/traccar/protocol/TytanProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,11 +15,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;
@@ -36,7 +38,7 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private void decodeExtraData(Position position, ChannelBuffer buf, int end) {
+ private void decodeExtraData(Position position, ByteBuf buf, int end) {
while (buf.readerIndex() < end) {
int type = buf.readUnsignedByte();
@@ -73,10 +75,10 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
position.set("antihijack", buf.readUnsignedByte());
break;
case 9:
- position.set("unauthorized", ChannelBuffers.hexDump(buf.readBytes(8)));
+ position.set("unauthorized", ByteBufUtil.hexDump(buf.readBytes(8)));
break;
case 10:
- position.set("authorized", ChannelBuffers.hexDump(buf.readBytes(8)));
+ position.set("authorized", ByteBufUtil.hexDump(buf.readBytes(8)));
break;
case 24:
for (int i = 0; i < length / 2; i++) {
@@ -124,16 +126,16 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedByte(); // protocol
buf.readUnsignedShort(); // length
int index = buf.readUnsignedByte() >> 3;
if (channel != null) {
- ChannelBuffer response = ChannelBuffers.copiedBuffer(
+ ByteBuf response = Unpooled.copiedBuffer(
"^" + index, StandardCharsets.US_ASCII);
- channel.write(response, remoteAddress);
+ channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
String id = String.valueOf(buf.readUnsignedInt());
diff --git a/src/org/traccar/protocol/TzoneProtocol.java b/src/org/traccar/protocol/TzoneProtocol.java
index 38d5b139a..21a304402 100644
--- a/src/org/traccar/protocol/TzoneProtocol.java
+++ b/src/org/traccar/protocol/TzoneProtocol.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,12 @@
*/
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 org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
+import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
+
import java.util.List;
public class TzoneProtocol extends BaseProtocol {
@@ -31,9 +31,9 @@ public class TzoneProtocol 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(256, 2, 2, 2, 0));
pipeline.addLast("objectDecoder", new TzoneProtocolDecoder(TzoneProtocol.this));
}
diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java
index 984891bb6..4983410a5 100644
--- a/src/org/traccar/protocol/TzoneProtocolDecoder.java
+++ b/src/org/traccar/protocol/TzoneProtocolDecoder.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,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;
@@ -57,7 +57,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
}
}
- private void decodeCards(Position position, ChannelBuffer buf) {
+ private void decodeCards(Position position, ByteBuf buf) {
int index = 1;
for (int i = 0; i < 4; i++) {
@@ -77,7 +77,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
length += 1;
}
- String num = ChannelBuffers.hexDump(buf.readBytes(length / 2));
+ String num = ByteBufUtil.hexDump(buf.readBytes(length / 2));
if (odd) {
num = num.substring(1);
@@ -92,7 +92,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
}
- private void decodePassengers(Position position, ChannelBuffer buf) {
+ private void decodePassengers(Position position, ByteBuf buf) {
int blockLength = buf.readUnsignedShort();
int blockEnd = buf.readerIndex() + blockLength;
@@ -112,7 +112,7 @@ public class TzoneProtocolDecoder 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
@@ -122,7 +122,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
int hardware = buf.readUnsignedShort();
long firmware = buf.readUnsignedInt();
- 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) {
return null;
diff --git a/test/org/traccar/protocol/TelicFrameDecoderTest.java b/test/org/traccar/protocol/TelicFrameDecoderTest.java
index dd0efacb6..5fcbcbb57 100644
--- a/test/org/traccar/protocol/TelicFrameDecoderTest.java
+++ b/test/org/traccar/protocol/TelicFrameDecoderTest.java
@@ -3,8 +3,6 @@ package org.traccar.protocol;
import org.junit.Test;
import org.traccar.ProtocolTest;
-import java.nio.ByteOrder;
-
public class TelicFrameDecoderTest extends ProtocolTest {
@Test
@@ -13,31 +11,31 @@ public class TelicFrameDecoderTest extends ProtocolTest {
TelicFrameDecoder decoder = new TelicFrameDecoder();
verifyFrame(
- binary(ByteOrder.LITTLE_ENDIAN, "303032363230333339337c3232367c31307c303032303034303130"),
- decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "303032363230333339337c3232367c31307c30303230303430313000")));
+ binary("303032363230333339337c3232367c31307c303032303034303130"),
+ decoder.decode(null, null, binary("303032363230333339337c3232367c31307c30303230303430313000")));
verifyFrame(
- binary(ByteOrder.LITTLE_ENDIAN, "3030333032303333393332352c3139303331373038333035322c302c3138303331373130333132372c3235393932342c3434353133332c332c302c302c392c2c2c39332c31323231303134312c2c303031302c30302c34302c3234302c302c30343036"),
- decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "630000003030333032303333393332352c3139303331373038333035322c302c3138303331373130333132372c3235393932342c3434353133332c332c302c302c392c2c2c39332c31323231303134312c2c303031302c30302c34302c3234302c302c3034303600")));
+ binary("3030333032303333393332352c3139303331373038333035322c302c3138303331373130333132372c3235393932342c3434353133332c332c302c302c392c2c2c39332c31323231303134312c2c303031302c30302c34302c3234302c302c30343036"),
+ decoder.decode(null, null, binary("630000003030333032303333393332352c3139303331373038333035322c302c3138303331373130333132372c3235393932342c3434353133332c332c302c302c392c2c2c39332c31323231303134312c2c303031302c30302c34302c3234302c302c3034303600")));
verifyFrame(
- binary(ByteOrder.LITTLE_ENDIAN, "303032363239363231385343434530315f534343457c3232367c31307c30323637"),
- decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "303032363239363231385343434530315f534343457c3232367c31307c3032363700")));
+ binary("303032363239363231385343434530315f534343457c3232367c31307c30323637"),
+ decoder.decode(null, null, binary("303032363239363231385343434530315f534343457c3232367c31307c3032363700")));
verifyFrame(
- binary(ByteOrder.LITTLE_ENDIAN, "30303434323936323138544c4f43303236372c30302c3031313030393030303239363231382c3139303331373038333033362c3235353137382c3434353037322c332c302c38322c2c2c2c3136382c31343734313239362c2c30302c30302c302c323137"),
- decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "6400000030303434323936323138544c4f43303236372c30302c3031313030393030303239363231382c3139303331373038333033362c3235353137382c3434353037322c332c302c38322c2c2c2c3136382c31343734313239362c2c30302c30302c302c32313700")));
+ binary("30303434323936323138544c4f43303236372c30302c3031313030393030303239363231382c3139303331373038333033362c3235353137382c3434353037322c332c302c38322c2c2c2c3136382c31343734313239362c2c30302c30302c302c323137"),
+ decoder.decode(null, null, binary("6400000030303434323936323138544c4f43303236372c30302c3031313030393030303239363231382c3139303331373038333033362c3235353137382c3434353037322c332c302c38322c2c2c2c3136382c31343734313239362c2c30302c30302c302c32313700")));
verifyNull(
- decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "00303032363937393238317c3233327c30337c30303230303430313000")));
+ decoder.decode(null, null, binary("00303032363937393238317c3233327c30337c30303230303430313000")));
verifyFrame(
- binary(ByteOrder.LITTLE_ENDIAN, "303032363937393238317c3233327c30337c303032303034303130"),
- decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "303032363937393238317c3233327c30337c30303230303430313000")));
+ binary("303032363937393238317c3233327c30337c303032303034303130"),
+ decoder.decode(null, null, binary("303032363937393238317c3233327c30337c30303230303430313000")));
verifyFrame(
- binary(ByteOrder.LITTLE_ENDIAN, "3030323039373932383139392c3231303231363038313930302c302c3231303231363038313835392c3031333839333338352c34363635383639352c332c302c302c382c2c2c3534312c36313239382c2c303030302c30302c302c3139362c302c30343037"),
- decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "650000003030323039373932383139392c3231303231363038313930302c302c3231303231363038313835392c3031333839333338352c34363635383639352c332c302c302c382c2c2c3534312c36313239382c2c303030302c30302c302c3139362c302c3034303700")));
+ binary("3030323039373932383139392c3231303231363038313930302c302c3231303231363038313835392c3031333839333338352c34363635383639352c332c302c302c382c2c2c3534312c36313239382c2c303030302c30302c302c3139362c302c30343037"),
+ decoder.decode(null, null, binary("650000003030323039373932383139392c3231303231363038313930302c302c3231303231363038313835392c3031333839333338352c34363635383639352c332c302c302c382c2c2c3534312c36313239382c2c303030302c30302c302c3139362c302c3034303700")));
}