From 685eaa95a6633fc840bae47a7ced290f37dbd4fb Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 18 Aug 2019 18:34:02 -0700 Subject: Fix modular type response --- .../protocol/CellocatorProtocolEncoder.java | 37 ++++++++++++++-------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'src/main/java/org/traccar/protocol/CellocatorProtocolEncoder.java') diff --git a/src/main/java/org/traccar/protocol/CellocatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/CellocatorProtocolEncoder.java index 52de4593c..76fa67686 100644 --- a/src/main/java/org/traccar/protocol/CellocatorProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/CellocatorProtocolEncoder.java @@ -27,24 +27,18 @@ public class CellocatorProtocolEncoder extends BaseProtocolEncoder { super(protocol); } - private ByteBuf encodeContent(long deviceId, int command, int data1, int data2) { + public static ByteBuf encodeContent(int type, int uniqueId, int packetNumber, ByteBuf content) { - ByteBuf buf = Unpooled.buffer(0); + ByteBuf buf = Unpooled.buffer(); buf.writeByte('M'); buf.writeByte('C'); buf.writeByte('G'); buf.writeByte('P'); - buf.writeByte(0); - buf.writeIntLE(Integer.parseInt(getUniqueId(deviceId))); - buf.writeByte(0); // command numerator + buf.writeByte(type); + buf.writeIntLE(uniqueId); + buf.writeByte(packetNumber); buf.writeIntLE(0); // authentication code - buf.writeByte(command); - buf.writeByte(command); - buf.writeByte(data1); - buf.writeByte(data1); - buf.writeByte(data2); - buf.writeByte(data2); - buf.writeIntLE(0); // command specific data + buf.writeBytes(content); byte checksum = 0; for (int i = 4; i < buf.writerIndex(); i++) { @@ -55,6 +49,23 @@ public class CellocatorProtocolEncoder extends BaseProtocolEncoder { return buf; } + private ByteBuf encodeCommand(long deviceId, int command, int data1, int data2) { + + ByteBuf content = Unpooled.buffer(); + content.writeByte(command); + content.writeByte(command); + content.writeByte(data1); + content.writeByte(data1); + content.writeByte(data2); + content.writeByte(data2); + content.writeIntLE(0); // command specific data + + ByteBuf buf = encodeContent(0, Integer.parseInt(getUniqueId(deviceId)), 0, content); + content.release(); + + return buf; + } + @Override protected Object encodeCommand(Command command) { @@ -62,7 +73,7 @@ public class CellocatorProtocolEncoder extends BaseProtocolEncoder { case Command.TYPE_OUTPUT_CONTROL: int data = Integer.parseInt(command.getString(Command.KEY_DATA)) << 4 + command.getInteger(Command.KEY_INDEX); - return encodeContent(command.getDeviceId(), 0x03, data, 0); + return encodeCommand(command.getDeviceId(), 0x03, data, 0); default: return null; } -- cgit v1.2.3