diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2021-05-05 19:49:18 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2021-05-05 19:49:18 -0700 |
commit | 056b1cfb785aa106b62f791b9476002471c2a8c3 (patch) | |
tree | a717b4acd1c3df3df92813f46c4745806927b8e0 /src | |
parent | 9330669fa5456d7be2395c395fbc4dde4635e923 (diff) | |
download | trackermap-server-056b1cfb785aa106b62f791b9476002471c2a8c3.tar.gz trackermap-server-056b1cfb785aa106b62f791b9476002471c2a8c3.tar.bz2 trackermap-server-056b1cfb785aa106b62f791b9476002471c2a8c3.zip |
Update code formatting
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/protocol/Mavlink2ProtocolDecoder.java | 50 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/Mavlink2ProtocolDecoderTest.java | 11 |
2 files changed, 39 insertions, 22 deletions
diff --git a/src/main/java/org/traccar/protocol/Mavlink2ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Mavlink2ProtocolDecoder.java index 666538479..431258388 100644 --- a/src/main/java/org/traccar/protocol/Mavlink2ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Mavlink2ProtocolDecoder.java @@ -15,18 +15,16 @@ */ package org.traccar.protocol; -import java.net.SocketAddress; -import java.time.Instant; -import java.util.Date; - +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.DeviceSession; import org.traccar.Protocol; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; -import io.netty.buffer.ByteBuf; -import io.netty.channel.Channel; +import java.net.SocketAddress; +import java.util.Date; public class Mavlink2ProtocolDecoder extends BaseProtocolDecoder { @@ -36,39 +34,51 @@ public class Mavlink2ProtocolDecoder extends BaseProtocolDecoder { @Override protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + ByteBuf buf = (ByteBuf) msg; - if (buf.readUnsignedByte() != 0xFD) { //Packet start marker + if (buf.readUnsignedByte() != 0xFD) { return null; } - buf.readUnsignedByte(); // Payload length - buf.readUnsignedByte(); // Incompatibility Flags - buf.readUnsignedByte(); // Compatibility Flags - buf.readUnsignedByte(); // Packet sequence number - int senderSystemId = buf.readUnsignedByte(); // System ID (sender) + + buf.readUnsignedByte(); // length + buf.readUnsignedByte(); // incompatibility flags + buf.readUnsignedByte(); // compatibility flags + buf.readUnsignedByte(); // index + + int senderSystemId = buf.readUnsignedByte(); + buf.readUnsignedByte(); // component id DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, Integer.toString(senderSystemId)); - buf.readUnsignedByte(); // Component ID (sender) if (deviceSession == null) { return null; } - int messageId = buf.readUnsignedMediumLE(); // Message ID (low, middle, high bytes) - if (messageId == 33) { + + int type = buf.readUnsignedMediumLE(); + if (type == 33) { + Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); + + position.set("timeBoot", buf.readUnsignedIntLE()); // time since system boot + position.setValid(true); - position.setTime(Date.from(Instant.now())); - position.set("timeBootms", buf.readUnsignedIntLE()); // Timestamp (time since system boot). + position.setTime(new Date()); position.setLatitude(buf.readIntLE() / 10000000.0); position.setLongitude(buf.readIntLE() / 10000000.0); - position.setAltitude(buf.readIntLE() / 1000.0); // Altitude (MSL). - position.set("relativeAltitude", buf.readIntLE() / 1000.0); // Altitude above ground + position.setAltitude(buf.readIntLE() / 1000.0); + position.set("relativeAltitude", buf.readIntLE() / 1000.0); + int groundSpeedX = buf.readShortLE(); int groundSpeedY = buf.readShortLE(); - buf.readShortLE(); // Ground Z Speed + buf.readShortLE(); // ground speed z double speed = Math.sqrt(Math.pow(groundSpeedX, 2) + Math.pow(groundSpeedY, 2)); position.setSpeed(UnitsConverter.knotsFromCps(speed)); + position.setCourse(buf.readUnsignedShortLE() / 100.0); + return position; + } + return null; } diff --git a/src/test/java/org/traccar/protocol/Mavlink2ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Mavlink2ProtocolDecoderTest.java index f4b6d8229..ccddb6a11 100644 --- a/src/test/java/org/traccar/protocol/Mavlink2ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Mavlink2ProtocolDecoderTest.java @@ -7,8 +7,15 @@ public class Mavlink2ProtocolDecoderTest extends ProtocolTest { @Test public void testDecode() throws Exception { + var decoder = new Mavlink2ProtocolDecoder(null); - verifyAttributes(decoder, binary("fd1c0000ce01012100004da91f004005d323b89aa30ea6ed070099fb0100f7fffdff0000942c4a88")); - verifyAttributes(decoder, binary("fd1c0000e7010121000047aa1f004005d323b89aa30e9ced070093fb0100f8fffdff0000952c70ff")); + + verifyAttributes(decoder, binary( + "fd1c0000ce01012100004da91f004005d323b89aa30ea6ed070099fb0100f7fffdff0000942c4a88")); + + verifyAttributes(decoder, binary( + "fd1c0000e7010121000047aa1f004005d323b89aa30e9ced070093fb0100f8fffdff0000952c70ff")); + } + } |