aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-06-08 11:07:43 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-06-08 11:07:43 +1200
commit4d9187e2ee98eee17d4adbcb84379e2c68fe2bcd (patch)
tree0751e189301c050e3a66ef25326190ea54fc7f92 /src
parente26b25c7c35cb99f3e0fb114bcedd76f090e0c3b (diff)
downloadtrackermap-server-4d9187e2ee98eee17d4adbcb84379e2c68fe2bcd.tar.gz
trackermap-server-4d9187e2ee98eee17d4adbcb84379e2c68fe2bcd.tar.bz2
trackermap-server-4d9187e2ee98eee17d4adbcb84379e2c68fe2bcd.zip
Migrate L, M, N protocols
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/protocol/L100FrameDecoder.java16
-rw-r--r--src/org/traccar/protocol/L100Protocol.java11
-rw-r--r--src/org/traccar/protocol/L100ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/LaipacProtocol.java15
-rw-r--r--src/org/traccar/protocol/LaipacProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/M2cProtocol.java13
-rw-r--r--src/org/traccar/protocol/M2cProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/M2mProtocol.java11
-rw-r--r--src/org/traccar/protocol/M2mProtocolDecoder.java8
-rw-r--r--src/org/traccar/protocol/MaestroProtocol.java15
-rw-r--r--src/org/traccar/protocol/MaestroProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/ManPowerProtocol.java13
-rw-r--r--src/org/traccar/protocol/ManPowerProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/MegastekFrameDecoder.java20
-rw-r--r--src/org/traccar/protocol/MegastekProtocol.java13
-rw-r--r--src/org/traccar/protocol/MegastekProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/MeiligaoFrameDecoder.java16
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocol.java12
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolDecoder.java41
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolEncoder.java12
-rw-r--r--src/org/traccar/protocol/MeitrackFrameDecoder.java14
-rw-r--r--src/org/traccar/protocol/MeitrackProtocol.java25
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolDecoder.java95
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocol.java13
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/Mta6Protocol.java15
-rw-r--r--src/org/traccar/protocol/Mta6ProtocolDecoder.java46
-rw-r--r--src/org/traccar/protocol/MtxProtocol.java15
-rw-r--r--src/org/traccar/protocol/MtxProtocolDecoder.java7
-rw-r--r--src/org/traccar/protocol/MxtFrameDecoder.java22
-rw-r--r--src/org/traccar/protocol/MxtProtocol.java14
-rw-r--r--src/org/traccar/protocol/MxtProtocolDecoder.java58
-rw-r--r--src/org/traccar/protocol/NavigilFrameDecoder.java22
-rw-r--r--src/org/traccar/protocol/NavigilProtocol.java14
-rw-r--r--src/org/traccar/protocol/NavigilProtocolDecoder.java158
-rw-r--r--src/org/traccar/protocol/NavisProtocol.java18
-rw-r--r--src/org/traccar/protocol/NavisProtocolDecoder.java106
-rw-r--r--src/org/traccar/protocol/NoranProtocol.java14
-rw-r--r--src/org/traccar/protocol/NoranProtocolDecoder.java52
-rw-r--r--src/org/traccar/protocol/NoranProtocolEncoder.java23
-rw-r--r--src/org/traccar/protocol/NvsFrameDecoder.java16
-rw-r--r--src/org/traccar/protocol/NvsProtocol.java9
-rw-r--r--src/org/traccar/protocol/NvsProtocolDecoder.java20
43 files changed, 491 insertions, 532 deletions
diff --git a/src/org/traccar/protocol/L100FrameDecoder.java b/src/org/traccar/protocol/L100FrameDecoder.java
index 98c2f9768..29839eb3a 100644
--- a/src/org/traccar/protocol/L100FrameDecoder.java
+++ b/src/org/traccar/protocol/L100FrameDecoder.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,16 +15,16 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import org.traccar.BaseFrameDecoder;
-public class L100FrameDecoder extends FrameDecoder {
+public class L100FrameDecoder 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() < 80) {
return null;
@@ -42,7 +42,7 @@ public class L100FrameDecoder extends FrameDecoder {
if (buf.readableBytes() >= index - buf.readerIndex()) {
buf.skipBytes(2); // header
- ChannelBuffer frame = buf.readBytes(index - buf.readerIndex() - 2);
+ ByteBuf frame = buf.readBytes(index - buf.readerIndex() - 2);
buf.skipBytes(2); // footer
return frame;
}
diff --git a/src/org/traccar/protocol/L100Protocol.java b/src/org/traccar/protocol/L100Protocol.java
index 245f073fb..2d29bee40 100644
--- a/src/org/traccar/protocol/L100Protocol.java
+++ b/src/org/traccar/protocol/L100Protocol.java
@@ -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 L100Protocol 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 L100FrameDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("stringDecoder", new StringDecoder());
diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java
index fe2c298e1..ad93baf67 100644
--- a/src/org/traccar/protocol/L100ProtocolDecoder.java
+++ b/src/org/traccar/protocol/L100ProtocolDecoder.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/LaipacProtocol.java b/src/org/traccar/protocol/LaipacProtocol.java
index 45b803a0f..aafada331 100644
--- a/src/org/traccar/protocol/LaipacProtocol.java
+++ b/src/org/traccar/protocol/LaipacProtocol.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 LaipacProtocol 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/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java
index bfaff9ec4..8634a0e32 100644
--- a/src/org/traccar/protocol/LaipacProtocolDecoder.java
+++ b/src/org/traccar/protocol/LaipacProtocolDecoder.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.Checksum;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
@@ -93,7 +94,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
String sentence = (String) msg;
if (sentence.startsWith("$ECHK") && channel != null) {
- channel.write(sentence + "\r\n"); // heartbeat
+ channel.writeAndFlush(new NetworkMessage(sentence + "\r\n", remoteAddress)); // heartbeat
return null;
}
@@ -146,15 +147,15 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
if (channel != null) {
if (event.equals("3")) {
- channel.write("$AVCFG,00000000,d*31\r\n");
+ channel.writeAndFlush(new NetworkMessage("$AVCFG,00000000,d*31\r\n", remoteAddress));
} else if (event.equals("X") || event.equals("4")) {
- channel.write("$AVCFG,00000000,x*2D\r\n");
+ channel.writeAndFlush(new NetworkMessage("$AVCFG,00000000,x*2D\r\n", remoteAddress));
} else if (event.equals("Z")) {
- channel.write("$AVCFG,00000000,z*2F\r\n");
+ channel.writeAndFlush(new NetworkMessage("$AVCFG,00000000,z*2F\r\n", remoteAddress));
} else if (Character.isLowerCase(status.charAt(0))) {
String response = "$EAVACK," + event + "," + checksum;
response += Checksum.nmea(response) + "\r\n";
- channel.write(response);
+ channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
}
diff --git a/src/org/traccar/protocol/M2cProtocol.java b/src/org/traccar/protocol/M2cProtocol.java
index 2c3187095..ef16108cd 100644
--- a/src/org/traccar/protocol/M2cProtocol.java
+++ b/src/org/traccar/protocol/M2cProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,11 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.CharacterDelimiterFrameDecoder;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -33,9 +32,9 @@ public class M2cProtocol 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, ']'));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
diff --git a/src/org/traccar/protocol/M2cProtocolDecoder.java b/src/org/traccar/protocol/M2cProtocolDecoder.java
index c11136f4c..67b2accb9 100644
--- a/src/org/traccar/protocol/M2cProtocolDecoder.java
+++ b/src/org/traccar/protocol/M2cProtocolDecoder.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.Parser;
diff --git a/src/org/traccar/protocol/M2mProtocol.java b/src/org/traccar/protocol/M2mProtocol.java
index 09393fed0..70dfc7b39 100644
--- a/src/org/traccar/protocol/M2mProtocol.java
+++ b/src/org/traccar/protocol/M2mProtocol.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.FixedLengthFrameDecoder;
+import io.netty.handler.codec.FixedLengthFrameDecoder;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -31,9 +30,9 @@ public class M2mProtocol 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 FixedLengthFrameDecoder(23));
pipeline.addLast("objectDecoder", new M2mProtocolDecoder(M2mProtocol.this));
}
diff --git a/src/org/traccar/protocol/M2mProtocolDecoder.java b/src/org/traccar/protocol/M2mProtocolDecoder.java
index b30919865..7bb704904 100644
--- a/src/org/traccar/protocol/M2mProtocolDecoder.java
+++ b/src/org/traccar/protocol/M2mProtocolDecoder.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,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.DateBuilder;
@@ -36,7 +36,7 @@ public class M2mProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
// Remove offset
for (int i = 0; i < buf.readableBytes(); i++) {
diff --git a/src/org/traccar/protocol/MaestroProtocol.java b/src/org/traccar/protocol/MaestroProtocol.java
index 5e0b69916..5a7cbcf4d 100644
--- a/src/org/traccar/protocol/MaestroProtocol.java
+++ b/src/org/traccar/protocol/MaestroProtocol.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.FixedLengthFrameDecoder;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.FixedLengthFrameDecoder;
+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 MaestroProtocol 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 FixedLengthFrameDecoder(160));
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("stringDecoder", new StringDecoder());
diff --git a/src/org/traccar/protocol/MaestroProtocolDecoder.java b/src/org/traccar/protocol/MaestroProtocolDecoder.java
index 6068c93b9..32072007e 100644
--- a/src/org/traccar/protocol/MaestroProtocolDecoder.java
+++ b/src/org/traccar/protocol/MaestroProtocolDecoder.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/ManPowerProtocol.java b/src/org/traccar/protocol/ManPowerProtocol.java
index 60ce8b282..5567cdccb 100644
--- a/src/org/traccar/protocol/ManPowerProtocol.java
+++ b/src/org/traccar/protocol/ManPowerProtocol.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 ManPowerProtocol 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/ManPowerProtocolDecoder.java b/src/org/traccar/protocol/ManPowerProtocolDecoder.java
index 0b1c410c3..d1b6bdc72 100644
--- a/src/org/traccar/protocol/ManPowerProtocolDecoder.java
+++ b/src/org/traccar/protocol/ManPowerProtocolDecoder.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.Parser;
diff --git a/src/org/traccar/protocol/MegastekFrameDecoder.java b/src/org/traccar/protocol/MegastekFrameDecoder.java
index d9cb07108..0bdd06a79 100644
--- a/src/org/traccar/protocol/MegastekFrameDecoder.java
+++ b/src/org/traccar/protocol/MegastekFrameDecoder.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,19 +15,19 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-import org.traccar.helper.StringFinder;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import org.traccar.BaseFrameDecoder;
+import org.traccar.helper.BufferUtil;
import java.nio.charset.StandardCharsets;
-public class MegastekFrameDecoder extends FrameDecoder {
+public class MegastekFrameDecoder 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;
@@ -42,12 +42,12 @@ public class MegastekFrameDecoder extends FrameDecoder {
while (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n') {
buf.skipBytes(1);
}
- int delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n"));
+ int delimiter = BufferUtil.indexOf("\r\n", buf);
if (delimiter == -1) {
delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '!');
}
if (delimiter != -1) {
- ChannelBuffer result = buf.readBytes(delimiter - buf.readerIndex());
+ ByteBuf result = buf.readBytes(delimiter - buf.readerIndex());
buf.skipBytes(1);
return result;
}
diff --git a/src/org/traccar/protocol/MegastekProtocol.java b/src/org/traccar/protocol/MegastekProtocol.java
index b28a05b92..862d1abd2 100644
--- a/src/org/traccar/protocol/MegastekProtocol.java
+++ b/src/org/traccar/protocol/MegastekProtocol.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 java.util.List;
@@ -32,9 +31,9 @@ public class MegastekProtocol 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 MegastekFrameDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("stringDecoder", new StringDecoder());
diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java
index 14d39e0cc..15f7be582 100644
--- a/src/org/traccar/protocol/MegastekProtocolDecoder.java
+++ b/src/org/traccar/protocol/MegastekProtocolDecoder.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/MeiligaoFrameDecoder.java b/src/org/traccar/protocol/MeiligaoFrameDecoder.java
index 9340b6198..e14d8ed58 100644
--- a/src/org/traccar/protocol/MeiligaoFrameDecoder.java
+++ b/src/org/traccar/protocol/MeiligaoFrameDecoder.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,21 +15,21 @@
*/
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 MeiligaoFrameDecoder extends FrameDecoder {
+public class MeiligaoFrameDecoder extends BaseFrameDecoder {
private static final int MESSAGE_HEADER = 4;
@Override
protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
+ ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
// Strip not '$' (0x24) bytes from the beginning
- while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != 0x24) {
+ while (buf.isReadable() && buf.getUnsignedByte(buf.readerIndex()) != 0x24) {
buf.readByte();
}
diff --git a/src/org/traccar/protocol/MeiligaoProtocol.java b/src/org/traccar/protocol/MeiligaoProtocol.java
index c72262017..0b745f0c6 100644
--- a/src/org/traccar/protocol/MeiligaoProtocol.java
+++ b/src/org/traccar/protocol/MeiligaoProtocol.java
@@ -15,10 +15,8 @@
*/
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;
@@ -41,17 +39,17 @@ public class MeiligaoProtocol 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 MeiligaoFrameDecoder());
pipeline.addLast("objectEncoder", new MeiligaoProtocolEncoder());
pipeline.addLast("objectDecoder", new MeiligaoProtocolDecoder(MeiligaoProtocol.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("objectEncoder", new MeiligaoProtocolEncoder());
pipeline.addLast("objectDecoder", new MeiligaoProtocolDecoder(MeiligaoProtocol.this));
}
diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
index 5ff0dedc7..35512945a 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
@@ -15,12 +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.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.BitUtil;
import org.traccar.helper.Checksum;
import org.traccar.helper.DateBuilder;
@@ -39,7 +40,7 @@ import java.util.regex.Pattern;
public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
- private Map<Byte, ChannelBuffer> photos = new HashMap<>();
+ private Map<Byte, ByteBuf> photos = new HashMap<>();
public MeiligaoProtocolDecoder(MeiligaoProtocol protocol) {
super(protocol);
@@ -153,7 +154,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_UPLOAD_COMPLETE = 0x0f80;
public static final int MSG_REBOOT_GPS = 0x4902;
- private DeviceSession identify(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
+ private DeviceSession identify(ByteBuf buf, Channel channel, SocketAddress remoteAddress) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 7; i++) {
@@ -184,10 +185,10 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
}
private static void sendResponse(
- Channel channel, SocketAddress remoteAddress, ChannelBuffer id, int type, ChannelBuffer msg) {
+ Channel channel, SocketAddress remoteAddress, ByteBuf id, int type, ByteBuf msg) {
if (channel != null) {
- ChannelBuffer buf = ChannelBuffers.buffer(
+ ByteBuf buf = Unpooled.buffer(
2 + 2 + id.readableBytes() + 2 + msg.readableBytes() + 2 + 2);
buf.writeByte('@');
@@ -196,18 +197,18 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
buf.writeBytes(id);
buf.writeShort(type);
buf.writeBytes(msg);
- buf.writeShort(Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.toByteBuffer()));
+ buf.writeShort(Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.nioBuffer()));
buf.writeByte('\r');
buf.writeByte('\n');
- channel.write(buf, remoteAddress);
+ channel.writeAndFlush(new NetworkMessage(buf, remoteAddress));
}
}
private String getServer(Channel channel) {
String server = Context.getConfig().getString(getProtocolName() + ".server");
if (server == null && channel != null) {
- InetSocketAddress address = (InetSocketAddress) channel.getLocalAddress();
+ InetSocketAddress address = (InetSocketAddress) channel.localAddress();
server = address.getAddress().getHostAddress() + ":" + address.getPort();
}
return server;
@@ -357,7 +358,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private List<Position> decodeRetransmission(ChannelBuffer buf, DeviceSession deviceSession) {
+ private List<Position> decodeRetransmission(ByteBuf buf, DeviceSession deviceSession) {
List<Position> positions = new LinkedList<>();
int count = buf.readUnsignedByte();
@@ -394,34 +395,34 @@ public class MeiligaoProtocolDecoder 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.readShort(); // length
- ChannelBuffer id = buf.readBytes(7);
+ ByteBuf id = buf.readBytes(7);
int command = buf.readUnsignedShort();
- ChannelBuffer response;
+ ByteBuf response;
if (command == MSG_LOGIN) {
- response = ChannelBuffers.wrappedBuffer(new byte[]{0x01});
+ response = Unpooled.wrappedBuffer(new byte[]{0x01});
sendResponse(channel, remoteAddress, id, MSG_LOGIN_RESPONSE, response);
return null;
} else if (command == MSG_HEARTBEAT) {
- response = ChannelBuffers.wrappedBuffer(new byte[]{0x01});
+ response = Unpooled.wrappedBuffer(new byte[]{0x01});
sendResponse(channel, remoteAddress, id, MSG_HEARTBEAT, response);
return null;
} else if (command == MSG_SERVER) {
- response = ChannelBuffers.copiedBuffer(getServer(channel), StandardCharsets.US_ASCII);
+ response = Unpooled.copiedBuffer(getServer(channel), StandardCharsets.US_ASCII);
sendResponse(channel, remoteAddress, id, MSG_SERVER, response);
return null;
} else if (command == MSG_UPLOAD_PHOTO) {
byte imageIndex = buf.readByte();
- photos.put(imageIndex, ChannelBuffers.dynamicBuffer());
- response = ChannelBuffers.copiedBuffer(new byte[]{imageIndex});
+ photos.put(imageIndex, Unpooled.buffer());
+ response = Unpooled.copiedBuffer(new byte[]{imageIndex});
sendResponse(channel, remoteAddress, id, MSG_UPLOAD_PHOTO_RESPONSE, response);
return null;
} else if (command == MSG_UPLOAD_COMPLETE) {
byte imageIndex = buf.readByte();
- response = ChannelBuffers.copiedBuffer(new byte[]{imageIndex, 0, 0});
+ response = Unpooled.copiedBuffer(new byte[]{imageIndex, 0, 0});
sendResponse(channel, remoteAddress, id, MSG_RETRANSMISSION, response);
return null;
}
diff --git a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java b/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
index 1b444e90a..6052b2617 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
@@ -15,8 +15,8 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import org.traccar.BaseProtocolEncoder;
import org.traccar.helper.Checksum;
import org.traccar.helper.DataConverter;
@@ -28,9 +28,9 @@ import java.util.TimeZone;
public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
- private ChannelBuffer encodeContent(long deviceId, int type, ChannelBuffer content) {
+ private ByteBuf encodeContent(long deviceId, int type, ByteBuf content) {
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
+ ByteBuf buf = Unpooled.buffer();
buf.writeByte('@');
buf.writeByte('@');
@@ -43,7 +43,7 @@ public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
buf.writeBytes(content);
- buf.writeShort(Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.toByteBuffer()));
+ buf.writeShort(Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.nioBuffer()));
buf.writeByte('\r');
buf.writeByte('\n');
@@ -54,7 +54,7 @@ public class MeiligaoProtocolEncoder 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/MeitrackFrameDecoder.java b/src/org/traccar/protocol/MeitrackFrameDecoder.java
index 1eb0dae0f..5133dd2dc 100644
--- a/src/org/traccar/protocol/MeitrackFrameDecoder.java
+++ b/src/org/traccar/protocol/MeitrackFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton@traccar.org)
+ * Copyright 2014 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,18 +15,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;
import java.nio.charset.StandardCharsets;
-public class MeitrackFrameDecoder extends FrameDecoder {
+public class MeitrackFrameDecoder 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;
diff --git a/src/org/traccar/protocol/MeitrackProtocol.java b/src/org/traccar/protocol/MeitrackProtocol.java
index e89825da5..b9be2a8fd 100644
--- a/src/org/traccar/protocol/MeitrackProtocol.java
+++ b/src/org/traccar/protocol/MeitrackProtocol.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,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.string.StringEncoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import org.traccar.model.Command;
-import java.nio.ByteOrder;
import java.util.List;
public class MeitrackProtocol extends BaseProtocol {
@@ -42,27 +39,23 @@ public class MeitrackProtocol 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 MeitrackFrameDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("objectEncoder", new MeitrackProtocolEncoder());
pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(MeitrackProtocol.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("stringEncoder", new StringEncoder());
pipeline.addLast("objectEncoder", new MeitrackProtocolEncoder());
pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(MeitrackProtocol.this));
}
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
+ });
}
}
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
index 9109323ec..a38f52b77 100644
--- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2017 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,12 +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.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.Checksum;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
@@ -38,7 +39,7 @@ import java.util.regex.Pattern;
public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
- private ChannelBuffer photo;
+ private ByteBuf photo;
public MeitrackProtocolDecoder(MeitrackProtocol protocol) {
super(protocol);
@@ -119,7 +120,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
}
}
- private Position decodeRegular(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
+ private Position decodeRegular(Channel channel, SocketAddress remoteAddress, ByteBuf buf) {
Parser parser = new Parser(PATTERN, buf.toString(StandardCharsets.US_ASCII));
if (!parser.matches()) {
@@ -270,7 +271,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
}
- private List<Position> decodeBinaryC(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
+ private List<Position> decodeBinaryC(Channel channel, SocketAddress remoteAddress, ByteBuf buf) {
List<Position> positions = new LinkedList<>();
String flag = buf.toString(2, 1, StandardCharsets.US_ASCII);
@@ -291,38 +292,38 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
- position.setLatitude(buf.readInt() * 0.000001);
- position.setLongitude(buf.readInt() * 0.000001);
+ position.setLatitude(buf.readIntLE() * 0.000001);
+ position.setLongitude(buf.readIntLE() * 0.000001);
- position.setTime(new Date((946684800 + buf.readUnsignedInt()) * 1000)); // 946684800 = 2000-01-01
+ position.setTime(new Date((946684800 + buf.readUnsignedIntLE()) * 1000)); // 946684800 = 2000-01-01
position.setValid(buf.readUnsignedByte() == 1);
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
int rssi = buf.readUnsignedByte();
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
- position.setCourse(buf.readUnsignedShort());
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
+ position.setCourse(buf.readUnsignedShortLE());
- position.set(Position.KEY_HDOP, buf.readUnsignedShort() * 0.1);
+ position.set(Position.KEY_HDOP, buf.readUnsignedShortLE() * 0.1);
- position.setAltitude(buf.readUnsignedShort());
+ position.setAltitude(buf.readUnsignedShortLE());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- position.set("runtime", buf.readUnsignedInt());
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
+ position.set("runtime", buf.readUnsignedIntLE());
position.setNetwork(new Network(CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedShort(),
- buf.readUnsignedShort(), buf.readUnsignedShort(),
+ buf.readUnsignedShortLE(), buf.readUnsignedShortLE(),
+ buf.readUnsignedShortLE(), buf.readUnsignedShortLE(),
rssi)));
- position.set(Position.KEY_STATUS, buf.readUnsignedShort());
+ position.set(Position.KEY_STATUS, buf.readUnsignedShortLE());
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.01);
- position.set(Position.KEY_POWER, buf.readUnsignedShort());
+ position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE());
+ position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.01);
+ position.set(Position.KEY_POWER, buf.readUnsignedShortLE());
- buf.readUnsignedInt(); // geo-fence
+ buf.readUnsignedIntLE(); // geo-fence
positions.add(position);
}
@@ -337,13 +338,13 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
}
command.append(String.format("%02x", checksum & 0xff).toUpperCase());
command.append("\r\n");
- channel.write(command.toString()); // delete processed data
+ channel.writeAndFlush(new NetworkMessage(command.toString(), remoteAddress)); // delete processed data
}
return positions;
}
- private List<Position> decodeBinaryE(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
+ private List<Position> decodeBinaryE(Channel channel, SocketAddress remoteAddress, ByteBuf buf) {
List<Position> positions = new LinkedList<>();
buf.readerIndex(buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',') + 1);
@@ -355,15 +356,15 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- buf.readUnsignedInt(); // remaining cache
- int count = buf.readUnsignedShort();
+ buf.readUnsignedIntLE(); // remaining cache
+ int count = buf.readUnsignedShortLE();
for (int i = 0; i < count; i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- buf.readUnsignedShort(); // length
- buf.readUnsignedShort(); // index
+ buf.readUnsignedShortLE(); // length
+ buf.readUnsignedShortLE(); // index
int paramCount = buf.readUnsignedByte();
for (int j = 0; j < paramCount; j++) {
@@ -392,22 +393,22 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
int id = buf.readUnsignedByte();
switch (id) {
case 0x08:
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE()));
break;
case 0x09:
- position.setCourse(buf.readUnsignedShort());
+ position.setCourse(buf.readUnsignedShortLE());
break;
case 0x0B:
- position.setAltitude(buf.readShort());
+ position.setAltitude(buf.readShortLE());
break;
case 0x19:
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.01);
+ position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.01);
break;
case 0x1A:
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
+ position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.01);
break;
default:
- buf.readUnsignedShort();
+ buf.readUnsignedShortLE();
break;
}
}
@@ -417,19 +418,19 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
int id = buf.readUnsignedByte();
switch (id) {
case 0x02:
- position.setLatitude(buf.readInt() * 0.000001);
+ position.setLatitude(buf.readIntLE() * 0.000001);
break;
case 0x03:
- position.setLongitude(buf.readInt() * 0.000001);
+ position.setLongitude(buf.readIntLE() * 0.000001);
break;
case 0x04:
- position.setTime(new Date((946684800 + buf.readUnsignedInt()) * 1000)); // 2000-01-01
+ position.setTime(new Date((946684800 + buf.readUnsignedIntLE()) * 1000)); // 2000-01-01
break;
case 0x0D:
- position.set("runtime", buf.readUnsignedInt());
+ position.set("runtime", buf.readUnsignedIntLE());
break;
default:
- buf.readUnsignedInt();
+ buf.readUnsignedIntLE();
break;
}
}
@@ -446,13 +447,13 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
return positions;
}
- private void requestPhotoPacket(Channel channel, String imei, String file, int index) {
+ private void requestPhotoPacket(Channel channel, SocketAddress socketAddress, String imei, String file, int index) {
if (channel != null) {
String content = "D00," + file + "," + index;
int length = 1 + imei.length() + 1 + content.length() + 5;
String response = String.format("@@O%02d,%s,%s*", length, imei, content);
response += Checksum.sum(response) + "\r\n";
- channel.write(response);
+ channel.writeAndFlush(new NetworkMessage(response, socketAddress));
}
}
@@ -460,7 +461,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
String imei = buf.toString(index + 1, 15, StandardCharsets.US_ASCII);
@@ -470,7 +471,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
switch (type) {
case "D00":
if (photo == null) {
- photo = ChannelBuffers.dynamicBuffer();
+ photo = Unpooled.buffer();
}
index = index + 1 + type.length() + 1;
@@ -498,13 +499,13 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
return position;
} else {
if ((current + 1) % 8 == 0) {
- requestPhotoPacket(channel, imei, file, current + 1);
+ requestPhotoPacket(channel, remoteAddress, imei, file, current + 1);
}
return null;
}
case "D03":
- photo = ChannelBuffers.dynamicBuffer();
- requestPhotoPacket(channel, imei, "camera_picture.jpg", 0);
+ photo = Unpooled.buffer();
+ requestPhotoPacket(channel, remoteAddress, imei, "camera_picture.jpg", 0);
return null;
case "CCC":
return decodeBinaryC(channel, remoteAddress, buf);
diff --git a/src/org/traccar/protocol/MiniFinderProtocol.java b/src/org/traccar/protocol/MiniFinderProtocol.java
index c36acb238..05641dcbe 100644
--- a/src/org/traccar/protocol/MiniFinderProtocol.java
+++ b/src/org/traccar/protocol/MiniFinderProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,11 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.CharacterDelimiterFrameDecoder;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import org.traccar.model.Command;
@@ -46,9 +45,9 @@ public class MiniFinderProtocol 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/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
index ab046eca3..d7af66ba7 100644
--- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
+++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.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.BitUtil;
diff --git a/src/org/traccar/protocol/Mta6Protocol.java b/src/org/traccar/protocol/Mta6Protocol.java
index 65a48808d..e0b3f6063 100644
--- a/src/org/traccar/protocol/Mta6Protocol.java
+++ b/src/org/traccar/protocol/Mta6Protocol.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.http.HttpRequestDecoder;
-import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
+import io.netty.handler.codec.http.HttpObjectAggregator;
+import io.netty.handler.codec.http.HttpRequestDecoder;
+import io.netty.handler.codec.http.HttpResponseEncoder;
import org.traccar.BaseProtocol;
import org.traccar.Context;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -33,11 +33,12 @@ public class Mta6Protocol 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("httpEncoder", new HttpResponseEncoder());
pipeline.addLast("httpDecoder", new HttpRequestDecoder());
+ pipeline.addLast("httpAggregator", new HttpObjectAggregator(65535));
pipeline.addLast("objectDecoder", new Mta6ProtocolDecoder(
Mta6Protocol.this, !Context.getConfig().getBoolean(getName() + ".can")));
}
diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
index 13b187e80..56a5669ae 100644
--- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.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,14 +15,14 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
-import org.jboss.netty.handler.codec.http.HttpRequest;
-import org.jboss.netty.handler.codec.http.HttpResponse;
-import org.jboss.netty.handler.codec.http.HttpResponseStatus;
-import org.jboss.netty.handler.codec.http.HttpVersion;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.handler.codec.http.DefaultFullHttpResponse;
+import io.netty.handler.codec.http.FullHttpRequest;
+import io.netty.handler.codec.http.FullHttpResponse;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.netty.handler.codec.http.HttpVersion;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.Protocol;
@@ -48,22 +48,20 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
}
private void sendContinue(Channel channel) {
- HttpResponse response = new DefaultHttpResponse(
+ FullHttpResponse response = new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE);
channel.write(response);
}
private void sendResponse(Channel channel, short packetId, short packetCount) {
- HttpResponse response = new DefaultHttpResponse(
- HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
-
- ChannelBuffer begin = ChannelBuffers.copiedBuffer("#ACK#", StandardCharsets.US_ASCII);
- ChannelBuffer end = ChannelBuffers.directBuffer(3);
+ ByteBuf begin = Unpooled.copiedBuffer("#ACK#", StandardCharsets.US_ASCII);
+ ByteBuf end = Unpooled.buffer(3);
end.writeByte(packetId);
end.writeByte(packetCount);
end.writeByte(0);
- response.setContent(ChannelBuffers.wrappedBuffer(begin, end));
+ FullHttpResponse response = new DefaultFullHttpResponse(
+ HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(begin, end));
channel.write(response);
}
@@ -71,7 +69,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
private int previousFloat;
- public float readFloat(ChannelBuffer buf) {
+ public float readFloat(ByteBuf buf) {
switch (buf.getUnsignedByte(buf.readerIndex()) >> 6) {
case 0:
previousFloat = buf.readInt() << 2;
@@ -98,7 +96,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
private long weekNumber;
- public Date readTime(ChannelBuffer buf) {
+ public Date readTime(ByteBuf buf) {
long weekTime = (long) (readFloat(buf) * 1000);
if (weekNumber == 0) {
weekNumber = buf.readUnsignedShort();
@@ -112,7 +110,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
}
- private List<Position> parseFormatA(DeviceSession deviceSession, ChannelBuffer buf) {
+ private List<Position> parseFormatA(DeviceSession deviceSession, ByteBuf buf) {
List<Position> positions = new LinkedList<>();
FloatReader latitudeReader = new FloatReader();
@@ -120,7 +118,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
TimeReader timeReader = new TimeReader();
try {
- while (buf.readable()) {
+ while (buf.isReadable()) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
@@ -199,7 +197,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
return positions;
}
- private Position parseFormatA1(DeviceSession deviceSession, ChannelBuffer buf) {
+ private Position parseFormatA1(DeviceSession deviceSession, ByteBuf buf) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
@@ -278,8 +276,8 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- HttpRequest request = (HttpRequest) msg;
- ChannelBuffer buf = request.getContent();
+ FullHttpRequest request = (FullHttpRequest) msg;
+ ByteBuf buf = request.content();
buf.skipBytes("id=".length());
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '&');
@@ -309,7 +307,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
} else {
return parseFormatA(deviceSession, buf);
}
- } //else if (0x34 0x38 0x4F 0x59)
+ } // else if (0x34 0x38 0x4F 0x59)
return null;
}
diff --git a/src/org/traccar/protocol/MtxProtocol.java b/src/org/traccar/protocol/MtxProtocol.java
index 58b2361cd..2f33909db 100644
--- a/src/org/traccar/protocol/MtxProtocol.java
+++ b/src/org/traccar/protocol/MtxProtocol.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 MtxProtocol 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/MtxProtocolDecoder.java b/src/org/traccar/protocol/MtxProtocolDecoder.java
index 412eac493..18bce399f 100644
--- a/src/org/traccar/protocol/MtxProtocolDecoder.java
+++ b/src/org/traccar/protocol/MtxProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,9 +15,10 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.model.Position;
@@ -60,7 +61,7 @@ public class MtxProtocolDecoder extends BaseProtocolDecoder {
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
if (channel != null) {
- channel.write("#ACK");
+ channel.writeAndFlush(new NetworkMessage("#ACK", remoteAddress));
}
Parser parser = new Parser(PATTERN, (String) msg);
diff --git a/src/org/traccar/protocol/MxtFrameDecoder.java b/src/org/traccar/protocol/MxtFrameDecoder.java
index b2cd6de93..d70e92da1 100644
--- a/src/org/traccar/protocol/MxtFrameDecoder.java
+++ b/src/org/traccar/protocol/MxtFrameDecoder.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,21 +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 org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import org.traccar.BaseFrameDecoder;
-import java.nio.ByteOrder;
-
-public class MxtFrameDecoder extends FrameDecoder {
+public class MxtFrameDecoder 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() < 2) {
return null;
@@ -37,7 +33,7 @@ public class MxtFrameDecoder extends FrameDecoder {
int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0x04);
if (index != -1) {
- ChannelBuffer result = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, 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/MxtProtocol.java b/src/org/traccar/protocol/MxtProtocol.java
index 03c1da71e..8bfb958ab 100644
--- a/src/org/traccar/protocol/MxtProtocol.java
+++ b/src/org/traccar/protocol/MxtProtocol.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 MxtProtocol extends BaseProtocol {
@@ -31,15 +29,13 @@ public class MxtProtocol 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 MxtFrameDecoder());
pipeline.addLast("objectDecoder", new MxtProtocolDecoder(MxtProtocol.this));
}
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
+ });
}
}
diff --git a/src/org/traccar/protocol/MxtProtocolDecoder.java b/src/org/traccar/protocol/MxtProtocolDecoder.java
index a97ae380d..be45b60c8 100644
--- a/src/org/traccar/protocol/MxtProtocolDecoder.java
+++ b/src/org/traccar/protocol/MxtProtocolDecoder.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,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.Checksum;
import org.traccar.helper.DateBuilder;
@@ -27,7 +28,6 @@ import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
-import java.nio.ByteOrder;
public class MxtProtocolDecoder extends BaseProtocolDecoder {
@@ -41,17 +41,17 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder {
private static void sendResponse(Channel channel, int device, long id, int crc) {
if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ ByteBuf response = Unpooled.buffer();
response.writeByte(device);
response.writeByte(MSG_ACK);
- response.writeInt((int) id);
- response.writeShort(crc);
- response.writeShort(Checksum.crc16(
- Checksum.CRC16_XMODEM, response.toByteBuffer()));
+ response.writeIntLE((int) id);
+ response.writeShortLE(crc);
+ response.writeShortLE(Checksum.crc16(
+ Checksum.CRC16_XMODEM, response.nioBuffer()));
- ChannelBuffer encoded = ChannelBuffers.dynamicBuffer();
+ ByteBuf encoded = Unpooled.buffer(0);
encoded.writeByte(0x01); // header
- while (response.readable()) {
+ while (response.isReadable()) {
int b = response.readByte();
if (b == 0x01 || b == 0x04 || b == 0x10 || b == 0x11 || b == 0x13) {
encoded.writeByte(0x10);
@@ -60,7 +60,7 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder {
encoded.writeByte(b);
}
encoded.writeByte(0x04); // ending
- channel.write(encoded);
+ channel.write(new NetworkMessage(encoded, channel.remoteAddress()));
}
}
@@ -68,13 +68,13 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedByte(); // start
int device = buf.readUnsignedByte(); // device descriptor
int type = buf.readUnsignedByte();
- long id = buf.readUnsignedInt();
+ long id = buf.readUnsignedIntLE();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(id));
if (deviceSession == null) {
return null;
@@ -88,11 +88,11 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // protocol
int infoGroups = buf.readUnsignedByte();
- position.set(Position.KEY_INDEX, buf.readUnsignedShort());
+ position.set(Position.KEY_INDEX, buf.readUnsignedShortLE());
DateBuilder dateBuilder = new DateBuilder().setDate(2000, 1, 1);
- long date = buf.readUnsignedInt();
+ long date = buf.readUnsignedIntLE();
long days = BitUtil.from(date, 6 + 6 + 5);
long hours = BitUtil.between(date, 6 + 6, 6 + 6 + 5);
@@ -104,10 +104,10 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder {
position.setTime(dateBuilder.getDate());
position.setValid(true);
- position.setLatitude(buf.readInt() / 1000000.0);
- position.setLongitude(buf.readInt() / 1000000.0);
+ position.setLatitude(buf.readIntLE() / 1000000.0);
+ position.setLongitude(buf.readIntLE() / 1000000.0);
- long flags = buf.readUnsignedInt();
+ long flags = buf.readUnsignedIntLE();
position.set(Position.KEY_IGNITION, BitUtil.check(flags, 0));
if (BitUtil.check(flags, 1)) {
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
@@ -115,7 +115,7 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_INPUT, BitUtil.between(flags, 2, 7));
position.set(Position.KEY_OUTPUT, BitUtil.between(flags, 7, 10));
position.setCourse(BitUtil.between(flags, 10, 13) * 45);
- //position.setValid(BitUtil.check(flags, 15));
+ // position.setValid(BitUtil.check(flags, 15));
position.set(Position.KEY_CHARGE, BitUtil.check(flags, 20));
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
@@ -135,34 +135,34 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_HDOP, buf.readUnsignedByte());
position.setAccuracy(buf.readUnsignedByte());
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- buf.readUnsignedShort(); // time since boot
+ buf.readUnsignedShortLE(); // time since boot
position.set(Position.KEY_POWER, buf.readUnsignedByte());
position.set(Position.PREFIX_TEMP + 1, buf.readByte());
}
if (BitUtil.check(infoGroups, 3)) {
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
}
if (BitUtil.check(infoGroups, 4)) {
- position.set(Position.KEY_HOURS, UnitsConverter.msFromMinutes(buf.readUnsignedInt()));
+ position.set(Position.KEY_HOURS, UnitsConverter.msFromMinutes(buf.readUnsignedIntLE()));
}
if (BitUtil.check(infoGroups, 5)) {
- buf.readUnsignedInt(); // reason
+ buf.readUnsignedIntLE(); // reason
}
if (BitUtil.check(infoGroups, 6)) {
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
+ position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.001);
+ position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE());
}
if (BitUtil.check(infoGroups, 7)) {
- position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedInt()));
+ position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE()));
}
buf.readerIndex(buf.writerIndex() - 3);
- sendResponse(channel, device, id, buf.readUnsignedShort());
+ sendResponse(channel, device, id, buf.readUnsignedShortLE());
return position;
}
diff --git a/src/org/traccar/protocol/NavigilFrameDecoder.java b/src/org/traccar/protocol/NavigilFrameDecoder.java
index 34eb28941..90912fb45 100644
--- a/src/org/traccar/protocol/NavigilFrameDecoder.java
+++ b/src/org/traccar/protocol/NavigilFrameDecoder.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,21 +15,19 @@
*/
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 NavigilFrameDecoder extends FrameDecoder {
+public class NavigilFrameDecoder extends BaseFrameDecoder {
private static final int MESSAGE_HEADER = 20;
private static final long PREAMBLE = 0x2477F5F6;
@Override
protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
+ ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
// Check minimum length
if (buf.readableBytes() < MESSAGE_HEADER) {
@@ -38,15 +36,15 @@ public class NavigilFrameDecoder extends FrameDecoder {
// Check for preamble
boolean hasPreamble = false;
- if (buf.getUnsignedInt(buf.readerIndex()) == PREAMBLE) {
+ if (buf.getUnsignedIntLE(buf.readerIndex()) == PREAMBLE) {
hasPreamble = true;
}
// Check length and return buffer
- int length = buf.getUnsignedShort(buf.readerIndex() + 6);
+ int length = buf.getUnsignedShortLE(buf.readerIndex() + 6);
if (buf.readableBytes() >= length) {
if (hasPreamble) {
- buf.readUnsignedInt();
+ buf.readUnsignedIntLE();
length -= 4;
}
return buf.readBytes(length);
diff --git a/src/org/traccar/protocol/NavigilProtocol.java b/src/org/traccar/protocol/NavigilProtocol.java
index 6646c6cc6..82f4af17d 100644
--- a/src/org/traccar/protocol/NavigilProtocol.java
+++ b/src/org/traccar/protocol/NavigilProtocol.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 NavigilProtocol extends BaseProtocol {
@@ -31,15 +29,13 @@ public class NavigilProtocol 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 NavigilFrameDecoder());
pipeline.addLast("objectDecoder", new NavigilProtocolDecoder(NavigilProtocol.this));
}
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
+ });
}
}
diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java
index 4f3b4ad74..e71f8e36b 100644
--- a/src/org/traccar/protocol/NavigilProtocolDecoder.java
+++ b/src/org/traccar/protocol/NavigilProtocolDecoder.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,18 +15,18 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.Checksum;
import org.traccar.helper.Log;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
-import java.nio.ByteOrder;
import java.util.Date;
public class NavigilProtocolDecoder extends BaseProtocolDecoder {
@@ -60,106 +60,106 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
private int senderSequenceNumber = 1;
private void sendAcknowledgment(Channel channel, int sequenceNumber) {
- ChannelBuffer data = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 4);
- data.writeShort(sequenceNumber);
- data.writeShort(0); // OK
+ ByteBuf data = Unpooled.buffer(4);
+ data.writeShortLE(sequenceNumber);
+ data.writeShortLE(0); // OK
- ChannelBuffer header = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 20);
+ ByteBuf header = Unpooled.buffer(20);
header.writeByte(1); header.writeByte(0);
- header.writeShort(senderSequenceNumber++);
- header.writeShort(MSG_ACKNOWLEDGEMENT);
- header.writeShort(header.capacity() + data.capacity());
- header.writeShort(0);
- header.writeShort(Checksum.crc16(Checksum.CRC16_CCITT_FALSE, data.toByteBuffer()));
- header.writeInt(0);
- header.writeInt((int) (System.currentTimeMillis() / 1000) + LEAP_SECONDS_DELTA);
+ header.writeShortLE(senderSequenceNumber++);
+ header.writeShortLE(MSG_ACKNOWLEDGEMENT);
+ header.writeShortLE(header.capacity() + data.capacity());
+ header.writeShortLE(0);
+ header.writeShortLE(Checksum.crc16(Checksum.CRC16_CCITT_FALSE, data.nioBuffer()));
+ header.writeIntLE(0);
+ header.writeIntLE((int) (System.currentTimeMillis() / 1000) + LEAP_SECONDS_DELTA);
if (channel != null) {
- channel.write(ChannelBuffers.copiedBuffer(header, data));
+ channel.writeAndFlush(new NetworkMessage(Unpooled.copiedBuffer(header, data), channel.remoteAddress()));
}
}
private Position parseUnitReport(
- DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
+ DeviceSession deviceSession, ByteBuf buf, int sequenceNumber) {
Position position = new Position(getProtocolName());
position.setValid(true);
position.set(Position.KEY_INDEX, sequenceNumber);
position.setDeviceId(deviceSession.getDeviceId());
- buf.readUnsignedShort(); // report trigger
- position.set(Position.KEY_FLAGS, buf.readUnsignedShort());
+ buf.readUnsignedShortLE(); // report trigger
+ position.set(Position.KEY_FLAGS, buf.readUnsignedShortLE());
- position.setLatitude(buf.readInt() * 0.0000001);
- position.setLongitude(buf.readInt() * 0.0000001);
- position.setAltitude(buf.readUnsignedShort());
+ position.setLatitude(buf.readIntLE() * 0.0000001);
+ position.setLongitude(buf.readIntLE() * 0.0000001);
+ position.setAltitude(buf.readUnsignedShortLE());
- position.set(Position.KEY_SATELLITES, buf.readUnsignedShort());
- position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedShort());
- position.set("gpsAntennaState", buf.readUnsignedShort());
+ position.set(Position.KEY_SATELLITES, buf.readUnsignedShortLE());
+ position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedShortLE());
+ position.set("gpsAntennaState", buf.readUnsignedShortLE());
- position.setSpeed(buf.readUnsignedShort() * 0.194384);
- position.setCourse(buf.readUnsignedShort());
+ position.setSpeed(buf.readUnsignedShortLE() * 0.194384);
+ position.setCourse(buf.readUnsignedShortLE());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- position.set(Position.KEY_DISTANCE, buf.readUnsignedInt());
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
+ position.set(Position.KEY_DISTANCE, buf.readUnsignedIntLE());
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
+ position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
- position.set(Position.KEY_CHARGE, buf.readUnsignedShort());
+ position.set(Position.KEY_CHARGE, buf.readUnsignedShortLE());
- position.setTime(convertTimestamp(buf.readUnsignedInt()));
+ position.setTime(convertTimestamp(buf.readUnsignedIntLE()));
return position;
}
private Position parseTg2Report(
- DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
+ DeviceSession deviceSession, ByteBuf buf, int sequenceNumber) {
Position position = new Position(getProtocolName());
position.setValid(true);
position.set(Position.KEY_INDEX, sequenceNumber);
position.setDeviceId(deviceSession.getDeviceId());
- buf.readUnsignedShort(); // report trigger
+ buf.readUnsignedShortLE(); // report trigger
buf.readUnsignedByte(); // reserved
buf.readUnsignedByte(); // assisted GPS age
- position.setTime(convertTimestamp(buf.readUnsignedInt()));
+ position.setTime(convertTimestamp(buf.readUnsignedIntLE()));
- position.setLatitude(buf.readInt() * 0.0000001);
- position.setLongitude(buf.readInt() * 0.0000001);
- position.setAltitude(buf.readUnsignedShort());
+ position.setLatitude(buf.readIntLE() * 0.0000001);
+ position.setLongitude(buf.readIntLE() * 0.0000001);
+ position.setAltitude(buf.readUnsignedShortLE());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());
- position.setSpeed(buf.readUnsignedShort() * 0.194384);
- position.setCourse(buf.readUnsignedShort());
+ position.setSpeed(buf.readUnsignedShortLE() * 0.194384);
+ position.setCourse(buf.readUnsignedShortLE());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- position.set("maximumSpeed", buf.readUnsignedShort());
- position.set("minimumSpeed", buf.readUnsignedShort());
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
+ position.set("maximumSpeed", buf.readUnsignedShortLE());
+ position.set("minimumSpeed", buf.readUnsignedShortLE());
- position.set(Position.PREFIX_IO + 1, buf.readUnsignedShort()); // VSAUT1 voltage
- position.set(Position.PREFIX_IO + 2, buf.readUnsignedShort()); // VSAUT2 voltage
- position.set(Position.PREFIX_IO + 3, buf.readUnsignedShort()); // solar voltage
+ position.set(Position.PREFIX_IO + 1, buf.readUnsignedShortLE()); // VSAUT1 voltage
+ position.set(Position.PREFIX_IO + 2, buf.readUnsignedShortLE()); // VSAUT2 voltage
+ position.set(Position.PREFIX_IO + 3, buf.readUnsignedShortLE()); // solar voltage
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
+ position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
return position;
}
private Position parsePositionReport(
- DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber, long timestamp) {
+ DeviceSession deviceSession, ByteBuf buf, int sequenceNumber, long timestamp) {
Position position = new Position(getProtocolName());
position.set(Position.KEY_INDEX, sequenceNumber);
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(convertTimestamp(timestamp));
- position.setLatitude(buf.readMedium() * 0.00002);
- position.setLongitude(buf.readMedium() * 0.00002);
+ position.setLatitude(buf.readMediumLE() * 0.00002);
+ position.setLongitude(buf.readMediumLE() * 0.00002);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
position.setCourse(buf.readUnsignedByte() * 2);
@@ -173,15 +173,15 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
}
private Position parsePositionReport2(
- DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber, long timestamp) {
+ DeviceSession deviceSession, ByteBuf buf, int sequenceNumber, long timestamp) {
Position position = new Position(getProtocolName());
position.set(Position.KEY_INDEX, sequenceNumber);
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(convertTimestamp(timestamp));
- position.setLatitude(buf.readInt() * 0.0000001);
- position.setLongitude(buf.readInt() * 0.0000001);
+ position.setLatitude(buf.readIntLE() * 0.0000001);
+ position.setLongitude(buf.readIntLE() * 0.0000001);
buf.readUnsignedByte(); // report trigger
@@ -191,13 +191,13 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
position.setValid((flags & 0x80) == 0x80 && (flags & 0x40) == 0x40);
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
return position;
}
private Position parseSnapshot4(
- DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
+ DeviceSession deviceSession, ByteBuf buf, int sequenceNumber) {
Position position = new Position(getProtocolName());
position.set(Position.KEY_INDEX, sequenceNumber);
@@ -208,34 +208,34 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // GNSS fix quality
buf.readUnsignedByte(); // GNSS assistance age
- long flags = buf.readUnsignedInt();
+ long flags = buf.readUnsignedIntLE();
position.setValid((flags & 0x0400) == 0x0400);
- position.setTime(convertTimestamp(buf.readUnsignedInt()));
+ position.setTime(convertTimestamp(buf.readUnsignedIntLE()));
- position.setLatitude(buf.readInt() * 0.0000001);
- position.setLongitude(buf.readInt() * 0.0000001);
- position.setAltitude(buf.readUnsignedShort());
+ position.setLatitude(buf.readIntLE() * 0.0000001);
+ position.setLongitude(buf.readIntLE() * 0.0000001);
+ position.setAltitude(buf.readUnsignedShortLE());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());
- position.setSpeed(buf.readUnsignedShort() * 0.194384);
- position.setCourse(buf.readUnsignedShort() * 0.1);
+ position.setSpeed(buf.readUnsignedShortLE() * 0.194384);
+ position.setCourse(buf.readUnsignedShortLE() * 0.1);
position.set("maximumSpeed", buf.readUnsignedByte());
position.set("minimumSpeed", buf.readUnsignedByte());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte()); // supply voltage 1
position.set(Position.PREFIX_IO + 2, buf.readUnsignedByte()); // supply voltage 2
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
+ position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
return position;
}
private Position parseTrackingData(
- DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber, long timestamp) {
+ DeviceSession deviceSession, ByteBuf buf, int sequenceNumber, long timestamp) {
Position position = new Position(getProtocolName());
position.set(Position.KEY_INDEX, sequenceNumber);
@@ -247,17 +247,17 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
short flags = buf.readUnsignedByte();
position.setValid((flags & 0x01) == 0x01);
- buf.readUnsignedShort(); // duration
+ buf.readUnsignedShortLE(); // duration
- position.setLatitude(buf.readInt() * 0.0000001);
- position.setLongitude(buf.readInt() * 0.0000001);
+ position.setLatitude(buf.readIntLE() * 0.0000001);
+ position.setLongitude(buf.readIntLE() * 0.0000001);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
position.setCourse(buf.readUnsignedByte() * 2.0);
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
+ position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE() * 0.001);
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
return position;
}
@@ -266,22 +266,22 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedByte(); // protocol version
buf.readUnsignedByte(); // version id
- int sequenceNumber = buf.readUnsignedShort();
- int messageId = buf.readUnsignedShort();
- buf.readUnsignedShort(); // length
- int flags = buf.readUnsignedShort();
- buf.readUnsignedShort(); // checksum
+ int sequenceNumber = buf.readUnsignedShortLE();
+ int messageId = buf.readUnsignedShortLE();
+ buf.readUnsignedShortLE(); // length
+ int flags = buf.readUnsignedShortLE();
+ buf.readUnsignedShortLE(); // checksum
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(buf.readUnsignedInt()));
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(buf.readUnsignedIntLE()));
if (deviceSession == null) {
return null;
}
- long timestamp = buf.readUnsignedInt();
+ long timestamp = buf.readUnsignedIntLE();
if ((flags & 0x1) == 0x0) {
sendAcknowledgment(channel, sequenceNumber);
diff --git a/src/org/traccar/protocol/NavisProtocol.java b/src/org/traccar/protocol/NavisProtocol.java
index 771c9d61d..fd306ee9f 100644
--- a/src/org/traccar/protocol/NavisProtocol.java
+++ b/src/org/traccar/protocol/NavisProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,10 +15,9 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
+import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.nio.ByteOrder;
@@ -32,15 +31,14 @@ public class NavisProtocol 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(4 * 1024, 12, 2, 2, 0));
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
+ pipeline.addLast("frameDecoder",
+ new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, 4 * 1024, 12, 2, 2, 0, false));
pipeline.addLast("objectDecoder", new NavisProtocolDecoder(NavisProtocol.this));
}
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
+ });
}
}
diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java
index 6881fb8ed..37001c35b 100644
--- a/src/org/traccar/protocol/NavisProtocolDecoder.java
+++ b/src/org/traccar/protocol/NavisProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 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,18 +15,18 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
-import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.List;
@@ -75,23 +75,23 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
}
}
- private ParseResult parsePosition(DeviceSession deviceSession, ChannelBuffer buf) {
+ private ParseResult parsePosition(DeviceSession deviceSession, ByteBuf buf) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int format;
if (buf.getUnsignedByte(buf.readerIndex()) == 0) {
- format = buf.readUnsignedShort();
+ format = buf.readUnsignedShortLE();
} else {
format = buf.readUnsignedByte();
}
position.set("format", format);
- long index = buf.readUnsignedInt();
+ long index = buf.readUnsignedIntLE();
position.set(Position.KEY_INDEX, index);
- position.set(Position.KEY_EVENT, buf.readUnsignedShort());
+ position.set(Position.KEY_EVENT, buf.readUnsignedShortLE());
buf.skipBytes(6); // event time
@@ -104,33 +104,33 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
if (isFormat(format, F10, F20, F30)) {
- position.set(Position.KEY_OUTPUT, buf.readUnsignedShort());
+ position.set(Position.KEY_OUTPUT, buf.readUnsignedShortLE());
} else if (isFormat(format, F40, F50, F51, F52)) {
position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
}
if (isFormat(format, F10, F20, F30, F40)) {
- position.set(Position.KEY_INPUT, buf.readUnsignedShort());
+ position.set(Position.KEY_INPUT, buf.readUnsignedShortLE());
} else if (isFormat(format, F50, F51, F52)) {
position.set(Position.KEY_INPUT, buf.readUnsignedByte());
}
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
+ position.set(Position.KEY_POWER, buf.readUnsignedShortLE() * 0.001);
+ position.set(Position.KEY_BATTERY, buf.readUnsignedShortLE());
if (isFormat(format, F10, F20, F30)) {
- position.set(Position.PREFIX_TEMP + 1, buf.readShort());
+ position.set(Position.PREFIX_TEMP + 1, buf.readShortLE());
}
if (isFormat(format, F10, F20, F50, F52)) {
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
+ position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE());
+ position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShortLE());
}
// Impulse counters
if (isFormat(format, F20, F50, F51, F52)) {
- buf.readUnsignedInt();
- buf.readUnsignedInt();
+ buf.readUnsignedIntLE();
+ buf.readUnsignedIntLE();
}
if (isFormat(format, F20, F50, F51, F52)) {
@@ -142,30 +142,30 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
.setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte() + 1, buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
- position.setLatitude(buf.readFloat() / Math.PI * 180);
- position.setLongitude(buf.readFloat() / Math.PI * 180);
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloat()));
- position.setCourse(buf.readUnsignedShort());
+ position.setLatitude(buf.readFloatLE() / Math.PI * 180);
+ position.setLongitude(buf.readFloatLE() / Math.PI * 180);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloatLE()));
+ position.setCourse(buf.readUnsignedShortLE());
- position.set(Position.KEY_ODOMETER, buf.readFloat() * 1000);
- position.set(Position.KEY_DISTANCE, buf.readFloat());
+ position.set(Position.KEY_ODOMETER, buf.readFloatLE() * 1000);
+ position.set(Position.KEY_DISTANCE, buf.readFloatLE());
// Segment times
- buf.readUnsignedShort();
- buf.readUnsignedShort();
+ buf.readUnsignedShortLE();
+ buf.readUnsignedShortLE();
}
// Other
if (isFormat(format, F51, F52)) {
- buf.readUnsignedShort();
+ buf.readUnsignedShortLE();
buf.readByte();
- buf.readUnsignedShort();
- buf.readUnsignedShort();
+ buf.readUnsignedShortLE();
+ buf.readUnsignedShortLE();
buf.readByte();
- buf.readUnsignedShort();
- buf.readUnsignedShort();
+ buf.readUnsignedShortLE();
+ buf.readUnsignedShortLE();
buf.readByte();
- buf.readUnsignedShort();
+ buf.readUnsignedShortLE();
}
// Four temperature sensors
@@ -179,12 +179,12 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
return new ParseResult(index, position);
}
- private Object processSingle(DeviceSession deviceSession, Channel channel, ChannelBuffer buf) {
+ private Object processSingle(DeviceSession deviceSession, Channel channel, ByteBuf buf) {
ParseResult result = parsePosition(deviceSession, buf);
- ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 8);
- response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<T", StandardCharsets.US_ASCII));
- response.writeInt((int) result.getId());
+ ByteBuf response = Unpooled.buffer(8);
+ response.writeBytes(Unpooled.copiedBuffer("*<T", StandardCharsets.US_ASCII));
+ response.writeIntLE((int) result.getId());
sendReply(channel, response);
if (result.getPosition().getFixTime() == null) {
@@ -194,7 +194,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
return result.getPosition();
}
- private Object processArray(DeviceSession deviceSession, Channel channel, ChannelBuffer buf) {
+ private Object processArray(DeviceSession deviceSession, Channel channel, ByteBuf buf) {
List<Position> positions = new LinkedList<>();
int count = buf.readUnsignedByte();
@@ -205,8 +205,8 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
}
}
- ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 8);
- response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<A", StandardCharsets.US_ASCII));
+ ByteBuf response = Unpooled.buffer(8);
+ response.writeBytes(Unpooled.copiedBuffer("*<A", StandardCharsets.US_ASCII));
response.writeByte(count);
sendReply(channel, response);
@@ -217,15 +217,15 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
return positions;
}
- private Object processHandshake(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
+ private Object processHandshake(Channel channel, SocketAddress remoteAddress, ByteBuf buf) {
buf.readByte(); // semicolon symbol
if (getDeviceSession(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII)) != null) {
- sendReply(channel, ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<S", StandardCharsets.US_ASCII));
+ sendReply(channel, Unpooled.copiedBuffer("*<S", StandardCharsets.US_ASCII));
}
return null;
}
- private static short checksum(ChannelBuffer buf) {
+ private static short checksum(ByteBuf buf) {
short sum = 0;
for (int i = 0; i < buf.readableBytes(); i++) {
sum ^= buf.getUnsignedByte(i);
@@ -233,17 +233,17 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
return sum;
}
- private void sendReply(Channel channel, ChannelBuffer data) {
- ChannelBuffer header = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 16);
- header.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, prefix, StandardCharsets.US_ASCII));
- header.writeInt((int) deviceUniqueId);
- header.writeInt((int) serverId);
- header.writeShort(data.readableBytes());
+ private void sendReply(Channel channel, ByteBuf data) {
+ ByteBuf header = Unpooled.buffer(16);
+ header.writeBytes(Unpooled.copiedBuffer(prefix, StandardCharsets.US_ASCII));
+ header.writeIntLE((int) deviceUniqueId);
+ header.writeIntLE((int) serverId);
+ header.writeShortLE(data.readableBytes());
header.writeByte(checksum(data));
header.writeByte(checksum(header));
if (channel != null) {
- channel.write(ChannelBuffers.copiedBuffer(header, data));
+ channel.writeAndFlush(new NetworkMessage(Unpooled.copiedBuffer(header, data), channel.remoteAddress()));
}
}
@@ -251,13 +251,13 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
prefix = buf.toString(buf.readerIndex(), 4, StandardCharsets.US_ASCII);
buf.skipBytes(prefix.length()); // prefix @NTC by default
- serverId = buf.readUnsignedInt();
- deviceUniqueId = buf.readUnsignedInt();
- int length = buf.readUnsignedShort();
+ serverId = buf.readUnsignedIntLE();
+ deviceUniqueId = buf.readUnsignedIntLE();
+ int length = buf.readUnsignedShortLE();
buf.skipBytes(2); // header and data XOR checksum
if (length == 0) {
diff --git a/src/org/traccar/protocol/NoranProtocol.java b/src/org/traccar/protocol/NoranProtocol.java
index 7d3dc4852..9cae57b32 100644
--- a/src/org/traccar/protocol/NoranProtocol.java
+++ b/src/org/traccar/protocol/NoranProtocol.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.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 NoranProtocol extends BaseProtocol {
@@ -38,15 +36,13 @@ public class NoranProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer 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 NoranProtocolEncoder());
pipeline.addLast("objectDecoder", new NoranProtocolDecoder(NoranProtocol.this));
}
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
+ });
}
}
diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java
index e10332ece..5e41cd6bc 100644
--- a/src/org/traccar/protocol/NoranProtocolDecoder.java
+++ b/src/org/traccar/protocol/NoranProtocolDecoder.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,18 +15,18 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
-import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -51,24 +51,22 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
- buf.readUnsignedShort(); // length
- int type = buf.readUnsignedShort();
+ buf.readUnsignedShortLE(); // length
+ int type = buf.readUnsignedShortLE();
if (type == MSG_SHAKE_HAND && channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 13);
- response.writeBytes(
- ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n*KW", StandardCharsets.US_ASCII));
+ ByteBuf response = Unpooled.buffer(13);
+ response.writeBytes(Unpooled.copiedBuffer("\r\n*KW", StandardCharsets.US_ASCII));
response.writeByte(0);
- response.writeShort(response.capacity());
- response.writeShort(MSG_SHAKE_HAND_RESPONSE);
+ response.writeShortLE(response.capacity());
+ response.writeShortLE(MSG_SHAKE_HAND_RESPONSE);
response.writeByte(1); // status
- response.writeBytes(
- ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", StandardCharsets.US_ASCII));
+ response.writeBytes(Unpooled.copiedBuffer("\r\n", StandardCharsets.US_ASCII));
- channel.write(response, remoteAddress);
+ channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
} else if (type == MSG_UPLOAD_POSITION || type == MSG_UPLOAD_POSITION_NEW
|| type == MSG_CONTROL_RESPONSE || type == MSG_ALARM) {
@@ -83,8 +81,8 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position(getProtocolName());
if (type == MSG_CONTROL_RESPONSE) {
- buf.readUnsignedInt(); // GIS ip
- buf.readUnsignedInt(); // GIS port
+ buf.readUnsignedIntLE(); // GIS ip
+ buf.readUnsignedIntLE(); // GIS port
}
position.setValid(BitUtil.check(buf.readUnsignedByte(), 0));
@@ -108,17 +106,17 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
}
if (newFormat) {
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedInt()));
- position.setCourse(buf.readFloat());
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedIntLE()));
+ position.setCourse(buf.readFloatLE());
} else {
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- position.setCourse(buf.readUnsignedShort());
+ position.setCourse(buf.readUnsignedShortLE());
}
- position.setLongitude(buf.readFloat());
- position.setLatitude(buf.readFloat());
+ position.setLongitude(buf.readFloatLE());
+ position.setLatitude(buf.readFloatLE());
if (!newFormat) {
- long timeValue = buf.readUnsignedInt();
+ long timeValue = buf.readUnsignedIntLE();
DateBuilder dateBuilder = new DateBuilder()
.setYear((int) BitUtil.from(timeValue, 26))
.setMonth((int) BitUtil.between(timeValue, 22, 26))
@@ -129,7 +127,7 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
position.setTime(dateBuilder.getDate());
}
- ChannelBuffer rawId;
+ ByteBuf rawId;
if (newFormat) {
rawId = buf.readBytes(12);
} else {
@@ -152,8 +150,8 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte());
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
} else if (type == MSG_UPLOAD_POSITION_NEW) {
- position.set(Position.PREFIX_TEMP + 1, buf.readShort());
- position.set(Position.KEY_ODOMETER, buf.readFloat());
+ position.set(Position.PREFIX_TEMP + 1, buf.readShortLE());
+ position.set(Position.KEY_ODOMETER, buf.readFloatLE());
}
return position;
diff --git a/src/org/traccar/protocol/NoranProtocolEncoder.java b/src/org/traccar/protocol/NoranProtocolEncoder.java
index 25b510a73..cb25cc94b 100644
--- a/src/org/traccar/protocol/NoranProtocolEncoder.java
+++ b/src/org/traccar/protocol/NoranProtocolEncoder.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,29 @@
*/
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;
import java.nio.charset.StandardCharsets;
public class NoranProtocolEncoder extends BaseProtocolEncoder {
- private ChannelBuffer encodeContent(String content) {
+ private ByteBuf encodeContent(String content) {
- ChannelBuffer buf = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, 12 + 56);
+ ByteBuf buf = Unpooled.buffer(12 + 56);
- buf.writeBytes(
- ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n*KW", StandardCharsets.US_ASCII));
+ buf.writeBytes(Unpooled.copiedBuffer("\r\n*KW", StandardCharsets.US_ASCII));
buf.writeByte(0);
- buf.writeShort(buf.capacity());
- buf.writeShort(NoranProtocolDecoder.MSG_CONTROL);
+ buf.writeShortLE(buf.capacity());
+ buf.writeShortLE(NoranProtocolDecoder.MSG_CONTROL);
buf.writeInt(0); // gis ip
- buf.writeShort(0); // gis port
+ buf.writeShortLE(0); // gis port
buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
buf.writerIndex(buf.writerIndex() + 50 - content.length());
- buf.writeBytes(
- ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", StandardCharsets.US_ASCII));
+ buf.writeBytes(Unpooled.copiedBuffer("\r\n", StandardCharsets.US_ASCII));
return buf;
}
diff --git a/src/org/traccar/protocol/NvsFrameDecoder.java b/src/org/traccar/protocol/NvsFrameDecoder.java
index 598bb1e4c..4fa1cab1c 100644
--- a/src/org/traccar/protocol/NvsFrameDecoder.java
+++ b/src/org/traccar/protocol/NvsFrameDecoder.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,18 +15,16 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import org.traccar.BaseFrameDecoder;
-public class NvsFrameDecoder extends FrameDecoder {
+public class NvsFrameDecoder 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 + 2) {
return null;
diff --git a/src/org/traccar/protocol/NvsProtocol.java b/src/org/traccar/protocol/NvsProtocol.java
index fdcb2bbcf..aaf447120 100644
--- a/src/org/traccar/protocol/NvsProtocol.java
+++ b/src/org/traccar/protocol/NvsProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,9 +15,8 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.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 NvsProtocol 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 NvsFrameDecoder());
pipeline.addLast("objectDecoder", new NvsProtocolDecoder(NvsProtocol.this));
}
diff --git a/src/org/traccar/protocol/NvsProtocolDecoder.java b/src/org/traccar/protocol/NvsProtocolDecoder.java
index db8347d3c..46909ff0c 100644
--- a/src/org/traccar/protocol/NvsProtocolDecoder.java
+++ b/src/org/traccar/protocol/NvsProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,11 +15,12 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
@@ -35,9 +36,10 @@ public class NvsProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private void sendResponse(Channel channel, String response) {
+ private void sendResponse(Channel channel, SocketAddress remoteAddress, String response) {
if (channel != null) {
- channel.write(ChannelBuffers.copiedBuffer(response, StandardCharsets.US_ASCII));
+ channel.writeAndFlush(new NetworkMessage(
+ Unpooled.copiedBuffer(response, StandardCharsets.US_ASCII), remoteAddress));
}
}
@@ -45,7 +47,7 @@ public class NvsProtocolDecoder 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()) == 0) {
@@ -55,9 +57,9 @@ public class NvsProtocolDecoder extends BaseProtocolDecoder {
String imei = buf.toString(buf.readerIndex(), 15, StandardCharsets.US_ASCII);
if (getDeviceSession(channel, remoteAddress, imei) != null) {
- sendResponse(channel, "OK");
+ sendResponse(channel, remoteAddress, "OK");
} else {
- sendResponse(channel, "NO01");
+ sendResponse(channel, remoteAddress, "NO01");
}
} else {