From 0af1cebf1e2f3f719edf5391252fcd4004a75157 Mon Sep 17 00:00:00 2001 From: user Date: Sun, 21 Oct 2012 21:42:46 +1300 Subject: JT600 protocol fix --- .../org/traccar/helper/ChannelBufferToolsTest.java | 11 ++++++++ .../traccar/protocol/Jt600ProtocolDecoderTest.java | 32 ++++++++++++++++++++++ .../protocol/Jt600ProtocolDecoderTest1.java | 32 ---------------------- 3 files changed, 43 insertions(+), 32 deletions(-) create mode 100644 test/org/traccar/protocol/Jt600ProtocolDecoderTest.java delete mode 100644 test/org/traccar/protocol/Jt600ProtocolDecoderTest1.java (limited to 'test/org/traccar') diff --git a/test/org/traccar/helper/ChannelBufferToolsTest.java b/test/org/traccar/helper/ChannelBufferToolsTest.java index 16ff036b8..792770dab 100644 --- a/test/org/traccar/helper/ChannelBufferToolsTest.java +++ b/test/org/traccar/helper/ChannelBufferToolsTest.java @@ -20,4 +20,15 @@ public class ChannelBufferToolsTest { factory.getBuffer(buf, 0, buf.length), 5); assertEquals(1903, result); } + + @Test + public void testReadHexString() { + byte[] buf = {0x01,(byte)0x90,0x34}; + String result = ChannelBufferTools.readHexString( + factory.getBuffer(buf, 0, buf.length), 5); + assertEquals("01903", result); + + result = Long.valueOf(result).toString(); + assertEquals("1903", result); + } } diff --git a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java new file mode 100644 index 000000000..c08ca0605 --- /dev/null +++ b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java @@ -0,0 +1,32 @@ +package org.traccar.protocol; + +import java.nio.charset.Charset; +import org.jboss.netty.buffer.ChannelBuffers; +import static org.junit.Assert.assertNotNull; +import org.junit.Test; + +public class Jt600ProtocolDecoderTest { + + @Test + public void testDecode() throws Exception { + + Jt600ProtocolDecoder decoder = new Jt600ProtocolDecoder(new TestDataManager(), 0); + + byte[] buf1 = {0x24,0x31,0x10,0x21,0x60,0x01,0x11,0x00,0x1B,0x16,0x02,0x11,0x05,0x59,0x10,0x22,0x32,(byte)0x98,0x62,0x11,0x40,0x46,0x22,0x7B,0x05,(byte)0x98,0x09,0x50,(byte)0x80,0x01,0x23,0x27,(byte)0x95,0x14,0x35,0x16,0x1F}; + assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf1))); + + byte[] buf2 = {0x24,0x31,0x20,(byte)0x82,0x00,0x29,0x11,0x00,0x1B,0x17,0x10,0x12,0x05,0x28,0x31,0x24,0x38,0x10,0x12,0x02,0x55,0x33,0x64,0x25,0x00,0x19,0x07,0x19,0x00,0x03,(byte)0xFD,0x2B,(byte)0x91,0x04,0x4D,0x1F,(byte)0xA0}; + assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf2))); + + byte[] buf3 = {0x24,0x31,0x20,(byte)0x82,0x00,0x29,0x11,0x00,0x1B,0x17,0x10,0x12,0x05,0x33,0x05,0x24,0x38,0x09,(byte)0x97,0x02,0x55,0x33,0x58,0x45,0x00,0x04,0x06,0x1E,0x00,0x03,(byte)0xEE,0x00,0x00,0x00,0x00,0x0C,0x00}; + assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf2))); + + assertNotNull(decoder.decode(null, null, + ChannelBuffers.copiedBuffer("(3110312099,W01,11404.6204,E,2232.9961,N,A,040511,063736,4,7,100,4,17,1,1,company)", Charset.defaultCharset()))); + + assertNotNull(decoder.decode(null, null, + ChannelBuffers.copiedBuffer("(3120820029,W01,02553.3555,E,2438.0997,S,A,171012,053339,0,8,20,6,31,5,20,20)", Charset.defaultCharset()))); + + } + +} diff --git a/test/org/traccar/protocol/Jt600ProtocolDecoderTest1.java b/test/org/traccar/protocol/Jt600ProtocolDecoderTest1.java deleted file mode 100644 index cdf8f1568..000000000 --- a/test/org/traccar/protocol/Jt600ProtocolDecoderTest1.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.traccar.protocol; - -import java.nio.charset.Charset; -import org.jboss.netty.buffer.ChannelBuffers; -import static org.junit.Assert.assertNotNull; -import org.junit.Test; - -public class Jt600ProtocolDecoderTest1 { - - @Test - public void testDecode() throws Exception { - - Jt600ProtocolDecoder decoder = new Jt600ProtocolDecoder(new TestDataManager(), 0); - - byte[] buf1 = {0x24,0x31,0x10,0x21,0x60,0x01,0x11,0x00,0x1B,0x16,0x02,0x11,0x05,0x59,0x10,0x22,0x32,(byte)0x98,0x62,0x11,0x40,0x46,0x22,0x7B,0x05,(byte)0x98,0x09,0x50,(byte)0x80,0x01,0x23,0x27,(byte)0x95,0x14,0x35,0x16,0x1F}; - assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf1))); - - byte[] buf2 = {0x24,0x31,0x20,(byte)0x82,0x00,0x29,0x11,0x00,0x1B,0x17,0x10,0x12,0x05,0x28,0x31,0x24,0x38,0x10,0x12,0x02,0x55,0x33,0x64,0x25,0x00,0x19,0x07,0x19,0x00,0x03,(byte)0xFD,0x2B,(byte)0x91,0x04,0x4D,0x1F,(byte)0xA0}; - assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf2))); - - byte[] buf3 = {0x24,0x31,0x20,(byte)0x82,0x00,0x29,0x11,0x00,0x1B,0x17,0x10,0x12,0x05,0x33,0x05,0x24,0x38,0x09,(byte)0x97,0x02,0x55,0x33,0x58,0x45,0x00,0x04,0x06,0x1E,0x00,0x03,(byte)0xEE,0x00,0x00,0x00,0x00,0x0C,0x00}; - assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf2))); - - assertNotNull(decoder.decode(null, null, - ChannelBuffers.copiedBuffer("(3110312099,W01,11404.6204,E,2232.9961,N,A,040511,063736,4,7,100,4,17,1,1,company)", Charset.defaultCharset()))); - - assertNotNull(decoder.decode(null, null, - ChannelBuffers.copiedBuffer("(3120820029,W01,02553.3555,E,2438.0997,S,A,171012,053339,0,8,20,6,31,5,20,20)", Charset.defaultCharset()))); - - } - -} -- cgit v1.2.3