From b149a7b71283f1a8481c9e3954d636afcff6169e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 27 Nov 2017 22:56:22 +1300 Subject: Support eeLink UDP format --- src/org/traccar/protocol/EelinkProtocol.java | 10 +++++++++- src/org/traccar/protocol/EelinkProtocolDecoder.java | 15 +++++++++++++-- test/org/traccar/protocol/EelinkProtocolDecoderTest.java | 6 ++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/org/traccar/protocol/EelinkProtocol.java b/src/org/traccar/protocol/EelinkProtocol.java index 5499094d9..3c3424cd4 100644 --- a/src/org/traccar/protocol/EelinkProtocol.java +++ b/src/org/traccar/protocol/EelinkProtocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2017 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,6 +15,7 @@ */ 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; @@ -45,6 +46,13 @@ public class EelinkProtocol extends BaseProtocol { pipeline.addLast("objectDecoder", new EelinkProtocolDecoder(EelinkProtocol.this)); } }); + serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { + @Override + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("objectEncoder", new EelinkProtocolEncoder()); + pipeline.addLast("objectDecoder", new EelinkProtocolDecoder(EelinkProtocol.this)); + } + }); } } diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java index 8d0f8016a..91ae16289 100644 --- a/src/org/traccar/protocol/EelinkProtocolDecoder.java +++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java @@ -265,6 +265,16 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer buf = (ChannelBuffer) msg; + DeviceSession deviceSession = null; + + if (buf.getByte(0) == 'E' && buf.getByte(1) == 'L') { + buf.skipBytes(2 + 2 + 2); // udp header + deviceSession = getDeviceSession( + channel, remoteAddress, ChannelBuffers.hexDump(buf.readBytes(8)).substring(1)); + } else { + deviceSession = getDeviceSession(channel, remoteAddress); + } + buf.skipBytes(2); // header int type = buf.readUnsignedByte(); buf.readShort(); // length @@ -276,11 +286,12 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder { if (type == MSG_LOGIN) { - getDeviceSession(channel, remoteAddress, ChannelBuffers.hexDump(buf.readBytes(8)).substring(1)); + if (deviceSession == null) { + getDeviceSession(channel, remoteAddress, ChannelBuffers.hexDump(buf.readBytes(8)).substring(1)); + } } else { - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); if (deviceSession == null) { return null; } diff --git a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java index 115eef1a3..83ca85c96 100644 --- a/test/org/traccar/protocol/EelinkProtocolDecoderTest.java +++ b/test/org/traccar/protocol/EelinkProtocolDecoderTest.java @@ -10,6 +10,12 @@ public class EelinkProtocolDecoderTest extends ProtocolTest { EelinkProtocolDecoder decoder = new EelinkProtocolDecoder(new EelinkProtocol()); + verifyNull(decoder, binary( + "454C0027E753035254407167747167670100180002035254407167747100200205020500010432000086BD")); + + verifyPosition(decoder, binary( + "454C0050EAE2035254407167747167671200410021590BD93803026B940D0C3952AD0021000000000501CC0001A53F0170F0AB1305890F11000000000000C2D0001C001600000000000000000000000000000000")); + verifyNull(decoder, binary( "676701000c007b03525440717505180104")); -- cgit v1.2.3