All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.divpundir.mavlink.definitions.ardupilotmega.Radio.kt Maven / Gradle / Ivy

The newest version!
package com.divpundir.mavlink.definitions.ardupilotmega

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.encodeUInt16
import com.divpundir.mavlink.serialization.encodeUInt8
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.Int
import kotlin.UByte
import kotlin.UInt
import kotlin.UShort
import kotlin.Unit

/**
 * Status generated by radio.
 *
 * @param rssi Local signal strength.
 * @param remrssi Remote signal strength.
 * @param txbuf How full the tx buffer is.
 * units = %
 * @param noise Background noise level.
 * @param remnoise Remote background noise level.
 * @param rxerrors Receive errors.
 * @param fixed Count of error corrected packets.
 */
@GeneratedMavMessage(
  id = 166u,
  crcExtra = 21,
)
public data class Radio(
  /**
   * Local signal strength.
   */
  @GeneratedMavField(type = "uint8_t")
  public val rssi: UByte = 0u,
  /**
   * Remote signal strength.
   */
  @GeneratedMavField(type = "uint8_t")
  public val remrssi: UByte = 0u,
  /**
   * How full the tx buffer is.
   * units = %
   */
  @GeneratedMavField(type = "uint8_t")
  public val txbuf: UByte = 0u,
  /**
   * Background noise level.
   */
  @GeneratedMavField(type = "uint8_t")
  public val noise: UByte = 0u,
  /**
   * Remote background noise level.
   */
  @GeneratedMavField(type = "uint8_t")
  public val remnoise: UByte = 0u,
  /**
   * Receive errors.
   */
  @GeneratedMavField(type = "uint16_t")
  public val rxerrors: UShort = 0u,
  /**
   * Count of error corrected packets.
   */
  @GeneratedMavField(type = "uint16_t")
  public val fixed: UShort = 0u,
) : MavMessage {
  override val instanceCompanion: MavMessage.MavCompanion = Companion

  override fun serializeV1(): ByteArray {
    val encoder = MavDataEncoder(SIZE_V1)
    encoder.encodeUInt16(rxerrors)
    encoder.encodeUInt16(fixed)
    encoder.encodeUInt8(rssi)
    encoder.encodeUInt8(remrssi)
    encoder.encodeUInt8(txbuf)
    encoder.encodeUInt8(noise)
    encoder.encodeUInt8(remnoise)
    return encoder.bytes
  }

  override fun serializeV2(): ByteArray {
    val encoder = MavDataEncoder(SIZE_V2)
    encoder.encodeUInt16(rxerrors)
    encoder.encodeUInt16(fixed)
    encoder.encodeUInt8(rssi)
    encoder.encodeUInt8(remrssi)
    encoder.encodeUInt8(txbuf)
    encoder.encodeUInt8(noise)
    encoder.encodeUInt8(remnoise)
    return encoder.bytes.truncateZeros()
  }

  public companion object : MavMessage.MavCompanion {
    private const val SIZE_V1: Int = 9

    private const val SIZE_V2: Int = 9

    override val id: UInt = 166u

    override val crcExtra: Byte = 21

    override fun deserialize(bytes: ByteArray): Radio {
      val decoder = MavDataDecoder(bytes)

      val rxerrors = decoder.safeDecodeUInt16()
      val fixed = decoder.safeDecodeUInt16()
      val rssi = decoder.safeDecodeUInt8()
      val remrssi = decoder.safeDecodeUInt8()
      val txbuf = decoder.safeDecodeUInt8()
      val noise = decoder.safeDecodeUInt8()
      val remnoise = decoder.safeDecodeUInt8()

      return Radio(
        rssi = rssi,
        remrssi = remrssi,
        txbuf = txbuf,
        noise = noise,
        remnoise = remnoise,
        rxerrors = rxerrors,
        fixed = fixed,
      )
    }

    public operator fun invoke(builderAction: Builder.() -> Unit): Radio =
        Builder().apply(builderAction).build()
  }

  public class Builder {
    public var rssi: UByte = 0u

    public var remrssi: UByte = 0u

    public var txbuf: UByte = 0u

    public var noise: UByte = 0u

    public var remnoise: UByte = 0u

    public var rxerrors: UShort = 0u

    public var fixed: UShort = 0u

    public fun build(): Radio = Radio(
      rssi = rssi,
      remrssi = remrssi,
      txbuf = txbuf,
      noise = noise,
      remnoise = remnoise,
      rxerrors = rxerrors,
      fixed = fixed,
    )
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy