aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/helper')
-rw-r--r--src/org/traccar/helper/ChannelBufferTools.java22
-rw-r--r--src/org/traccar/helper/Crc.java8
2 files changed, 30 insertions, 0 deletions
diff --git a/src/org/traccar/helper/ChannelBufferTools.java b/src/org/traccar/helper/ChannelBufferTools.java
index c0df86bcd..ef2ebc313 100644
--- a/src/org/traccar/helper/ChannelBufferTools.java
+++ b/src/org/traccar/helper/ChannelBufferTools.java
@@ -97,6 +97,28 @@ public class ChannelBufferTools {
return result.toString();
}
+
+ /**
+ * Read BCD coded coordinate (first byte has sign bit)
+ */
+ public static double readCoordinate(ChannelBuffer buf) {
+ int b1 = buf.readUnsignedByte();
+ 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;
+ }
+
/**
* Convert integer array to byte array
diff --git a/src/org/traccar/helper/Crc.java b/src/org/traccar/helper/Crc.java
index 84224a781..5a668f30a 100644
--- a/src/org/traccar/helper/Crc.java
+++ b/src/org/traccar/helper/Crc.java
@@ -136,6 +136,14 @@ public class Crc {
}
return (int) checksum.getValue();
}
+
+ public static int xorChecksum(ByteBuffer buf) {
+ int checksum = 0;
+ for (int i = 0; i < buf.remaining(); i++) {
+ checksum ^= buf.get(i);
+ }
+ return checksum;
+ }
public static String nmeaChecksum(String msg) {
int checksum = 0;