diff options
-rw-r--r-- | src/org/traccar/protocol/TeltonikaProtocol.java | 4 | ||||
-rw-r--r-- | src/org/traccar/protocol/TeltonikaProtocolDecoder.java | 11 | ||||
-rw-r--r-- | test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java | 14 |
3 files changed, 22 insertions, 7 deletions
diff --git a/src/org/traccar/protocol/TeltonikaProtocol.java b/src/org/traccar/protocol/TeltonikaProtocol.java index 524e6d5b5..d0177da97 100644 --- a/src/org/traccar/protocol/TeltonikaProtocol.java +++ b/src/org/traccar/protocol/TeltonikaProtocol.java @@ -39,14 +39,14 @@ public class TeltonikaProtocol extends BaseProtocol { protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new TeltonikaFrameDecoder()); pipeline.addLast("objectEncoder", new TeltonikaProtocolEncoder()); - pipeline.addLast("objectDecoder", new TeltonikaProtocolDecoder(TeltonikaProtocol.this)); + pipeline.addLast("objectDecoder", new TeltonikaProtocolDecoder(TeltonikaProtocol.this, false)); } }); serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("objectEncoder", new TeltonikaProtocolEncoder()); - pipeline.addLast("objectDecoder", new TeltonikaProtocolDecoder(TeltonikaProtocol.this)); + pipeline.addLast("objectDecoder", new TeltonikaProtocolDecoder(TeltonikaProtocol.this, true)); } }); } diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java index 3f5b68f67..d8a7b0bc0 100644 --- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java +++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java @@ -35,8 +35,11 @@ import java.util.List; public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { - public TeltonikaProtocolDecoder(TeltonikaProtocol protocol) { + boolean connectionless; + + public TeltonikaProtocolDecoder(TeltonikaProtocol protocol, boolean connectionless) { super(protocol); + this.connectionless = connectionless; } private DeviceSession parseIdentification(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { @@ -249,7 +252,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, int locationPacketId, String... imei) { List<Position> positions = new LinkedList<>(); - if (!(channel instanceof DatagramChannel)) { + if (!connectionless) { buf.readUnsignedInt(); // data length } @@ -278,7 +281,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { } if (channel != null) { - if (channel instanceof DatagramChannel) { + if (connectionless) { ChannelBuffer response = ChannelBuffers.dynamicBuffer(); response.writeShort(5); response.writeShort(0); @@ -301,7 +304,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer buf = (ChannelBuffer) msg; - if (channel instanceof DatagramChannel) { + if (connectionless) { return decodeUdp(channel, remoteAddress, buf); } else { return decodeTcp(channel, remoteAddress, buf); diff --git a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java index dd484cad7..2eb5271d1 100644 --- a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java @@ -1,5 +1,6 @@ package org.traccar.protocol; +import org.junit.Ignore; import org.junit.Test; import org.traccar.ProtocolTest; @@ -8,7 +9,7 @@ public class TeltonikaProtocolDecoderTest extends ProtocolTest { @Test public void testDecode() throws Exception { - TeltonikaProtocolDecoder decoder = new TeltonikaProtocolDecoder(new TeltonikaProtocol()); + TeltonikaProtocolDecoder decoder = new TeltonikaProtocolDecoder(new TeltonikaProtocol(), false); verifyNull(decoder, binary( "000F313233343536373839303132333435")); @@ -60,4 +61,15 @@ public class TeltonikaProtocolDecoderTest extends ProtocolTest { } + @Ignore + @Test + public void testDecodeConnectionless() throws Exception { + + TeltonikaProtocolDecoder decoder = new TeltonikaProtocolDecoder(new TeltonikaProtocol(), true); + + verifyPositions(decoder, false, binary( + "0049cafe0122000f33353734353430373237313339373508010000015d3766f6a800003eef961ec6215e0063006d09003100070401000200f001c8000242381c18003201c7000000e10001")); + + } + } |