aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/protocol/AutoFon45ProtocolDecoder.java27
-rw-r--r--src/org/traccar/protocol/TotemProtocolDecoder.java3
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;