From f36f7f5700785f11660f3ec29d4cabe7e31d1a13 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Sun, 22 May 2016 15:10:43 +0500 Subject: Log Command result --- src/org/traccar/MainEventHandler.java | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/org/traccar/MainEventHandler.java') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index 16c4fd7be..bdb451e11 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -24,6 +24,7 @@ import org.jboss.netty.channel.socket.DatagramChannel; import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler; import org.jboss.netty.handler.timeout.IdleStateEvent; import org.traccar.helper.Log; +import org.traccar.model.Event; import org.traccar.model.Position; import java.text.SimpleDateFormat; @@ -49,6 +50,9 @@ public class MainEventHandler extends IdleStateAwareChannelHandler { s.append("lon: ").append(String.format("%.5f", position.getLongitude())).append(", "); s.append("speed: ").append(String.format("%.1f", position.getSpeed())).append(", "); s.append("course: ").append(String.format("%.1f", position.getCourse())); + if ((position.getAttributes().get(Event.KEY_RESULT) != null)) { + s.append(", result:").append(position.getAttributes().get(Event.KEY_RESULT)); + } Log.info(s.toString()); Position lastPosition = Context.getConnectionManager().getLastPosition(position.getDeviceId()); -- cgit v1.2.3 From f8808f942a094efb723c66b83eeed8a88a8e01c6 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Sun, 22 May 2016 15:14:34 +0500 Subject: Added missed space --- src/org/traccar/MainEventHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org/traccar/MainEventHandler.java') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index bdb451e11..5a8952abe 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -51,7 +51,7 @@ public class MainEventHandler extends IdleStateAwareChannelHandler { s.append("speed: ").append(String.format("%.1f", position.getSpeed())).append(", "); s.append("course: ").append(String.format("%.1f", position.getCourse())); if ((position.getAttributes().get(Event.KEY_RESULT) != null)) { - s.append(", result:").append(position.getAttributes().get(Event.KEY_RESULT)); + s.append(", result: ").append(position.getAttributes().get(Event.KEY_RESULT)); } Log.info(s.toString()); -- cgit v1.2.3 From 0065906b1c745eb4305469e562b9c740e694074c Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 23 May 2016 09:41:27 +0500 Subject: Two optimizations --- src/org/traccar/MainEventHandler.java | 5 +++-- src/org/traccar/protocol/WondexProtocolDecoder.java | 14 ++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src/org/traccar/MainEventHandler.java') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index 5a8952abe..0f20b312b 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -50,8 +50,9 @@ public class MainEventHandler extends IdleStateAwareChannelHandler { s.append("lon: ").append(String.format("%.5f", position.getLongitude())).append(", "); s.append("speed: ").append(String.format("%.1f", position.getSpeed())).append(", "); s.append("course: ").append(String.format("%.1f", position.getCourse())); - if ((position.getAttributes().get(Event.KEY_RESULT) != null)) { - s.append(", result: ").append(position.getAttributes().get(Event.KEY_RESULT)); + Object cmdResult = position.getAttributes().get(Event.KEY_RESULT); + if (cmdResult != null) { + s.append(", result: ").append(cmdResult); } Log.info(s.toString()); diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java index 837f40a08..366466143 100644 --- a/src/org/traccar/protocol/WondexProtocolDecoder.java +++ b/src/org/traccar/protocol/WondexProtocolDecoder.java @@ -61,26 +61,28 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder { protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { - if (((ChannelBuffer) msg).getUnsignedByte(0) == 0xD0) { + ChannelBuffer buf = (ChannelBuffer) msg; - long deviceId = ((Long.reverseBytes((((ChannelBuffer) msg).getLong(0)))) >> 32) & 0xFFFFFFFFL; + if (buf.getUnsignedByte(0) == 0xD0) { + + long deviceId = ((Long.reverseBytes(buf.getLong(0))) >> 32) & 0xFFFFFFFFL; identify(String.valueOf(deviceId), channel, remoteAddress); return null; - } else if (((ChannelBuffer) msg).toString(StandardCharsets.US_ASCII).startsWith("$OK:") - || ((ChannelBuffer) msg).toString(StandardCharsets.US_ASCII).startsWith("$ERR:")) { + } else if (buf.toString(StandardCharsets.US_ASCII).startsWith("$OK:") + || buf.toString(StandardCharsets.US_ASCII).startsWith("$ERR:")) { Position position = new Position(); position.setProtocol(getProtocolName()); position.setDeviceId(getDeviceId()); getLastLocation(position, new Date()); position.setValid(false); - position.set(Event.KEY_RESULT, ((ChannelBuffer) msg).toString(StandardCharsets.US_ASCII)); + position.set(Event.KEY_RESULT, buf.toString(StandardCharsets.US_ASCII)); return position; } else { - Parser parser = new Parser(PATTERN, ((ChannelBuffer) msg).toString(StandardCharsets.US_ASCII)); + Parser parser = new Parser(PATTERN, buf.toString(StandardCharsets.US_ASCII)); if (!parser.matches()) { return null; } -- cgit v1.2.3