From 103fbde721753b8be65c39e0e9118943c6bebc68 Mon Sep 17 00:00:00 2001 From: seym45 Date: Mon, 24 Jul 2023 20:34:00 +0400 Subject: Add Gator content encoder and test snippets --- src/main/java/org/traccar/protocol/GatorProtocolEncoder.java | 10 ++++++++-- .../java/org/traccar/protocol/GatorProtocolEncoderTest.java | 12 +++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java index 0d4353c8f..125031eee 100644 --- a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java @@ -75,8 +75,14 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder { } private ByteBuf encodeContent(long deviceId, String mainOrder, String content) { - // FIXME: implement this method - return null; + String pseudoIPAddress = encodeId(deviceId); + int length = 4 + 1 + 1; // ip 4 bytes, calibration byte and end byte + String hexStringLength = String.format("%02X", length); + + String packet = "2424" + mainOrder + "00" + hexStringLength + pseudoIPAddress; + String calibration = getCalibrationByteFromHexString(packet); + packet = packet + calibration + "0D"; + return Unpooled.wrappedBuffer(DataConverter.parseHex(packet)); } diff --git a/src/test/java/org/traccar/protocol/GatorProtocolEncoderTest.java b/src/test/java/org/traccar/protocol/GatorProtocolEncoderTest.java index 7e8f51008..74ac35440 100644 --- a/src/test/java/org/traccar/protocol/GatorProtocolEncoderTest.java +++ b/src/test/java/org/traccar/protocol/GatorProtocolEncoderTest.java @@ -4,16 +4,22 @@ import org.junit.jupiter.api.Test; import org.traccar.ProtocolTest; import org.traccar.model.Command; -import java.nio.charset.StandardCharsets; - import static org.junit.jupiter.api.Assertions.assertEquals; public class GatorProtocolEncoderTest extends ProtocolTest { @Test - void encodeId() throws Exception { + void encodeId() throws Exception { var encoder = inject(new GatorProtocolEncoder(null)); assertEquals("2008958C", encoder.encodeId(13332082112L)); + } + @Test + public void testEncode() throws Exception { + var encoder = inject(new GatorProtocolEncoder(null)); + Command command = new Command(); + command.setDeviceId(13332082112L); + command.setType(Command.TYPE_ROLLCALL); + verifyCommand(encoder, command, binary("24243000062008958C070D")); } } -- cgit v1.2.3