main.com.divpundir.mavlink.definitions.common.SafetyAllowedArea.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of definitions Show documentation
Show all versions of definitions Show documentation
A modern MAVLink library for the JVM written in Kotlin.
package com.divpundir.mavlink.definitions.common
import com.divpundir.mavlink.api.GeneratedMavField
import com.divpundir.mavlink.api.GeneratedMavMessage
import com.divpundir.mavlink.api.MavDeserializer
import com.divpundir.mavlink.api.MavEnumValue
import com.divpundir.mavlink.api.MavMessage
import com.divpundir.mavlink.serialization.decodeEnumValue
import com.divpundir.mavlink.serialization.decodeFloat
import com.divpundir.mavlink.serialization.encodeEnumValue
import com.divpundir.mavlink.serialization.encodeFloat
import com.divpundir.mavlink.serialization.truncateZeros
import java.nio.ByteBuffer
import java.nio.ByteOrder
import kotlin.Byte
import kotlin.ByteArray
import kotlin.Float
import kotlin.Int
import kotlin.UInt
import kotlin.Unit
/**
* Read out the safety zone the MAV currently assumes.
*/
@GeneratedMavMessage(
id = 55u,
crcExtra = 3,
)
public data class SafetyAllowedArea(
/**
* Coordinate frame. Can be either global, GPS, right-handed with Z axis up or local, right
* handed, Z axis down.
*/
@GeneratedMavField(type = "uint8_t")
public val frame: MavEnumValue = MavEnumValue.fromValue(0u),
/**
* x position 1 / Latitude 1
*/
@GeneratedMavField(type = "float")
public val p1x: Float = 0F,
/**
* y position 1 / Longitude 1
*/
@GeneratedMavField(type = "float")
public val p1y: Float = 0F,
/**
* z position 1 / Altitude 1
*/
@GeneratedMavField(type = "float")
public val p1z: Float = 0F,
/**
* x position 2 / Latitude 2
*/
@GeneratedMavField(type = "float")
public val p2x: Float = 0F,
/**
* y position 2 / Longitude 2
*/
@GeneratedMavField(type = "float")
public val p2y: Float = 0F,
/**
* z position 2 / Altitude 2
*/
@GeneratedMavField(type = "float")
public val p2z: Float = 0F,
) : MavMessage {
public override val instanceMetadata: MavMessage.Metadata = METADATA
public override fun serializeV1(): ByteArray {
val outputBuffer = ByteBuffer.allocate(SIZE_V1).order(ByteOrder.LITTLE_ENDIAN)
outputBuffer.encodeFloat(p1x)
outputBuffer.encodeFloat(p1y)
outputBuffer.encodeFloat(p1z)
outputBuffer.encodeFloat(p2x)
outputBuffer.encodeFloat(p2y)
outputBuffer.encodeFloat(p2z)
outputBuffer.encodeEnumValue(frame.value, 1)
return outputBuffer.array()
}
public override fun serializeV2(): ByteArray {
val outputBuffer = ByteBuffer.allocate(SIZE_V2).order(ByteOrder.LITTLE_ENDIAN)
outputBuffer.encodeFloat(p1x)
outputBuffer.encodeFloat(p1y)
outputBuffer.encodeFloat(p1z)
outputBuffer.encodeFloat(p2x)
outputBuffer.encodeFloat(p2y)
outputBuffer.encodeFloat(p2z)
outputBuffer.encodeEnumValue(frame.value, 1)
return outputBuffer.array().truncateZeros()
}
public companion object {
private const val ID: UInt = 55u
private const val CRC_EXTRA: Byte = 3
private const val SIZE_V1: Int = 25
private const val SIZE_V2: Int = 25
private val DESERIALIZER: MavDeserializer = MavDeserializer { bytes ->
val inputBuffer = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN)
val p1x = inputBuffer.decodeFloat()
val p1y = inputBuffer.decodeFloat()
val p1z = inputBuffer.decodeFloat()
val p2x = inputBuffer.decodeFloat()
val p2y = inputBuffer.decodeFloat()
val p2z = inputBuffer.decodeFloat()
val frame = inputBuffer.decodeEnumValue(1).let { value ->
val entry = MavFrame.getEntryFromValueOrNull(value)
if (entry != null) MavEnumValue.of(entry) else MavEnumValue.fromValue(value)
}
SafetyAllowedArea(
frame = frame,
p1x = p1x,
p1y = p1y,
p1z = p1z,
p2x = p2x,
p2y = p2y,
p2z = p2z,
)
}
private val METADATA: MavMessage.Metadata = MavMessage.Metadata(ID,
CRC_EXTRA, DESERIALIZER)
public val classMetadata: MavMessage.Metadata = METADATA
public fun builder(builderAction: Builder.() -> Unit): SafetyAllowedArea =
Builder().apply(builderAction).build()
}
public class Builder {
public var frame: MavEnumValue = MavEnumValue.fromValue(0u)
public var p1x: Float = 0F
public var p1y: Float = 0F
public var p1z: Float = 0F
public var p2x: Float = 0F
public var p2y: Float = 0F
public var p2z: Float = 0F
public fun build(): SafetyAllowedArea = SafetyAllowedArea(
frame = frame,
p1x = p1x,
p1y = p1y,
p1z = p1z,
p2x = p2x,
p2y = p2y,
p2z = p2z,
)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy