From 4620fc2db16f05bcd3578b4f5a3239b229d7c99f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 24 Jul 2024 06:51:44 -0700 Subject: Refactor Astra decoder --- .../java/org/traccar/protocol/AstraProtocolDecoder.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/main') 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) { -- cgit v1.2.3