aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2012-12-21 22:04:03 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2012-12-21 22:04:03 +1300
commitfe9f9b034713cb98531d73698a65bd03d18a771c (patch)
treee6c9c976951b018936fa849deeae5fd96afb3bb3 /src/org/traccar/helper
parentb10a929a464eb866b47d08619d3f792fb00a92e4 (diff)
downloadtrackermap-server-fe9f9b034713cb98531d73698a65bd03d18a771c.tar.gz
trackermap-server-fe9f9b034713cb98531d73698a65bd03d18a771c.tar.bz2
trackermap-server-fe9f9b034713cb98531d73698a65bd03d18a771c.zip
Added GT06 protocol (fix #100)
Diffstat (limited to 'src/org/traccar/helper')
-rw-r--r--src/org/traccar/helper/Crc.java20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/org/traccar/helper/Crc.java b/src/org/traccar/helper/Crc.java
index 5da774d65..cef0cc482 100644
--- a/src/org/traccar/helper/Crc.java
+++ b/src/org/traccar/helper/Crc.java
@@ -15,6 +15,8 @@
*/
package org.traccar.helper;
+import java.nio.ByteBuffer;
+
/**
* CRC functions
*/
@@ -93,35 +95,35 @@ public class Crc {
private static final int crc16CcittStart = 0xFFFF;
private static final int crc16CcittXorout = 0xFFFF;
- private static int crc16Unreflected(byte[] buf, int crc_in, int[] table) {
+ private static int crc16Unreflected(ByteBuffer buf, int crc_in, int[] table) {
int crc16 = crc_in;
- for (int i = 0; i < buf.length; i++) {
- crc16 = table[((crc16 >> 8) ^ buf[i]) & 0xff] ^ (crc16 << 8);
+ for (int i = 0; i < buf.remaining(); i++) {
+ crc16 = table[((crc16 >> 8) ^ buf.get(i)) & 0xff] ^ (crc16 << 8);
}
return crc16 & 0xFFFF;
}
- private static int crc16Reflected(byte[] buf, int crc_in, int[] table) {
+ private static int crc16Reflected(ByteBuffer buf, int crc_in, int[] table) {
int crc16 = crc_in;
- for (int i = 0; i < buf.length; i++) {
- crc16 = table[(crc16 ^ buf[i]) & 0xff] ^ (crc16 >> 8);
+ for (int i = 0; i < buf.remaining(); i++) {
+ crc16 = table[(crc16 ^ buf.get(i)) & 0xff] ^ (crc16 >> 8);
}
return crc16 & 0xFFFF;
}
- public static int crc16Ccitt(byte[] buf) {
+ public static int crc16Ccitt(ByteBuffer buf) {
return crc16Reflected(buf, crc16CcittStart, crc16CcittTableReverse) ^ crc16CcittXorout;
}
- public static int crc16X25Ccitt(byte[] buf) {
+ public static int crc16X25Ccitt(ByteBuffer buf) {
return crc16Unreflected(buf, crc16CcittStart, crc16CcittTable);
}
- public static int crc16CcittSeed(byte[] buf, int seed) {
+ public static int crc16CcittSeed(ByteBuffer buf, int seed) {
return crc16Reflected(buf, seed, crc16CcittTableReverse) ^ crc16CcittXorout;
}