diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-25 11:39:59 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-25 11:39:59 +1300 |
commit | 926adc73e8415e424191d62a0e5bd0e8fe3ad5ef (patch) | |
tree | 350a9f4401c2f817809f64f80022b349c4ef5e76 /src/org/traccar | |
parent | 957740cfb5d74098971a8d4186eda4f9383774d8 (diff) | |
download | traccar-server-926adc73e8415e424191d62a0e5bd0e8fe3ad5ef.tar.gz traccar-server-926adc73e8415e424191d62a0e5bd0e8fe3ad5ef.tar.bz2 traccar-server-926adc73e8415e424191d62a0e5bd0e8fe3ad5ef.zip |
Fix few check style issues
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/protocol/AutoFon45ProtocolDecoder.java | 27 | ||||
-rw-r--r-- | src/org/traccar/protocol/TotemProtocolDecoder.java | 3 |
2 files changed, 13 insertions, 17 deletions
diff --git a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java index 53361c4ed..c09aecf95 100644 --- a/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java +++ b/src/org/traccar/protocol/AutoFon45ProtocolDecoder.java @@ -36,14 +36,24 @@ public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder { return (degrees + seconds) * ((raw & 0x0f) == 0 ? -1 : 1); } + private static byte checksum(byte[] bytes, int offset, int len) { + byte result = 0x3B; + for (int i = offset; i < offset + len; i++) { + result += 0x56 ^ bytes[i]; + result++; + result ^= 0xC5 + bytes[i]; + result--; + } + return result; + } + public AutoFon45ProtocolDecoder(AutoFon45Protocol protocol) { super(protocol); } @Override protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) - throws Exception { + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { ChannelBuffer buf = (ChannelBuffer) msg; @@ -62,7 +72,7 @@ public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder { if (channel != null) { byte[] response = "resp_crc=".getBytes("US-ASCII"); response = Arrays.copyOf(response, response.length + 1); - response[response.length - 1] = crc(bytes, 0, 18); + response[response.length - 1] = checksum(bytes, 0, 18); channel.write(ChannelBuffers.wrappedBuffer(response)); } } else if (type == MSG_LOCATION) { @@ -121,15 +131,4 @@ public class AutoFon45ProtocolDecoder extends BaseProtocolDecoder { return null; } - private byte crc(byte[] bytes, int offset, int len) { - byte GPRS_CRC = 0x3B; - for (int i = offset; i < offset + len; i++) { - GPRS_CRC += 0x56 ^ bytes[i]; - GPRS_CRC++; - GPRS_CRC ^= 0xC5 + bytes[i]; - GPRS_CRC--; - } - return GPRS_CRC; - } - } diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java index 556a9fa1e..321b78b7c 100644 --- a/src/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/org/traccar/protocol/TotemProtocolDecoder.java @@ -16,9 +16,6 @@ package org.traccar.protocol; import java.net.SocketAddress; -import java.util.Calendar; -import java.util.TimeZone; -import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; |