aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper/ChannelBufferTools.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/helper/ChannelBufferTools.java')
-rw-r--r--src/org/traccar/helper/ChannelBufferTools.java26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/org/traccar/helper/ChannelBufferTools.java b/src/org/traccar/helper/ChannelBufferTools.java
index 12e8fc93d..75c16ae50 100644
--- a/src/org/traccar/helper/ChannelBufferTools.java
+++ b/src/org/traccar/helper/ChannelBufferTools.java
@@ -55,14 +55,14 @@ public class ChannelBufferTools {
return null;
}
-
+
/**
* Convert hex to integer (length in hex digits)
*/
public static int readHexInteger(ChannelBuffer buf, int length) {
-
+
int result = 0;
-
+
for (int i = 0; i < length / 2; i++) {
int b = buf.readUnsignedByte();
result *= 10;
@@ -70,13 +70,13 @@ public class ChannelBufferTools {
result *= 10;
result += b & 0x0f;
}
-
+
if (length % 2 == 1) {
int b = buf.getUnsignedByte(buf.readerIndex());
result *= 10;
result += b >>> 4;
}
-
+
return result;
}
@@ -84,22 +84,22 @@ public class ChannelBufferTools {
* 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();
}
-
+
/**
* Read BCD coded coordinate (first byte has sign bit)
*/
@@ -108,16 +108,16 @@ public class ChannelBufferTools {
int b2 = buf.readUnsignedByte();
int b3 = buf.readUnsignedByte();
int b4 = buf.readUnsignedByte();
-
+
double value = (b2 & 0xf) * 10 + (b3 >> 4);
value += (((b3 & 0xf) * 10 + (b4 >> 4)) * 10 + (b4 & 0xf)) / 1000.0;
value /= 60;
value += ((b1 >> 4 & 0x7) * 10 + (b1 & 0xf)) * 10 + (b2 >> 4);
-
+
if ((b1 & 0x80) != 0) {
value = -value;
}
-
+
return value;
}