aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/WialonProtocol.java16
-rw-r--r--src/org/traccar/protocol/WialonProtocolDecoder.java19
-rw-r--r--src/org/traccar/protocol/WondexFrameDecoder.java30
-rw-r--r--src/org/traccar/protocol/WondexProtocol.java17
-rw-r--r--src/org/traccar/protocol/WondexProtocolDecoder.java8
5 files changed, 48 insertions, 42 deletions
diff --git a/src/org/traccar/protocol/WialonProtocol.java b/src/org/traccar/protocol/WialonProtocol.java
index 02da154e2..119d9899b 100644
--- a/src/org/traccar/protocol/WialonProtocol.java
+++ b/src/org/traccar/protocol/WialonProtocol.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,16 +15,16 @@
*/
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 org.traccar.BaseProtocol;
import org.traccar.Context;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import org.traccar.model.Command;
+import io.netty.handler.codec.LineBasedFrameDecoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
+
import java.nio.charset.StandardCharsets;
import java.util.List;
@@ -41,9 +41,9 @@ public class WialonProtocol 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(4 * 1024));
pipeline.addLast("stringEncoder", new StringEncoder());
boolean utf8 = Context.getConfig().getBoolean(getName() + ".utf8");
diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java
index 5bc3e9972..805c12cf9 100644
--- a/src/org/traccar/protocol/WialonProtocolDecoder.java
+++ b/src/org/traccar/protocol/WialonProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,9 +15,10 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
@@ -57,14 +58,14 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
.groupEnd("?")
.compile();
- private void sendResponse(Channel channel, String prefix, Integer number) {
+ private void sendResponse(Channel channel, SocketAddress remoteAddress, String prefix, Integer number) {
if (channel != null) {
StringBuilder response = new StringBuilder(prefix);
if (number != null) {
response.append(number);
}
response.append("\r\n");
- channel.write(response.toString());
+ channel.writeAndFlush(new NetworkMessage(response.toString(), remoteAddress));
}
}
@@ -140,12 +141,12 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
String imei = values[0].indexOf('.') >= 0 ? values[1] : values[0];
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession != null) {
- sendResponse(channel, "#AL#", 1);
+ sendResponse(channel, remoteAddress, "#AL#", 1);
}
} else if (sentence.startsWith("#P#")) {
- sendResponse(channel, "#AP#", null); // heartbeat
+ sendResponse(channel, remoteAddress, "#AP#", null); // heartbeat
} else if (sentence.startsWith("#SD#") || sentence.startsWith("#D#")) {
@@ -153,7 +154,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
channel, remoteAddress, sentence.substring(sentence.indexOf('#', 1) + 1));
if (position != null) {
- sendResponse(channel, "#AD#", 1);
+ sendResponse(channel, remoteAddress, "#AD#", 1);
return position;
}
@@ -170,7 +171,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
}
}
- sendResponse(channel, "#AB#", messages.length);
+ sendResponse(channel, remoteAddress, "#AB#", messages.length);
if (!positions.isEmpty()) {
return positions;
}
@@ -183,7 +184,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, new Date());
position.setValid(false);
position.set(Position.KEY_RESULT, sentence.substring(sentence.indexOf('#', 1) + 1));
- sendResponse(channel, "#AM#", 1);
+ sendResponse(channel, remoteAddress, "#AM#", 1);
return position;
}
}
diff --git a/src/org/traccar/protocol/WondexFrameDecoder.java b/src/org/traccar/protocol/WondexFrameDecoder.java
index db65ff80f..c17bcd078 100644
--- a/src/org/traccar/protocol/WondexFrameDecoder.java
+++ b/src/org/traccar/protocol/WondexFrameDecoder.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,19 +15,24 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-import org.traccar.helper.StringFinder;
+import java.nio.charset.StandardCharsets;
-public class WondexFrameDecoder extends FrameDecoder {
+import org.traccar.BaseFrameDecoder;
+import org.traccar.NetworkMessage;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+
+public class WondexFrameDecoder extends BaseFrameDecoder {
private static final int KEEP_ALIVE_LENGTH = 8;
@Override
protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
+ ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
if (buf.readableBytes() < KEEP_ALIVE_LENGTH) {
return null;
@@ -36,17 +41,18 @@ public class WondexFrameDecoder extends FrameDecoder {
if (buf.getUnsignedByte(buf.readerIndex()) == 0xD0) {
// Send response
- ChannelBuffer frame = buf.readBytes(KEEP_ALIVE_LENGTH);
+ ByteBuf frame = buf.readBytes(KEEP_ALIVE_LENGTH);
if (channel != null) {
- channel.write(frame);
+ channel.writeAndFlush(new NetworkMessage(frame, channel.remoteAddress()));
}
return frame;
} else {
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n"));
+ ByteBuf delimiter = Unpooled.wrappedBuffer("\r\n".getBytes(StandardCharsets.US_ASCII));
+ int index = ByteBufUtil.indexOf(delimiter, buf);
if (index != -1) {
- ChannelBuffer frame = buf.readBytes(index - buf.readerIndex());
+ ByteBuf frame = buf.readBytes(index - buf.readerIndex());
buf.skipBytes(2);
return frame;
}
diff --git a/src/org/traccar/protocol/WondexProtocol.java b/src/org/traccar/protocol/WondexProtocol.java
index ef25265aa..a43c8b06a 100644
--- a/src/org/traccar/protocol/WondexProtocol.java
+++ b/src/org/traccar/protocol/WondexProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,14 +15,13 @@
*/
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 org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import org.traccar.model.Command;
+import io.netty.handler.codec.string.StringEncoder;
+
import java.util.List;
public class WondexProtocol extends BaseProtocol {
@@ -41,18 +40,18 @@ public class WondexProtocol 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 WondexFrameDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("objectEncoder", new WondexProtocolEncoder());
pipeline.addLast("objectDecoder", new WondexProtocolDecoder(WondexProtocol.this));
}
});
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
+ serverList.add(new TrackerServer(true, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("objectEncoder", new WondexProtocolEncoder());
pipeline.addLast("objectDecoder", new WondexProtocolDecoder(WondexProtocol.this));
diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java
index a0fa436e4..7845cb26a 100644
--- a/src/org/traccar/protocol/WondexProtocolDecoder.java
+++ b/src/org/traccar/protocol/WondexProtocolDecoder.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,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.Parser;
@@ -60,7 +60,7 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
if (buf.getUnsignedByte(0) == 0xD0) {