aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/GranitProtocolDecoder.java
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-07-06 14:54:24 +0500
committerAbyss777 <abyss@fox5.ru>2016-07-06 14:54:24 +0500
commit49f00254695ae56aa03c0174f5aadfe1a0e4c836 (patch)
treec1074e438dcb8aed8c2c2f4d172cb88e75d1bc58 /src/org/traccar/protocol/GranitProtocolDecoder.java
parent387d798a8fc66ec6792851a199fc83c4636fc6d8 (diff)
downloadtrackermap-server-49f00254695ae56aa03c0174f5aadfe1a0e4c836.tar.gz
trackermap-server-49f00254695ae56aa03c0174f5aadfe1a0e4c836.tar.bz2
trackermap-server-49f00254695ae56aa03c0174f5aadfe1a0e4c836.zip
Style fixes and optimizations
Diffstat (limited to 'src/org/traccar/protocol/GranitProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/GranitProtocolDecoder.java23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/org/traccar/protocol/GranitProtocolDecoder.java b/src/org/traccar/protocol/GranitProtocolDecoder.java
index 16229dc18..6f334d3c5 100644
--- a/src/org/traccar/protocol/GranitProtocolDecoder.java
+++ b/src/org/traccar/protocol/GranitProtocolDecoder.java
@@ -39,11 +39,11 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder {
}
public static void appendChecksum(ChannelBuffer buffer, int length) {
- buffer.writeByte(0x2a); // asterisk
+ buffer.writeByte('*');
int checksum = Checksum.xor(buffer.toByteBuffer(0, length)) & 0xFF;
String checksumString = String.format("%02X", checksum);
buffer.writeBytes(checksumString.getBytes(StandardCharsets.US_ASCII));
- buffer.writeByte(0x0D); buffer.writeByte(0x0A);
+ buffer.writeByte('\r'); buffer.writeByte('\n');
}
private static void sendResponseCurrent(Channel channel, int deviceId, long time) {
@@ -132,12 +132,10 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
-
- if (hasDeviceId() && buf.toString(StandardCharsets.US_ASCII).contains("OK")
- || buf.toString(StandardCharsets.US_ASCII).startsWith("ERROR")
- || buf.toString(StandardCharsets.US_ASCII).startsWith("+PR")
- || buf.toString(StandardCharsets.US_ASCII).startsWith("+IDNT")
- || buf.toString(StandardCharsets.US_ASCII).startsWith("+BBMD")) {
+ String bufString = buf.toString(StandardCharsets.US_ASCII);
+ if (hasDeviceId() && bufString.contains("OK") || bufString.startsWith("ERROR")
+ || bufString.startsWith("+PR") || bufString.startsWith("+IDNT")
+ || bufString.startsWith("+BBMD")) {
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(getDeviceId());
@@ -145,7 +143,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder {
position.setTime(new Date());
getLastLocation(position, new Date());
position.setValid(false);
- position.set(Position.KEY_RESULT, buf.toString(StandardCharsets.US_ASCII));
+ position.set(Position.KEY_RESULT, bufString);
return position;
}
@@ -153,10 +151,9 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder {
if (buf.readableBytes() < HEADER_LENGTH) {
return null;
}
+ buf.skipBytes(HEADER_LENGTH);
- String header = buf.readBytes(HEADER_LENGTH).toString(StandardCharsets.US_ASCII);
-
- if (header.equals("+RRCB~")) {
+ if (bufString.startsWith("+RRCB~")) {
buf.skipBytes(2); //binary length 26
int deviceId = buf.readUnsignedShort();
if (!identify(String.valueOf(deviceId), channel, remoteAddress)) {
@@ -175,7 +172,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder {
decodeStructure(buf, position);
return position;
- } else if (header.equals("+DDAT~")) {
+ } else if (bufString.startsWith("+DDAT~")) {
buf.skipBytes(2); //binary length
int deviceId = buf.readUnsignedShort();
if (!identify(String.valueOf(deviceId), channel, remoteAddress)) {