From 9c03a0505f46a92f645dc927dba2da6458facfb1 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 3 Nov 2022 20:29:36 -0700 Subject: Reuse checksum code --- .../java/org/traccar/protocol/MeitrackProtocolDecoder.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java index 8a58ebc5e..8e5269ec8 100644 --- a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -363,17 +363,13 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { positions.add(position); } - if (channel != null) { + if (channel == null) { StringBuilder command = new StringBuilder("@@"); command.append(flag).append(27 + positions.size() / 10).append(","); 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", checksum & 0xff).toUpperCase()); + command.append(Checksum.sum(command.toString())); command.append("\r\n"); - channel.writeAndFlush(new NetworkMessage(command.toString(), remoteAddress)); // delete processed data + channel.writeAndFlush(new NetworkMessage(command.toString(), remoteAddress)); } return positions; -- cgit v1.2.3