From ae84a13424be6bd55ddc12182554ba859b5dc786 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 24 May 2014 14:28:45 +1200 Subject: Delete recorded data (fix #419) --- src/org/traccar/ServerManager.java | 1 + src/org/traccar/protocol/MeitrackProtocolDecoder.java | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java index b640462b0..56b1f8416 100644 --- a/src/org/traccar/ServerManager.java +++ b/src/org/traccar/ServerManager.java @@ -524,6 +524,7 @@ public class ServerManager { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { pipeline.addLast("frameDecoder", new MeitrackFrameDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(ServerManager.this)); } }; diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 7f63b4b64..3d3d31002 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -29,6 +29,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.traccar.BaseProtocolDecoder; import org.traccar.ServerManager; import org.traccar.helper.ChannelBufferTools; +import org.traccar.helper.Crc; import org.traccar.helper.Log; import org.traccar.model.ExtendedInfoFormatter; import org.traccar.model.Position; @@ -67,7 +68,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { "(\\p{XDigit}+)," + // Power ".*(\r\n)?"); - private Position decodeRegularMessage(ChannelBuffer buf) { + private Position decodeRegularMessage(Channel channel, ChannelBuffer buf) { // Parse message String sentence = buf.toString(Charset.defaultCharset()); @@ -152,7 +153,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { return position; } - private List decodeBinaryMessage(ChannelBuffer buf) { + private List decodeBinaryMessage(Channel channel, ChannelBuffer buf) { List positions = new LinkedList(); Integer index = ChannelBufferTools.find(buf, 0, buf.readableBytes(), ","); @@ -225,6 +226,16 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { positions.add(position); } + // Delete recorded data + if (channel != null) { + StringBuilder command = new StringBuilder("@@W28,"); + command.append(imei).append(",CCC,").append(positions.size()).append("*"); + int checksum = 0; + for (int i = 0; i < command.length(); i += 1) checksum += command.charAt(i); + command.append(String.format("%02x\r\n", checksum & 0xff).toUpperCase()); + channel.write(command.toString()); + } + return positions; } @@ -241,9 +252,9 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { String type = buf.toString(index + 1, 3, Charset.defaultCharset()); if (type.equals("CCC")) { - return decodeBinaryMessage(buf); + return decodeBinaryMessage(channel, buf); } else { - return decodeRegularMessage(buf); + return decodeRegularMessage(channel, buf); } } -- cgit v1.2.3