diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-02-18 13:18:28 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-18 13:18:28 -0800 |
commit | 0e209e80f03e72095e5b449679925066b01403d2 (patch) | |
tree | 881ab37ce5867fd8358d4bdf0195824c47e26be2 /src/org/traccar/protocol/WatchProtocolDecoder.java | |
parent | 774d560ecb5f8da9e64059a4d25622c4fba55bf2 (diff) | |
parent | c82be0541481955a0832948574244f31757f7067 (diff) | |
download | traccar-server-0e209e80f03e72095e5b449679925066b01403d2.tar.gz traccar-server-0e209e80f03e72095e5b449679925066b01403d2.tar.bz2 traccar-server-0e209e80f03e72095e5b449679925066b01403d2.zip |
Merge pull request #4221 from flocsy/8bit-voice-message
Fixed 8bit voice message
Diffstat (limited to 'src/org/traccar/protocol/WatchProtocolDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/WatchProtocolDecoder.java | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index 78b190030..70b207e9b 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -16,7 +16,10 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import io.netty.channel.Channel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; @@ -38,6 +41,8 @@ import java.util.regex.Pattern; public class WatchProtocolDecoder extends BaseProtocolDecoder { + private static final Logger LOGGER = LoggerFactory.getLogger(WatchProtocolDecoder.class); + public WatchProtocolDecoder(Protocol protocol) { super(protocol); } @@ -64,13 +69,16 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { private void sendResponse(Channel channel, String id, String index, String content) { if (channel != null) { + String response; if (index != null) { - channel.writeAndFlush(new NetworkMessage(String.format("[%s*%s*%s*%04x*%s]", - manufacturer, id, index, content.length(), content), channel.remoteAddress())); + response = String.format("[%s*%s*%s*%04x*%s]", + manufacturer, id, index, content.length(), content); } else { - channel.writeAndFlush(new NetworkMessage(String.format("[%s*%s*%04x*%s]", - manufacturer, id, content.length(), content), channel.remoteAddress())); + response = String.format("[%s*%s*%04x*%s]", + manufacturer, id, content.length(), content); } + ByteBuf buf = Unpooled.copiedBuffer(response, StandardCharsets.US_ASCII); + channel.writeAndFlush(new NetworkMessage(buf, channel.remoteAddress())); } } @@ -180,9 +188,9 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { ByteBuf buf = (ByteBuf) msg; - buf.skipBytes(1); // header + buf.skipBytes(1); // '[' header manufacturer = buf.readSlice(2).toString(StandardCharsets.US_ASCII); - buf.skipBytes(1); // delimiter + buf.skipBytes(1); // '*' delimiter int idIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*'); String id = buf.readSlice(idIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII); @@ -191,7 +199,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { return null; } - buf.skipBytes(1); // delimiter + buf.skipBytes(1); // '*' delimiter String index = null; int contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*'); @@ -200,13 +208,13 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { 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 + buf.skipBytes(1); // '*' delimiter } buf.skipBytes(4); // length - buf.skipBytes(1); // delimiter + buf.skipBytes(1); // '*' delimiter - buf.writerIndex(buf.writerIndex() - 1); // ignore ending + buf.writerIndex(buf.writerIndex() - 1); // ']' ignore ending contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ','); if (contentIndex < 0) { @@ -296,6 +304,14 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { } else if (type.equals("TK")) { + if (buf.readableBytes() == 1) { + byte result = buf.readByte(); + if (result != '1') { + LOGGER.warn(type + "," + result); + } + return null; + } + Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); |