diff options
-rw-r--r-- | src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java | 48 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/GalileoProtocolDecoderTest.java | 3 |
2 files changed, 49 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java b/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java index fc8a49cf5..b5c6f77ef 100644 --- a/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java @@ -23,6 +23,7 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.NetworkMessage; import org.traccar.Protocol; import org.traccar.helper.BitBuffer; +import org.traccar.helper.BitUtil; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import org.traccar.session.DeviceSession; @@ -66,7 +67,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { }; int[] l3 = { 0x63, 0x64, 0x6f, 0x5d, 0x65, 0x66, 0x67, 0x68, - 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e + 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0xfa }; int[] l4 = { 0x20, 0x33, 0x44, 0x90, 0xc0, 0xc2, 0xc3, 0xd3, @@ -88,6 +89,8 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { } TAG_LENGTH_MAP.put(0x5b, 7); // variable length TAG_LENGTH_MAP.put(0x5c, 68); + TAG_LENGTH_MAP.put(0xfd, 8); + TAG_LENGTH_MAP.put(0xfe, 8); } private static int getTagLength(int tag) { @@ -239,6 +242,8 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { } } else if (header == 0x07) { return decodePhoto(channel, remoteAddress, buf); + } else if (header == 0x08) { + return decodeCompressedPositions(channel, remoteAddress, buf); } return null; @@ -259,7 +264,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { position.setValid(bits.readUnsigned(1) == 0); position.setLongitude(360 * bits.readUnsigned(22) / 4194304.0 - 180); - position.setLatitude(360 * bits.readUnsigned(21) / 2097152.0 - 90); + position.setLatitude(180 * bits.readUnsigned(21) / 2097152.0 - 90); if (bits.readUnsigned(1) > 0) { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } @@ -392,4 +397,43 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { return position; } + private List<Position> decodeCompressedPositions(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + + buf.readUnsignedShortLE(); // length + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null) { + return null; + } + + List<Position> positions = new LinkedList<>(); + while (buf.readableBytes() > 2) { + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + decodeMinimalDataSet(position, buf); + + int[] tags = new int[BitUtil.to(buf.readUnsignedByte(), 8)]; + for (int i = 0; i < tags.length; i++) { + tags[i] = buf.readUnsignedByte(); + } + + for (int tag : tags) { + decodeTag(position, buf, tag); + } + + positions.add(position); + + } + + sendResponse(channel, 0x02, buf.readUnsignedShortLE()); + + for (Position p : positions) { + p.setDeviceId(deviceSession.getDeviceId()); + } + + return positions.isEmpty() ? null : positions; + } + } diff --git a/src/test/java/org/traccar/protocol/GalileoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/GalileoProtocolDecoderTest.java index f676b1cc1..8c08fee14 100644 --- a/src/test/java/org/traccar/protocol/GalileoProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/GalileoProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class GalileoProtocolDecoderTest extends ProtocolTest { var decoder = inject(new GalileoProtocolDecoder(null)); verifyNotNull(decoder, binary( + "01004e01001c0747ea59333030323334303639363034353930000012000063c85e6903000b0321a8f846aba50000000202001e205f5ec863300c4643fdfdbbe6c8fb330000000034e7013505d400000000")); + + verifyNotNull(decoder, binary( "01006501001c05cf1f8133303032333430363939303130313000004a000062d8f3ee03000b000f85402088970000000602003503333030323334303639393031303130100000207af3d862300cbe08ee00acfaf001330000760634b301350840090a416b2f42920e")); verifyPositions(decoder, binary( |