diff options
author | Anton Tananaev <anton@traccar.org> | 2024-07-24 06:51:44 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-07-24 06:51:44 -0700 |
commit | 4620fc2db16f05bcd3578b4f5a3239b229d7c99f (patch) | |
tree | 80fa8c2eb9722f27a558da0f59c27be220cce805 /src/main | |
parent | 1f1edcfb0e7ca5a6daf2a9a251a433062344d680 (diff) | |
download | trackermap-server-4620fc2db16f05bcd3578b4f5a3239b229d7c99f.tar.gz trackermap-server-4620fc2db16f05bcd3578b4f5a3239b229d7c99f.tar.bz2 trackermap-server-4620fc2db16f05bcd3578b4f5a3239b229d7c99f.zip |
Refactor Astra decoder
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/traccar/protocol/AstraProtocolDecoder.java | 16 |
1 files changed, 12 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) { |