aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorGavriel Fleischer <flocsy@gmail.com>2019-02-17 21:42:29 +0200
committerGavriel Fleischer <flocsy@gmail.com>2019-02-17 21:43:35 +0200
commit074b1c302dcd6671737d44c69aa83d0fdd179168 (patch)
treeeb13840ebd001a544e145f15016c340f57c8d651 /src/org/traccar/protocol
parentc80d01e1646b8cb1a626f33bbd488d02f15335cc (diff)
downloadtraccar-server-074b1c302dcd6671737d44c69aa83d0fdd179168.tar.gz
traccar-server-074b1c302dcd6671737d44c69aa83d0fdd179168.tar.bz2
traccar-server-074b1c302dcd6671737d44c69aa83d0fdd179168.zip
resolving review issues
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/WatchFrameDecoder.java12
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java24
2 files changed, 16 insertions, 20 deletions
diff --git a/src/org/traccar/protocol/WatchFrameDecoder.java b/src/org/traccar/protocol/WatchFrameDecoder.java
index b4a82c0be..f99bd52e2 100644
--- a/src/org/traccar/protocol/WatchFrameDecoder.java
+++ b/src/org/traccar/protocol/WatchFrameDecoder.java
@@ -31,10 +31,10 @@ public class WatchFrameDecoder extends BaseFrameDecoder {
if (endIndex > 0) {
ByteBuf frame = Unpooled.buffer();
while (buf.readerIndex() < endIndex) {
- byte b = buf.readByte();
- if (b == '}') {
- byte c = buf.readByte();
- switch (c) {
+ byte b1 = buf.readByte();
+ if (b1 == '}') {
+ byte b2 = buf.readByte();
+ switch (b2) {
case 0x01:
frame.writeByte('}');
break;
@@ -52,10 +52,10 @@ public class WatchFrameDecoder extends BaseFrameDecoder {
break;
default:
throw new IllegalArgumentException(String.format(
- "unexpected byte at %d: 0x%02x", buf.readerIndex() - 1, c));
+ "unexpected byte at %d: 0x%02x", buf.readerIndex() - 1, b2));
}
} else {
- frame.writeByte(b);
+ frame.writeByte(b1);
}
}
return frame;
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index aaf63206c..70b207e9b 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.java
@@ -67,7 +67,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
.expression("(.*)") // cell and wifi
.compile();
- private void sendTextResponse(Channel channel, String id, String index, String content) {
+ private void sendResponse(Channel channel, String id, String index, String content) {
if (channel != null) {
String response;
if (index != null) {
@@ -182,10 +182,6 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
return manufacturer;
}
- protected int nextIndexOf(ByteBuf buf, char delimiter) {
- return buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) delimiter);
- }
-
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -196,7 +192,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
manufacturer = buf.readSlice(2).toString(StandardCharsets.US_ASCII);
buf.skipBytes(1); // '*' delimiter
- int idIndex = nextIndexOf(buf, '*');
+ int idIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
String id = buf.readSlice(idIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
@@ -206,10 +202,10 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(1); // '*' delimiter
String index = null;
- int contentIndex = nextIndexOf(buf, '*');
+ int contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
if (contentIndex + 5 < buf.writerIndex() && buf.getByte(contentIndex + 5) == '*'
&& buf.toString(contentIndex + 1, 4, StandardCharsets.US_ASCII).matches("\\p{XDigit}+")) {
- int indexLength = nextIndexOf(buf, '*') - buf.readerIndex();
+ int indexLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*') - buf.readerIndex();
hasIndex = true;
index = buf.readSlice(indexLength).toString(StandardCharsets.US_ASCII);
buf.skipBytes(1); // '*' delimiter
@@ -220,7 +216,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
buf.writerIndex(buf.writerIndex() - 1); // ']' ignore ending
- contentIndex = nextIndexOf(buf, ',');
+ contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
if (contentIndex < 0) {
contentIndex = buf.writerIndex();
}
@@ -233,11 +229,11 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
if (type.equals("INIT")) {
- sendTextResponse(channel, id, index, "INIT,1");
+ sendResponse(channel, id, index, "INIT,1");
} else if (type.equals("LK")) {
- sendTextResponse(channel, id, index, "LK");
+ sendResponse(channel, id, index, "LK");
if (buf.isReadable()) {
String[] values = buf.toString(StandardCharsets.US_ASCII).split(",");
@@ -262,14 +258,14 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
if (position != null) {
position.set(Position.KEY_ALARM, Position.ALARM_SOS);
}
- sendTextResponse(channel, id, index, "AL");
+ sendResponse(channel, id, index, "AL");
}
return position;
} else if (type.equals("TKQ")) {
- sendTextResponse(channel, id, index, "TKQ");
+ sendResponse(channel, id, index, "TKQ");
} else if (type.equals("PULSE") || type.equals("heart") || type.equals("bphrt")) {
@@ -311,7 +307,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
if (buf.readableBytes() == 1) {
byte result = buf.readByte();
if (result != '1') {
- LOGGER.error(type + "," + result);
+ LOGGER.warn(type + "," + result);
}
return null;
}