From 0af1cebf1e2f3f719edf5391252fcd4004a75157 Mon Sep 17 00:00:00 2001 From: user Date: Sun, 21 Oct 2012 21:42:46 +1300 Subject: JT600 protocol fix --- src/org/traccar/helper/ChannelBufferTools.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/org/traccar/helper') diff --git a/src/org/traccar/helper/ChannelBufferTools.java b/src/org/traccar/helper/ChannelBufferTools.java index 9139ed7ae..4f1ebb7c0 100644 --- a/src/org/traccar/helper/ChannelBufferTools.java +++ b/src/org/traccar/helper/ChannelBufferTools.java @@ -15,6 +15,7 @@ */ package org.traccar.helper; +import java.util.Formatter; import org.jboss.netty.buffer.ChannelBuffer; /** @@ -77,4 +78,23 @@ public class ChannelBufferTools { return result; } + /** + * Return hex string + */ + public static String readHexString(ChannelBuffer buf, int length) { + + StringBuilder result = new StringBuilder(); + Formatter formatter = new Formatter(result); + + for (int i = 0; i < length / 2; i++) { + formatter.format("%02x", buf.readByte()); + } + + if (length % 2 == 1) { + int b = buf.getUnsignedByte(buf.readerIndex()); + formatter.format("%01x", b >>> 4); + } + + return result.toString(); + } } -- cgit v1.2.3