aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/helper/Checksum.java8
-rw-r--r--src/main/java/org/traccar/protocol/Arnavi4FrameDecoder.java21
-rw-r--r--src/main/java/org/traccar/protocol/Arnavi4Protocol.java22
-rw-r--r--src/main/java/org/traccar/protocol/Arnavi4ProtocolDecoder.java57
4 files changed, 49 insertions, 59 deletions
diff --git a/src/main/java/org/traccar/helper/Checksum.java b/src/main/java/org/traccar/helper/Checksum.java
index adfa697c5..d41dc2992 100644
--- a/src/main/java/org/traccar/helper/Checksum.java
+++ b/src/main/java/org/traccar/helper/Checksum.java
@@ -168,6 +168,14 @@ public final class Checksum {
return checksum;
}
+ public static int modulo256(ByteBuffer buf) {
+ int checksum = 0;
+ while (buf.hasRemaining()) {
+ checksum = (checksum + buf.get()) & 0xFF;
+ }
+ return checksum;
+ }
+
public static String sum(String msg) {
byte checksum = 0;
for (byte b : msg.getBytes(StandardCharsets.US_ASCII)) {
diff --git a/src/main/java/org/traccar/protocol/Arnavi4FrameDecoder.java b/src/main/java/org/traccar/protocol/Arnavi4FrameDecoder.java
index b13f3fd7d..fae2d3fde 100644
--- a/src/main/java/org/traccar/protocol/Arnavi4FrameDecoder.java
+++ b/src/main/java/org/traccar/protocol/Arnavi4FrameDecoder.java
@@ -15,12 +15,12 @@
*/
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 Arnavi4FrameDecoder extends FrameDecoder {
+public class Arnavi4FrameDecoder extends BaseFrameDecoder {
private static final int MIN_LENGTH = 4;
private static final int HEADER_LENGTH = 10;
@@ -32,8 +32,7 @@ public class Arnavi4FrameDecoder extends FrameDecoder {
private boolean firstPacket = true;
@Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
+ protected Object decode(ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
if (buf.readableBytes() < MIN_LENGTH) {
return null;
@@ -44,19 +43,19 @@ public class Arnavi4FrameDecoder extends FrameDecoder {
firstPacket = false;
length = HEADER_LENGTH;
} else {
- int index = buf.getUnsignedByte(1); // parcel number
+ int index = buf.getUnsignedByte(1);
if (index == COMMAND_ANSWER_PARCEL_NUMBER) {
length = COMMAND_ANSWER_PACKET_LENGTH;
} else {
- int pos = 2; // start sign + parcel number
+ int pos = 2;
while (pos + PACKET_WRAPPER_LENGTH < buf.readableBytes()
&& buf.getByte(pos) != PACKAGE_END_SIGN) {
int dataLength = buf.getUnsignedShort(pos + 1);
- pos += PACKET_WRAPPER_LENGTH + dataLength; // packet type + data length + unixtime + data + crc
+ pos += PACKET_WRAPPER_LENGTH + dataLength;
}
- if (buf.getByte(pos) != PACKAGE_END_SIGN) { // end sign
+ if (buf.getByte(pos) != PACKAGE_END_SIGN) {
return null;
}
diff --git a/src/main/java/org/traccar/protocol/Arnavi4Protocol.java b/src/main/java/org/traccar/protocol/Arnavi4Protocol.java
index 381a9b457..8a9337b56 100644
--- a/src/main/java/org/traccar/protocol/Arnavi4Protocol.java
+++ b/src/main/java/org/traccar/protocol/Arnavi4Protocol.java
@@ -1,4 +1,5 @@
/*
+ * Copyright 2020 Anton Tananaev (anton@traccar.org)
* Copyright 2017 Ivan Muratov (binakot@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,31 +16,20 @@
*/
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 Arnavi4Protocol extends BaseProtocol {
public Arnavi4Protocol() {
- super("arnavi4");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
+ TrackerServer server = new TrackerServer(false, getName()) {
@Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new Arnavi4FrameDecoder());
- pipeline.addLast("objectDecoder", new Arnavi4ProtocolDecoder(Arnavi4Protocol.this));
+ protected void addProtocolHandlers(PipelineBuilder pipeline) {
+ pipeline.addLast(new Arnavi4FrameDecoder());
+ pipeline.addLast(new Arnavi4ProtocolDecoder(Arnavi4Protocol.this));
}
};
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
}
}
diff --git a/src/main/java/org/traccar/protocol/Arnavi4ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Arnavi4ProtocolDecoder.java
index 06abb563f..94ad8bb1f 100644
--- a/src/main/java/org/traccar/protocol/Arnavi4ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Arnavi4ProtocolDecoder.java
@@ -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.Checksum;
import org.traccar.model.Position;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@@ -52,30 +52,24 @@ public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder {
private void sendResponse(Channel channel, byte version, int index) {
if (channel != null) {
- final ChannelBuffer response;
+ ByteBuf response = Unpooled.buffer();
+ response.writeByte(0x7b);
if (version == HEADER_VERSION_1) {
- response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 4);
- response.writeByte(0x7b);
response.writeByte(0x00);
response.writeByte((byte) index);
- response.writeByte(0x7d);
} else if (version == HEADER_VERSION_2) {
- response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 9);
- response.writeByte(0x7b);
response.writeByte(0x04);
response.writeByte(0x00);
- byte[] timeBytes = ByteBuffer.allocate(4).putInt((int) (System.currentTimeMillis() / 1000)).array();
- response.writeByte(Checksum.modulo256(timeBytes));
- response.writeBytes(timeBytes);
- response.writeByte(0x7d);
- } else {
- return; // Ignore unsupported header's versions
+ ByteBuffer time = ByteBuffer.allocate(4).putInt((int) (System.currentTimeMillis() / 1000));
+ response.writeByte(Checksum.modulo256(time));
+ response.writeBytes(time);
}
- channel.write(response);
+ response.writeByte(0x7d);
+ channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
}
}
- private Position decodePosition(DeviceSession deviceSession, ChannelBuffer buf, int length, Date time) {
+ private Position decodePosition(DeviceSession deviceSession, ByteBuf buf, int length, Date time) {
final Position position = new Position();
position.setProtocol(getProtocolName());
@@ -88,12 +82,12 @@ public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder {
short tag = buf.readUnsignedByte();
switch (tag) {
case TAG_LATITUDE:
- position.setLatitude(buf.readFloat());
+ position.setLatitude(buf.readFloatLE());
position.setValid(true);
break;
case TAG_LONGITUDE:
- position.setLongitude(buf.readFloat());
+ position.setLongitude(buf.readFloatLE());
position.setValid(true);
break;
@@ -101,26 +95,25 @@ public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder {
position.setCourse(buf.readUnsignedByte() * 2);
position.setAltitude(buf.readUnsignedByte() * 10);
byte satellites = buf.readByte();
- position.set(Position.KEY_SATELLITES, satellites & 0x0F + (satellites >> 4) & 0x0F); // gps+glonass
+ position.set(Position.KEY_SATELLITES, satellites & 0x0F + (satellites >> 4) & 0x0F);
position.setSpeed(buf.readUnsignedByte());
break;
default:
- buf.readBytes(4); // Skip unsupported tags
+ buf.skipBytes(4);
break;
}
- readBytes += 5; // 1 byte tag + 4 bytes value
+ readBytes += 1 + 4;
}
return position;
}
@Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ ByteBuf buf = (ByteBuf) msg;
byte startSign = buf.readByte();
@@ -128,7 +121,7 @@ public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder {
byte version = buf.readByte();
- String imei = String.valueOf(buf.readLong());
+ String imei = String.valueOf(buf.readLongLE());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession != null) {
@@ -155,20 +148,20 @@ public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder {
case RECORD_TEXT:
case RECORD_FILE:
case RECORD_BINARY:
- int length = buf.readUnsignedShort();
- Date time = new Date(buf.readUnsignedInt() * 1000);
+ int length = buf.readUnsignedShortLE();
+ Date time = new Date(buf.readUnsignedIntLE() * 1000);
if (recordType == RECORD_DATA) {
positions.add(decodePosition(deviceSession, buf, length, time));
} else {
- buf.readBytes(length); // Skip other types of record
+ buf.readBytes(length);
}
- buf.readUnsignedByte(); // crc
+ buf.readUnsignedByte(); // checksum
break;
default:
- return null; // Ignore unsupported types of record
+ return null;
}
recordType = buf.readByte();