diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/helper/Crc.java | 20 | ||||
-rw-r--r-- | src/org/traccar/protocol/Gt06ProtocolEncoder.java | 4 |
2 files changed, 10 insertions, 14 deletions
diff --git a/src/org/traccar/helper/Crc.java b/src/org/traccar/helper/Crc.java index 7aa7d094a..3df6ffd71 100644 --- a/src/org/traccar/helper/Crc.java +++ b/src/org/traccar/helper/Crc.java @@ -99,21 +99,17 @@ public class Crc { private static int crc16Unreflected(ByteBuffer buf, int crc_in, int[] table) { int crc16 = crc_in; - - for (int i = 0; i < buf.remaining(); i++) { - crc16 = table[((crc16 >> 8) ^ buf.get(i)) & 0xff] ^ (crc16 << 8); + while (buf.hasRemaining()) { + crc16 = table[((crc16 >> 8) ^ buf.get()) & 0xff] ^ (crc16 << 8); } - return crc16 & 0xFFFF; } private static int crc16Reflected(ByteBuffer buf, int crc_in, int[] table) { int crc16 = crc_in; - - for (int i = 0; i < buf.remaining(); i++) { - crc16 = table[(crc16 ^ buf.get(i)) & 0xff] ^ (crc16 >> 8); + while (buf.hasRemaining()) { + crc16 = table[(crc16 ^ buf.get()) & 0xff] ^ (crc16 >> 8); } - return crc16 & 0xFFFF; } @@ -131,16 +127,16 @@ public class Crc { public static int crc32(ByteBuffer buf) { CRC32 checksum = new CRC32(); - for (int i = 0; i < buf.remaining(); i++) { - checksum.update(buf.get(i)); + while (buf.hasRemaining()) { + checksum.update(buf.get()); } 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); + while (buf.hasRemaining()) { + checksum ^= buf.get(); } return checksum; } diff --git a/src/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/org/traccar/protocol/Gt06ProtocolEncoder.java index 495e2fff5..e842c3a69 100644 --- a/src/org/traccar/protocol/Gt06ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolEncoder.java @@ -53,9 +53,9 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { switch (command.getType()) { case Command.TYPE_ENGINE_STOP: - return encodeContent("RELAY,1#"); + return encodeContent("Relay,1#"); case Command.TYPE_ENGINE_RESUME: - return encodeContent("RELAY,0#"); + return encodeContent("Relay,0#"); } return null; |