commonMain.com.divpundir.mavlink.definitions.common.GlobalPositionInt.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.MavMessage
import com.divpundir.mavlink.serialization.MavDataDecoder
import com.divpundir.mavlink.serialization.MavDataEncoder
import com.divpundir.mavlink.serialization.encodeInt16
import com.divpundir.mavlink.serialization.encodeInt32
import com.divpundir.mavlink.serialization.encodeUInt16
import com.divpundir.mavlink.serialization.encodeUInt32
import com.divpundir.mavlink.serialization.safeDecodeInt16
import com.divpundir.mavlink.serialization.safeDecodeInt32
import com.divpundir.mavlink.serialization.safeDecodeUInt16
import com.divpundir.mavlink.serialization.safeDecodeUInt32
import com.divpundir.mavlink.serialization.truncateZeros
import kotlin.Byte
import kotlin.ByteArray
import kotlin.Int
import kotlin.Short
import kotlin.UInt
import kotlin.UShort
import kotlin.Unit
/**
* The filtered global position (e.g. fused GPS and accelerometers). The position is in GPS-frame
* (right-handed, Z-up). It
* is designed as scaled integer message since the resolution of float is not
* sufficient.
*
* @param timeBootMs Timestamp (time since system boot).
* units = ms
* @param lat Latitude, expressed
* units = degE7
* @param lon Longitude, expressed
* units = degE7
* @param alt Altitude (MSL). Note that virtually all GPS modules provide both WGS84 and MSL.
* units = mm
* @param relativeAlt Altitude above home
* units = mm
* @param vx Ground X Speed (Latitude, positive north)
* units = cm/s
* @param vy Ground Y Speed (Longitude, positive east)
* units = cm/s
* @param vz Ground Z Speed (Altitude, positive down)
* units = cm/s
* @param hdg Vehicle heading (yaw angle), 0.0..359.99 degrees. If unknown, set to: UINT16_MAX
* units = cdeg
*/
@GeneratedMavMessage(
id = 33u,
crcExtra = 104,
)
public data class GlobalPositionInt(
/**
* Timestamp (time since system boot).
* units = ms
*/
@GeneratedMavField(type = "uint32_t")
public val timeBootMs: UInt = 0u,
/**
* Latitude, expressed
* units = degE7
*/
@GeneratedMavField(type = "int32_t")
public val lat: Int = 0,
/**
* Longitude, expressed
* units = degE7
*/
@GeneratedMavField(type = "int32_t")
public val lon: Int = 0,
/**
* Altitude (MSL). Note that virtually all GPS modules provide both WGS84 and MSL.
* units = mm
*/
@GeneratedMavField(type = "int32_t")
public val alt: Int = 0,
/**
* Altitude above home
* units = mm
*/
@GeneratedMavField(type = "int32_t")
public val relativeAlt: Int = 0,
/**
* Ground X Speed (Latitude, positive north)
* units = cm/s
*/
@GeneratedMavField(type = "int16_t")
public val vx: Short = 0,
/**
* Ground Y Speed (Longitude, positive east)
* units = cm/s
*/
@GeneratedMavField(type = "int16_t")
public val vy: Short = 0,
/**
* Ground Z Speed (Altitude, positive down)
* units = cm/s
*/
@GeneratedMavField(type = "int16_t")
public val vz: Short = 0,
/**
* Vehicle heading (yaw angle), 0.0..359.99 degrees. If unknown, set to: UINT16_MAX
* units = cdeg
*/
@GeneratedMavField(type = "uint16_t")
public val hdg: UShort = 0u,
) : MavMessage {
override val instanceCompanion: MavMessage.MavCompanion = Companion
override fun serializeV1(): ByteArray {
val encoder = MavDataEncoder(SIZE_V1)
encoder.encodeUInt32(timeBootMs)
encoder.encodeInt32(lat)
encoder.encodeInt32(lon)
encoder.encodeInt32(alt)
encoder.encodeInt32(relativeAlt)
encoder.encodeInt16(vx)
encoder.encodeInt16(vy)
encoder.encodeInt16(vz)
encoder.encodeUInt16(hdg)
return encoder.bytes
}
override fun serializeV2(): ByteArray {
val encoder = MavDataEncoder(SIZE_V2)
encoder.encodeUInt32(timeBootMs)
encoder.encodeInt32(lat)
encoder.encodeInt32(lon)
encoder.encodeInt32(alt)
encoder.encodeInt32(relativeAlt)
encoder.encodeInt16(vx)
encoder.encodeInt16(vy)
encoder.encodeInt16(vz)
encoder.encodeUInt16(hdg)
return encoder.bytes.truncateZeros()
}
public companion object : MavMessage.MavCompanion {
private const val SIZE_V1: Int = 28
private const val SIZE_V2: Int = 28
override val id: UInt = 33u
override val crcExtra: Byte = 104
override fun deserialize(bytes: ByteArray): GlobalPositionInt {
val decoder = MavDataDecoder(bytes)
val timeBootMs = decoder.safeDecodeUInt32()
val lat = decoder.safeDecodeInt32()
val lon = decoder.safeDecodeInt32()
val alt = decoder.safeDecodeInt32()
val relativeAlt = decoder.safeDecodeInt32()
val vx = decoder.safeDecodeInt16()
val vy = decoder.safeDecodeInt16()
val vz = decoder.safeDecodeInt16()
val hdg = decoder.safeDecodeUInt16()
return GlobalPositionInt(
timeBootMs = timeBootMs,
lat = lat,
lon = lon,
alt = alt,
relativeAlt = relativeAlt,
vx = vx,
vy = vy,
vz = vz,
hdg = hdg,
)
}
public operator fun invoke(builderAction: Builder.() -> Unit): GlobalPositionInt =
Builder().apply(builderAction).build()
}
public class Builder {
public var timeBootMs: UInt = 0u
public var lat: Int = 0
public var lon: Int = 0
public var alt: Int = 0
public var relativeAlt: Int = 0
public var vx: Short = 0
public var vy: Short = 0
public var vz: Short = 0
public var hdg: UShort = 0u
public fun build(): GlobalPositionInt = GlobalPositionInt(
timeBootMs = timeBootMs,
lat = lat,
lon = lon,
alt = alt,
relativeAlt = relativeAlt,
vx = vx,
vy = vy,
vz = vz,
hdg = hdg,
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy