commonMain.com.divpundir.mavlink.definitions.common.MissionItemInt.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of definitions-jvm Show documentation
Show all versions of definitions-jvm Show documentation
A modern MAVLink library for the JVM written in Kotlin.
The newest version!
package com.divpundir.mavlink.definitions.common
import com.divpundir.mavlink.api.GeneratedMavField
import com.divpundir.mavlink.api.GeneratedMavMessage
import com.divpundir.mavlink.api.MavEnumValue
import com.divpundir.mavlink.api.MavMessage
import com.divpundir.mavlink.serialization.MavDataDecoder
import com.divpundir.mavlink.serialization.MavDataEncoder
import com.divpundir.mavlink.serialization.encodeEnumValue
import com.divpundir.mavlink.serialization.encodeFloat
import com.divpundir.mavlink.serialization.encodeInt32
import com.divpundir.mavlink.serialization.encodeUInt16
import com.divpundir.mavlink.serialization.encodeUInt8
import com.divpundir.mavlink.serialization.safeDecodeEnumValue
import com.divpundir.mavlink.serialization.safeDecodeFloat
import com.divpundir.mavlink.serialization.safeDecodeInt32
import com.divpundir.mavlink.serialization.safeDecodeUInt16
import com.divpundir.mavlink.serialization.safeDecodeUInt8
import com.divpundir.mavlink.serialization.truncateZeros
import kotlin.Byte
import kotlin.ByteArray
import kotlin.Float
import kotlin.Int
import kotlin.UByte
import kotlin.UInt
import kotlin.UShort
import kotlin.Unit
/**
* Message encoding a mission item. This message is emitted to announce
* the presence of a mission item and to set a mission item on the system. The
* mission item can be either in x, y, z meters (type: LOCAL) or x:lat, y:lon, z:altitude. Local frame
* is Z-down, right handed (NED), global frame is Z-up, right handed (ENU). NaN or INT32_MAX may be
* used in float/integer params (respectively) to indicate optional/default values (e.g. to use the
* component's current latitude, yaw rather than a specific value). See also
* https://mavlink.io/en/services/mission.html.
*
* @param targetSystem System ID
* @param targetComponent Component ID
* @param seq Waypoint ID (sequence number). Starts at zero. Increases monotonically for each
* waypoint, no gaps in the sequence (0,1,2,3,4).
* @param frame The coordinate system of the waypoint.
* @param command The scheduled action for the waypoint.
* @param current false:0, true:1
* @param autocontinue Autocontinue to next waypoint. 0: false, 1: true. Set false to pause mission
* after the item completes.
* @param param1 PARAM1, see MAV_CMD enum
* @param param2 PARAM2, see MAV_CMD enum
* @param param3 PARAM3, see MAV_CMD enum
* @param param4 PARAM4, see MAV_CMD enum
* @param x PARAM5 / local: x position in meters * 1e4, global: latitude in degrees * 10^7
* @param y PARAM6 / y position: local: x position in meters * 1e4, global: longitude in degrees
* *10^7
* @param z PARAM7 / z position: global: altitude in meters (relative or absolute, depending on
* frame.
* @param missionType Mission type.
*/
@GeneratedMavMessage(
id = 73u,
crcExtra = 38,
)
public data class MissionItemInt(
/**
* System ID
*/
@GeneratedMavField(type = "uint8_t")
public val targetSystem: UByte = 0u,
/**
* Component ID
*/
@GeneratedMavField(type = "uint8_t")
public val targetComponent: UByte = 0u,
/**
* Waypoint ID (sequence number). Starts at zero. Increases monotonically for each waypoint, no
* gaps in the sequence (0,1,2,3,4).
*/
@GeneratedMavField(type = "uint16_t")
public val seq: UShort = 0u,
/**
* The coordinate system of the waypoint.
*/
@GeneratedMavField(type = "uint8_t")
public val frame: MavEnumValue = MavEnumValue.fromValue(0u),
/**
* The scheduled action for the waypoint.
*/
@GeneratedMavField(type = "uint16_t")
public val command: MavEnumValue = MavEnumValue.fromValue(0u),
/**
* false:0, true:1
*/
@GeneratedMavField(type = "uint8_t")
public val current: UByte = 0u,
/**
* Autocontinue to next waypoint. 0: false, 1: true. Set false to pause mission after the item
* completes.
*/
@GeneratedMavField(type = "uint8_t")
public val autocontinue: UByte = 0u,
/**
* PARAM1, see MAV_CMD enum
*/
@GeneratedMavField(type = "float")
public val param1: Float = 0F,
/**
* PARAM2, see MAV_CMD enum
*/
@GeneratedMavField(type = "float")
public val param2: Float = 0F,
/**
* PARAM3, see MAV_CMD enum
*/
@GeneratedMavField(type = "float")
public val param3: Float = 0F,
/**
* PARAM4, see MAV_CMD enum
*/
@GeneratedMavField(type = "float")
public val param4: Float = 0F,
/**
* PARAM5 / local: x position in meters * 1e4, global: latitude in degrees * 10^7
*/
@GeneratedMavField(type = "int32_t")
public val x: Int = 0,
/**
* PARAM6 / y position: local: x position in meters * 1e4, global: longitude in degrees *10^7
*/
@GeneratedMavField(type = "int32_t")
public val y: Int = 0,
/**
* PARAM7 / z position: global: altitude in meters (relative or absolute, depending on frame.
*/
@GeneratedMavField(type = "float")
public val z: Float = 0F,
/**
* Mission type.
*/
@GeneratedMavField(
type = "uint8_t",
extension = true,
)
public val missionType: MavEnumValue = MavEnumValue.fromValue(0u),
) : MavMessage {
override val instanceCompanion: MavMessage.MavCompanion = Companion
override fun serializeV1(): ByteArray {
val encoder = MavDataEncoder(SIZE_V1)
encoder.encodeFloat(param1)
encoder.encodeFloat(param2)
encoder.encodeFloat(param3)
encoder.encodeFloat(param4)
encoder.encodeInt32(x)
encoder.encodeInt32(y)
encoder.encodeFloat(z)
encoder.encodeUInt16(seq)
encoder.encodeEnumValue(command.value, 2)
encoder.encodeUInt8(targetSystem)
encoder.encodeUInt8(targetComponent)
encoder.encodeEnumValue(frame.value, 1)
encoder.encodeUInt8(current)
encoder.encodeUInt8(autocontinue)
return encoder.bytes
}
override fun serializeV2(): ByteArray {
val encoder = MavDataEncoder(SIZE_V2)
encoder.encodeFloat(param1)
encoder.encodeFloat(param2)
encoder.encodeFloat(param3)
encoder.encodeFloat(param4)
encoder.encodeInt32(x)
encoder.encodeInt32(y)
encoder.encodeFloat(z)
encoder.encodeUInt16(seq)
encoder.encodeEnumValue(command.value, 2)
encoder.encodeUInt8(targetSystem)
encoder.encodeUInt8(targetComponent)
encoder.encodeEnumValue(frame.value, 1)
encoder.encodeUInt8(current)
encoder.encodeUInt8(autocontinue)
encoder.encodeEnumValue(missionType.value, 1)
return encoder.bytes.truncateZeros()
}
public companion object : MavMessage.MavCompanion {
private const val SIZE_V1: Int = 37
private const val SIZE_V2: Int = 38
override val id: UInt = 73u
override val crcExtra: Byte = 38
override fun deserialize(bytes: ByteArray): MissionItemInt {
val decoder = MavDataDecoder(bytes)
val param1 = decoder.safeDecodeFloat()
val param2 = decoder.safeDecodeFloat()
val param3 = decoder.safeDecodeFloat()
val param4 = decoder.safeDecodeFloat()
val x = decoder.safeDecodeInt32()
val y = decoder.safeDecodeInt32()
val z = decoder.safeDecodeFloat()
val seq = decoder.safeDecodeUInt16()
val command = decoder.safeDecodeEnumValue(2).let { value ->
val entry = MavCmd.getEntryFromValueOrNull(value)
if (entry != null) MavEnumValue.of(entry) else MavEnumValue.fromValue(value)
}
val targetSystem = decoder.safeDecodeUInt8()
val targetComponent = decoder.safeDecodeUInt8()
val frame = decoder.safeDecodeEnumValue(1).let { value ->
val entry = MavFrame.getEntryFromValueOrNull(value)
if (entry != null) MavEnumValue.of(entry) else MavEnumValue.fromValue(value)
}
val current = decoder.safeDecodeUInt8()
val autocontinue = decoder.safeDecodeUInt8()
val missionType = decoder.safeDecodeEnumValue(1).let { value ->
val entry = MavMissionType.getEntryFromValueOrNull(value)
if (entry != null) MavEnumValue.of(entry) else MavEnumValue.fromValue(value)
}
return MissionItemInt(
targetSystem = targetSystem,
targetComponent = targetComponent,
seq = seq,
frame = frame,
command = command,
current = current,
autocontinue = autocontinue,
param1 = param1,
param2 = param2,
param3 = param3,
param4 = param4,
x = x,
y = y,
z = z,
missionType = missionType,
)
}
public operator fun invoke(builderAction: Builder.() -> Unit): MissionItemInt =
Builder().apply(builderAction).build()
}
public class Builder {
public var targetSystem: UByte = 0u
public var targetComponent: UByte = 0u
public var seq: UShort = 0u
public var frame: MavEnumValue = MavEnumValue.fromValue(0u)
public var command: MavEnumValue = MavEnumValue.fromValue(0u)
public var current: UByte = 0u
public var autocontinue: UByte = 0u
public var param1: Float = 0F
public var param2: Float = 0F
public var param3: Float = 0F
public var param4: Float = 0F
public var x: Int = 0
public var y: Int = 0
public var z: Float = 0F
public var missionType: MavEnumValue = MavEnumValue.fromValue(0u)
public fun build(): MissionItemInt = MissionItemInt(
targetSystem = targetSystem,
targetComponent = targetComponent,
seq = seq,
frame = frame,
command = command,
current = current,
autocontinue = autocontinue,
param1 = param1,
param2 = param2,
param3 = param3,
param4 = param4,
x = x,
y = y,
z = z,
missionType = missionType,
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy