aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-10-05 16:25:42 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-10-05 16:25:42 +1300
commit1570f3cda955c895498edafaa87b12aa4fdd6c33 (patch)
treedbd7b2fae6a48507e9e92d304282ba89657e6e6f
parentc261ba04b0e8c1a0cc9c9be8a9fb7dfc6bf0d826 (diff)
downloadtraccar-server-1570f3cda955c895498edafaa87b12aa4fdd6c33.tar.gz
traccar-server-1570f3cda955c895498edafaa87b12aa4fdd6c33.tar.bz2
traccar-server-1570f3cda955c895498edafaa87b12aa4fdd6c33.zip
Fix checksum calculation methods
-rw-r--r--src/org/traccar/helper/Crc.java20
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolEncoder.java4
-rw-r--r--test/org/traccar/protocol/Gt06ProtocolEncoderTest.java2
3 files changed, 11 insertions, 15 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;
diff --git a/test/org/traccar/protocol/Gt06ProtocolEncoderTest.java b/test/org/traccar/protocol/Gt06ProtocolEncoderTest.java
index 2eadb2e20..7f616d9df 100644
--- a/test/org/traccar/protocol/Gt06ProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/Gt06ProtocolEncoderTest.java
@@ -18,7 +18,7 @@ public class Gt06ProtocolEncoderTest {
command.setType(Command.TYPE_ENGINE_STOP);
Assert.assertEquals(encoder.encodeCommand(command), ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
- "787812800c0000000052454c41592c312300001c300d0a")));
+ "787812800c0000000052656c61792c312300009dee0d0a")));
}