diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2014-05-24 14:28:45 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2014-05-24 14:28:45 +1200 |
commit | ae84a13424be6bd55ddc12182554ba859b5dc786 (patch) | |
tree | 5557a966abe0cc98f4483efe9cf557f9d23bb1ea /src/org/traccar/protocol | |
parent | 1db9f7f27f9d4779dbd1a4a55a3be450604204a4 (diff) | |
download | trackermap-server-ae84a13424be6bd55ddc12182554ba859b5dc786.tar.gz trackermap-server-ae84a13424be6bd55ddc12182554ba859b5dc786.tar.bz2 trackermap-server-ae84a13424be6bd55ddc12182554ba859b5dc786.zip |
Delete recorded data (fix #419)
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r-- | src/org/traccar/protocol/MeitrackProtocolDecoder.java | 19 |
1 files changed, 15 insertions, 4 deletions
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<Position> decodeBinaryMessage(ChannelBuffer buf) { + private List<Position> decodeBinaryMessage(Channel channel, ChannelBuffer buf) { List<Position> positions = new LinkedList<Position>(); 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); } } |