From c80d01e1646b8cb1a626f33bbd488d02f15335cc Mon Sep 17 00:00:00 2001 From: Gavriel Fleischer Date: Sun, 17 Feb 2019 04:53:22 +0200 Subject: fixed WatchProtocolDecoder response after removed StringEncoder --- src/org/traccar/protocol/WatchProtocolDecoder.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index bf4d99a49..aaf63206c 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -16,6 +16,7 @@ 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; @@ -66,15 +67,18 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { .expression("(.*)") // cell and wifi .compile(); - private void sendResponse(Channel channel, String id, String index, String content) { + private void sendTextResponse(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())); } } @@ -229,11 +233,11 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { if (type.equals("INIT")) { - sendResponse(channel, id, index, "INIT,1"); + sendTextResponse(channel, id, index, "INIT,1"); } else if (type.equals("LK")) { - sendResponse(channel, id, index, "LK"); + sendTextResponse(channel, id, index, "LK"); if (buf.isReadable()) { String[] values = buf.toString(StandardCharsets.US_ASCII).split(","); @@ -258,14 +262,14 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { if (position != null) { position.set(Position.KEY_ALARM, Position.ALARM_SOS); } - sendResponse(channel, id, index, "AL"); + sendTextResponse(channel, id, index, "AL"); } return position; } else if (type.equals("TKQ")) { - sendResponse(channel, id, index, "TKQ"); + sendTextResponse(channel, id, index, "TKQ"); } else if (type.equals("PULSE") || type.equals("heart") || type.equals("bphrt")) { -- cgit v1.2.3