diff options
-rw-r--r-- | src/main/java/org/traccar/protocol/AstraProtocolDecoder.java | 16 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/AstraProtocolDecoderTest.java | 3 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/AstraProtocolDecoder.java b/src/main/java/org/traccar/protocol/AstraProtocolDecoder.java index 366bf9e8b..a7bfd4625 100644 --- a/src/main/java/org/traccar/protocol/AstraProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/AstraProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2024 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,13 +51,21 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder { ByteBuf buf = (ByteBuf) msg; + byte protocol = buf.readByte(); + buf.readUnsignedShort(); // length + + return switch (protocol) { + case 'K' -> decodeK(channel, remoteAddress, buf); + default -> null; + }; + } + + private Object decodeK(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + if (channel != null) { channel.writeAndFlush(new NetworkMessage(Unpooled.wrappedBuffer(new byte[] {0x06}), remoteAddress)); } - buf.readUnsignedByte(); // protocol - buf.readUnsignedShort(); // length - String imei = String.format("%08d", buf.readUnsignedInt()) + String.format("%07d", buf.readUnsignedMedium()); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); if (deviceSession == null) { diff --git a/src/test/java/org/traccar/protocol/AstraProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/AstraProtocolDecoderTest.java index 3dabcac5d..cf1978f4e 100644 --- a/src/test/java/org/traccar/protocol/AstraProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/AstraProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class AstraProtocolDecoderTest extends ProtocolTest { var decoder = inject(new AstraProtocolDecoder(null)); + verifyNull(decoder, binary( + "58003d018b0000000000bf514f00b70000006000093e60514f00b6032fec49ffdc7627000041020000000100010000000000090001010000008f00aba3")); + verifyPositions(decoder, binary( "4b00700529c0c265976b8202cba9ff00676d864554a9c30000000020073401006436000300030008000000000000a0000100001920c43d00009600428302cba9ff00676d864554aa3e000000002007240100643b000300020008000000000000b0000100001920c43d00009600420f0e")); |