aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-06-06 16:51:47 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-06-06 16:51:47 +1200
commit562535fd538e7b05b6fe96c0f56eb2ec0ae1fd0e (patch)
tree44fa438ebc6be56ede7307b18a2116fff14d8cc8 /src/org
parent9c99076dc2416c4e0725007af0e5f2f2f444c05c (diff)
downloadtrackermap-server-562535fd538e7b05b6fe96c0f56eb2ec0ae1fd0e.tar.gz
trackermap-server-562535fd538e7b05b6fe96c0f56eb2ec0ae1fd0e.tar.bz2
trackermap-server-562535fd538e7b05b6fe96c0f56eb2ec0ae1fd0e.zip
Migrate more protocols
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/protocol/BceFrameDecoder.java20
-rw-r--r--src/org/traccar/protocol/BceProtocol.java14
-rw-r--r--src/org/traccar/protocol/BceProtocolDecoder.java42
-rw-r--r--src/org/traccar/protocol/BlackKiteProtocol.java16
-rw-r--r--src/org/traccar/protocol/BlackKiteProtocolDecoder.java48
-rw-r--r--src/org/traccar/protocol/BoxProtocol.java13
-rw-r--r--src/org/traccar/protocol/BoxProtocolDecoder.java7
-rw-r--r--src/org/traccar/protocol/CalAmpProtocol.java9
-rw-r--r--src/org/traccar/protocol/CalAmpProtocolDecoder.java20
-rw-r--r--src/org/traccar/protocol/CarTrackProtocol.java13
-rw-r--r--src/org/traccar/protocol/CarTrackProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/CarcellProtocol.java13
-rw-r--r--src/org/traccar/protocol/CarcellProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/CarscopProtocol.java13
-rw-r--r--src/org/traccar/protocol/CarscopProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/CastelProtocol.java26
-rw-r--r--src/org/traccar/protocol/CastelProtocolDecoder.java157
-rw-r--r--src/org/traccar/protocol/CastelProtocolEncoder.java17
-rw-r--r--src/org/traccar/protocol/CautelaProtocol.java13
-rw-r--r--src/org/traccar/protocol/CautelaProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/CellocatorFrameDecoder.java28
-rw-r--r--src/org/traccar/protocol/CellocatorProtocol.java24
-rw-r--r--src/org/traccar/protocol/CellocatorProtocolDecoder.java44
-rw-r--r--src/org/traccar/protocol/CellocatorProtocolEncoder.java18
-rw-r--r--src/org/traccar/protocol/CguardProtocol.java15
-rw-r--r--src/org/traccar/protocol/CguardProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/CityeasyProtocol.java11
-rw-r--r--src/org/traccar/protocol/CityeasyProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/CityeasyProtocolEncoder.java14
-rw-r--r--src/org/traccar/protocol/ContinentalProtocol.java9
-rw-r--r--src/org/traccar/protocol/ContinentalProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/CradlepointProtocol.java15
-rw-r--r--src/org/traccar/protocol/CradlepointProtocolDecoder.java2
33 files changed, 308 insertions, 349 deletions
diff --git a/src/org/traccar/protocol/BceFrameDecoder.java b/src/org/traccar/protocol/BceFrameDecoder.java
index 4fac79f85..15ae40148 100644
--- a/src/org/traccar/protocol/BceFrameDecoder.java
+++ b/src/org/traccar/protocol/BceFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,18 +15,18 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import org.traccar.BaseFrameDecoder;
-public class BceFrameDecoder extends FrameDecoder {
+public class BceFrameDecoder extends BaseFrameDecoder {
private static final int HANDSHAKE_LENGTH = 7; // "#BCE#\r\n"
private boolean header = true;
- private static byte checksum(ChannelBuffer buf, int end) {
+ private static byte checksum(ByteBuf buf, int end) {
byte result = 0;
for (int i = 0; i < end; i++) {
result += buf.getByte(buf.readerIndex() + i);
@@ -36,9 +36,7 @@ public class BceFrameDecoder extends FrameDecoder {
@Override
protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
+ ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
if (header && buf.readableBytes() >= HANDSHAKE_LENGTH) {
buf.skipBytes(HANDSHAKE_LENGTH);
@@ -48,7 +46,7 @@ public class BceFrameDecoder extends FrameDecoder {
int end = 8; // IMEI
while (buf.readableBytes() >= end + 2 + 1 + 1 + 1) {
- end += buf.getUnsignedShort(buf.readerIndex() + end) + 2;
+ end += buf.getUnsignedShortLE(buf.readerIndex() + end) + 2;
if (buf.readableBytes() > end && checksum(buf, end) == buf.getByte(buf.readerIndex() + end)) {
return buf.readBytes(end + 1);
diff --git a/src/org/traccar/protocol/BceProtocol.java b/src/org/traccar/protocol/BceProtocol.java
index 5374fd0e1..880a4df70 100644
--- a/src/org/traccar/protocol/BceProtocol.java
+++ b/src/org/traccar/protocol/BceProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,10 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
-import java.nio.ByteOrder;
import java.util.List;
public class BceProtocol extends BaseProtocol {
@@ -31,15 +29,13 @@ public class BceProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("frameDecoder", new BceFrameDecoder());
pipeline.addLast("objectDecoder", new BceProtocolDecoder(BceProtocol.this));
}
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
+ });
}
}
diff --git a/src/org/traccar/protocol/BceProtocolDecoder.java b/src/org/traccar/protocol/BceProtocolDecoder.java
index f48757a4f..301be7847 100644
--- a/src/org/traccar/protocol/BceProtocolDecoder.java
+++ b/src/org/traccar/protocol/BceProtocolDecoder.java
@@ -15,11 +15,12 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.BitUtil;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.CellTower;
@@ -27,7 +28,6 @@ import org.traccar.model.Network;
import org.traccar.model.Position;
import java.net.SocketAddress;
-import java.nio.ByteOrder;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@@ -50,9 +50,9 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
- String imei = String.format("%015d", buf.readLong());
+ String imei = String.format("%015d", buf.readLongLE());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
@@ -62,7 +62,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
while (buf.readableBytes() > 1) {
- int dataEnd = buf.readUnsignedShort() + buf.readerIndex();
+ int dataEnd = buf.readUnsignedShortLE() + buf.readerIndex();
int type = buf.readUnsignedByte();
int confirmKey = buf.readUnsignedByte() & 0x7F;
@@ -73,7 +73,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
int structEnd = buf.readUnsignedByte() + buf.readerIndex();
- long time = buf.readUnsignedInt();
+ long time = buf.readUnsignedIntLE();
if ((time & 0x0f) == DATA_TYPE) {
time = time >> 4 << 1;
@@ -84,7 +84,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
int mask;
List<Integer> masks = new LinkedList<>();
do {
- mask = buf.readUnsignedShort();
+ mask = buf.readUnsignedShortLE();
masks.add(mask);
} while (BitUtil.check(mask, 15));
@@ -92,8 +92,8 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
if (BitUtil.check(mask, 0)) {
position.setValid(true);
- position.setLongitude(buf.readFloat());
- position.setLatitude(buf.readFloat());
+ position.setLongitude(buf.readFloatLE());
+ position.setLatitude(buf.readFloatLE());
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
int status = buf.readUnsignedByte();
@@ -101,18 +101,18 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_HDOP, BitUtil.from(status, 4));
position.setCourse(buf.readUnsignedByte() * 2);
- position.setAltitude(buf.readUnsignedShort());
+ position.setAltitude(buf.readUnsignedShortLE());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
}
if (BitUtil.check(mask, 1)) {
- position.set(Position.KEY_INPUT, buf.readUnsignedShort());
+ position.set(Position.KEY_INPUT, buf.readUnsignedShortLE());
}
for (int i = 1; i <= 8; i++) {
if (BitUtil.check(mask, i + 1)) {
- position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort());
+ position.set(Position.PREFIX_ADC + i, buf.readUnsignedShortLE());
}
}
@@ -131,8 +131,8 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
if (BitUtil.check(mask, 14)) {
position.setNetwork(new Network(CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedByte(),
- buf.readUnsignedShort(), buf.readUnsignedShort(),
+ buf.readUnsignedShortLE(), buf.readUnsignedByte(),
+ buf.readUnsignedShortLE(), buf.readUnsignedShortLE(),
buf.readUnsignedByte())));
buf.readUnsignedByte();
}
@@ -147,9 +147,9 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
// Send response
if (type == MSG_ASYNC_STACK && channel != null) {
- ChannelBuffer response = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, 8 + 2 + 2 + 1);
- response.writeLong(Long.parseLong(imei));
- response.writeShort(2);
+ ByteBuf response = Unpooled.buffer(8 + 2 + 2 + 1);
+ response.writeLongLE(Long.parseLong(imei));
+ response.writeShortLE(2);
response.writeByte(MSG_STACK_COFIRM);
response.writeByte(confirmKey);
@@ -159,7 +159,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
}
response.writeByte(checksum);
- channel.write(response);
+ channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
}
diff --git a/src/org/traccar/protocol/BlackKiteProtocol.java b/src/org/traccar/protocol/BlackKiteProtocol.java
index db32f5328..3e0b918f8 100644
--- a/src/org/traccar/protocol/BlackKiteProtocol.java
+++ b/src/org/traccar/protocol/BlackKiteProtocol.java
@@ -1,6 +1,6 @@
/*
* Copyright 2015 Vijay Kumar (vijaykumar@zilogic.com)
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,10 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
-import java.nio.ByteOrder;
import java.util.List;
public class BlackKiteProtocol extends BaseProtocol {
@@ -32,15 +30,13 @@ public class BlackKiteProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new GalileoFrameDecoder());
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
+ // pipeline.addLast("frameDecoder", new GalileoFrameDecoder()); TODO uncomment
pipeline.addLast("objectDecoder", new BlackKiteProtocolDecoder(BlackKiteProtocol.this));
}
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
+ });
}
}
diff --git a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
index 7fc39fc7c..9701a8059 100644
--- a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
+++ b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
* Copyright 2015 Vijay Kumar (vijaykumar@zilogic.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,16 +16,16 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.BitUtil;
import org.traccar.model.Position;
import java.net.SocketAddress;
-import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import java.util.HashSet;
@@ -56,11 +56,11 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder {
private static final int TAG_XT3 = 0x62;
private void sendReply(Channel channel, int checksum) {
- ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 3);
+ ByteBuf reply = Unpooled.buffer(3);
reply.writeByte(0x02);
- reply.writeShort((short) checksum);
+ reply.writeShortLE((short) checksum);
if (channel != null) {
- channel.write(reply);
+ channel.writeAndFlush(new NetworkMessage(reply, channel.remoteAddress()));
}
}
@@ -68,10 +68,10 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
buf.readUnsignedByte(); // header
- int length = (buf.readUnsignedShort() & 0x7fff) + 3;
+ int length = (buf.readUnsignedShortLE() & 0x7fff) + 3;
List<Position> positions = new LinkedList<>();
Set<Integer> tags = new HashSet<>();
@@ -99,27 +99,27 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder {
break;
case TAG_DATE:
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
+ position.setTime(new Date(buf.readUnsignedIntLE() * 1000));
break;
case TAG_COORDINATES:
hasLocation = true;
position.setValid((buf.readUnsignedByte() & 0xf0) == 0x00);
- position.setLatitude(buf.readInt() / 1000000.0);
- position.setLongitude(buf.readInt() / 1000000.0);
+ position.setLatitude(buf.readIntLE() / 1000000.0);
+ position.setLongitude(buf.readIntLE() / 1000000.0);
break;
case TAG_SPEED_COURSE:
- position.setSpeed(buf.readUnsignedShort() * 0.0539957);
- position.setCourse(buf.readUnsignedShort() * 0.1);
+ position.setSpeed(buf.readUnsignedShortLE() * 0.0539957);
+ position.setCourse(buf.readUnsignedShortLE() * 0.1);
break;
case TAG_ALTITUDE:
- position.setAltitude(buf.readShort());
+ position.setAltitude(buf.readShortLE());
break;
case TAG_STATUS:
- int status = buf.readUnsignedShort();
+ int status = buf.readUnsignedShortLE();
position.set(Position.KEY_IGNITION, BitUtil.check(status, 9));
if (BitUtil.check(status, 15)) {
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
@@ -128,33 +128,33 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder {
break;
case TAG_DIGITAL_INPUTS:
- int input = buf.readUnsignedShort();
+ int input = buf.readUnsignedShortLE();
for (int i = 0; i < 16; i++) {
position.set(Position.PREFIX_IO + (i + 1), BitUtil.check(input, i));
}
break;
case TAG_DIGITAL_OUTPUTS:
- int output = buf.readUnsignedShort();
+ int output = buf.readUnsignedShortLE();
for (int i = 0; i < 16; i++) {
position.set(Position.PREFIX_IO + (i + 17), BitUtil.check(output, i));
}
break;
case TAG_INPUT_VOLTAGE1:
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort() / 1000.0);
+ position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE() / 1000.0);
break;
case TAG_INPUT_VOLTAGE2:
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort() / 1000.0);
+ position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShortLE() / 1000.0);
break;
case TAG_INPUT_VOLTAGE3:
- position.set(Position.PREFIX_ADC + 3, buf.readUnsignedShort() / 1000.0);
+ position.set(Position.PREFIX_ADC + 3, buf.readUnsignedShortLE() / 1000.0);
break;
case TAG_INPUT_VOLTAGE4:
- position.set(Position.PREFIX_ADC + 4, buf.readUnsignedShort() / 1000.0);
+ position.set(Position.PREFIX_ADC + 4, buf.readUnsignedShortLE() / 1000.0);
break;
case TAG_XT1:
@@ -178,7 +178,7 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- sendReply(channel, buf.readUnsignedShort());
+ sendReply(channel, buf.readUnsignedShortLE());
for (Position p : positions) {
p.setDeviceId(deviceSession.getDeviceId());
diff --git a/src/org/traccar/protocol/BoxProtocol.java b/src/org/traccar/protocol/BoxProtocol.java
index 36e7790f0..6e76ee635 100644
--- a/src/org/traccar/protocol/BoxProtocol.java
+++ b/src/org/traccar/protocol/BoxProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,11 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.CharacterDelimiterFrameDecoder;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -33,9 +32,9 @@ public class BoxProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\r'));
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("stringDecoder", new StringDecoder());
diff --git a/src/org/traccar/protocol/BoxProtocolDecoder.java b/src/org/traccar/protocol/BoxProtocolDecoder.java
index 63238bcef..ef18f1555 100644
--- a/src/org/traccar/protocol/BoxProtocolDecoder.java
+++ b/src/org/traccar/protocol/BoxProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2014 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,9 +15,10 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
@@ -62,7 +63,7 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder {
} else if (sentence.startsWith("E,")) {
if (channel != null) {
- channel.write("A," + sentence.substring(2) + "\r");
+ channel.write(new NetworkMessage("A," + sentence.substring(2) + "\r", remoteAddress));
}
} else if (sentence.startsWith("L,")) {
diff --git a/src/org/traccar/protocol/CalAmpProtocol.java b/src/org/traccar/protocol/CalAmpProtocol.java
index a3577f10c..29cb2974f 100644
--- a/src/org/traccar/protocol/CalAmpProtocol.java
+++ b/src/org/traccar/protocol/CalAmpProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,9 +15,8 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -30,9 +29,9 @@ public class CalAmpProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
+ serverList.add(new TrackerServer(true, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("objectDecoder", new CalAmpProtocolDecoder(CalAmpProtocol.this));
}
});
diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
index f717d3c5d..9e9bd1336 100644
--- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java
+++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,11 +15,13 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.BitUtil;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
@@ -52,7 +54,7 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
private void sendResponse(Channel channel, SocketAddress remoteAddress, int type, int index, int result) {
if (channel != null) {
- ChannelBuffer response = ChannelBuffers.directBuffer(10);
+ ByteBuf response = Unpooled.buffer(10);
response.writeByte(SERVICE_RESPONSE);
response.writeByte(MSG_ACK);
response.writeShort(index);
@@ -60,11 +62,11 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
response.writeByte(result);
response.writeByte(0);
response.writeMedium(0);
- channel.write(response, remoteAddress);
+ channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
}
- private Position decodePosition(DeviceSession deviceSession, int type, ChannelBuffer buf) {
+ private Position decodePosition(DeviceSession deviceSession, int type, ByteBuf buf) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
@@ -143,14 +145,14 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
if (BitUtil.check(buf.getByte(buf.readerIndex()), 7)) {
int content = buf.readUnsignedByte();
if (BitUtil.check(content, 0)) {
- String id = ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte()));
+ String id = ByteBufUtil.hexDump(buf.readBytes(buf.readUnsignedByte()));
getDeviceSession(channel, remoteAddress, id);
}
diff --git a/src/org/traccar/protocol/CarTrackProtocol.java b/src/org/traccar/protocol/CarTrackProtocol.java
index d235c92be..2ac6598a4 100644
--- a/src/org/traccar/protocol/CarTrackProtocol.java
+++ b/src/org/traccar/protocol/CarTrackProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,11 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.CharacterDelimiterFrameDecoder;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -33,9 +32,9 @@ public class CarTrackProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "##"));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
diff --git a/src/org/traccar/protocol/CarTrackProtocolDecoder.java b/src/org/traccar/protocol/CarTrackProtocolDecoder.java
index 94215379d..87c4ae345 100644
--- a/src/org/traccar/protocol/CarTrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/CarTrackProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2014 - 2018 Anton Tananaev (anton@traccar.org)
* Copyright 2014 Rohit
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,7 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.DateBuilder;
diff --git a/src/org/traccar/protocol/CarcellProtocol.java b/src/org/traccar/protocol/CarcellProtocol.java
index c9fedad65..40ecfbbe7 100644
--- a/src/org/traccar/protocol/CarcellProtocol.java
+++ b/src/org/traccar/protocol/CarcellProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,12 +17,11 @@ package org.traccar.protocol;
import java.util.List;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.CharacterDelimiterFrameDecoder;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import org.traccar.model.Command;
@@ -37,9 +36,9 @@ public class CarcellProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\r'));
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("stringDecoder", new StringDecoder());
diff --git a/src/org/traccar/protocol/CarcellProtocolDecoder.java b/src/org/traccar/protocol/CarcellProtocolDecoder.java
index 52b777b81..a4da7982e 100644
--- a/src/org/traccar/protocol/CarcellProtocolDecoder.java
+++ b/src/org/traccar/protocol/CarcellProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@ package org.traccar.protocol;
import java.net.SocketAddress;
import java.util.regex.Pattern;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.Parser;
diff --git a/src/org/traccar/protocol/CarscopProtocol.java b/src/org/traccar/protocol/CarscopProtocol.java
index 01a754027..c52b025bc 100644
--- a/src/org/traccar/protocol/CarscopProtocol.java
+++ b/src/org/traccar/protocol/CarscopProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,11 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.CharacterDelimiterFrameDecoder;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -33,9 +32,9 @@ public class CarscopProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '^'));
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("stringDecoder", new StringDecoder());
diff --git a/src/org/traccar/protocol/CarscopProtocolDecoder.java b/src/org/traccar/protocol/CarscopProtocolDecoder.java
index 7f9dcc3b7..d8634b512 100644
--- a/src/org/traccar/protocol/CarscopProtocolDecoder.java
+++ b/src/org/traccar/protocol/CarscopProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.DateBuilder;
diff --git a/src/org/traccar/protocol/CastelProtocol.java b/src/org/traccar/protocol/CastelProtocol.java
index d5ba5cd55..3e3c5699e 100644
--- a/src/org/traccar/protocol/CastelProtocol.java
+++ b/src/org/traccar/protocol/CastelProtocol.java
@@ -15,15 +15,12 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
+import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import org.traccar.model.Command;
-import java.nio.ByteOrder;
import java.util.List;
public class CastelProtocol extends BaseProtocol {
@@ -37,26 +34,21 @@ public class CastelProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0));
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
+ pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0)); // TODO LE frame decoder
pipeline.addLast("objectEncoder", new CastelProtocolEncoder());
pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this));
}
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
-
- server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
+ });
+ serverList.add(new TrackerServer(true, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("objectEncoder", new CastelProtocolEncoder());
pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this));
}
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
+ });
}
}
diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java
index 2ac79f9cf..296309989 100644
--- a/src/org/traccar/protocol/CastelProtocolDecoder.java
+++ b/src/org/traccar/protocol/CastelProtocolDecoder.java
@@ -15,11 +15,13 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.Checksum;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.ObdDecoder;
@@ -29,7 +31,6 @@ import org.traccar.model.Network;
import org.traccar.model.Position;
import java.net.SocketAddress;
-import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.LinkedList;
@@ -100,7 +101,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
public static final short MSG_CC_PETROL_CONTROL = 0x4583;
public static final short MSG_CC_HEARTBEAT_RESPONSE = (short) 0x8206;
- private Position readPosition(DeviceSession deviceSession, ChannelBuffer buf) {
+ private Position readPosition(DeviceSession deviceSession, ByteBuf buf) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
@@ -110,10 +111,10 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
.setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
- double lat = buf.readUnsignedInt() / 3600000.0;
- double lon = buf.readUnsignedInt() / 3600000.0;
- position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShort()));
- position.setCourse(buf.readUnsignedShort() * 0.1);
+ double lat = buf.readUnsignedIntLE() / 3600000.0;
+ double lon = buf.readUnsignedIntLE() / 3600000.0;
+ position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShortLE()));
+ position.setCourse(buf.readUnsignedShortLE() * 0.1);
int flags = buf.readUnsignedByte();
if ((flags & 0x02) == 0) {
@@ -140,13 +141,13 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private void decodeObd(Position position, ChannelBuffer buf, boolean groups) {
+ private void decodeObd(Position position, ByteBuf buf, boolean groups) {
int count = buf.readUnsignedByte();
int[] pids = new int[count];
for (int i = 0; i < count; i++) {
- pids[i] = buf.readUnsignedShort() & 0xff;
+ pids[i] = buf.readUnsignedShortLE() & 0xff;
}
if (groups) {
@@ -161,10 +162,10 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
value = buf.readUnsignedByte();
break;
case 2:
- value = buf.readUnsignedShort();
+ value = buf.readUnsignedShortLE();
break;
case 4:
- value = buf.readInt();
+ value = buf.readIntLE();
break;
default:
value = 0;
@@ -174,21 +175,21 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
}
}
- private void decodeStat(Position position, ChannelBuffer buf) {
+ private void decodeStat(Position position, ByteBuf buf) {
- buf.readUnsignedInt(); // ACC ON time
- buf.readUnsignedInt(); // UTC time
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
- position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt());
- buf.readUnsignedShort(); // current fuel consumption
- position.set(Position.KEY_STATUS, buf.readUnsignedInt());
+ buf.readUnsignedIntLE(); // ACC ON time
+ buf.readUnsignedIntLE(); // UTC time
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
+ position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedIntLE());
+ position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedIntLE());
+ buf.readUnsignedShortLE(); // current fuel consumption
+ position.set(Position.KEY_STATUS, buf.readUnsignedIntLE());
buf.skipBytes(8);
}
private void sendResponse(
Channel channel, SocketAddress remoteAddress,
- int version, ChannelBuffer id, short type, ChannelBuffer content) {
+ int version, ByteBuf id, short type, ByteBuf content) {
if (channel != null) {
int length = 2 + 2 + 1 + id.readableBytes() + 2 + 2 + 2;
@@ -196,41 +197,41 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
length += content.readableBytes();
}
- ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, length);
+ ByteBuf response = Unpooled.buffer(length);
response.writeByte('@'); response.writeByte('@');
- response.writeShort(length);
+ response.writeShortLE(length);
response.writeByte(version);
response.writeBytes(id);
- response.writeShort(ChannelBuffers.swapShort(type));
+ response.writeShort(type);
if (content != null) {
response.writeBytes(content);
}
- response.writeShort(
- Checksum.crc16(Checksum.CRC16_X25, response.toByteBuffer(0, response.writerIndex())));
+ response.writeShortLE(
+ Checksum.crc16(Checksum.CRC16_X25, response.nioBuffer(0, response.writerIndex())));
response.writeByte(0x0D); response.writeByte(0x0A);
- channel.write(response, remoteAddress);
+ channel.write(new NetworkMessage(response, remoteAddress));
}
}
private void sendResponse(
- Channel channel, SocketAddress remoteAddress, ChannelBuffer id, short type) {
+ Channel channel, SocketAddress remoteAddress, ByteBuf id, short type) {
if (channel != null) {
int length = 2 + 2 + id.readableBytes() + 2 + 4 + 8 + 2 + 2;
- ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, length);
+ ByteBuf response = Unpooled.buffer(length);
response.writeByte('@'); response.writeByte('@');
- response.writeShort(length);
+ response.writeShortLE(length);
response.writeBytes(id);
- response.writeShort(ChannelBuffers.swapShort(type));
- response.writeInt(0);
+ response.writeShort(type);
+ response.writeIntLE(0);
for (int i = 0; i < 8; i++) {
response.writeByte(0xff);
}
- response.writeShort(
- Checksum.crc16(Checksum.CRC16_X25, response.toByteBuffer(0, response.writerIndex())));
+ response.writeShortLE(
+ Checksum.crc16(Checksum.CRC16_X25, response.nioBuffer(0, response.writerIndex())));
response.writeByte(0x0D); response.writeByte(0x0A);
- channel.write(response, remoteAddress);
+ channel.write(new NetworkMessage(response, remoteAddress));
}
}
@@ -284,8 +285,8 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
}
private Object decodeSc(
- Channel channel, SocketAddress remoteAddress, ChannelBuffer buf,
- int version, ChannelBuffer id, short type, DeviceSession deviceSession) {
+ Channel channel, SocketAddress remoteAddress, ByteBuf buf,
+ int version, ByteBuf id, short type, DeviceSession deviceSession) {
if (type == MSG_SC_HEARTBEAT) {
@@ -295,28 +296,28 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
|| type == MSG_SC_ALARM || type == MSG_SC_CURRENT_LOCATION || type == MSG_SC_FUEL) {
if (type == MSG_SC_LOGIN) {
- ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 10);
- response.writeInt(0xFFFFFFFF);
- response.writeShort(0);
- response.writeInt((int) (System.currentTimeMillis() / 1000));
+ ByteBuf response = Unpooled.buffer(10);
+ response.writeIntLE(0xFFFFFFFF);
+ response.writeShortLE(0);
+ response.writeIntLE((int) (System.currentTimeMillis() / 1000));
sendResponse(channel, remoteAddress, version, id, MSG_SC_LOGIN_RESPONSE, response);
}
if (type == MSG_SC_GPS) {
buf.readUnsignedByte(); // historical
} else if (type == MSG_SC_ALARM) {
- buf.readUnsignedInt(); // alarm
+ buf.readUnsignedIntLE(); // alarm
} else if (type == MSG_SC_CURRENT_LOCATION) {
- buf.readUnsignedShort();
+ buf.readUnsignedShortLE();
}
- buf.readUnsignedInt(); // ACC ON time
- buf.readUnsignedInt(); // UTC time
- long odometer = buf.readUnsignedInt();
- long tripOdometer = buf.readUnsignedInt();
- long fuelConsumption = buf.readUnsignedInt();
- buf.readUnsignedShort(); // current fuel consumption
- long status = buf.readUnsignedInt();
+ buf.readUnsignedIntLE(); // ACC ON time
+ buf.readUnsignedIntLE(); // UTC time
+ long odometer = buf.readUnsignedIntLE();
+ long tripOdometer = buf.readUnsignedIntLE();
+ long fuelConsumption = buf.readUnsignedIntLE();
+ buf.readUnsignedShortLE(); // current fuel consumption
+ long status = buf.readUnsignedIntLE();
buf.skipBytes(8);
int count = buf.readUnsignedByte();
@@ -340,13 +341,13 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
for (Position position : positions) {
decodeAlarm(position, alarm);
}
- buf.readUnsignedShort(); // description
- buf.readUnsignedShort(); // threshold
+ buf.readUnsignedShortLE(); // description
+ buf.readUnsignedShortLE(); // threshold
}
}
} else if (type == MSG_SC_FUEL) {
for (Position position : positions) {
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
+ position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE());
}
}
@@ -356,7 +357,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
} else if (type == MSG_SC_GPS_SLEEP) {
- buf.readUnsignedInt(); // device time
+ buf.readUnsignedIntLE(); // device time
return readPosition(deviceSession, buf);
@@ -370,7 +371,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
decodeStat(position, buf);
- buf.readUnsignedShort(); // sample rate
+ buf.readUnsignedShortLE(); // sample rate
decodeObd(position, buf, true);
return position;
@@ -382,7 +383,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
decodeStat(position, buf);
buf.readUnsignedByte(); // flag
- position.add(ObdDecoder.decodeCodes(ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte()))));
+ position.add(ObdDecoder.decodeCodes(ByteBufUtil.hexDump(buf.readBytes(buf.readUnsignedByte()))));
return position;
@@ -404,7 +405,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
decodeStat(position, buf);
position.setNetwork(new Network(
- CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort())));
+ CellTower.fromLacCid(buf.readUnsignedShortLE(), buf.readUnsignedShortLE())));
return position;
@@ -412,20 +413,20 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
Position position = createPosition(deviceSession);
- buf.readUnsignedShort(); // index
+ buf.readUnsignedShortLE(); // index
buf.readUnsignedByte(); // response count
buf.readUnsignedByte(); // response index
int failureCount = buf.readUnsignedByte();
for (int i = 0; i < failureCount; i++) {
- buf.readUnsignedShort(); // tag
+ buf.readUnsignedShortLE(); // tag
}
int successCount = buf.readUnsignedByte();
for (int i = 0; i < successCount; i++) {
- buf.readUnsignedShort(); // tag
+ buf.readUnsignedShortLE(); // tag
position.set(Position.KEY_RESULT,
- buf.readBytes(buf.readUnsignedShort()).toString(StandardCharsets.US_ASCII));
+ buf.readBytes(buf.readUnsignedShortLE()).toString(StandardCharsets.US_ASCII));
}
return position;
@@ -436,8 +437,8 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
}
private Object decodeCc(
- Channel channel, SocketAddress remoteAddress, ChannelBuffer buf,
- int version, ChannelBuffer id, short type, DeviceSession deviceSession) {
+ Channel channel, SocketAddress remoteAddress, ByteBuf buf,
+ int version, ByteBuf id, short type, DeviceSession deviceSession) {
if (type == MSG_CC_HEARTBEAT) {
@@ -451,16 +452,16 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
for (int i = 0; i < count; i++) {
Position position = readPosition(deviceSession, buf);
- position.set(Position.KEY_STATUS, buf.readUnsignedInt());
+ position.set(Position.KEY_STATUS, buf.readUnsignedIntLE());
position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
buf.readUnsignedByte(); // geo-fencing id
buf.readUnsignedByte(); // geo-fencing flags
buf.readUnsignedByte(); // additional flags
position.setNetwork(new Network(
- CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort())));
+ CellTower.fromLacCid(buf.readUnsignedShortLE(), buf.readUnsignedShortLE())));
positions.add(position);
}
@@ -473,9 +474,9 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
Position position = readPosition(deviceSession, buf);
- position.set(Position.KEY_STATUS, buf.readUnsignedInt());
+ position.set(Position.KEY_STATUS, buf.readUnsignedIntLE());
position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
buf.readUnsignedByte(); // geo-fencing id
buf.readUnsignedByte(); // geo-fencing flags
@@ -493,8 +494,8 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
}
private Object decodeMpip(
- Channel channel, SocketAddress remoteAddress, ChannelBuffer buf,
- int version, ChannelBuffer id, short type, DeviceSession deviceSession) {
+ Channel channel, SocketAddress remoteAddress, ByteBuf buf,
+ int version, ByteBuf id, short type, DeviceSession deviceSession) {
if (type == 0x4001) {
@@ -506,8 +507,8 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
sendResponse(channel, remoteAddress, id, (short) 0x1001);
- buf.readUnsignedInt(); // index
- buf.readUnsignedInt(); // unix time
+ buf.readUnsignedIntLE(); // index
+ buf.readUnsignedIntLE(); // unix time
buf.readUnsignedByte();
return readPosition(deviceSession, buf);
@@ -537,18 +538,18 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
- int header = buf.readUnsignedShort();
- buf.readUnsignedShort(); // length
+ int header = buf.readUnsignedShortLE();
+ buf.readUnsignedShortLE(); // length
int version = -1;
if (header == 0x4040) {
version = buf.readUnsignedByte();
}
- ChannelBuffer id = buf.readBytes(20);
- short type = ChannelBuffers.swapShort(buf.readShort());
+ ByteBuf id = buf.readBytes(20);
+ short type = buf.readShort();
DeviceSession deviceSession = getDeviceSession(
channel, remoteAddress, id.toString(StandardCharsets.US_ASCII).trim());
diff --git a/src/org/traccar/protocol/CastelProtocolEncoder.java b/src/org/traccar/protocol/CastelProtocolEncoder.java
index 806dac19e..dde8ac11f 100644
--- a/src/org/traccar/protocol/CastelProtocolEncoder.java
+++ b/src/org/traccar/protocol/CastelProtocolEncoder.java
@@ -15,37 +15,36 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import org.traccar.BaseProtocolEncoder;
import org.traccar.Context;
import org.traccar.helper.Checksum;
import org.traccar.helper.Log;
import org.traccar.model.Command;
-import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
public class CastelProtocolEncoder extends BaseProtocolEncoder {
- private ChannelBuffer encodeContent(long deviceId, short type, ChannelBuffer content) {
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ private ByteBuf encodeContent(long deviceId, short type, ByteBuf content) {
+ ByteBuf buf = Unpooled.buffer(0);
String uniqueId = Context.getIdentityManager().getById(deviceId).getUniqueId();
buf.writeByte('@');
buf.writeByte('@');
- buf.writeShort(2 + 2 + 1 + 20 + 2 + content.readableBytes() + 2 + 2); // length
+ buf.writeShortLE(2 + 2 + 1 + 20 + 2 + content.readableBytes() + 2 + 2); // length
buf.writeByte(1); // protocol version
buf.writeBytes(uniqueId.getBytes(StandardCharsets.US_ASCII));
buf.writeZero(20 - uniqueId.length());
- buf.writeShort(ChannelBuffers.swapShort(type));
+ buf.writeShort(type);
buf.writeBytes(content);
- buf.writeShort(Checksum.crc16(Checksum.CRC16_X25, buf.toByteBuffer()));
+ buf.writeShortLE(Checksum.crc16(Checksum.CRC16_X25, buf.nioBuffer()));
buf.writeByte('\r');
buf.writeByte('\n');
@@ -55,7 +54,7 @@ public class CastelProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- ChannelBuffer content = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ ByteBuf content = Unpooled.buffer(0);
switch (command.getType()) {
case Command.TYPE_ENGINE_STOP:
content.writeByte(1);
diff --git a/src/org/traccar/protocol/CautelaProtocol.java b/src/org/traccar/protocol/CautelaProtocol.java
index 89ab7a1d0..dc5c82193 100644
--- a/src/org/traccar/protocol/CautelaProtocol.java
+++ b/src/org/traccar/protocol/CautelaProtocol.java
@@ -15,12 +15,11 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.LineBasedFrameDecoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -33,9 +32,9 @@ public class CautelaProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("stringDecoder", new StringDecoder());
diff --git a/src/org/traccar/protocol/CautelaProtocolDecoder.java b/src/org/traccar/protocol/CautelaProtocolDecoder.java
index 7c48ff690..ce231591e 100644
--- a/src/org/traccar/protocol/CautelaProtocolDecoder.java
+++ b/src/org/traccar/protocol/CautelaProtocolDecoder.java
@@ -15,7 +15,7 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.DateBuilder;
diff --git a/src/org/traccar/protocol/CellocatorFrameDecoder.java b/src/org/traccar/protocol/CellocatorFrameDecoder.java
index b4708f5db..8cdba18e0 100644
--- a/src/org/traccar/protocol/CellocatorFrameDecoder.java
+++ b/src/org/traccar/protocol/CellocatorFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,29 +15,24 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelHandlerContext;
+import org.traccar.BaseFrameDecoder;
import org.traccar.helper.Log;
-public class CellocatorFrameDecoder extends FrameDecoder {
+public class CellocatorFrameDecoder extends BaseFrameDecoder {
private static final int MESSAGE_MINIMUM_LENGTH = 15;
@Override
protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
+ ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
- // Check minimum length
- int available = buf.readableBytes();
- if (available < MESSAGE_MINIMUM_LENGTH) {
+ if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
return null;
}
- // Size depending on message type
int length = 0;
int type = buf.getUnsignedByte(4);
switch (type) {
@@ -51,8 +46,8 @@ public class CellocatorFrameDecoder extends FrameDecoder {
length = 70;
break;
case CellocatorProtocolDecoder.MSG_CLIENT_SERIAL:
- if (available >= 19) {
- length = 19 + buf.getUnsignedShort(16);
+ if (buf.readableBytes() >= 19) {
+ length = 19 + buf.getUnsignedShortLE(16);
}
break;
case CellocatorProtocolDecoder.MSG_CLIENT_MODULAR:
@@ -63,8 +58,7 @@ public class CellocatorFrameDecoder extends FrameDecoder {
break;
}
- // Read packet
- if (length > 0 && available >= length) {
+ if (length > 0 && buf.readableBytes() >= length) {
return buf.readBytes(length);
}
diff --git a/src/org/traccar/protocol/CellocatorProtocol.java b/src/org/traccar/protocol/CellocatorProtocol.java
index 4a20bc977..bf186e67f 100644
--- a/src/org/traccar/protocol/CellocatorProtocol.java
+++ b/src/org/traccar/protocol/CellocatorProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,14 +15,11 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import org.traccar.model.Command;
-import java.nio.ByteOrder;
import java.util.List;
public class CellocatorProtocol extends BaseProtocol {
@@ -35,26 +32,21 @@ public class CellocatorProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("frameDecoder", new CellocatorFrameDecoder());
pipeline.addLast("objectEncoder", new CellocatorProtocolEncoder());
pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this));
}
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
-
- server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
+ });
+ serverList.add(new TrackerServer(true, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("objectEncoder", new CellocatorProtocolEncoder());
pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this));
}
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
+ });
}
}
diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
index 67db9aa7d..426b6bf3b 100644
--- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,17 +15,17 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
-import java.nio.ByteOrder;
public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
@@ -44,15 +44,15 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
private byte commandCount;
private void sendReply(Channel channel, SocketAddress remoteAddress, long deviceId, byte packetNumber) {
- ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 28);
+ ByteBuf reply = Unpooled.buffer(28);
reply.writeByte('M');
reply.writeByte('C');
reply.writeByte('G');
reply.writeByte('P');
reply.writeByte(MSG_SERVER_ACKNOWLEDGE);
- reply.writeInt((int) deviceId);
+ reply.writeIntLE((int) deviceId);
reply.writeByte(commandCount++);
- reply.writeInt(0); // authentication code
+ reply.writeIntLE(0); // authentication code
reply.writeByte(0);
reply.writeByte(packetNumber);
reply.writeZero(11);
@@ -64,7 +64,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
reply.writeByte(checksum);
if (channel != null) {
- channel.write(reply, remoteAddress);
+ channel.write(new NetworkMessage(reply, remoteAddress));
}
}
@@ -85,14 +85,14 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
buf.skipBytes(4); // system code
int type = buf.readUnsignedByte();
- long deviceUniqueId = buf.readUnsignedInt();
+ long deviceUniqueId = buf.readUnsignedIntLE();
if (type != MSG_CLIENT_SERIAL) {
- buf.readUnsignedShort(); // communication control
+ buf.readUnsignedShortLE(); // communication control
}
byte packetNumber = buf.readByte();
@@ -121,17 +121,17 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
position.set("mode", buf.readUnsignedByte());
- position.set(Position.PREFIX_IO + 1, buf.readUnsignedInt());
+ position.set(Position.PREFIX_IO + 1, buf.readUnsignedIntLE());
operator <<= 8;
operator += buf.readUnsignedByte();
position.set(Position.KEY_OPERATOR, operator);
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedInt());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
+ position.set(Position.PREFIX_ADC + 1, buf.readUnsignedIntLE());
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedMediumLE());
buf.skipBytes(6); // multi-purpose data
- position.set(Position.KEY_GPS, buf.readUnsignedShort());
+ position.set(Position.KEY_GPS, buf.readUnsignedShortLE());
position.set("locationStatus", buf.readUnsignedByte());
position.set("mode1", buf.readUnsignedByte());
position.set("mode2", buf.readUnsignedByte());
@@ -139,15 +139,15 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.setValid(true);
- position.setLongitude(buf.readInt() / Math.PI * 180 / 100000000);
- position.setLatitude(buf.readInt() / Math.PI * 180 / 100000000.0);
- position.setAltitude(buf.readInt() * 0.01);
- position.setSpeed(UnitsConverter.knotsFromMps(buf.readInt() * 0.01));
- position.setCourse(buf.readUnsignedShort() / Math.PI * 180.0 / 1000.0);
+ position.setLongitude(buf.readIntLE() / Math.PI * 180 / 100000000);
+ position.setLatitude(buf.readIntLE() / Math.PI * 180 / 100000000.0);
+ position.setAltitude(buf.readIntLE() * 0.01);
+ position.setSpeed(UnitsConverter.knotsFromMps(buf.readIntLE() * 0.01));
+ position.setCourse(buf.readUnsignedShortLE() / Math.PI * 180.0 / 1000.0);
DateBuilder dateBuilder = new DateBuilder()
.setTimeReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedShort());
+ .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedShortLE());
position.setTime(dateBuilder.getDate());
return position;
diff --git a/src/org/traccar/protocol/CellocatorProtocolEncoder.java b/src/org/traccar/protocol/CellocatorProtocolEncoder.java
index bb143d349..4eef42128 100644
--- a/src/org/traccar/protocol/CellocatorProtocolEncoder.java
+++ b/src/org/traccar/protocol/CellocatorProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,34 +15,32 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import org.traccar.BaseProtocolEncoder;
import org.traccar.helper.Log;
import org.traccar.model.Command;
-import java.nio.ByteOrder;
-
public class CellocatorProtocolEncoder extends BaseProtocolEncoder {
- private ChannelBuffer encodeContent(long deviceId, int command, int data1, int data2) {
+ private ByteBuf encodeContent(long deviceId, int command, int data1, int data2) {
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ ByteBuf buf = Unpooled.buffer(0);
buf.writeByte('M');
buf.writeByte('C');
buf.writeByte('G');
buf.writeByte('P');
buf.writeByte(0);
- buf.writeInt(Integer.parseInt(getUniqueId(deviceId)));
+ buf.writeIntLE(Integer.parseInt(getUniqueId(deviceId)));
buf.writeByte(0); // command numerator
- buf.writeInt(0); // authentication code
+ buf.writeIntLE(0); // authentication code
buf.writeByte(command);
buf.writeByte(command);
buf.writeByte(data1);
buf.writeByte(data1);
buf.writeByte(data2);
buf.writeByte(data2);
- buf.writeInt(0); // command specific data
+ buf.writeIntLE(0); // command specific data
byte checksum = 0;
for (int i = 4; i < buf.writerIndex(); i++) {
diff --git a/src/org/traccar/protocol/CguardProtocol.java b/src/org/traccar/protocol/CguardProtocol.java
index 460bd331f..5d2ffb6fd 100644
--- a/src/org/traccar/protocol/CguardProtocol.java
+++ b/src/org/traccar/protocol/CguardProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,11 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.LineBasedFrameDecoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -33,9 +32,9 @@ public class CguardProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
diff --git a/src/org/traccar/protocol/CguardProtocolDecoder.java b/src/org/traccar/protocol/CguardProtocolDecoder.java
index 2e20537c8..806f500ab 100644
--- a/src/org/traccar/protocol/CguardProtocolDecoder.java
+++ b/src/org/traccar/protocol/CguardProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.Parser;
diff --git a/src/org/traccar/protocol/CityeasyProtocol.java b/src/org/traccar/protocol/CityeasyProtocol.java
index 7e5ca0ba0..82b33e0f4 100644
--- a/src/org/traccar/protocol/CityeasyProtocol.java
+++ b/src/org/traccar/protocol/CityeasyProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,10 +15,9 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
+import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import org.traccar.model.Command;
@@ -37,9 +36,9 @@ public class CityeasyProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0));
pipeline.addLast("objectEncoder", new CityeasyProtocolEncoder());
pipeline.addLast("objectDecoder", new CityeasyProtocolDecoder(CityeasyProtocol.this));
diff --git a/src/org/traccar/protocol/CityeasyProtocolDecoder.java b/src/org/traccar/protocol/CityeasyProtocolDecoder.java
index 7a1d8119d..5e5568402 100644
--- a/src/org/traccar/protocol/CityeasyProtocolDecoder.java
+++ b/src/org/traccar/protocol/CityeasyProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,9 +15,9 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.Checksum;
@@ -69,12 +69,12 @@ public class CityeasyProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
buf.skipBytes(2); // header
buf.readUnsignedShort(); // length
- String imei = ChannelBuffers.hexDump(buf.readBytes(7));
+ String imei = ByteBufUtil.hexDump(buf.readBytes(7));
DeviceSession deviceSession = getDeviceSession(
channel, remoteAddress, imei, imei + Checksum.luhn(Long.parseLong(imei)));
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/CityeasyProtocolEncoder.java b/src/org/traccar/protocol/CityeasyProtocolEncoder.java
index 387926e03..e143563f0 100644
--- a/src/org/traccar/protocol/CityeasyProtocolEncoder.java
+++ b/src/org/traccar/protocol/CityeasyProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,8 +17,8 @@ package org.traccar.protocol;
import java.util.TimeZone;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import org.traccar.BaseProtocolEncoder;
import org.traccar.helper.Checksum;
import org.traccar.helper.Log;
@@ -26,9 +26,9 @@ import org.traccar.model.Command;
public class CityeasyProtocolEncoder extends BaseProtocolEncoder {
- private ChannelBuffer encodeContent(int type, ChannelBuffer content) {
+ private ByteBuf encodeContent(int type, ByteBuf content) {
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
+ ByteBuf buf = Unpooled.buffer();
buf.writeByte('S');
buf.writeByte('S');
@@ -36,7 +36,7 @@ public class CityeasyProtocolEncoder extends BaseProtocolEncoder {
buf.writeShort(type);
buf.writeBytes(content);
buf.writeInt(0x0B);
- buf.writeShort(Checksum.crc16(Checksum.CRC16_KERMIT, buf.toByteBuffer()));
+ buf.writeShort(Checksum.crc16(Checksum.CRC16_KERMIT, buf.nioBuffer()));
buf.writeByte('\r');
buf.writeByte('\n');
@@ -46,7 +46,7 @@ public class CityeasyProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- ChannelBuffer content = ChannelBuffers.dynamicBuffer();
+ ByteBuf content = Unpooled.buffer();
switch (command.getType()) {
case Command.TYPE_POSITION_SINGLE:
diff --git a/src/org/traccar/protocol/ContinentalProtocol.java b/src/org/traccar/protocol/ContinentalProtocol.java
index 5f43a51f7..540128120 100644
--- a/src/org/traccar/protocol/ContinentalProtocol.java
+++ b/src/org/traccar/protocol/ContinentalProtocol.java
@@ -15,10 +15,9 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
+import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -31,9 +30,9 @@ public class ContinentalProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0));
pipeline.addLast("objectDecoder", new ContinentalProtocolDecoder(ContinentalProtocol.this));
}
diff --git a/src/org/traccar/protocol/ContinentalProtocolDecoder.java b/src/org/traccar/protocol/ContinentalProtocolDecoder.java
index 5ea1d3246..20134fc1f 100644
--- a/src/org/traccar/protocol/ContinentalProtocolDecoder.java
+++ b/src/org/traccar/protocol/ContinentalProtocolDecoder.java
@@ -15,8 +15,8 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.Channel;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.BitUtil;
@@ -41,7 +41,7 @@ public class ContinentalProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
buf.skipBytes(2); // header
buf.readUnsignedShort(); // length
diff --git a/src/org/traccar/protocol/CradlepointProtocol.java b/src/org/traccar/protocol/CradlepointProtocol.java
index 6ed54aa17..51de43bd9 100644
--- a/src/org/traccar/protocol/CradlepointProtocol.java
+++ b/src/org/traccar/protocol/CradlepointProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,12 +15,11 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import io.netty.handler.codec.LineBasedFrameDecoder;
+import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
+import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -33,9 +32,9 @@ public class CradlepointProtocol extends BaseProtocol {
@Override
public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ serverList.add(new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
diff --git a/src/org/traccar/protocol/CradlepointProtocolDecoder.java b/src/org/traccar/protocol/CradlepointProtocolDecoder.java
index 48bd67021..222f73ec3 100644
--- a/src/org/traccar/protocol/CradlepointProtocolDecoder.java
+++ b/src/org/traccar/protocol/CradlepointProtocolDecoder.java
@@ -15,7 +15,7 @@
*/
package org.traccar.protocol;
-import org.jboss.netty.channel.Channel;
+import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.DateBuilder;