aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-12-29 13:53:20 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2014-12-29 13:53:20 +1300
commit2d7a970cc4b49f68b3fbb56d5903bb91b38f3798 (patch)
treef6f602e3d541df3ef6e93bfebcf0576ef5ea2029
parent7dbd8dd192b1d48a8b26168763ecf29d97433319 (diff)
downloadtrackermap-server-2d7a970cc4b49f68b3fbb56d5903bb91b38f3798.tar.gz
trackermap-server-2d7a970cc4b49f68b3fbb56d5903bb91b38f3798.tar.bz2
trackermap-server-2d7a970cc4b49f68b3fbb56d5903bb91b38f3798.zip
Correctly decode Noran ids (fix #915)
-rw-r--r--src/org/traccar/protocol/NoranProtocolDecoder.java7
-rw-r--r--test/org/traccar/protocol/NoranProtocolDecoderTest.java13
2 files changed, 9 insertions, 11 deletions
diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java
index 161d07a50..b6fa93607 100644
--- a/src/org/traccar/protocol/NoranProtocolDecoder.java
+++ b/src/org/traccar/protocol/NoranProtocolDecoder.java
@@ -110,12 +110,7 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
position.setTime(time.getTime());
// Identification
- ChannelBuffer rawId = buf.readBytes(11);
- int index = 0;
- while (rawId.readable() && rawId.readByte() != 0) {
- index += 1;
- }
- String id = rawId.toString(0, index, Charset.defaultCharset());
+ String id = buf.readBytes(11).toString(Charset.defaultCharset()).replaceAll("[^\\p{Print}]", "");
try {
position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
} catch(Exception error) {
diff --git a/test/org/traccar/protocol/NoranProtocolDecoderTest.java b/test/org/traccar/protocol/NoranProtocolDecoderTest.java
index 83ecac0d0..4742cf730 100644
--- a/test/org/traccar/protocol/NoranProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/NoranProtocolDecoderTest.java
@@ -15,11 +15,14 @@ public class NoranProtocolDecoderTest {
NoranProtocolDecoder decoder = new NoranProtocolDecoder(new TestDataManager(), null, null);
- int[] buf1 = {0x0f,0x00,0x00,0x00,0x4e,0x52,0x30,0x39,0x46,0x30,0x34,0x31,0x35,0x35,0x00};
- assertNull(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertArray(buf1))));
-
- int[] buf2 = {0x22,0x00,0x08,0x00,0x01,0x0c,0x00,0x8a,0x00,0x7e,0x9d,0xaa,0x42,0x31,0x7b,0xdd,0x41,0xa7,0xf3,0xe2,0x38,0x4e,0x52,0x30,0x39,0x46,0x30,0x34,0x31,0x35,0x35,0x00,0x00,0x00};
- verify(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertArray(buf2))));
+ assertNull(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertArray(
+ new int[] {0x0f,0x00,0x00,0x00,0x4e,0x52,0x30,0x39,0x46,0x30,0x34,0x31,0x35,0x35,0x00}))));
+
+ verify(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertArray(
+ new int[] {0x22,0x00,0x08,0x00,0x01,0x0c,0x00,0x8a,0x00,0x7e,0x9d,0xaa,0x42,0x31,0x7b,0xdd,0x41,0xa7,0xf3,0xe2,0x38,0x4e,0x52,0x30,0x39,0x46,0x30,0x34,0x31,0x35,0x35,0x00,0x00,0x00}))));
+
+ verify(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, ChannelBufferTools.convertArray(
+ new int[] {0x34,0x00,0x08,0x00,0x01,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x42,0x91,0x25,0x11,0x43,0x38,0x8d,0x17,0xc2,0x4e,0x52,0x30,0x39,0x42,0x31,0x31,0x30,0x39,0x30,0x00,0x00,0x31,0x34,0x2d,0x31,0x32,0x2d,0x32,0x35,0x20,0x30,0x30,0x3a,0x33,0x33,0x3a,0x30,0x37,0x00}))));
}