From 358b591bc457786927ac1466e10181bbffbcf56b Mon Sep 17 00:00:00 2001 From: Ivan Muratov Date: Thu, 13 Jul 2017 08:42:17 +0300 Subject: Replace MODULO256 checksum method. Added covering tests. --- src/org/traccar/protocol/Arnavi4ProtocolDecoder.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java b/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java index caa8dd28f..46caebb71 100644 --- a/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java +++ b/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java @@ -5,6 +5,7 @@ import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; +import org.traccar.helper.Checksum; import org.traccar.model.Position; import java.net.SocketAddress; @@ -35,14 +36,6 @@ public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private static int modulo256Checksum(byte[] bytes) { - int sum = 0; - for (byte b : bytes) { - sum = (sum + b) & 0xFF; - } - return sum; - } - private Position decodePosition(DeviceSession deviceSession, ChannelBuffer buf, long timestamp) { final Position position = new Position(); @@ -107,7 +100,7 @@ public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder { response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 9); response.writeBytes(new byte[]{0x7B, 0x04, 0x00}); byte[] timestampBytes = ByteBuffer.allocate(4).putInt((int) (System.currentTimeMillis() / 1000)).array(); - response.writeByte(modulo256Checksum(timestampBytes)); + response.writeByte(Checksum.modulo256(timestampBytes)); response.writeBytes(timestampBytes); response.writeByte(0x7D); -- cgit v1.2.3