aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorSrgian Danity <srgian.danity@smartdiesel.ro>2017-01-18 14:40:44 +0200
committerSrgian Danity <srgian.danity@smartdiesel.ro>2017-01-18 14:40:44 +0200
commit2bc8572b6e93cff19cf47f2cb0183594fe3cb510 (patch)
tree2b5cfb36a00eec60670ce10f24eec8b8fb17b21f /src/org/traccar/protocol
parent92f9691c9817526bd025377cb44aa336e7625592 (diff)
downloadtrackermap-server-2bc8572b6e93cff19cf47f2cb0183594fe3cb510.tar.gz
trackermap-server-2bc8572b6e93cff19cf47f2cb0183594fe3cb510.tar.bz2
trackermap-server-2bc8572b6e93cff19cf47f2cb0183594fe3cb510.zip
Added UDP support on Teltonika Decoder
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java52
1 files changed, 43 insertions, 9 deletions
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index 074d89703..a9bb4c6a0 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -18,6 +18,7 @@ package org.traccar.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.socket.DatagramChannel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.BitUtil;
@@ -211,11 +212,14 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
}
- private List<Position> parseData(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
+ private List<Position> parseData(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf,
+ boolean connectionless, int avlOffset, short packetId) {
List<Position> positions = new LinkedList<>();
- buf.skipBytes(4); // marker
- buf.readUnsignedInt(); // data length
+ buf.skipBytes(avlOffset); // marker
+ if (!connectionless) {
+ buf.readUnsignedInt(); // data length
+ }
int codec = buf.readUnsignedByte();
int count = buf.readUnsignedByte();
@@ -240,27 +244,57 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
}
if (channel != null) {
- ChannelBuffer response = ChannelBuffers.directBuffer(4);
- response.writeInt(count);
- channel.write(response);
+ if (connectionless) {
+ ChannelBuffer response = ChannelBuffers.directBuffer(5);
+ response.writeShort(3);
+ response.writeShort(packetId);
+ response.writeByte(0x02);
+ channel.write(response, remoteAddress);
+ } else {
+ ChannelBuffer response = ChannelBuffers.directBuffer(4);
+ response.writeInt(count);
+ channel.write(response);
+ }
}
return positions;
}
@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;
+ if (channel instanceof DatagramChannel) {
+ return decodeUDP(channel, remoteAddress, buf);
+ } else {
+ return decodeTCP(channel, remoteAddress, buf);
+ }
+ }
+
+ protected Object decodeTCP(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception {
+
if (buf.getUnsignedShort(0) > 0) {
parseIdentification(channel, remoteAddress, buf);
} else {
- return parseData(channel, remoteAddress, buf);
+ return parseData(channel, remoteAddress, buf, false, 4, (short) 0);
}
return null;
}
+ protected Object decodeUDP(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception {
+ int udpPacketLength = buf.getUnsignedShort(0);
+ short udpPacketId = buf.getShort(2);
+ byte udpPacketType = buf.getByte(4);
+
+ byte packetId = buf.getByte(5);
+ int imeiLength = buf.getUnsignedShort(6);
+ String imei = buf.toString(8, imeiLength, StandardCharsets.US_ASCII);
+ int avlDataArrOffset = 8 + imeiLength;
+ int avlDataArrLength = udpPacketLength - avlDataArrOffset + 2;
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
+ return parseData(channel, remoteAddress, buf, true, avlDataArrOffset, udpPacketId);
+ }
+
}