From 37a594b4ac0297988b2d2d073bfaee5700df043e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 21 Oct 2015 13:59:10 +1300 Subject: Log all commands to devices --- src/org/traccar/BaseProtocolEncoder.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/org/traccar/BaseProtocolEncoder.java b/src/org/traccar/BaseProtocolEncoder.java index 296ee2d4b..d53607e68 100644 --- a/src/org/traccar/BaseProtocolEncoder.java +++ b/src/org/traccar/BaseProtocolEncoder.java @@ -18,7 +18,9 @@ package org.traccar; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.handler.codec.oneone.OneToOneEncoder; +import org.traccar.helper.Log; import org.traccar.model.Command; +import org.traccar.model.Position; public abstract class BaseProtocolEncoder extends OneToOneEncoder { @@ -30,7 +32,22 @@ public abstract class BaseProtocolEncoder extends OneToOneEncoder { protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (msg instanceof Command) { - return encodeCommand((Command) msg); + Command command = (Command) msg; + Object encodedCommand = encodeCommand(command); + + // Log command + StringBuilder s = new StringBuilder(); + s.append(String.format("[%08X] ", channel.getId())); + s.append("command type: ").append(command.getType()).append(", "); + s.append("id : ").append(command.getDeviceId()).append(" "); + if (encodedCommand != null) { + s.append("sent"); + } else { + s.append("not sent"); + } + Log.info(s.toString()); + + return encodedCommand; } return msg; -- cgit v1.2.3