aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/helper/ChannelBufferTools.java14
-rw-r--r--test/org/traccar/helper/ChannelBufferToolsTest.java6
2 files changed, 20 insertions, 0 deletions
diff --git a/src/org/traccar/helper/ChannelBufferTools.java b/src/org/traccar/helper/ChannelBufferTools.java
index ef2ebc313..0de07610d 100644
--- a/src/org/traccar/helper/ChannelBufferTools.java
+++ b/src/org/traccar/helper/ChannelBufferTools.java
@@ -17,6 +17,7 @@ package org.traccar.helper;
import java.util.Formatter;
import org.jboss.netty.buffer.ChannelBuffer;
+import org.traccar.protocol.IntellitracFrameDecoder;
/**
* ChannelBuffer helper methods
@@ -130,4 +131,17 @@ public class ChannelBufferTools {
}
return out;
}
+
+ /**
+ * Convert hex string to byte array
+ */
+ public static byte[] convertHexString(String in) {
+ int count = in.length() / 2;
+ byte[] out = new byte[count];
+ for (int i = 0; i < count; i++) {
+ out[i] = Integer.valueOf(in.substring(i * 2, (i + 1) * 2), 16).byteValue();
+ }
+ return out;
+ }
+
}
diff --git a/test/org/traccar/helper/ChannelBufferToolsTest.java b/test/org/traccar/helper/ChannelBufferToolsTest.java
index 792770dab..67c58058b 100644
--- a/test/org/traccar/helper/ChannelBufferToolsTest.java
+++ b/test/org/traccar/helper/ChannelBufferToolsTest.java
@@ -31,4 +31,10 @@ public class ChannelBufferToolsTest {
result = Long.valueOf(result).toString();
assertEquals("1903", result);
}
+
+ @Test
+ public void convertHexStringTest() {
+ assertArrayEquals(ChannelBufferTools.convertHexString("1234"), new byte[] {0x12,0x34});
+ }
+
}