aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Muratov <binakot@gmail.com>2017-07-14 09:39:40 +0300
committerIvan Muratov <binakot@gmail.com>2017-07-14 09:39:40 +0300
commit1af08aed1a880d30a16d8ab66b65ab56b5a53f4a (patch)
tree19a68cd6de1909a92974655947819d0fafbda575 /src
parentf643173b6b2c52a3896d6ee13578edd86f9eb3e7 (diff)
parent01ec19f81270e38451e6a8b898abb22d6a2a3994 (diff)
downloadtrackermap-server-1af08aed1a880d30a16d8ab66b65ab56b5a53f4a.tar.gz
trackermap-server-1af08aed1a880d30a16d8ab66b65ab56b5a53f4a.tar.bz2
trackermap-server-1af08aed1a880d30a16d8ab66b65ab56b5a53f4a.zip
Merge branch 'master' into anravi4_fix
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/helper/Checksum.java2
-rw-r--r--src/org/traccar/protocol/Arnavi4FrameDecoder.java37
-rw-r--r--src/org/traccar/protocol/Arnavi4Protocol.java18
-rw-r--r--src/org/traccar/protocol/Arnavi4ProtocolDecoder.java69
4 files changed, 82 insertions, 44 deletions
diff --git a/src/org/traccar/helper/Checksum.java b/src/org/traccar/helper/Checksum.java
index 7a0151d36..44cef9635 100644
--- a/src/org/traccar/helper/Checksum.java
+++ b/src/org/traccar/helper/Checksum.java
@@ -243,7 +243,7 @@ public final class Checksum {
return (10 - (checksum % 10)) % 10;
}
- public static int modulo256(byte... bytes) {
+ public static int modulo256(byte[] bytes) {
int sum = 0;
for (byte b : bytes) {
sum = (sum + b) & 0xFF;
diff --git a/src/org/traccar/protocol/Arnavi4FrameDecoder.java b/src/org/traccar/protocol/Arnavi4FrameDecoder.java
index 97bf75a20..a50ece641 100644
--- a/src/org/traccar/protocol/Arnavi4FrameDecoder.java
+++ b/src/org/traccar/protocol/Arnavi4FrameDecoder.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2017 Ivan Muratov (binakot@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.traccar.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
@@ -5,11 +20,10 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.frame.FrameDecoder;
-/**
- * Created by Ivan Muratov @binakot on 12.07.2017.
- */
public class Arnavi4FrameDecoder extends FrameDecoder {
+ static final int PACKET_MIN_LENGTH = 4;
+
static final byte HEADER_START_SIGN = (byte) 0xFF;
static final byte HEADER_VERSION_1 = 0x22;
static final byte HEADER_VERSION_2 = 0x23;
@@ -26,23 +40,20 @@ public class Arnavi4FrameDecoder extends FrameDecoder {
Channel channel,
ChannelBuffer buf) throws Exception {
- if (buf.readableBytes() == 0) {
+ if (buf.readableBytes() < PACKET_MIN_LENGTH) {
return null;
}
- byte[] bytes = new byte[buf.readableBytes()];
- buf.getBytes(0, bytes);
-
- if (bytes[0] == HEADER_START_SIGN
- && bytes.length == HEADER_LENGTH
- && (bytes[1] == HEADER_VERSION_1 || bytes[1] == HEADER_VERSION_2)) {
+ if (buf.getByte(0) == HEADER_START_SIGN
+ && buf.readableBytes() == HEADER_LENGTH
+ && (buf.getByte(1) == HEADER_VERSION_1 || buf.getByte(1) == HEADER_VERSION_2)) {
return buf.readBytes(HEADER_LENGTH);
}
- int parcelNumber = bytes[1] & 0xFF;
- if (bytes[0] == PACKAGE_START_SIGN && bytes[bytes.length - 1] == PACKAGE_END_SIGN
+ int parcelNumber = buf.getByte(1) & 0xFF;
+ if (buf.getByte(0) == PACKAGE_START_SIGN && buf.getByte(buf.readableBytes() - 1) == PACKAGE_END_SIGN
&& parcelNumber >= PACKAGE_MIN_PARCEL_NUMBER && parcelNumber <= PACKAGE_MAX_PARCEL_NUMBER) {
- return buf.readBytes(bytes.length);
+ return buf;
}
return null;
diff --git a/src/org/traccar/protocol/Arnavi4Protocol.java b/src/org/traccar/protocol/Arnavi4Protocol.java
index 227397980..381a9b457 100644
--- a/src/org/traccar/protocol/Arnavi4Protocol.java
+++ b/src/org/traccar/protocol/Arnavi4Protocol.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2017 Ivan Muratov (binakot@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.traccar.protocol;
import org.jboss.netty.bootstrap.ServerBootstrap;
@@ -8,9 +23,6 @@ import org.traccar.TrackerServer;
import java.nio.ByteOrder;
import java.util.List;
-/**
- * Created by Ivan Muratov @binakot on 11.07.2017.
- */
public class Arnavi4Protocol extends BaseProtocol {
public Arnavi4Protocol() {
diff --git a/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java b/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java
index c5ec3f31f..e2a1da29f 100644
--- a/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2017 Ivan Muratov (binakot@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.traccar.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
@@ -21,9 +36,6 @@ import static org.traccar.protocol.Arnavi4FrameDecoder.HEADER_VERSION_2;
import static org.traccar.protocol.Arnavi4FrameDecoder.PACKAGE_START_SIGN;
import static org.traccar.protocol.Arnavi4FrameDecoder.PACKAGE_END_SIGN;
-/**
- * Created by Ivan Muratov @binakot on 11.07.2017.
- */
public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder {
private static final byte RECORD_PING = 0x00;
@@ -40,38 +52,42 @@ public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private Position decodePosition(DeviceSession deviceSession, ChannelBuffer buf, long timestamp) {
+ private Position decodePosition(DeviceSession deviceSession, ChannelBuffer buf, int length, Date time) {
final Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setTime(new Date(timestamp));
+ position.setTime(time);
- while (buf.readableBytes() > 0) {
- short tagId = buf.readUnsignedByte();
- int tagValue = buf.readInt();
- switch (tagId) {
+ int readBytes = 0;
+ while (readBytes < length) {
+ short tag = buf.readUnsignedByte();
+ switch (tag) {
case TAG_LATITUDE:
- position.setLatitude(Float.intBitsToFloat(tagValue));
+ position.setLatitude(buf.readFloat());
position.setValid(true);
break;
case TAG_LONGITUDE:
- position.setLongitude(Float.intBitsToFloat(tagValue));
+ position.setLongitude(buf.readFloat());
position.setValid(true);
break;
case TAG_COORD_PARAMS:
- position.setSpeed((tagValue >> 24) * 1.852);
- position.set(Position.KEY_SATELLITES, (tagValue >> 16 & 0x0F) + (tagValue >> 20 & 0x0F));
- position.setAltitude((tagValue >> 8 & 0xFF) * 10.0);
- position.setCourse((tagValue & 0xFF) * 2.0);
+ position.setCourse(buf.readUnsignedByte() * 2.0);
+ position.setAltitude(buf.readUnsignedByte() * 10.0);
+ byte satellites = buf.readByte();
+ position.set(Position.KEY_SATELLITES, satellites & 0x0F + (satellites >> 4) & 0x0F); // gps + glonass
+ position.setSpeed(buf.readByte() * 1.852);
break;
default:
- break; // Skip other tags
+ buf.readBytes(4); // Skip other tags
+ break;
}
+
+ readBytes += 5; // 1 byte tag + 4 bytes value
}
return position;
@@ -127,37 +143,36 @@ public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder {
List<Position> positions = new LinkedList<>();
- int parcelNumber = buf.readUnsignedByte();
+ int index = buf.readUnsignedByte();
- byte recordStartSign = buf.readByte();
- while (recordStartSign != PACKAGE_END_SIGN) {
- switch (recordStartSign) {
+ byte recordType = buf.readByte();
+ while (recordType != PACKAGE_END_SIGN) {
+ switch (recordType) {
case RECORD_PING:
case RECORD_DATA:
case RECORD_TEXT:
case RECORD_FILE:
case RECORD_BINARY:
int length = buf.readUnsignedShort();
- long timestamp = buf.readUnsignedInt() * 1000;
- ChannelBuffer recordBuf = buf.readBytes(length);
+ Date time = new Date(buf.readUnsignedInt() * 1000);
- if (recordStartSign == RECORD_DATA) {
- positions.add(decodePosition(deviceSession, recordBuf, timestamp));
+ if (recordType == RECORD_DATA) {
+ positions.add(decodePosition(deviceSession, buf, length, time));
}
buf.readUnsignedByte(); // crc
break;
default:
- throw new IllegalArgumentException("unsupported record type");
+ return null; // Unsupported types of package
}
- recordStartSign = buf.readByte();
+ recordType = buf.readByte();
}
if (channel != null) {
final ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 4);
- response.writeBytes(new byte[]{0x7B, 0x00, (byte) parcelNumber, 0x7D});
+ response.writeBytes(new byte[]{0x7B, 0x00, (byte) index, 0x7D});
channel.write(response);
}